()
| 2834 | // ─── MCP Server Mode ───────────────────────────────────────────────────────── |
| 2835 | |
| 2836 | function runMCP() { |
| 2837 | // Minimal MCP server implementation over stdio. |
| 2838 | // Tool calls are handled async — we buffer the response and write it |
| 2839 | // when the handler resolves. This fixes the bug where smallcode_agent |
| 2840 | // (which calls the async runAgentLoop) would return before completing. |
| 2841 | const rl = readline.createInterface({ input: process.stdin }); |
| 2842 | |
| 2843 | rl.on('line', async (line) => { |
| 2844 | try { |
| 2845 | const request = JSON.parse(line); |
| 2846 | const response = await handleMCPRequest(request); |
| 2847 | console.log(JSON.stringify(response)); |
| 2848 | } catch (err) { |
| 2849 | console.log(JSON.stringify({ |
| 2850 | jsonrpc: '2.0', |
| 2851 | id: null, |
| 2852 | error: { code: -32700, message: 'Parse error' } |
| 2853 | })); |
| 2854 | } |
| 2855 | }); |
| 2856 | } |
| 2857 | |
| 2858 | async function handleMCPRequest(request) { |
| 2859 | const { id, method } = request; |
no test coverage detected