UNPKG

evolution-api-mcp

Version:

MCP Server for Evolution API v2 - Integrate WhatsApp functionality with Claude Desktop and other MCP clients

121 lines (120 loc) 3.16 kB
/** * MCP Server Core Implementation * Main MCP server class using MCP TypeScript SDK with STDIO transport */ import { Server } from '@modelcontextprotocol/sdk/server/index.js'; import { ConfigurationManager } from '../config/configuration-manager'; import { EvolutionHttpClient } from '../clients/evolution-http-client'; import { McpToolGenerator } from './tool-generator'; import { McpToolRegistry } from './tool-registry'; /** * MCP Server configuration interface */ export interface McpServerConfig { name: string; version: string; evolutionUrl: string; evolutionApiKey: string; enableLogging?: boolean; httpTimeout?: number; retryAttempts?: number; retryDelay?: number; } /** * Evolution API MCP Server * Implements the MCP protocol for Evolution API v2 integration */ export declare class EvolutionMcpServer { private server; private httpClient?; private toolGenerator; private toolRegistry; private config?; private isInitialized; constructor(toolGenerator?: McpToolGenerator, toolRegistry?: McpToolRegistry); /** * Initialize the MCP server with configuration */ initialize(configManager?: ConfigurationManager): Promise<void>; /** * Start the server with STDIO transport for Claude Desktop integration */ startStdio(): Promise<void>; /** * Start the server with HTTP transport for other MCP clients */ startHttp(port?: number): Promise<void>; /** * Shutdown the server gracefully */ shutdown(): Promise<void>; /** * Generate and register all MCP tools */ private registerTools; /** * Setup MCP request handlers */ private setupRequestHandlers; /** * Format tool response for Claude Desktop */ private formatToolResponse; /** * Create error handler for tools */ private createErrorHandler; /** * Create parameter validator for tools */ private createValidator; /** * Transform configuration from Config to McpServerConfig */ private transformConfig; /** * Setup error handling for the server */ private setupErrorHandling; /** * Setup process handlers for graceful shutdown (STDIO mode) */ private setupProcessHandlers; /** * Setup process handlers for graceful shutdown (HTTP mode) */ private setupHttpProcessHandlers; /** * Get server statistics */ getStats(): { initialized: boolean; toolCount: number; serverInfo: { name: string; version: string; }; httpClientStats?: { requestCount: number; }; }; /** * Health check method */ healthCheck(): Promise<{ healthy: boolean; details: any; }>; /** * Get the HTTP client instance (for testing) */ getHttpClient(): EvolutionHttpClient | undefined; /** * Get the tool registry instance (for testing) */ getToolRegistry(): McpToolRegistry; /** * Get the server instance (for testing) */ getServer(): Server; }