Skip to content

fix: return 404 instead of 401 for terminated sessions - #57

Draft
felixweinberger wants to merge 1 commit into
mainfrom
claude/festive-dirac-yr51dy
Draft

felixweinberger wants to merge 1 commit into
mainfrom
claude/festive-dirac-yr51dy

Conversation

@felixweinberger

Copy link
Copy Markdown

Summary

/mcp returned 401 for a session that had ended (5 min idle timeout, DELETE, server restart). The spec says the server MUST return 404 so the client starts a new session. With 401, clients retry auth with a token that is still valid and never recover.

  • The response now matches what the SDK transport sends: 404, -32001, Session not found.
  • Another user's session also gets that 404, so the response doesn't reveal which session IDs are live.
  • An invalid token still gets 401 with WWW-Authenticate.

Fixes #11

Test plan

  • npm run build, npm run lint, npm test pass. The new tests fail on main (401 received). Run locally with the example app servers at 2.0.3 rather than the locked 2.0.4; they aren't on this path.
  • Ran the server against Redis with curl: 404 after DELETE, after the real idle timeout, after a restart, for an unknown ID and for another user. Re-initializing with the same token works.
  • Not tested with Cursor, the client in Client continuously sends requests after server restart, causing 401 Unauthorized #11.

Generated by Claude Code

The spec requires HTTP 404 for a request that carries a terminated
session ID, so the client knows to re-initialize. A 401 made clients
retry auth with a token that was still valid.

Another user's session gets the same 404, so the response does not
reveal which session IDs are live.

Co-authored-by: fweinberger <fweinberger@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Client continuously sends requests after server restart, causing 401 Unauthorized

2 participants