-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest-mcp-servers.ts
More file actions
100 lines (82 loc) · 2.74 KB
/
test-mcp-servers.ts
File metadata and controls
100 lines (82 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env bun
import { spawn } from 'node:child_process';
import { join } from 'node:path';
console.log('🧪 Testing MCP Servers...\n');
async function testMCPServer(packageName: string, serverName: string) {
console.log(`Testing ${packageName} MCP server...`);
const serverPath = join(__dirname, 'packages', packageName, 'src', 'mcp', 'server.ts');
const server = spawn('bun', ['run', serverPath], {
stdio: ['pipe', 'pipe', 'pipe'],
env: {
...process.env,
...(packageName === 'courtlistener-sdk' ? { COURTLISTENER_API_TOKEN: 'test-token' } : {})
}
});
let output = '';
let errorOutput = '';
server.stdout.on('data', (data) => {
output += data.toString();
});
server.stderr.on('data', (data) => {
errorOutput += data.toString();
});
// Wait for server to start
await new Promise(resolve => setTimeout(resolve, 1000));
// Send initialize request
const initRequest = {
jsonrpc: "2.0",
method: "initialize",
params: {
protocolVersion: "0.1.0",
capabilities: {},
clientInfo: {
name: "test-client",
version: "1.0.0"
}
},
id: 1
};
server.stdin.write(JSON.stringify(initRequest) + '\n');
// Wait for response
await new Promise(resolve => setTimeout(resolve, 1000));
// Check outputs
const combinedOutput = output + errorOutput;
if (combinedOutput.includes('MCP server running on stdio')) {
console.log(`✅ ${packageName} MCP server started successfully`);
// Try to parse the response
const lines = output.split('\n');
for (const line of lines) {
if (line.trim().startsWith('{')) {
try {
const response = JSON.parse(line);
if (response.result?.serverInfo?.name) {
console.log(` Server name: ${response.result.serverInfo.name}`);
console.log(` Version: ${response.result.serverInfo.version || 'N/A'}`);
}
} catch (e) {
// Continue checking other lines
}
}
}
} else {
console.log(`❌ ${packageName} MCP server failed to start`);
console.log(' Output:', output);
console.log(' Error:', errorOutput);
}
server.kill();
await new Promise(resolve => setTimeout(resolve, 100));
console.log();
}
async function runTests() {
try {
await testMCPServer('ecfr-sdk', 'eCFRSDKServer');
await testMCPServer('federal-register-sdk', 'FederalRegisterServer');
await testMCPServer('courtlistener-sdk', 'CourtListenerRESTAPIServer');
await testMCPServer('govinfo-sdk', 'GovInfoServer');
await testMCPServer('dol-sdk', 'DOLServer');
console.log('🎉 All MCP server tests completed!\n');
} catch (error) {
console.error('❌ MCP server test failed:', error.message);
}
}
runTests();