Repository navigation
fix(mcp): support mcp SDK v2 alongside v1 - #68
Merged
Merged
Conversation
The mcp extra declared mcp>=1.0.0 with no upper bound. mcp 2.x renamed FastMCP to MCPServer and moved it to mcp.server.mcpserver, so a fresh install resolving mcp 2.x made the import fail silently and is_available() report the MCP integration as unusable. - Add a v1/v2 import fallback for FastMCP/Context in server.py, resources.py, and tools.py. - mcp 2.x rejects Context injection on resources with no URI template variables. Pass the toolbar's MCPContext into register_resources directly instead of reading it off ctx.request_context.lifespan_context, removing the need for a ctx parameter on the two static resources (debug://requests, debug://config). - Drop a get_config() reference to a non-existent DebugToolbarConfig.slow_request_threshold_ms attribute that always raised AttributeError when the resource was read; surfaced once the MCPContext type flowed through more precisely after the refactor above. - Raise the mcp lower bound to the oldest version that actually imports cleanly against currently resolvable pydantic (1.21.1); mcp>=1.0.0 through 1.21.0 fail to import under a fresh resolve. Verified end-to-end over stdio with an mcp ClientSession (list_tools, call_tool, list_resources, read_resource) against both mcp 1.22.0 (locked) and mcp 2.3.0 (throwaway uv --with env).
JacobCoffee
enabled auto-merge (squash)
October 11, 2026 01:07
Contributor
|
Merged
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 was wrong
The
mcpextra declaredmcp>=1.0.0with no upper bound. mcp 2.x renamedFastMCPtoMCPServerand moved it tomcp.server.mcpserver, so a fresh install that resolves mcp 2.x made thefrom mcp.server.fastmcp import FastMCPimport fail silently, anddebug_toolbar.mcp.is_available()reported the MCP integration as unusable.Separately, mcp 2.x rejects
Contextinjection on resources whose URI has no template variables, which our two static resources (debug://requests,debug://config) relied on to reach toolbar storage.What changed
mcp.server.fastmcp.FastMCP/Context, falling back tomcp.server.mcpserver.MCPServer/Context) inserver.py,resources.py, andtools.py, guarded withTYPE_CHECKINGso the type checker still sees a concreteFastMCPtype.create_mcp_servernow builds the sharedMCPContextonce and passes it directly intoregister_resources, instead of resources reading it offctx.request_context.lifespan_context. This removes the need for actx: Contextparameter on the two static resources, which is what mcp 2.x rejected.get_config()reference to a non-existentDebugToolbarConfig.slow_request_threshold_msattribute, which always raisedAttributeErrorwhen that resource was read (surfaced bytyonceMCPContext's type flowed through more precisely after the above refactor).mcplower bound from>=1.0.0to>=1.21.1: every mcp release from 1.0.0 through 1.21.0 fails to import against a freshly resolved (current) pydantic, so the old floor was dishonest.ctx, because such handlers are registered as templates with 0 matched URI vars rather than as real static resources).How verified
uv run pytest tests/unit/mcp/— 50 passed, 1 skipped, against the locked mcp 1.22.0.uv run --with 'mcp==2.3.0'env — 50 passed, 1 skipped.make ci(lint, fmt, type-check, tests, docs) passes.mcp.ClientSession(spawningpython -m debug_toolbar.mcp), callinglist_tools/call_tool/list_resources/read_resource, against both mcp 1.22.0 and mcp 2.3.0.examples/mcp_server_example.py'screate_app()still builds the Litestar app; notests/examples/suite exists yet on main (PR test: add tests for example apps #65 not merged).