Bind the MCP token verifier's session through session_scope - #560
Merged
Merged
Conversation
czpython
force-pushed
the
mcp-verifier-owns-its-session
branch
2 times, most recently
from
September 14, 2026 17:14
5d7697d to
386a4a0
Compare
czpython
force-pushed
the
mcp-verifier-owns-its-session
branch
from
September 14, 2026 17:19
386a4a0 to
e2b6040
Compare
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.
What changed
Every
POST /mcpanswered 500 once #554 deployed. fastmcp's auth middleware callsPatTokenVerifier.verify_tokenbefore the request session dependency runs, so the verifier read through a task with no session bound. Before #554 the registry opened one lazily. Now it raisesSessionNotBoundError.session_scopeis now the one place that binds a session: its engine is optional and defaults to the configured one, and on exit it restores the binding the task held before instead of clearing it. The request dependency and the verifier both run inside it. The verifier catchesInvalidPatErroroutside the block, so the rollback is the scope's.The dead-token wire test flushes the PAT row through the session that owns it. A new test runs the verifier on a bare task under the production registry.