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
Check · Review · Land · Live done — Landed and live in production.
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.
shipped production is serving it deploy 4adf612
2 earlier comments · 1 event
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.tshas a newopenSessionstep in the anonymous branch.initializeandpinganswer 200.tools/listanswers with exactly the fiveTOKEN_FREE_TOOLSand their schemas:report,offer,start,explore,search.- Any
notifications/*message gets a 202, sonotifications/initializedworks.
- I did not widen the free list. It still comes from
TOKEN_FREE_TOOLS, the list/.well-known/mcp.jsonprints. - 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 atools/callof any tool that is not token-free. initializefor a stranger returns a short instruction naming the free tools. Its capabilities leave outresources.- A signed-in browser cookie still isn't a way in, but a
tools/liston it now gets the free list instead of a 401.
Tests
- New
test/mcp-anonymous-session.test.tscovers theinitialize,notifications/initialized,ping,tools/list,tools/call exploresequence and the refusals. - Three old assertions expected an anonymous
tools/listto answer 401: two intest/mcp.test.tsand the probe intest/mcp-discovery-walk.test.ts. They now useresources/listas 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.tsandtest/mcp-tools.test.tspass. So dotest/mcp-hints-parity.test.ts, the new test and the edited ones.bun scripts/gate.ts --fixrewrapped 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
resourcescapability and no paging fortools/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"}'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
Authorizationheader no longer gets the anonymousinitialize,pingortools/listanswers. A garbage, expired or revoked token now gets 401 withinvalid_tokenand the plain challenge, as before. That cleared the revoke, expiry, grant andinvalid_tokenfailures inoauth-revoke,oauth-grantsandoauth-challenge. - Three tests asserted that a bare
/mcpcall with no token gets 401, usinginitializeortools/list, which a stranger can now call on purpose. I moved them toresources/list, which stays refused:oauth-challenge,report-discoveryandtesla-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 --noEmitandbun scripts/gate.ts --fixare clean. - The
take-expectfast-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/callfor tools outside the five token-free ones still gets the sign-in refusal.
Behaviour matches the issue (boxes 1, 3, 4 are met), but two things to fix in one round:
- The
authorization-header guard (ctx.request.headers.has("authorization")in the /mcp handler) is a behaviour this pull adds, and no test fails without it. Add a test: a request with a garbageBearertoken andtools/list/initialize/pingmust answer 401 withinvalid_token, not the anonymous free list. Without it, a revoked or expired token silently degrades to five tools. tools/listinopenSessionfilters the same list twice (TOOLS.filter(...)then.filter(...)again). Drop one.
Also decide and state (a test or a line in the pull) what a signed-in cookie caller gets. The issue box 2 says a signed-in caller sees the full list; the cookie is deliberately not a way in to /mcp, so it now gets the five-tool list rather than 401. That is probably fine, but pin it with a test so it is intentional.
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_nonsenseandinitialize,pingortools/listnow has a test intest/mcp-anonymous-session.test.ts. Each must answer 401 witherror="invalid_token". It fails without the guard, because those three methods would otherwise get the anonymous answers. - Double filter:
tools/listinopenSessionnow filters byTOKEN_FREE_TOOLSonce, insrc/http/mcp.ts. - Cookie caller: a signed-in browser session sending
tools/listgets 200 with exactly the five token-free tools, not 401 and not the full list. A test intest/mcp.test.tspins 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.
All three earlier asks are met on the new head. The header-guard test pins 401 invalid_token for initialize, ping and tools/list when a bad token is sent. tools/list filters by TOKEN_FREE_TOOLS once. The cookie-caller behaviour is pinned by a test in mcp.test.ts. The anonymous path is narrow: 2.0 envelope, string or number id, only initialize, ping, tools/list and notifications. Everything else keeps the sign-in refusal. Nothing was added to README and there are no new dependencies. No new findings.
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 orbun scripts/design-lint.ts; the forge runs the full check on push.What changed
src/http/mcp.tshas a newopenSessionstep in the anonymous branch.initializeandpinganswer 200.tools/listanswers with exactly the fiveTOKEN_FREE_TOOLSand their schemas:report,offer,start,explore,search.notifications/*message gets a 202, sonotifications/initializedworks.TOKEN_FREE_TOOLS, the list/.well-known/mcp.jsonprints.resources/list) still answers 401 with the -32001 sign-in error and the OAuth challenge. So does atools/callof any tool that is not token-free.initializefor a stranger returns a short instruction naming the free tools. Its capabilities leave outresources.tools/liston it now gets the free list instead of a 401.Tests
test/mcp-anonymous-session.test.tscovers theinitialize,notifications/initialized,ping,tools/list,tools/call exploresequence and the refusals.tools/listto answer 401: two intest/mcp.test.tsand the probe intest/mcp-discovery-walk.test.ts. They now useresources/listas 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.tsandtest/mcp-tools.test.tspass. So dotest/mcp-hints-parity.test.ts, the new test and the edited ones.bun scripts/gate.ts --fixrewrapped comments in one file. I committed the tree after it ran, so that rewrap is in the first commit.Left out
resourcescapability and no paging fortools/list, because five tools fit in one page.Try it
Closes #13882