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

An MCP client with no token can initialize and list tools, and sees the five token-free ones #13899

Merged opened this

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

Merged

A client with no token can now start an MCP session over POST /mcp. Type check and the MCP tests I ran pass. I did not run the full suite or bun scripts/design-lint.ts; the forge runs the full check on push.

Notes

opened this

A client with no token can now start an MCP session over POST /mcp. Type check and the MCP tests I ran pass. I did not run the full suite or bun scripts/design-lint.ts; the forge runs the full check on push.

What changed

  • src/http/mcp.ts has a new openSession step in the anonymous branch.
    • initialize and ping answer 200.
    • tools/list answers with exactly the five TOKEN_FREE_TOOLS and their schemas: report, offer, start, explore, search.
    • Any notifications/* message gets a 202, so notifications/initialized works.
  • I did not widen the free list. It still comes from TOKEN_FREE_TOOLS, the list /.well-known/mcp.json prints.
  • Signed-in and token callers take the old path and still see the full list.
  • Every other anonymous method (for example resources/list) still answers 401 with the -32001 sign-in error and the OAuth challenge. So does a tools/call of any tool that is not token-free.
  • initialize for a stranger returns a short instruction naming the free tools. Its capabilities leave out resources.
  • A signed-in browser cookie still isn't a way in, but a tools/list on it now gets the free list instead of a 401.

Tests

  • New test/mcp-anonymous-session.test.ts covers the initialize, notifications/initialized, ping, tools/list, tools/call explore sequence and the refusals.
  • Three old assertions expected an anonymous tools/list to answer 401: two in test/mcp.test.ts and the probe in test/mcp-discovery-walk.test.ts. They now use resources/list as the not-free method, so they still check the 401 and the OAuth challenge.
  • bun x tsc --noEmit, test/mcp-size.test.ts, test/mcp-anonymous.test.ts and test/mcp-tools.test.ts pass. So do test/mcp-hints-parity.test.ts, the new test and the edited ones.
  • bun scripts/gate.ts --fix rewrapped comments in one file. I committed the tree after it ran, so that rewrap is in the first commit.

Left out

  • An anonymous client gets no resources capability and no paging for tools/list, because five tools fit in one page.

Try it

curl -s localhost:PORT/mcp -H 'content-type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'

Closes #13882

2 earlier comments
commented

A client with no token can now start an MCP session over POST /mcp. Type check and the MCP tests I ran pass. I did not run the full suite or bun scripts/design-lint.ts; the forge runs the full check on push.

What changed

  • src/http/mcp.ts has a new openSession step in the anonymous branch.
    • initialize and ping answer 200.
    • tools/list answers with exactly the five TOKEN_FREE_TOOLS and their schemas: report, offer, start, explore, search.
    • Any notifications/* message gets a 202, so notifications/initialized works.
  • I did not widen the free list. It still comes from TOKEN_FREE_TOOLS, the list /.well-known/mcp.json prints.
  • Signed-in and token callers take the old path and still see the full list.
  • Every other anonymous method (for example resources/list) still answers 401 with the -32001 sign-in error and the OAuth challenge. So does a tools/call of any tool that is not token-free.
  • initialize for a stranger returns a short instruction naming the free tools. Its capabilities leave out resources.
  • A signed-in browser cookie still isn't a way in, but a tools/list on it now gets the free list instead of a 401.

Tests

  • New test/mcp-anonymous-session.test.ts covers the initialize, notifications/initialized, ping, tools/list, tools/call explore sequence and the refusals.
  • Three old assertions expected an anonymous tools/list to answer 401: two in test/mcp.test.ts and the probe in test/mcp-discovery-walk.test.ts. They now use resources/list as the not-free method, so they still check the 401 and the OAuth challenge.
  • bun x tsc --noEmit, test/mcp-size.test.ts, test/mcp-anonymous.test.ts and test/mcp-tools.test.ts pass. So do test/mcp-hints-parity.test.ts, the new test and the edited ones.
  • bun scripts/gate.ts --fix rewrapped comments in one file. I committed the tree after it ran, so that rewrap is in the first commit.

Left out

  • An anonymous client gets no resources capability and no paging for tools/list, because five tools fit in one page.

Try it

curl -s localhost:PORT/mcp -H 'content-type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
commented

The fix is pushed (14742b650) and pull #13899 now points at it. The first push reported "the remote end hung up", but it had gone through. I haven't seen the forge's check re-run on it yet.

What changed

  • A request that carries an Authorization header no longer gets the anonymous initialize, ping or tools/list answers. A garbage, expired or revoked token now gets 401 with invalid_token and the plain challenge, as before. That cleared the revoke, expiry, grant and invalid_token failures in oauth-revoke, oauth-grants and oauth-challenge.
  • Three tests asserted that a bare /mcp call with no token gets 401, using initialize or tools/list, which a stranger can now call on purpose. I moved them to resources/list, which stays refused: oauth-challenge, report-discovery and tesla-journey. The tests were wrong here, not the code.
  • I also fixed a missing space in const ANON_HINT ="…".

Checked here

  • The oauth, report-discovery, tesla-journey, mcp and mcp-anonymous-session suites pass (90 tests). bun x tsc --noEmit and bun scripts/gate.ts --fix are clean.
  • The take-expect fast-forward failure from shard 6 passes when I run it alone (5 of 5). I treated it as flaky and changed nothing for it.

Left out

  • Anonymous tools/call for tools outside the five token-free ones still gets the sign-in refusal.
commented

All three review points are addressed and pushed to #13899 (6863183fe). The MCP and anonymous-session suites pass (52 tests), tsc --noEmit is clean, and gate.ts --fix changed nothing. I did not run the other suites this time.

  • Header guard test: a request with Authorization: Bearer forge_nonsense and initialize, ping or tools/list now has a test in test/mcp-anonymous-session.test.ts. Each must answer 401 with error="invalid_token". It fails without the guard, because those three methods would otherwise get the anonymous answers.
  • Double filter: tools/list in openSession now filters by TOKEN_FREE_TOOLS once, in src/http/mcp.ts.
  • Cookie caller: a signed-in browser session sending tools/list gets 200 with exactly the five token-free tools, not 401 and not the full list. A test in test/mcp.test.ts pins that. I kept this on purpose: a cookie still isn't a way in to /mcp, so it is treated as a stranger. A caller who wants the full list sends a token.

I disagree with nothing in the review.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs