/** * MCP (Model Context Protocol) types and interfaces * * MCP is an open protocol by Anthropic that standardizes how AI applications * connect to external tools and data sources. * * @see https://modelcontextprotocol.io/specification/2024-11-05/ */ /** * Transport type for MCP server connection */ export type MCPTransport = 'stdio' | 'http'; /** * Connection status of an MCP client */ export type MCPConnectionStatus = 'disconnected' | 'connecting' | 'connected' | 'error'; /** * Options for connecting to an MCP server via stdio transport */ export interface MCPStdioOptions { /** Command to spawn (e.g., 'npx', 'node', 'python') */ command: string; /** Arguments to pass to the command */ args?: string[]; /** Environment variables for the spawned process */ env?: Record; /** Working directory for the spawned process */ cwd?: string; } /** * Options for connecting to an MCP server via HTTP transport */ export interface MCPHttpOptions { /** Server URL (e.g., 'http://localhost:3000/mcp') */ url: string; /** Custom headers for HTTP requests */ headers?: Record; } /** * Configuration for an MCP client */ export interface MCPClientConfig { /** Unique name/identifier for this server connection */ name: string; /** Transport type */ transport: MCPTransport; /** Stdio transport options (required if transport is 'stdio') */ stdio?: MCPStdioOptions; /** HTTP transport options (required if transport is 'http') */ http?: MCPHttpOptions; /** Connection timeout in milliseconds (default: 30000) */ timeout?: number; /** Client name reported to server (default: '@compilr-dev/agents') */ clientName?: string; /** Client version reported to server (default: '1.0.0') */ clientVersion?: string; } /** * Simplified configuration for quick server setup * Allows shorthand notation for common configurations */ export interface MCPServerConfig { /** Unique name/identifier for this server */ name: string; /** Transport type */ transport: MCPTransport; /** Command to spawn */ command?: string; /** Command arguments */ args?: string[]; /** Environment variables */ env?: Record; /** Working directory */ cwd?: string; /** Server URL */ url?: string; /** Custom headers */ headers?: Record; /** Connection timeout in milliseconds */ timeout?: number; } /** * MCP tool definition from the server * Based on MCP specification's Tool type */ export interface MCPToolDefinition { /** Tool name (unique identifier) */ name: string; /** Human-readable description */ description?: string; /** JSON Schema for tool input */ inputSchema: { type: 'object'; properties?: Record; required?: string[]; additionalProperties?: boolean; [key: string]: unknown; }; } /** * Content block in MCP tool result */ export interface MCPContentBlock { type: 'text' | 'image' | 'resource' | 'audio'; text?: string; data?: string; mimeType?: string; uri?: string; } /** * Result from calling an MCP tool */ export interface MCPToolResult { /** Content blocks (text, images, resources) */ content: MCPContentBlock[]; /** Whether the tool execution resulted in an error */ isError?: boolean; } /** * Event types emitted by MCPClient */ export type MCPClientEventType = 'tools_changed' | 'error' | 'disconnected' | 'connected'; /** * Event emitted by MCPClient */ export interface MCPClientEvent { type: MCPClientEventType; serverName: string; error?: Error; tools?: MCPToolDefinition[]; } /** * Handler for MCP client events */ export type MCPClientEventHandler = (event: MCPClientEvent) => void; /** * Options for MCPManager */ export interface MCPManagerOptions { /** Prefix for tool names (default: 'mcp') */ toolPrefix?: string; /** Whether to auto-connect servers when added (default: true) */ autoConnect?: boolean; /** Event handler for manager events */ onEvent?: MCPClientEventHandler; } /** * Convert shorthand MCPServerConfig to full MCPClientConfig */ export declare function normalizeServerConfig(config: MCPServerConfig): MCPClientConfig;