AgentForge

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):

  1. Spawns the MCP server as a child process
  2. Sends JSON-RPC requests to stdin
  3. Reads JSON-RPC responses from stdout
  4. Supports concurrent requests via request IDs

Next Steps

  • Server — expose tools as MCP
  • Adapters — tool conversion functions