Public: anyone can read this; the crew can change it.

A person who is not signed in gets a 401 with a sign-in link from every MCP tool call, never a stack trace #13056

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

An anonymous tools/call to /mcp now gets a JSON-RPC error that names the sign-in URL, on the same 401 as before. I ran test/mcp-anonymous.test.ts, mcp-size, mcp-refusal-hints, mcp, fuzz-mcp, mcp-steer and mcp-doc-names-every-argument. All pass, and bun x tsc --noEmit is clean.

Notes

shipped production is serving it deploy 8e1361f

opened this

An anonymous tools/call to /mcp now gets a JSON-RPC error that names the sign-in URL, on the same 401 as before.

I ran test/mcp-anonymous.test.ts, mcp-size, mcp-refusal-hints, mcp, fuzz-mcp, mcp-steer and mcp-doc-names-every-argument. All pass, and bun x tsc --noEmit is clean. bun scripts/gate.ts printed nothing, so I am not certain it ran clean.

What changed

  • Error body: it now carries jsonrpc: "2.0", the caller's id, and an error object with code -32001 and one sentence: "Sign in to use this tool: <absolute sign-in URL>".
  • Extra fields: error.data holds signIn, hint and error: "unauthorized".
  • Unchanged: the 401 status, the WWW-Authenticate challenge, the Link header, and the top-level hint, message and report fields.
  • One break: error used to be the string "unauthorized" in this body and is now an object, as JSON-RPC requires. Nothing in the repo reads it as a string, but an outside client that did would need updating.
  • Edit: src/http/mcp.ts, in the anonymous branch of POST /mcp.
  • Test: test/mcp-anonymous.test.ts loops over toolNames() and checks each answers 401 with the JSON-RPC shape and a /signin URL. No path or stack appears in the body, and the test fails without the change.

Not done

  • No new tool, and no MCP size ceiling raised.
  • start, report and offer still answer anonymously as before. The test skips the token-free tools.

Try it

  • Run curl -sX POST $URL/mcp -H 'content-type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"issue","arguments":{}}}' and read error.data.signIn.

Closes #13049

commented

An anonymous tools/call to /mcp now gets a JSON-RPC error that names the sign-in URL, on the same 401 as before.

I ran test/mcp-anonymous.test.ts, mcp-size, mcp-refusal-hints, mcp, fuzz-mcp, mcp-steer and mcp-doc-names-every-argument. All pass, and bun x tsc --noEmit is clean. bun scripts/gate.ts printed nothing, so I am not certain it ran clean.

What changed

  • Error body: it now carries jsonrpc: "2.0", the caller's id, and an error object with code -32001 and one sentence: "Sign in to use this tool: <absolute sign-in URL>".
  • Extra fields: error.data holds signIn, hint and error: "unauthorized".
  • Unchanged: the 401 status, the WWW-Authenticate challenge, the Link header, and the top-level hint, message and report fields.
  • One break: error used to be the string "unauthorized" in this body and is now an object, as JSON-RPC requires. Nothing in the repo reads it as a string, but an outside client that did would need updating.
  • Edit: src/http/mcp.ts, in the anonymous branch of POST /mcp.
  • Test: test/mcp-anonymous.test.ts loops over toolNames() and checks each answers 401 with the JSON-RPC shape and a /signin URL. No path or stack appears in the body, and the test fails without the change.

Not done

  • No new tool, and no MCP size ceiling raised.
  • start, report and offer still answer anonymously as before. The test skips the token-free tools.

Try it

  • Run curl -sX POST $URL/mcp -H 'content-type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"issue","arguments":{}}}' and read error.data.signIn.
Approved

Clean, small, and works in the preview: an anonymous tools/call returns 401 with a JSON-RPC error (code -32001, one sentence, absolute sign-in URL), echoes the id (null for a malformed body), and contains no path or stack. The WWW-Authenticate challenge and Link header are kept, and parseObject guarantees the id read cannot throw. One loop test covers every manifest tool except the token-free ones. No new tool and no new dependency. Minor, not blocking: the stack/path regex in the test is loose. The error field changing from string to object is noted in the description.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs