#!/usr/bin/env node
import { spawn } from 'child_process';
import { writeFileSync } from 'fs';
const SERVER_PATH = './dist/index.js';
async function runCommand(args) {
return new Promise((resolve) => {
const startTime = Date.now();
const proc = spawn('npx', ['@modelcontextprotocol/inspector', '--cli', 'node', SERVER_PATH, ...args], {
stdio: 'pipe'
});
let output = '';
proc.stdout?.on('data', (data) => { output += data.toString(); });
proc.stderr?.on('data', (data) => { output += data.toString(); });
proc.on('close', () => {
resolve({ duration: Date.now() - startTime, output });
});
proc.on('error', () => {
resolve({ duration: Date.now() - startTime, output: '' });
});
});
}
async function benchmark(name, args, iterations = 3) {
const durations = [];
for (let i = 0; i < iterations; i++) {
const result = await runCommand(args);
durations.push(result.duration);
}
const avg = durations.reduce((a, b) => a + b, 0) / durations.length;
const min = Math.min(...durations);
const max = Math.max(...durations);
return { name, avg: Math.round(avg), min, max, iterations };
}
async function main() {
console.log('Performance Benchmarks\n');
const results = [];
results.push(await benchmark('tools/list', ['--method', 'tools/list']));
console.log(`✓ tools/list: ${results.at(-1).avg}ms avg`);
results.push(await benchmark('crawl_read', [
'--method', 'tools/call',
'--tool-name', 'crawl_read',
'--tool-arg', 'url=https://example.com'
], 2));
console.log(`✓ crawl_read: ${results.at(-1).avg}ms avg`);
results.push(await benchmark('crawl_fetch_markdown', [
'--method', 'tools/call',
'--tool-name', 'crawl_fetch_markdown',
'--tool-arg', 'url=https://httpbin.org/html'
], 2));
console.log(`✓ crawl_fetch_markdown: ${results.at(-1).avg}ms avg`);
console.log('\nSummary:');
console.log(JSON.stringify(results, null, 2));
writeFileSync('performance-results.json', JSON.stringify({
timestamp: new Date().toISOString(),
results
}, null, 2));
console.log('\n✓ Results saved to performance-results.json');
}
main().catch(console.error);