From 039e94aab47ea2a459177a19066a4bd2e1c84ead Mon Sep 17 00:00:00 2001 From: Jake Shore Date: Mon, 2 Feb 2026 06:49:49 -0500 Subject: [PATCH] Initial commit: Close Crm MCP Server 2026 Complete Version - 100+ API tools - Full Close Crm API coverage - Claude Desktop integration - Railway deployment support - Docker containerization - Comprehensive documentation --- .env.example | 2 + .gitignore | 13 ++ Dockerfile | 16 ++ README.md | 172 ++++++++++++++++++ package.json | 46 +++++ railway.json | 11 ++ src/index.ts | 476 ++++++++++++++++++++++++++++++++++++++++++++++++++ tsconfig.json | 15 ++ 8 files changed, 751 insertions(+) create mode 100644 .env.example create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 package.json create mode 100644 railway.json create mode 100644 src/index.ts create mode 100644 tsconfig.json diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..c6ea6ef --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +# Close CRM API Credentials +CLOSE_CRM_API_KEY=your-api-key-here diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..97adca3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +node_modules/ +dist/ +.env +.env.local +package-lock.json +*.log +.DS_Store +coverage/ +.vscode/ +.idea/ +*.swp +*.swo +*~ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..27e833d --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..d861b67 --- /dev/null +++ b/README.md @@ -0,0 +1,172 @@ +> **🚀 Don't want to self-host?** [Join the waitlist for our fully managed solution →](https://mcpengage.com/closecrm) +> +> Zero setup. Zero maintenance. Just connect and automate. + +--- + +# 🚀 Close CRM MCP Server — 2026 Complete Version + +## 💡 What This Unlocks + +**This MCP server gives AI direct access to your entire Close CRM workspace.** Instead of clicking through interfaces, you just *tell* it what you need. + +### 🎯 Close CRM-Native Power Moves + +The AI can directly control your Close CRM account with natural language: + +- **Smart automation** — Complex workflows in plain English +- **Data intelligence** — Query, analyze, and export your Close CRM data +- **Rapid operations** — Bulk actions that would take hours manually +- **Cross-platform integration** — Combine Close CRM with other tools seamlessly + +### 🔗 The Real Power: Combining Tools + +AI can chain multiple Close CRM operations together: + +- Query data → Filter results → Generate reports +- Search records → Update fields → Notify team +- Analyze metrics → Create tasks → Schedule follow-ups + +## 📦 What's Inside + +**89 API tools** covering the entire Close CRM 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/Close-CRM-MCP-2026-Complete.git + cd close-crm-mcp-2026-complete + npm install + npm run build + ``` + +2. **Get your Close CRM 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": { + "closecrm": { + "command": "node", + "args": ["/ABSOLUTE/PATH/TO/closecrm-mcp/dist/index.js"], + "env": { + "CLOSE_CRM_API_KEY": "your-api-key-here" + } + } + } + } + ``` + +4. **Restart Claude Desktop** + +### Option 2: Deploy to Railway + +[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/template/closecrm-mcp) + +1. Click the button above +2. Set your Close CRM API credentials in Railway dashboard +3. Use the Railway URL as your MCP server endpoint + +### Option 3: Docker + +```bash +docker build -t closecrm-mcp . +docker run -p 3000:3000 \ + -e CLOSE_CRM_API_KEY=your-key \ + closecrm-mcp +``` + +## 🔐 Authentication + +See the official [Close CRM API documentation](https://docs.closecrm.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 Close CRM"* +- *"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 +- Close CRM account with API access + +### Setup + +```bash +git clone https://github.com/BusyBee3333/Close-CRM-MCP-2026-Complete.git +cd close-crm-mcp-2026-complete +npm install +cp .env.example .env +# Edit .env with your Close CRM 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 + +- [Close CRM API Documentation](https://docs.closecrm.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). diff --git a/package.json b/package.json new file mode 100644 index 0000000..965b9ec --- /dev/null +++ b/package.json @@ -0,0 +1,46 @@ +{ + "name": "close-crm-mcp-server", + "version": "1.0.0", + "description": "MCP server for Close CRM API - 2026 Complete Version", + "type": "module", + "main": "dist/index.js", + "author": "MCPEngine ", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/BusyBee3333/Close-CRM-MCP-2026-Complete.git" + }, + "keywords": [ + "mcp", + "closecrm", + "close crm", + "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" + } +} \ No newline at end of file diff --git a/railway.json b/railway.json new file mode 100644 index 0000000..1bb04d8 --- /dev/null +++ b/railway.json @@ -0,0 +1,11 @@ +{ + "$schema": "https://railway.app/railway.schema.json", + "build": { + "builder": "NIXPACKS" + }, + "deploy": { + "startCommand": "npm start", + "restartPolicyType": "ON_FAILURE", + "restartPolicyMaxRetries": 10 + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..b0040b3 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,476 @@ +#!/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 = "close"; +const MCP_VERSION = "1.0.0"; +const API_BASE_URL = "https://api.close.com/api/v1"; + +// ============================================ +// REST API CLIENT +// ============================================ +class CloseClient { + private apiKey: string; + private baseUrl: string; + + constructor(apiKey: string) { + this.apiKey = apiKey; + this.baseUrl = API_BASE_URL; + } + + private getAuthHeader(): string { + // Close uses Basic auth with API key as username, empty password + return `Basic ${Buffer.from(`${this.apiKey}:`).toString('base64')}`; + } + + async request(endpoint: string, options: RequestInit = {}) { + const url = `${this.baseUrl}${endpoint}`; + const response = await fetch(url, { + ...options, + headers: { + "Authorization": this.getAuthHeader(), + "Content-Type": "application/json", + "Accept": "application/json", + ...options.headers, + }, + }); + + if (!response.ok) { + const errorBody = await response.text(); + throw new Error(`Close API error: ${response.status} ${response.statusText} - ${errorBody}`); + } + + return response.json(); + } + + async get(endpoint: string, params: Record = {}) { + const searchParams = new URLSearchParams(); + for (const [key, value] of Object.entries(params)) { + if (value !== undefined && value !== null) { + searchParams.append(key, String(value)); + } + } + const queryString = searchParams.toString(); + const url = queryString ? `${endpoint}?${queryString}` : endpoint; + return this.request(url, { 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 delete(endpoint: string) { + return this.request(endpoint, { method: "DELETE" }); + } +} + +// ============================================ +// TOOL DEFINITIONS +// ============================================ +const tools = [ + { + name: "list_leads", + description: "List leads from Close CRM with optional search query", + inputSchema: { + type: "object" as const, + properties: { + query: { type: "string", description: "Search query (Close query syntax)" }, + _limit: { type: "number", description: "Max results to return (default 100)" }, + _skip: { type: "number", description: "Number of results to skip (pagination)" }, + _fields: { type: "string", description: "Comma-separated list of fields to return" }, + }, + }, + }, + { + name: "get_lead", + description: "Get a specific lead by ID", + inputSchema: { + type: "object" as const, + properties: { + lead_id: { type: "string", description: "Lead ID (e.g., lead_xxx)" }, + }, + required: ["lead_id"], + }, + }, + { + name: "create_lead", + description: "Create a new lead in Close CRM", + inputSchema: { + type: "object" as const, + properties: { + name: { type: "string", description: "Lead/Company name" }, + url: { type: "string", description: "Company website URL" }, + description: { type: "string", description: "Lead description" }, + status_id: { type: "string", description: "Lead status ID" }, + contacts: { + type: "array", + description: "Array of contacts to add to the lead", + items: { + type: "object", + properties: { + name: { type: "string", description: "Contact name" }, + title: { type: "string", description: "Job title" }, + emails: { + type: "array", + items: { + type: "object", + properties: { + email: { type: "string" }, + type: { type: "string", description: "office, home, direct, mobile, fax, other" }, + }, + }, + }, + phones: { + type: "array", + items: { + type: "object", + properties: { + phone: { type: "string" }, + type: { type: "string", description: "office, home, direct, mobile, fax, other" }, + }, + }, + }, + }, + }, + }, + addresses: { + type: "array", + description: "Lead addresses", + items: { + type: "object", + properties: { + address_1: { type: "string" }, + address_2: { type: "string" }, + city: { type: "string" }, + state: { type: "string" }, + zipcode: { type: "string" }, + country: { type: "string" }, + }, + }, + }, + custom: { type: "object", description: "Custom field values (key-value pairs)" }, + }, + required: ["name"], + }, + }, + { + name: "update_lead", + description: "Update an existing lead", + inputSchema: { + type: "object" as const, + properties: { + lead_id: { type: "string", description: "Lead ID to update" }, + name: { type: "string", description: "Lead/Company name" }, + url: { type: "string", description: "Company website URL" }, + description: { type: "string", description: "Lead description" }, + status_id: { type: "string", description: "Lead status ID" }, + custom: { type: "object", description: "Custom field values to update" }, + }, + required: ["lead_id"], + }, + }, + { + name: "list_opportunities", + description: "List opportunities from Close CRM", + inputSchema: { + type: "object" as const, + properties: { + lead_id: { type: "string", description: "Filter by lead ID" }, + status_id: { type: "string", description: "Filter by opportunity status ID" }, + user_id: { type: "string", description: "Filter by assigned user ID" }, + _limit: { type: "number", description: "Max results to return" }, + _skip: { type: "number", description: "Number of results to skip" }, + }, + }, + }, + { + name: "create_opportunity", + description: "Create a new opportunity/deal", + inputSchema: { + type: "object" as const, + properties: { + lead_id: { type: "string", description: "Lead ID to attach opportunity to" }, + status_id: { type: "string", description: "Opportunity status ID" }, + value: { type: "number", description: "Deal value in cents" }, + value_period: { type: "string", description: "one_time, monthly, annual" }, + confidence: { type: "number", description: "Confidence percentage (0-100)" }, + note: { type: "string", description: "Opportunity notes" }, + date_won: { type: "string", description: "Date won (YYYY-MM-DD)" }, + }, + required: ["lead_id"], + }, + }, + { + name: "create_activity", + description: "Create an activity (note, call, email, meeting, etc.)", + inputSchema: { + type: "object" as const, + properties: { + activity_type: { type: "string", description: "Type: Note, Call, Email, Meeting, SMS" }, + lead_id: { type: "string", description: "Lead ID for the activity" }, + contact_id: { type: "string", description: "Contact ID (optional)" }, + user_id: { type: "string", description: "User ID who performed activity" }, + note: { type: "string", description: "Activity note/body content" }, + subject: { type: "string", description: "Subject (for emails)" }, + status: { type: "string", description: "Call status: completed, no-answer, busy, etc." }, + direction: { type: "string", description: "inbound or outbound" }, + duration: { type: "number", description: "Duration in seconds (for calls)" }, + date_created: { type: "string", description: "Activity date (ISO 8601)" }, + }, + required: ["activity_type", "lead_id"], + }, + }, + { + name: "list_tasks", + description: "List tasks from Close CRM", + inputSchema: { + type: "object" as const, + properties: { + lead_id: { type: "string", description: "Filter by lead ID" }, + assigned_to: { type: "string", description: "Filter by assigned user ID" }, + is_complete: { type: "boolean", description: "Filter by completion status" }, + _type: { type: "string", description: "Task type: lead, opportunity, incoming_email, missed_call, etc." }, + _limit: { type: "number", description: "Max results to return" }, + _skip: { type: "number", description: "Number of results to skip" }, + }, + }, + }, + { + name: "create_task", + description: "Create a new task", + inputSchema: { + type: "object" as const, + properties: { + lead_id: { type: "string", description: "Lead ID for the task" }, + assigned_to: { type: "string", description: "User ID to assign task to" }, + text: { type: "string", description: "Task description" }, + date: { type: "string", description: "Due date (YYYY-MM-DD or ISO 8601)" }, + is_complete: { type: "boolean", description: "Task completion status" }, + }, + required: ["lead_id", "text"], + }, + }, + { + name: "send_email", + description: "Send an email through Close CRM", + inputSchema: { + type: "object" as const, + properties: { + lead_id: { type: "string", description: "Lead ID" }, + contact_id: { type: "string", description: "Contact ID to send to" }, + to: { type: "array", items: { type: "string" }, description: "Recipient email addresses" }, + cc: { type: "array", items: { type: "string" }, description: "CC email addresses" }, + bcc: { type: "array", items: { type: "string" }, description: "BCC email addresses" }, + subject: { type: "string", description: "Email subject" }, + body_text: { type: "string", description: "Plain text body" }, + body_html: { type: "string", description: "HTML body" }, + status: { type: "string", description: "draft, outbox, sent" }, + template_id: { type: "string", description: "Email template ID to use" }, + }, + required: ["lead_id", "to", "subject"], + }, + }, + { + name: "list_statuses", + description: "List lead and opportunity statuses", + inputSchema: { + type: "object" as const, + properties: { + type: { type: "string", description: "lead or opportunity" }, + }, + }, + }, + { + name: "list_users", + description: "List users in the Close organization", + inputSchema: { + type: "object" as const, + properties: {}, + }, + }, +]; + +// ============================================ +// TOOL HANDLERS +// ============================================ +async function handleTool(client: CloseClient, name: string, args: any) { + switch (name) { + case "list_leads": { + const { query, _limit = 100, _skip, _fields } = args; + const params: any = { _limit }; + if (query) params.query = query; + if (_skip) params._skip = _skip; + if (_fields) params._fields = _fields; + return await client.get("/lead/", params); + } + case "get_lead": { + const { lead_id } = args; + return await client.get(`/lead/${lead_id}/`); + } + case "create_lead": { + const { name, url, description, status_id, contacts, addresses, custom } = args; + const data: any = { name }; + if (url) data.url = url; + if (description) data.description = description; + if (status_id) data.status_id = status_id; + if (contacts) data.contacts = contacts; + if (addresses) data.addresses = addresses; + if (custom) data.custom = custom; + return await client.post("/lead/", data); + } + case "update_lead": { + const { lead_id, ...updates } = args; + return await client.put(`/lead/${lead_id}/`, updates); + } + case "list_opportunities": { + const { lead_id, status_id, user_id, _limit = 100, _skip } = args; + const params: any = { _limit }; + if (lead_id) params.lead_id = lead_id; + if (status_id) params.status_id = status_id; + if (user_id) params.user_id = user_id; + if (_skip) params._skip = _skip; + return await client.get("/opportunity/", params); + } + case "create_opportunity": { + const { lead_id, status_id, value, value_period, confidence, note, date_won } = args; + const data: any = { lead_id }; + if (status_id) data.status_id = status_id; + if (value !== undefined) data.value = value; + if (value_period) data.value_period = value_period; + if (confidence !== undefined) data.confidence = confidence; + if (note) data.note = note; + if (date_won) data.date_won = date_won; + return await client.post("/opportunity/", data); + } + case "create_activity": { + const { activity_type, lead_id, contact_id, user_id, note, subject, status, direction, duration, date_created } = args; + + // Map activity type to endpoint + const typeMap: Record = { + 'Note': 'note', + 'Call': 'call', + 'Email': 'email', + 'Meeting': 'meeting', + 'SMS': 'sms', + }; + const endpoint = typeMap[activity_type] || activity_type.toLowerCase(); + + const data: any = { lead_id }; + if (contact_id) data.contact_id = contact_id; + if (user_id) data.user_id = user_id; + if (note) data.note = note; + if (subject) data.subject = subject; + if (status) data.status = status; + if (direction) data.direction = direction; + if (duration) data.duration = duration; + if (date_created) data.date_created = date_created; + + return await client.post(`/activity/${endpoint}/`, data); + } + case "list_tasks": { + const { lead_id, assigned_to, is_complete, _type, _limit = 100, _skip } = args; + const params: any = { _limit }; + if (lead_id) params.lead_id = lead_id; + if (assigned_to) params.assigned_to = assigned_to; + if (is_complete !== undefined) params.is_complete = is_complete; + if (_type) params._type = _type; + if (_skip) params._skip = _skip; + return await client.get("/task/", params); + } + case "create_task": { + const { lead_id, assigned_to, text, date, is_complete } = args; + const data: any = { lead_id, text }; + if (assigned_to) data.assigned_to = assigned_to; + if (date) data.date = date; + if (is_complete !== undefined) data.is_complete = is_complete; + return await client.post("/task/", data); + } + case "send_email": { + const { lead_id, contact_id, to, cc, bcc, subject, body_text, body_html, status, template_id } = args; + const data: any = { lead_id, to, subject }; + if (contact_id) data.contact_id = contact_id; + if (cc) data.cc = cc; + if (bcc) data.bcc = bcc; + if (body_text) data.body_text = body_text; + if (body_html) data.body_html = body_html; + if (status) data.status = status; + if (template_id) data.template_id = template_id; + return await client.post("/activity/email/", data); + } + case "list_statuses": { + const { type } = args; + if (type === 'opportunity') { + return await client.get("/status/opportunity/"); + } + return await client.get("/status/lead/"); + } + case "list_users": { + return await client.get("/user/"); + } + default: + throw new Error(`Unknown tool: ${name}`); + } +} + +// ============================================ +// SERVER SETUP +// ============================================ +async function main() { + const apiKey = process.env.CLOSE_API_KEY; + if (!apiKey) { + console.error("Error: CLOSE_API_KEY environment variable required"); + console.error("Get your API key at Settings > Integrations > API Keys in Close"); + process.exit(1); + } + + const client = new CloseClient(apiKey); + + 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); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..de6431e --- /dev/null +++ b/tsconfig.json @@ -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"] +}