bench
Benchmark response latency for all configured MCP servers to identify performance issues.
Instructions
Benchmark response latency for all configured MCP servers
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/server.ts:77-114 (registration)Registers the 'bench' MCP tool with the server using server.tool(). The tool is named 'bench' and benchmarks response latency for all configured MCP servers.
server.tool( "bench", "Benchmark response latency for all configured MCP servers", {}, async () => { const servers = await scanConfigs(); if (servers.length === 0) { return { content: [{ type: "text", text: "No MCP servers found in any configuration." }], }; } const results: ScanResult[] = []; for (const s of servers) { results.push(await testServer(s)); } const responding = results .filter((r) => r.status === "ok" && r.latencyMs !== undefined) .sort((a, b) => (a.latencyMs ?? 0) - (b.latencyMs ?? 0)); if (responding.length === 0) { return { content: [{ type: "text", text: "No servers responded for benchmarking." }], }; } const lines = responding.map((r, i) => { const ms = r.latencyMs!; const rating = ms < 500 ? "Fast" : ms < 2000 ? "OK" : "Slow"; return `${i + 1}. ${r.server.name} — ${ms}ms (${rating})`; }); return { content: [{ type: "text", text: lines.join("\n") }], }; } ); - src/server.ts:81-113 (handler)The handler function for the 'bench' tool. It scans configs, tests each server, filters OK responses with latency, sorts by latency, and returns a ranked list with ratings (Fast/OK/Slow).
async () => { const servers = await scanConfigs(); if (servers.length === 0) { return { content: [{ type: "text", text: "No MCP servers found in any configuration." }], }; } const results: ScanResult[] = []; for (const s of servers) { results.push(await testServer(s)); } const responding = results .filter((r) => r.status === "ok" && r.latencyMs !== undefined) .sort((a, b) => (a.latencyMs ?? 0) - (b.latencyMs ?? 0)); if (responding.length === 0) { return { content: [{ type: "text", text: "No servers responded for benchmarking." }], }; } const lines = responding.map((r, i) => { const ms = r.latencyMs!; const rating = ms < 500 ? "Fast" : ms < 2000 ? "OK" : "Slow"; return `${i + 1}. ${r.server.name} — ${ms}ms (${rating})`; }); return { content: [{ type: "text", text: lines.join("\n") }], }; } - src/index.ts:68-86 (registration)CLI command registration for 'bench' using Commander. Defines the CLI interface for the bench subcommand with --json option.
program .command("bench") .description("Benchmark MCP server response times") .option("--json", "Output results as JSON") .action(async (opts) => { const servers = await discoverServers(opts.json); if (servers.length === 0) return; const results = await testAllServers(servers, opts.json, "Benchmarking servers...", "Benchmark complete"); if (opts.json) { const sorted = results .filter((r) => r.status === "ok" && r.latencyMs !== undefined) .sort((a, b) => (a.latencyMs ?? 0) - (b.latencyMs ?? 0)); console.log(JSON.stringify(sorted.map(formatScanResult), null, 2)); } else { printBenchResults(results); } }); - src/index.ts:72-86 (handler)CLI action handler for the 'bench' command. Discovers servers, tests all, optionally formats as JSON, or prints results using printBenchResults.
.action(async (opts) => { const servers = await discoverServers(opts.json); if (servers.length === 0) return; const results = await testAllServers(servers, opts.json, "Benchmarking servers...", "Benchmark complete"); if (opts.json) { const sorted = results .filter((r) => r.status === "ok" && r.latencyMs !== undefined) .sort((a, b) => (a.latencyMs ?? 0) - (b.latencyMs ?? 0)); console.log(JSON.stringify(sorted.map(formatScanResult), null, 2)); } else { printBenchResults(results); } }); - src/ui.ts:107-141 (helper)printBenchResults - UI helper that formats and prints benchmark results as a table with rank, server name, latency, and rating (Fast/OK/Slow).
export function printBenchResults(results: ScanResult[]): void { const sorted = results .filter((r) => r.status === "ok" && r.latencyMs !== undefined) .sort((a, b) => (a.latencyMs ?? 0) - (b.latencyMs ?? 0)); if (sorted.length === 0) { console.log(chalk.yellow(" No servers responded for benchmarking.\n")); return; } const table = new Table({ head: [ chalk.white("#"), chalk.white("Server"), chalk.white("Latency"), chalk.white("Rating"), ], style: { head: [], border: ["dim"] }, }); sorted.forEach((r, i) => { const ms = r.latencyMs!; const rating = ms < 500 ? chalk.green("⚡ Fast") : ms < 2000 ? chalk.yellow("⏳ OK") : chalk.red("🐌 Slow"); table.push([String(i + 1), chalk.cyan(r.server.name), `${ms}ms`, rating]); }); console.log(table.toString()); console.log(); }