MCPcopy Create free account
hub / github.com/chokcoco/iCSS / testMCPProtocol

Function testMCPProtocol

MCP/diagnose-mcp.js:76–133  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

74
75// 手动测试 MCP 协议
76function testMCPProtocol() {
77 console.log('\n3️⃣ Testing MCP Protocol Manually:\n');
78
79 return new Promise((resolve) => {
80 const serverProcess = spawn('node', ['./server.js'], {
81 stdio: ['pipe', 'pipe', 'pipe']
82 });
83
84 let stdout = '';
85 let stderr = '';
86
87 serverProcess.stdout.on('data', (data) => {
88 stdout += data.toString();
89 });
90
91 serverProcess.stderr.on('data', (data) => {
92 stderr += data.toString();
93 });
94
95 // 发送 MCP 初始化请求
96 const initRequest = JSON.stringify({
97 jsonrpc: "2.0",
98 id: 1,
99 method: "initialize",
100 params: {
101 protocolVersion: "2024-11-05",
102 capabilities: {},
103 clientInfo: {
104 name: "test-client",
105 version: "1.0.0"
106 }
107 }
108 }) + '\n';
109
110 serverProcess.stdin.write(initRequest);
111
112 // 等待响应
113 setTimeout(() => {
114 serverProcess.kill();
115
116 console.log(' 📤 Sent initialization request');
117
118 if (stdout.trim()) {
119 console.log(' ✅ Got stdout response:');
120 console.log(` ${stdout.trim()}`);
121 } else {
122 console.log(' ❌ No stdout response');
123 }
124
125 if (stderr.trim()) {
126 console.log(' ⚠️ Got stderr:');
127 console.log(` ${stderr.trim()}`);
128 }
129
130 resolve(stdout.length > 0);
131 }, 3000);
132 });
133}

Callers 1

runDiagnosisFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected