Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(server): surface protocol errors from remote MCP servers (#2984)
Nguyễn Tuấn Anhab809f04e318
diff --git a/server/mcp-remote-proxy.test.ts b/server/mcp-remote-proxy.test.tsindex aa8c12c862..42c6665c24 100644--- a/server/mcp-remote-proxy.test.ts+++ b/server/mcp-remote-proxy.test.ts@@ -62,6 +62,11 @@ async function remoteFixture(mode: "http" | "event-stream" | "sse") {}const refusedWith = (frame.params?.arguments as Record<string, unknown>)?.status;if (typeof refusedWith === "number") return res.writeHead(refusedWith).end(TOKEN);+ if ((frame.params?.arguments as Record<string, unknown>)?.html) return res.writeHead(200, { "content-type": "text/html" }).end("<html><body>Sign in required</body></html>");+ if ((frame.params?.arguments as Record<string, unknown>)?.drop) {+ if (mode === "event-stream") return res.writeHead(200, { "content-type": "text/event-stream", "mcp-session-id": "disposable-session" }).end();+ return res.writeHead(200, { "content-type": "application/json", "mcp-session-id": "disposable-session" }).end(JSON.stringify({ jsonrpc: "2.0", id: "not-the-request", result: {} }));+ }if ((frame.params?.arguments as Record<string, unknown>)?.error) error = { code: -32000, message: TOKEN };else result = { content: [{ type: "text", text: (frame.params?.arguments as Record<string, unknown>)?.large ? "x".repeat(2_000_000) : "read completed" }] };} else {@@ -201,6 +206,26 @@ describe("scoped remote MCP subprocess", () => {expect(JSON.stringify(reply)).not.toContain(fixture.spec.url);});+ it("names a protocol failure instead of the bare remote error", async () => {+ fixture = await remoteFixture("http");+ start(gateServer({ name: "notes", server: fixture.spec, budget: 0, threadId: "fixture", toolScope: { allow: ["mcp:notes:read"] } })!);+ await initialize();+ send({ id: 2, method: "tools/call", params: { name: "read", arguments: { html: true } } });+ const reply = await answer();+ expect(reply.error).toEqual({ code: -32603, message: "unexpected content type" });+ expect(JSON.stringify(reply)).not.toContain("Sign in required");+ expect(JSON.stringify(reply)).not.toContain(fixture.spec.url);+ });++ it("names an event stream that ended without the response", async () => {+ fixture = await remoteFixture("event-stream");+ start(gateServer({ name: "notes", server: fixture.spec, budget: 0, threadId: "fixture", toolScope: { allow: ["mcp:notes:read"] } })!);+ await initialize();+ send({ id: 2, method: "tools/call", params: { name: "read", arguments: { drop: true } } });+ const reply = await answer();+ expect(reply.error).toEqual({ code: -32603, message: "event stream ended without the response" });+ });+it("says when the remote server cannot be reached", async () => {fixture = await remoteFixture("http");start(gateServer({ name: "notes", server: fixture.spec, budget: 0, threadId: "fixture", toolScope: { allow: ["mcp:notes:read"] } })!);diff --git a/server/mcp-remote-proxy.ts b/server/mcp-remote-proxy.tsindex dc5f611b60..09813c8336 100644--- a/server/mcp-remote-proxy.ts+++ b/server/mcp-remote-proxy.ts@@ -336,6 +336,7 @@ async function handle(message: Json): Promise<void> {else if (failure instanceof McpHttpError && failure.status === 401) error(message.id, -32603, CREDENTIALS_REFUSED);else if (failure instanceof McpHttpError && failure.kind === "status" && !signal.aborted) error(message.id, -32603, remoteStatusText(failure.status));else if (failure instanceof McpHttpError && failure.kind === "network" && failure.message === "request failed" && !signal.aborted) error(message.id, -32603, "Could not reach this MCP server. Check its URL and that it is online.");+ else if (failure instanceof McpHttpError && failure.kind === "protocol" && !signal.aborted) error(message.id, -32603, remoteErrorText(failure.message));else error(message.id, signal.aborted ? -32800 : -32603, signal.aborted ? "MCP request cancelled" : "Remote MCP request failed");} finally { pending.delete(id); }}