MCP Client
Connect to MCP servers and use their tools in AgentForge agents.
MCPClient
import { MCPClient } from '@ahzan-agentforge/core';
const client = new MCPClient({
command: 'npx',
args: ['@modelcontextprotocol/server-filesystem', '/path/to/dir'],
timeout: 30_000,
});
await client.connect();MCPClientConfig
interface MCPClientConfig {
command: string; // Command to start the MCP server
args?: string[]; // Command arguments
env?: Record<string, string>; // Environment variables
timeout?: number; // Connection timeout (ms)
transport?: MCPTransport;
}Using MCP Tools in Agents
const client = new MCPClient({ command: 'npx', args: ['my-mcp-server'] });
await client.connect();
const mcpTools = await client.listTools();
const tools = mcpTools.map(fromMCPTool);
const agent = defineAgent({
name: 'mcp-agent',
description: 'Agent with MCP tools',
tools: [...myTools, ...tools],
llm,
systemPrompt: '...',
});Transport
The client communicates via stdio (JSON-RPC 2.0 over stdin/stdout):
- Spawns the MCP server as a child process
- Sends JSON-RPC requests to stdin
- Reads JSON-RPC responses from stdout
- Supports concurrent requests via request IDs