Client API Reference
Complete API documentation for the MCPClient class and related types.
MCPClient
The main client class for connecting to MCP servers.
Constructor
constructor(name: string, version: string)
Parameters
name
- Your application nameversion
- Your application version
Methods
connect()
async connect(config: TransportConfig): Promise<void>
Establishes connection to an MCP server.
Parameters
config
- Transport configuration object
Example
await client.connect({ type: 'stdio', options: { command: 'mcp-server', args: ['--verbose'] } });
disconnect()
async disconnect(): Promise<void>
Closes the connection to the MCP server.
tools.list()
async tools.list(): Promise<Tool[]>
Lists all available tools from the server.
Returns
Array of Tool objects with the following structure:
interface Tool { name: string; description?: string; inputSchema: { type: 'object'; properties: Record<string, any>; required?: string[]; }; }
tools.call()
async tools.call(request: CallToolRequest): Promise<any>
Executes a tool on the server.
Parameters
interface CallToolRequest { name: string; arguments: Record<string, any>; }
MCPClientWithAI
Extended client with AI integration capabilities.
Constructor
constructor( name: string, version: string, aiConfig: AIProviderConfig )
Parameters
name
- Your application nameversion
- Your application versionaiConfig
- AI provider configuration
interface AIProviderConfig { provider: 'openai' | 'anthropic'; apiKey: string; baseURL?: string; }
Methods
Inherits all methods from MCPClient plus:
queryAI()
async queryAI( query: string, options?: AIQueryOptions ): Promise<string>
Uses AI to intelligently process queries and call appropriate tools.
Parameters
query
- Natural language queryoptions
- Optional query configuration
interface AIQueryOptions { model?: string; temperature?: number; maxTokens?: number; systemPrompt?: string; }
Transport Configurations
StdioTransportConfig
interface StdioTransportConfig { type: 'stdio'; options: { command: string; args?: string[]; env?: Record<string, string>; }; }
HTTPTransportConfig
interface HTTPTransportConfig { type: 'http'; options: { url: string; headers?: Record<string, string>; }; }
SSETransportConfig
interface SSETransportConfig { type: 'sse'; options: { url: string; headers?: Record<string, string>; }; }
Error Types
OmniMCP provides specialized error classes for better error handling:
ConnectionError
- Connection failuresTimeoutError
- Operation timeoutsValidationError
- Invalid parametersAuthenticationError
- Auth failuresRateLimitError
- Rate limit exceeded
All errors extend the base MCPError
class:
class MCPError extends Error { errorCode: string; context: ErrorContext; retryable: boolean; getUserMessage(): string; }
Utility Functions
retry()
async function retry<T>( operation: () => Promise<T>, options?: RetryOptions ): Promise<T>
Retries an operation with exponential backoff.
interface RetryOptions { maxAttempts?: number; initialDelay?: number; maxDelay?: number; backoffFactor?: number; shouldRetry?: (error: any) => boolean; onRetry?: (attempt: number, error: any) => void; }