Skip to content

fix(http): plumb per-request auth user into handler state#9

Merged
Tritlo merged 4 commits into
mainfrom
fix/http-per-request-auth-user
May 27, 2026
Merged

fix(http): plumb per-request auth user into handler state#9
Tritlo merged 4 commits into
mainfrom
fix/http-per-request-auth-user

Conversation

@Tritlo

@Tritlo Tritlo commented May 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

This fixes a JWT HTTP transport identity bug where mcp_handler_init only ran for the first initialize request against the process-wide MCPServerState, causing later authenticated HTTP requests to run handlers with state initialized for the first user.

The first commit is the supplied patch, credited to Kris Nuttycombe. Follow-up commits keep that patch separate and add hardening/tests:

  • clears mcp_current_user after each handler run
  • runs ProcessClientInput continuations with the originating request user
  • updates test state constructors for the new field
  • adds a regression test that initializes as one user and verifies a later request sees its own JWT identity

This also fixes the Docker CI build so it uses the committed cabal.project.freeze dependency plan and installs pkg-config, which the frozen zlib flags require.

Credit

Original patch provided by Kris Nuttycombe (@nuttycom).

Validation

  • cabal test all
  • mcp-types: 101 examples, 0 failures
  • mcp: 82 examples, 0 failures
  • Docker CI passed on GitHub Actions run 26519296957

Tritlo added 2 commits May 27, 2026 03:06
The JWT HTTP transport's handleMCPRequestCore invoked the user-supplied mcp_handler_init hook only on the first initialize request to the server-process-wide singleton MCPServerState, after which the authenticated MCPHandlerUser was discarded for every subsequent request.

servant-auth still gated each request, but the identity threaded into tool handlers was permanently that of whoever ran initialize first. In a multi-tenant deployment this meant any authenticated caller transparently impersonated the first-arriving user.

Add mcp_current_user to MCPServerState, set it from the current request while processMethod runs, and expose getCurrentUser for handlers.
Clear mcp_current_user after each handler run and run client-input continuations with the originating request user instead of whatever user last touched shared state.

Update test states for the new field and add an integration tool/test that initializes as one user, then verifies a later request sees its own JWT identity.
@Tritlo Tritlo marked this pull request as ready for review May 27, 2026 14:25
@Tritlo Tritlo merged commit e81ec1b into main May 27, 2026
1 check passed

@nuttycom nuttycom left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

post-hoc ACK, thank you for the quick merge!

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.

2 participants