Files
jiang 75d8d526f9 feat(agent): add external MCP client support
Reuse OpenCode 2 HTTP/stdio clients with per-session read-only grants,
native approval and sanitized owner-scoped MCP status. Narrow the
environment inherited by trusted local MCP processes.

Validated in an isolated checkout with bun run check and 20 focused tests.
2026-10-08 18:36:07 +08:00

18 lines
1.3 KiB
TypeScript

import { createInterface } from "node:readline";
// A minimal legacy stdio fixture. No third-party SDK or external service.
for await (const line of createInterface({ input: process.stdin })) {
const request = JSON.parse(line);
if (request.id === undefined) continue;
let result: unknown;
if (request.method === "initialize") result = { protocolVersion: request.params.protocolVersion, capabilities: { tools: {} }, serverInfo: { name: "tjwater-mcp-fixture", version: "1" } };
else if (request.method === "tools/list") result = { tools: [{ name: "echo", description: "Read-only fixture echo", inputSchema: { type: "object", properties: { value: { type: "string" } }, required: ["value"] }, annotations: { readOnlyHint: true } }] };
else if (request.method === "tools/call") result = { content: [{ type: "text", text: JSON.stringify({ value: request.params.arguments.value, internal_token_empty: !process.env.AGENT_INTERNAL_TOKEN, model_key_empty: !process.env.DEEPSEEK_API_KEY, own_token_present: process.env.MCP_FIXTURE_TOKEN === "MCP_ONLY" }) }] };
else if (request.method === "ping") result = {};
else {
process.stdout.write(`${JSON.stringify({ jsonrpc: "2.0", id: request.id, error: { code: -32601, message: "Method not found" } })}\n`);
continue;
}
process.stdout.write(`${JSON.stringify({ jsonrpc: "2.0", id: request.id, result })}\n`);
}