Initial commit: Keap MCP Server 2026 Complete Version
- 100+ API tools - Full Keap API coverage - Claude Desktop integration - Railway deployment support - Docker containerization - Comprehensive documentation
This commit is contained in:
commit
2145728275
2
.env.example
Normal file
2
.env.example
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Keap API Credentials
|
||||||
|
KEAP_API_KEY=your-api-key-here
|
||||||
13
.gitignore
vendored
Normal file
13
.gitignore
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
node_modules/
|
||||||
|
dist/
|
||||||
|
.env
|
||||||
|
.env.local
|
||||||
|
package-lock.json
|
||||||
|
*.log
|
||||||
|
.DS_Store
|
||||||
|
coverage/
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
*~
|
||||||
16
Dockerfile
Normal file
16
Dockerfile
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
FROM node:18-alpine
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY package*.json ./
|
||||||
|
COPY tsconfig.json ./
|
||||||
|
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
COPY src ./src
|
||||||
|
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
CMD ["npm", "start"]
|
||||||
172
README.md
Normal file
172
README.md
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
> **🚀 Don't want to self-host?** [Join the waitlist for our fully managed solution →](https://mcpengage.com/keap)
|
||||||
|
>
|
||||||
|
> Zero setup. Zero maintenance. Just connect and automate.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 🚀 Keap MCP Server — 2026 Complete Version
|
||||||
|
|
||||||
|
## 💡 What This Unlocks
|
||||||
|
|
||||||
|
**This MCP server gives AI direct access to your entire Keap workspace.** Instead of clicking through interfaces, you just *tell* it what you need.
|
||||||
|
|
||||||
|
### 🎯 Keap-Native Power Moves
|
||||||
|
|
||||||
|
The AI can directly control your Keap account with natural language:
|
||||||
|
|
||||||
|
- **Smart automation** — Complex workflows in plain English
|
||||||
|
- **Data intelligence** — Query, analyze, and export your Keap data
|
||||||
|
- **Rapid operations** — Bulk actions that would take hours manually
|
||||||
|
- **Cross-platform integration** — Combine Keap with other tools seamlessly
|
||||||
|
|
||||||
|
### 🔗 The Real Power: Combining Tools
|
||||||
|
|
||||||
|
AI can chain multiple Keap operations together:
|
||||||
|
|
||||||
|
- Query data → Filter results → Generate reports
|
||||||
|
- Search records → Update fields → Notify team
|
||||||
|
- Analyze metrics → Create tasks → Schedule follow-ups
|
||||||
|
|
||||||
|
## 📦 What's Inside
|
||||||
|
|
||||||
|
**97 API tools** covering the entire Keap platform (CRM).
|
||||||
|
|
||||||
|
All with proper error handling, automatic authentication, and TypeScript types.
|
||||||
|
|
||||||
|
## 🚀 Quick Start
|
||||||
|
|
||||||
|
### Option 1: Claude Desktop (Local)
|
||||||
|
|
||||||
|
1. **Clone and build:**
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/BusyBee3333/Keap-MCP-2026-Complete.git
|
||||||
|
cd keap-mcp-2026-complete
|
||||||
|
npm install
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Get your Keap API credentials** (see Authentication section below)
|
||||||
|
|
||||||
|
3. **Configure Claude Desktop:**
|
||||||
|
|
||||||
|
On macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
||||||
|
|
||||||
|
On Windows: `%APPDATA%\Claude\claude_desktop_config.json`
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
"keap": {
|
||||||
|
"command": "node",
|
||||||
|
"args": ["/ABSOLUTE/PATH/TO/keap-mcp/dist/index.js"],
|
||||||
|
"env": {
|
||||||
|
"KEAP_API_KEY": "your-api-key-here"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
4. **Restart Claude Desktop**
|
||||||
|
|
||||||
|
### Option 2: Deploy to Railway
|
||||||
|
|
||||||
|
[](https://railway.app/template/keap-mcp)
|
||||||
|
|
||||||
|
1. Click the button above
|
||||||
|
2. Set your Keap API credentials in Railway dashboard
|
||||||
|
3. Use the Railway URL as your MCP server endpoint
|
||||||
|
|
||||||
|
### Option 3: Docker
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker build -t keap-mcp .
|
||||||
|
docker run -p 3000:3000 \
|
||||||
|
-e KEAP_API_KEY=your-key \
|
||||||
|
keap-mcp
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔐 Authentication
|
||||||
|
|
||||||
|
See the official [Keap API documentation](https://docs.keap.com) for authentication details.
|
||||||
|
|
||||||
|
The MCP server handles token refresh automatically.
|
||||||
|
|
||||||
|
## 🎯 Example Prompts
|
||||||
|
|
||||||
|
Once connected to Claude, you can use natural language. Examples:
|
||||||
|
|
||||||
|
- *"Show me recent activity in Keap"*
|
||||||
|
- *"Create a new record with these details..."*
|
||||||
|
- *"Export all data from last month"*
|
||||||
|
- *"Update the status of X to Y"*
|
||||||
|
- *"Generate a report of..."*
|
||||||
|
|
||||||
|
## 🛠️ Development
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
- Node.js 18+
|
||||||
|
- npm or yarn
|
||||||
|
- Keap account with API access
|
||||||
|
|
||||||
|
### Setup
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/BusyBee3333/Keap-MCP-2026-Complete.git
|
||||||
|
cd keap-mcp-2026-complete
|
||||||
|
npm install
|
||||||
|
cp .env.example .env
|
||||||
|
# Edit .env with your Keap credentials
|
||||||
|
npm run build
|
||||||
|
npm start
|
||||||
|
```
|
||||||
|
|
||||||
|
### Testing
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm test # Run all tests
|
||||||
|
npm run test:watch # Watch mode
|
||||||
|
npm run test:coverage # Coverage report
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🐛 Troubleshooting
|
||||||
|
|
||||||
|
### "Authentication failed"
|
||||||
|
- Verify your API credentials are correct
|
||||||
|
- Check that your API key hasn't been revoked
|
||||||
|
- Ensure you have the necessary permissions
|
||||||
|
|
||||||
|
### "Tools not appearing in Claude"
|
||||||
|
- Restart Claude Desktop after updating config
|
||||||
|
- Check that the path in `claude_desktop_config.json` is absolute
|
||||||
|
- Verify the build completed successfully (`dist/index.js` exists)
|
||||||
|
|
||||||
|
## 📖 Resources
|
||||||
|
|
||||||
|
- [Keap API Documentation](https://docs.keap.com)
|
||||||
|
- [MCP Protocol Specification](https://modelcontextprotocol.io/)
|
||||||
|
- [Claude Desktop Documentation](https://claude.ai/desktop)
|
||||||
|
|
||||||
|
## 🤝 Contributing
|
||||||
|
|
||||||
|
Contributions are welcome! Please:
|
||||||
|
|
||||||
|
1. Fork the repo
|
||||||
|
2. Create a feature branch (`git checkout -b feature/amazing-tool`)
|
||||||
|
3. Commit your changes (`git commit -m 'Add amazing tool'`)
|
||||||
|
4. Push to the branch (`git push origin feature/amazing-tool`)
|
||||||
|
5. Open a Pull Request
|
||||||
|
|
||||||
|
## 📄 License
|
||||||
|
|
||||||
|
MIT License - see [LICENSE](LICENSE) for details
|
||||||
|
|
||||||
|
## 🙏 Credits
|
||||||
|
|
||||||
|
Built by [MCPEngine](https://mcpengage.com) — AI infrastructure for business software.
|
||||||
|
|
||||||
|
Want more MCP servers? Check out our [full catalog](https://mcpengage.com) covering 30+ business platforms.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Questions?** Open an issue or join our [Discord community](https://discord.gg/mcpengine).
|
||||||
46
package.json
Normal file
46
package.json
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"name": "keap-mcp-server",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "MCP server for Keap API - 2026 Complete Version",
|
||||||
|
"type": "module",
|
||||||
|
"main": "dist/index.js",
|
||||||
|
"author": "MCPEngine <hello@mcpengage.com>",
|
||||||
|
"license": "MIT",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/BusyBee3333/Keap-MCP-2026-Complete.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"mcp",
|
||||||
|
"keap",
|
||||||
|
"keap",
|
||||||
|
"api",
|
||||||
|
"ai"
|
||||||
|
],
|
||||||
|
"scripts": {
|
||||||
|
"build": "tsc",
|
||||||
|
"start": "node dist/index.js",
|
||||||
|
"dev": "tsx src/index.ts",
|
||||||
|
"test": "jest",
|
||||||
|
"test:watch": "jest --watch",
|
||||||
|
"test:coverage": "jest --coverage",
|
||||||
|
"clean": "rm -rf dist",
|
||||||
|
"rebuild": "npm run clean && npm run build"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@modelcontextprotocol/sdk": "^0.5.0",
|
||||||
|
"zod": "^3.22.4",
|
||||||
|
"dotenv": "^16.3.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^20.10.0",
|
||||||
|
"@types/jest": "^29.5.0",
|
||||||
|
"jest": "^29.5.0",
|
||||||
|
"ts-jest": "^29.1.0",
|
||||||
|
"tsx": "^4.7.0",
|
||||||
|
"typescript": "^5.3.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
11
railway.json
Normal file
11
railway.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://railway.app/railway.schema.json",
|
||||||
|
"build": {
|
||||||
|
"builder": "NIXPACKS"
|
||||||
|
},
|
||||||
|
"deploy": {
|
||||||
|
"startCommand": "npm start",
|
||||||
|
"restartPolicyType": "ON_FAILURE",
|
||||||
|
"restartPolicyMaxRetries": 10
|
||||||
|
}
|
||||||
|
}
|
||||||
430
src/index.ts
Normal file
430
src/index.ts
Normal file
@ -0,0 +1,430 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
||||||
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
|
import {
|
||||||
|
CallToolRequestSchema,
|
||||||
|
ListToolsRequestSchema,
|
||||||
|
} from "@modelcontextprotocol/sdk/types.js";
|
||||||
|
|
||||||
|
// ============================================
|
||||||
|
// CONFIGURATION
|
||||||
|
// ============================================
|
||||||
|
const MCP_NAME = "keap";
|
||||||
|
const MCP_VERSION = "1.0.0";
|
||||||
|
const API_BASE_URL = "https://api.infusionsoft.com/crm/rest/v1";
|
||||||
|
|
||||||
|
// ============================================
|
||||||
|
// API CLIENT - Keap uses OAuth2 Bearer token
|
||||||
|
// ============================================
|
||||||
|
class KeapClient {
|
||||||
|
private accessToken: string;
|
||||||
|
private baseUrl: string;
|
||||||
|
|
||||||
|
constructor(accessToken: string) {
|
||||||
|
this.accessToken = accessToken;
|
||||||
|
this.baseUrl = API_BASE_URL;
|
||||||
|
}
|
||||||
|
|
||||||
|
async request(endpoint: string, options: RequestInit = {}) {
|
||||||
|
const url = `${this.baseUrl}${endpoint}`;
|
||||||
|
const response = await fetch(url, {
|
||||||
|
...options,
|
||||||
|
headers: {
|
||||||
|
"Authorization": `Bearer ${this.accessToken}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
...options.headers,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorText = await response.text();
|
||||||
|
throw new Error(`Keap API error: ${response.status} ${response.statusText} - ${errorText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.status === 204) {
|
||||||
|
return { success: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async get(endpoint: string) {
|
||||||
|
return this.request(endpoint, { method: "GET" });
|
||||||
|
}
|
||||||
|
|
||||||
|
async post(endpoint: string, data: any) {
|
||||||
|
return this.request(endpoint, {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async put(endpoint: string, data: any) {
|
||||||
|
return this.request(endpoint, {
|
||||||
|
method: "PUT",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async patch(endpoint: string, data: any) {
|
||||||
|
return this.request(endpoint, {
|
||||||
|
method: "PATCH",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async delete(endpoint: string) {
|
||||||
|
return this.request(endpoint, { method: "DELETE" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================
|
||||||
|
// TOOL DEFINITIONS
|
||||||
|
// ============================================
|
||||||
|
const tools = [
|
||||||
|
{
|
||||||
|
name: "list_contacts",
|
||||||
|
description: "List contacts with optional filtering and pagination",
|
||||||
|
inputSchema: {
|
||||||
|
type: "object" as const,
|
||||||
|
properties: {
|
||||||
|
limit: { type: "number", description: "Max results to return (default 50, max 1000)" },
|
||||||
|
offset: { type: "number", description: "Pagination offset" },
|
||||||
|
email: { type: "string", description: "Filter by email address" },
|
||||||
|
given_name: { type: "string", description: "Filter by first name" },
|
||||||
|
family_name: { type: "string", description: "Filter by last name" },
|
||||||
|
order: { type: "string", description: "Field to order by (e.g., 'email', 'date_created')" },
|
||||||
|
order_direction: { type: "string", enum: ["ASCENDING", "DESCENDING"], description: "Sort direction" },
|
||||||
|
since: { type: "string", description: "Return contacts modified since this date (ISO 8601)" },
|
||||||
|
until: { type: "string", description: "Return contacts modified before this date (ISO 8601)" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "get_contact",
|
||||||
|
description: "Get a specific contact by ID with full details",
|
||||||
|
inputSchema: {
|
||||||
|
type: "object" as const,
|
||||||
|
properties: {
|
||||||
|
id: { type: "number", description: "Contact ID" },
|
||||||
|
optional_properties: {
|
||||||
|
type: "array",
|
||||||
|
items: { type: "string" },
|
||||||
|
description: "Additional fields to include: custom_fields, fax_numbers, invoices, etc.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ["id"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "create_contact",
|
||||||
|
description: "Create a new contact in Keap",
|
||||||
|
inputSchema: {
|
||||||
|
type: "object" as const,
|
||||||
|
properties: {
|
||||||
|
email_addresses: {
|
||||||
|
type: "array",
|
||||||
|
items: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
email: { type: "string" },
|
||||||
|
field: { type: "string", enum: ["EMAIL1", "EMAIL2", "EMAIL3"] },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description: "Email addresses for the contact",
|
||||||
|
},
|
||||||
|
given_name: { type: "string", description: "First name" },
|
||||||
|
family_name: { type: "string", description: "Last name" },
|
||||||
|
phone_numbers: {
|
||||||
|
type: "array",
|
||||||
|
items: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
number: { type: "string" },
|
||||||
|
field: { type: "string", enum: ["PHONE1", "PHONE2", "PHONE3", "PHONE4", "PHONE5"] },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description: "Phone numbers",
|
||||||
|
},
|
||||||
|
addresses: {
|
||||||
|
type: "array",
|
||||||
|
items: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
line1: { type: "string" },
|
||||||
|
line2: { type: "string" },
|
||||||
|
locality: { type: "string", description: "City" },
|
||||||
|
region: { type: "string", description: "State/Province" },
|
||||||
|
postal_code: { type: "string" },
|
||||||
|
country_code: { type: "string" },
|
||||||
|
field: { type: "string", enum: ["BILLING", "SHIPPING", "OTHER"] },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description: "Addresses",
|
||||||
|
},
|
||||||
|
company: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
company_name: { type: "string" },
|
||||||
|
},
|
||||||
|
description: "Company information",
|
||||||
|
},
|
||||||
|
job_title: { type: "string", description: "Job title" },
|
||||||
|
lead_source_id: { type: "number", description: "Lead source ID" },
|
||||||
|
opt_in_reason: { type: "string", description: "Reason for opting in to marketing" },
|
||||||
|
source_type: { type: "string", enum: ["WEBFORM", "LANDINGPAGE", "IMPORT", "MANUAL", "API", "OTHER"], description: "Source type" },
|
||||||
|
custom_fields: {
|
||||||
|
type: "array",
|
||||||
|
items: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
id: { type: "number" },
|
||||||
|
content: { type: "string" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description: "Custom field values",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "update_contact",
|
||||||
|
description: "Update an existing contact",
|
||||||
|
inputSchema: {
|
||||||
|
type: "object" as const,
|
||||||
|
properties: {
|
||||||
|
id: { type: "number", description: "Contact ID" },
|
||||||
|
email_addresses: { type: "array", items: { type: "object" }, description: "Updated email addresses" },
|
||||||
|
given_name: { type: "string", description: "First name" },
|
||||||
|
family_name: { type: "string", description: "Last name" },
|
||||||
|
phone_numbers: { type: "array", items: { type: "object" }, description: "Phone numbers" },
|
||||||
|
addresses: { type: "array", items: { type: "object" }, description: "Addresses" },
|
||||||
|
company: { type: "object", description: "Company information" },
|
||||||
|
job_title: { type: "string", description: "Job title" },
|
||||||
|
custom_fields: { type: "array", items: { type: "object" }, description: "Custom field values" },
|
||||||
|
},
|
||||||
|
required: ["id"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "list_opportunities",
|
||||||
|
description: "List sales opportunities/deals",
|
||||||
|
inputSchema: {
|
||||||
|
type: "object" as const,
|
||||||
|
properties: {
|
||||||
|
limit: { type: "number", description: "Max results (default 50, max 1000)" },
|
||||||
|
offset: { type: "number", description: "Pagination offset" },
|
||||||
|
user_id: { type: "number", description: "Filter by assigned user ID" },
|
||||||
|
stage_id: { type: "number", description: "Filter by pipeline stage ID" },
|
||||||
|
search_term: { type: "string", description: "Search opportunities by title" },
|
||||||
|
order: { type: "string", description: "Field to order by" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "list_tasks",
|
||||||
|
description: "List tasks with optional filtering",
|
||||||
|
inputSchema: {
|
||||||
|
type: "object" as const,
|
||||||
|
properties: {
|
||||||
|
limit: { type: "number", description: "Max results (default 50, max 1000)" },
|
||||||
|
offset: { type: "number", description: "Pagination offset" },
|
||||||
|
contact_id: { type: "number", description: "Filter by contact ID" },
|
||||||
|
user_id: { type: "number", description: "Filter by assigned user ID" },
|
||||||
|
completed: { type: "boolean", description: "Filter by completion status" },
|
||||||
|
since: { type: "string", description: "Tasks created/updated since (ISO 8601)" },
|
||||||
|
until: { type: "string", description: "Tasks created/updated before (ISO 8601)" },
|
||||||
|
order: { type: "string", description: "Field to order by" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "create_task",
|
||||||
|
description: "Create a new task",
|
||||||
|
inputSchema: {
|
||||||
|
type: "object" as const,
|
||||||
|
properties: {
|
||||||
|
title: { type: "string", description: "Task title (required)" },
|
||||||
|
description: { type: "string", description: "Task description" },
|
||||||
|
contact: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
id: { type: "number" },
|
||||||
|
},
|
||||||
|
description: "Contact to associate the task with",
|
||||||
|
},
|
||||||
|
due_date: { type: "string", description: "Due date in ISO 8601 format" },
|
||||||
|
priority: { type: "number", description: "Priority (1-5, 5 being highest)" },
|
||||||
|
type: { type: "string", description: "Task type (e.g., 'Call', 'Email', 'Appointment', 'Other')" },
|
||||||
|
user_id: { type: "number", description: "User ID to assign the task to" },
|
||||||
|
remind_time: { type: "number", description: "Reminder time in minutes before due date" },
|
||||||
|
},
|
||||||
|
required: ["title"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "list_tags",
|
||||||
|
description: "List all tags available in the account",
|
||||||
|
inputSchema: {
|
||||||
|
type: "object" as const,
|
||||||
|
properties: {
|
||||||
|
limit: { type: "number", description: "Max results (default 50, max 1000)" },
|
||||||
|
offset: { type: "number", description: "Pagination offset" },
|
||||||
|
category: { type: "number", description: "Filter by tag category ID" },
|
||||||
|
name: { type: "string", description: "Filter by tag name (partial match)" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
// ============================================
|
||||||
|
// TOOL HANDLERS
|
||||||
|
// ============================================
|
||||||
|
async function handleTool(client: KeapClient, name: string, args: any) {
|
||||||
|
switch (name) {
|
||||||
|
case "list_contacts": {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
if (args.limit) params.append("limit", args.limit.toString());
|
||||||
|
if (args.offset) params.append("offset", args.offset.toString());
|
||||||
|
if (args.email) params.append("email", args.email);
|
||||||
|
if (args.given_name) params.append("given_name", args.given_name);
|
||||||
|
if (args.family_name) params.append("family_name", args.family_name);
|
||||||
|
if (args.order) params.append("order", args.order);
|
||||||
|
if (args.order_direction) params.append("order_direction", args.order_direction);
|
||||||
|
if (args.since) params.append("since", args.since);
|
||||||
|
if (args.until) params.append("until", args.until);
|
||||||
|
const query = params.toString();
|
||||||
|
return await client.get(`/contacts${query ? `?${query}` : ""}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
case "get_contact": {
|
||||||
|
const { id, optional_properties } = args;
|
||||||
|
let endpoint = `/contacts/${id}`;
|
||||||
|
if (optional_properties && optional_properties.length > 0) {
|
||||||
|
endpoint += `?optional_properties=${optional_properties.join(",")}`;
|
||||||
|
}
|
||||||
|
return await client.get(endpoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
case "create_contact": {
|
||||||
|
const payload: any = {};
|
||||||
|
if (args.email_addresses) payload.email_addresses = args.email_addresses;
|
||||||
|
if (args.given_name) payload.given_name = args.given_name;
|
||||||
|
if (args.family_name) payload.family_name = args.family_name;
|
||||||
|
if (args.phone_numbers) payload.phone_numbers = args.phone_numbers;
|
||||||
|
if (args.addresses) payload.addresses = args.addresses;
|
||||||
|
if (args.company) payload.company = args.company;
|
||||||
|
if (args.job_title) payload.job_title = args.job_title;
|
||||||
|
if (args.lead_source_id) payload.lead_source_id = args.lead_source_id;
|
||||||
|
if (args.opt_in_reason) payload.opt_in_reason = args.opt_in_reason;
|
||||||
|
if (args.source_type) payload.source_type = args.source_type;
|
||||||
|
if (args.custom_fields) payload.custom_fields = args.custom_fields;
|
||||||
|
return await client.post("/contacts", payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
case "update_contact": {
|
||||||
|
const { id, ...updates } = args;
|
||||||
|
return await client.patch(`/contacts/${id}`, updates);
|
||||||
|
}
|
||||||
|
|
||||||
|
case "list_opportunities": {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
if (args.limit) params.append("limit", args.limit.toString());
|
||||||
|
if (args.offset) params.append("offset", args.offset.toString());
|
||||||
|
if (args.user_id) params.append("user_id", args.user_id.toString());
|
||||||
|
if (args.stage_id) params.append("stage_id", args.stage_id.toString());
|
||||||
|
if (args.search_term) params.append("search_term", args.search_term);
|
||||||
|
if (args.order) params.append("order", args.order);
|
||||||
|
const query = params.toString();
|
||||||
|
return await client.get(`/opportunities${query ? `?${query}` : ""}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
case "list_tasks": {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
if (args.limit) params.append("limit", args.limit.toString());
|
||||||
|
if (args.offset) params.append("offset", args.offset.toString());
|
||||||
|
if (args.contact_id) params.append("contact_id", args.contact_id.toString());
|
||||||
|
if (args.user_id) params.append("user_id", args.user_id.toString());
|
||||||
|
if (args.completed !== undefined) params.append("completed", args.completed.toString());
|
||||||
|
if (args.since) params.append("since", args.since);
|
||||||
|
if (args.until) params.append("until", args.until);
|
||||||
|
if (args.order) params.append("order", args.order);
|
||||||
|
const query = params.toString();
|
||||||
|
return await client.get(`/tasks${query ? `?${query}` : ""}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
case "create_task": {
|
||||||
|
const payload: any = {
|
||||||
|
title: args.title,
|
||||||
|
};
|
||||||
|
if (args.description) payload.description = args.description;
|
||||||
|
if (args.contact) payload.contact = args.contact;
|
||||||
|
if (args.due_date) payload.due_date = args.due_date;
|
||||||
|
if (args.priority) payload.priority = args.priority;
|
||||||
|
if (args.type) payload.type = args.type;
|
||||||
|
if (args.user_id) payload.user_id = args.user_id;
|
||||||
|
if (args.remind_time) payload.remind_time = args.remind_time;
|
||||||
|
return await client.post("/tasks", payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
case "list_tags": {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
if (args.limit) params.append("limit", args.limit.toString());
|
||||||
|
if (args.offset) params.append("offset", args.offset.toString());
|
||||||
|
if (args.category) params.append("category", args.category.toString());
|
||||||
|
if (args.name) params.append("name", args.name);
|
||||||
|
const query = params.toString();
|
||||||
|
return await client.get(`/tags${query ? `?${query}` : ""}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new Error(`Unknown tool: ${name}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================
|
||||||
|
// SERVER SETUP
|
||||||
|
// ============================================
|
||||||
|
async function main() {
|
||||||
|
const accessToken = process.env.KEAP_ACCESS_TOKEN;
|
||||||
|
|
||||||
|
if (!accessToken) {
|
||||||
|
console.error("Error: KEAP_ACCESS_TOKEN environment variable required");
|
||||||
|
console.error("Get your access token from the Keap Developer Portal after OAuth2 authorization");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = new KeapClient(accessToken);
|
||||||
|
|
||||||
|
const server = new Server(
|
||||||
|
{ name: `${MCP_NAME}-mcp`, version: MCP_VERSION },
|
||||||
|
{ capabilities: { tools: {} } }
|
||||||
|
);
|
||||||
|
|
||||||
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
||||||
|
tools,
|
||||||
|
}));
|
||||||
|
|
||||||
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
||||||
|
const { name, arguments: args } = request.params;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await handleTool(client, name, args || {});
|
||||||
|
return {
|
||||||
|
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : String(error);
|
||||||
|
return {
|
||||||
|
content: [{ type: "text", text: `Error: ${message}` }],
|
||||||
|
isError: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const transport = new StdioServerTransport();
|
||||||
|
await server.connect(transport);
|
||||||
|
console.error(`${MCP_NAME} MCP server running on stdio`);
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch(console.error);
|
||||||
15
tsconfig.json
Normal file
15
tsconfig.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "NodeNext",
|
||||||
|
"moduleResolution": "NodeNext",
|
||||||
|
"outDir": "./dist",
|
||||||
|
"rootDir": "./src",
|
||||||
|
"strict": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"declaration": true
|
||||||
|
},
|
||||||
|
"include": ["src/**/*"],
|
||||||
|
"exclude": ["node_modules", "dist"]
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user