diff --git a/.codex/mcp_996_gui_proxy.js b/.codex/mcp_996_gui_proxy.js index cbc2bff2..0511ac57 100644 --- a/.codex/mcp_996_gui_proxy.js +++ b/.codex/mcp_996_gui_proxy.js @@ -68,9 +68,12 @@ const tools = [ ]; let input = Buffer.alloc(0); +let responseMode = "lsp"; process.stdin.on("data", (chunk) => { log(`stdin bytes=${chunk.length}`); + log(`stdin utf8=${JSON.stringify(chunk.toString("utf8"))}`); + log(`stdin hex=${chunk.toString("hex")}`); input = Buffer.concat([input, chunk]); readMessages(); }); @@ -80,6 +83,33 @@ process.on("uncaughtException", (error) => log(`uncaught ${error.stack || error. function readMessages() { while (true) { + let firstNonWhitespace = 0; + while ( + firstNonWhitespace < input.length && + [9, 10, 13, 32].includes(input[firstNonWhitespace]) + ) { + firstNonWhitespace += 1; + } + if (firstNonWhitespace > 0) input = input.slice(firstNonWhitespace); + if (input.length === 0) return; + + if (input[0] === 123) { + responseMode = "ndjson"; + const lineEnd = input.indexOf("\n"); + if (lineEnd < 0) return; + const body = input.slice(0, lineEnd).toString("utf8").trim(); + input = input.slice(lineEnd + 1); + if (!body) continue; + log(`message ${body}`); + handle(JSON.parse(body)).catch((error) => { + respond(JSON.parse(body).id, null, { + code: -32603, + message: error && error.message ? error.message : String(error), + }); + }); + continue; + } + let headerEnd = input.indexOf("\r\n\r\n"); let separatorLength = 4; if (headerEnd < 0) { @@ -131,6 +161,21 @@ async function handle(message) { return; } + if (message.method === "resources/list") { + respond(message.id, { resources: [] }); + return; + } + + if (message.method === "resources/templates/list") { + respond(message.id, { resourceTemplates: [] }); + return; + } + + if (message.method === "prompts/list") { + respond(message.id, { prompts: [] }); + return; + } + if (message.method === "tools/call") { const name = message.params?.name; const args = message.params?.arguments || {}; @@ -210,5 +255,9 @@ function respond(id, result, error) { : { jsonrpc: "2.0", id, result }; const body = JSON.stringify(payload); log(`respond id=${id} bytes=${Buffer.byteLength(body, "utf8")} error=${Boolean(error)}`); - process.stdout.write(`Content-Length: ${Buffer.byteLength(body, "utf8")}\r\n\r\n${body}`); + if (responseMode === "ndjson") { + process.stdout.write(`${body}\n`); + } else { + process.stdout.write(`Content-Length: ${Buffer.byteLength(body, "utf8")}\r\n\r\n${body}`); + } }