Skip to content

Bind the MCP token verifier's session through session_scope - #560

Merged
czpython merged 1 commit into
mainfrom
mcp-verifier-owns-its-session
Sep 14, 2026
Merged

czpython merged 1 commit into
mainfrom
mcp-verifier-owns-its-session

Conversation

@czpython

@czpython czpython commented Sep 14, 2026

Copy link
Copy Markdown
Owner

What changed

Every POST /mcp answered 500 once #554 deployed. fastmcp's auth middleware calls PatTokenVerifier.verify_token before 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 raises SessionNotBoundError.

session_scope is 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 catches InvalidPatError outside 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.

@czpython czpython changed the title Bind the MCP token verifier's own database session Bind the MCP token verifier's session through session_scope Sep 14, 2026
@czpython
czpython force-pushed the mcp-verifier-owns-its-session branch 2 times, most recently from 5d7697d to 386a4a0 Compare September 14, 2026 17:14
@czpython
czpython force-pushed the mcp-verifier-owns-its-session branch from 386a4a0 to e2b6040 Compare September 14, 2026 17:19
@czpython
czpython merged commit 09204a0 into main Sep 14, 2026
2 of 3 checks passed
@czpython
czpython deleted the mcp-verifier-owns-its-session branch September 14, 2026 17:24
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.

1 participant