MCPcopy
hub / github.com/Doorman11991/smallcode / runMCP

Function runMCP

bin/smallcode.js:2836–2856  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2834// ─── MCP Server Mode ─────────────────────────────────────────────────────────
2835
2836function 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
2858async function handleMCPRequest(request) {
2859 const { id, method } = request;

Callers 1

mainFunction · 0.85

Calls 1

handleMCPRequestFunction · 0.85

Tested by

no test coverage detected