Repository navigation
Expand file tree
/
Copy pathserver.mjs
More file actions
42 lines (40 loc) · 1.36 KB
/
Copy pathserver.mjs
File metadata and controls
42 lines (40 loc) · 1.36 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
import readline from 'node:readline';
const reply = (id, result) => process.stdout.write(`${JSON.stringify({ jsonrpc: '2.0', id, result })}\n`);
const input = readline.createInterface({ input: process.stdin, terminal: false });
input.on('line', (line) => {
let message;
try {
message = JSON.parse(line);
} catch {
return;
}
if (message.method === 'initialize') {
reply(message.id, {
protocolVersion: '2025-06-18',
capabilities: { tools: {} },
serverInfo: { name: 'example-safe-plugin', version: '1.0.0' },
});
} else if (message.method === 'tools/list') {
reply(message.id, {
tools: [
{
name: 'safe_echo',
description: 'Return text unchanged without side effects.',
inputSchema: {
type: 'object',
properties: { text: { type: 'string' } },
required: ['text'],
additionalProperties: false,
},
},
],
});
} else if (message.method === 'tools/call') {
const text = typeof message.params?.arguments?.text === 'string' ? message.params.arguments.text : '';
reply(message.id, { content: [{ type: 'text', text }] });
} else if (message.id !== undefined) {
process.stdout.write(
`${JSON.stringify({ jsonrpc: '2.0', id: message.id, error: { code: -32601, message: 'Method not found' } })}\n`,
);
}
});