-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathserver.mjs
More file actions
45 lines (42 loc) · 1.32 KB
/
Copy pathserver.mjs
File metadata and controls
45 lines (42 loc) · 1.32 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
import { createInterface } from 'node:readline';
const input = createInterface({ input: process.stdin, crlfDelay: Infinity });
input.on('line', (line) => {
if (!line.trim()) return;
let message;
try {
message = JSON.parse(line);
} catch {
return;
}
if (message.id === undefined) return;
const response = handle(message);
process.stdout.write(`${JSON.stringify({ jsonrpc: '2.0', id: message.id, ...response })}\n`);
});
function handle(message) {
if (message.method === 'initialize') {
return {
result: {
protocolVersion: message.params?.protocolVersion ?? '2025-06-18',
capabilities: { tools: {} },
serverInfo: { name: 'hello-mcode-mcp', version: '0.1.0' },
},
};
}
if (message.method === 'tools/list') {
return {
result: {
tools: [
{
name: 'hello_mcode',
description: 'Return a greeting from the example MCP server.',
inputSchema: { type: 'object', properties: {}, additionalProperties: false },
},
],
},
};
}
if (message.method === 'tools/call' && message.params?.name === 'hello_mcode') {
return { result: { content: [{ type: 'text', text: 'Hello from MCode MCP!' }] } };
}
return { error: { code: -32601, message: `Method not found: ${String(message.method)}` } };
}