名称: MCP模拟客户端 描述: 为服务器测试创建模拟MCP客户端,支持请求/响应模拟。 允许工具: 读取、写入、编辑、Bash、全局搜索、Grep
MCP模拟客户端
为服务器测试创建模拟MCP客户端。
生成模式
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
import { spawn } from 'child_process';
export async function createTestClient(serverCmd: string, args: string[]) {
const proc = spawn(serverCmd, args, { stdio: ['pipe', 'pipe', 'inherit'] });
const transport = new StdioClientTransport({ reader: proc.stdout!, writer: proc.stdin! });
const client = new Client({ name: 'test-client', version: '1.0.0' }, { capabilities: {} });
await client.connect(transport);
return { client, close: () => proc.kill() };
}
export async function testTool(client: Client, name: string, args: Record<string, unknown>) {
const result = await client.callTool({ name, arguments: args });
return result;
}
目标流程
- mcp服务器测试套件
- mcp工具实现