fix(http): plumb per-request auth user into handler state#9
Merged
Conversation
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.
nuttycom
reviewed
May 27, 2026
nuttycom
left a comment
There was a problem hiding this comment.
post-hoc ACK, thank you for the quick merge!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This fixes a JWT HTTP transport identity bug where
mcp_handler_initonly ran for the firstinitializerequest against the process-wideMCPServerState, 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:
mcp_current_userafter each handler runProcessClientInputcontinuations with the originating request userThis also fixes the Docker CI build so it uses the committed
cabal.project.freezedependency plan and installspkg-config, which the frozenzlibflags require.Credit
Original patch provided by Kris Nuttycombe (@nuttycom).
Validation
cabal test allmcp-types: 101 examples, 0 failuresmcp: 82 examples, 0 failures26519296957