-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest-mcp.js
More file actions
executable file
·85 lines (75 loc) · 2.11 KB
/
test-mcp.js
File metadata and controls
executable file
·85 lines (75 loc) · 2.11 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
#!/usr/bin/env node
import { spawn } from "child_process";
import readline from "readline";
// Start the MCP server
const server = spawn("node", ["build/index.js"], {
stdio: ["pipe", "pipe", process.stderr],
});
const rl = readline.createInterface({
input: server.stdout,
terminal: false,
});
let initialized = false;
rl.on("line", (line) => {
console.log("Raw line:", line);
try {
const response = JSON.parse(line);
console.log("\n=== Parsed Response ===");
console.log(JSON.stringify(response, null, 2));
if (!initialized && response.result && response.id === 1) {
initialized = true;
// Send notifications/initialized
const initializedNotification = {
jsonrpc: "2.0",
method: "notifications/initialized",
params: {},
};
server.stdin.write(JSON.stringify(initializedNotification) + "\n");
// Now request tools list
console.log("\n--- Requesting tools list ---");
const listToolsRequest = {
jsonrpc: "2.0",
id: 2,
method: "tools/list",
params: {},
};
server.stdin.write(JSON.stringify(listToolsRequest) + "\n");
} else if (response.result && response.result.tools) {
console.log(`\n=== Found ${response.result.tools.length} tools ===\n`);
response.result.tools.forEach((tool, index) => {
console.log(`${index + 1}. ${tool.name}`);
console.log(` Description: ${tool.description}`);
console.log("");
});
server.kill();
process.exit(0);
}
} catch (e) {
// Not JSON, probably a log message
// Ignore
}
});
// Send initialize request
console.log("--- Initializing MCP server ---");
const initRequest = {
jsonrpc: "2.0",
id: 1,
method: "initialize",
params: {
protocolVersion: "2025-11-25",
capabilities: {},
clientInfo: {
name: "test-client",
version: "1.0.0",
},
},
};
server.stdin.write(JSON.stringify(initRequest) + "\n");
// Wait for initialization
setTimeout(() => {
if (!initialized) {
console.error("Initialization timeout");
server.kill();
process.exit(1);
}
}, 10000);