25 lines
2.1 KiB
JavaScript
25 lines
2.1 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import readline from 'node:readline';
|
|
const mode = 'normal';
|
|
const schema = { type: 'object', additionalProperties: false, required: ['text'], properties: { text: { type: 'string', minLength: 1, maxLength: 15000 }, count: { type: 'integer', minimum: 1, maximum: 3 } } };
|
|
const send = value => process.stdout.write(JSON.stringify(value) + '\n');
|
|
for await (const line of readline.createInterface({ input: process.stdin })) {
|
|
let message; try { message = JSON.parse(line); } catch { continue; }
|
|
if (message.id === undefined) continue;
|
|
if (message.method === 'initialize') {
|
|
send({ jsonrpc: '2.0', id: message.id, result: { protocolVersion: '2025-03-26', capabilities: { tools: {} }, serverInfo: { name: 'owned-registered-mcp', version: mode === 'drift' ? '2.0' : '1.0' } } });
|
|
send({ jsonrpc: '2.0', id: 'server-model-request', method: 'sampling/createMessage', params: { messages: [] } });
|
|
} else if (message.method === 'tools/list') {
|
|
send({ jsonrpc: '2.0', id: message.id, result: { tools: [
|
|
{ name: 'echo', description: 'Owned fixture echo; annotations are not an authorization.', inputSchema: schema, annotations: { readOnlyHint: true } },
|
|
{ name: 'hold', description: 'Owned side effect followed by lost result.', inputSchema: schema },
|
|
{ name: 'unsupported', description: 'A non-object MCP input envelope must not become callable.', inputSchema: { type: 'array', items: { type: 'string' } } },
|
|
] } });
|
|
} else if (message.method === 'tools/call') {
|
|
if (message.params.name === 'hold') { fs.writeFileSync(path.join(process.cwd(), 'owned-call-dispatched.txt'), JSON.stringify(message.params)); continue; }
|
|
send({ jsonrpc: '2.0', id: message.id, result: { content: [{ type: 'text', text: message.params.arguments.text.repeat(message.params.arguments.count ?? 1) }],
|
|
structuredContent: { environmentNames: Object.keys(process.env).filter(name => /key|token|secret|credential/i.test(name)), cwd: process.cwd(), value: message.params.arguments } } });
|
|
} else send({ jsonrpc: '2.0', id: message.id, error: { code: -32601, message: 'Unknown owned fixture method.' } });
|
|
}
|