UNPKG

smartlead-mcp-server

Version:

MCP server for Smartlead campaign management integration. Features include creating campaigns, updating campaign settings, and managing campaign sequences.

82 lines 3.11 kB
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; import { isAddClientParams, isFetchAllClientsParams } from '../types/clientManagement.js'; // SmartLead API base URL const SMARTLEAD_API_URL = 'https://server.smartlead.ai/api/v1'; // Handler for Client Management-related tools export async function handleClientManagementTool(toolName, args, apiClient, withRetry) { switch (toolName) { case 'smartlead_add_client': { return handleAddClient(args, apiClient, withRetry); } case 'smartlead_fetch_all_clients': { return handleFetchAllClients(args, apiClient, withRetry); } default: throw new Error(`Unknown Client Management tool: ${toolName}`); } } // Create a modified client for SmartLead API with the correct base URL function createSmartLeadClient(apiClient) { return { get: (url, config) => apiClient.get(`${SMARTLEAD_API_URL}${url}`, config), post: (url, data, config) => apiClient.post(`${SMARTLEAD_API_URL}${url}`, data, config), put: (url, data, config) => apiClient.put(`${SMARTLEAD_API_URL}${url}`, data, config), delete: (url, config) => apiClient.delete(`${SMARTLEAD_API_URL}${url}`, config) }; } // Individual handlers for each tool async function handleAddClient(args, apiClient, withRetry) { if (!isAddClientParams(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid arguments for smartlead_add_client'); } try { const smartLeadClient = createSmartLeadClient(apiClient); const response = await withRetry(async () => smartLeadClient.post('/client/save', args), 'add client'); return { content: [ { type: 'text', text: JSON.stringify(response.data, null, 2), }, ], isError: false, }; } catch (error) { return { content: [{ type: 'text', text: `API Error: ${error.response?.data?.message || error.message}` }], isError: true, }; } } async function handleFetchAllClients(args, apiClient, withRetry) { if (!isFetchAllClientsParams(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid arguments for smartlead_fetch_all_clients'); } try { const smartLeadClient = createSmartLeadClient(apiClient); const response = await withRetry(async () => smartLeadClient.get('/client/'), 'fetch all clients'); return { content: [ { type: 'text', text: JSON.stringify(response.data, null, 2), }, ], isError: false, }; } catch (error) { return { content: [{ type: 'text', text: `API Error: ${error.response?.data?.message || error.message}` }], isError: true, }; } } //# sourceMappingURL=clientManagement.js.map