Support mcp 2.x (FastMCP -> MCPServer); stop skipping a broken server import - #8
Merged
Merged
Conversation
… import mcp 2.0.0 (released between 2026-07-22 and 2026-07-29) removed `mcp.server.fastmcp` and renamed FastMCP to MCPServer. `agent_gate.server` imports FastMCP at module scope, so with `mcp>=1.2` now resolving to 2.x the module no longer imports -- which breaks the shipped `agent-gate` console script for anyone installing the package today. CI surfaced this as a coverage failure rather than a test failure because tests/test_server.py swallowed *any* ImportError from `agent_gate.server` into unittest.SkipTest. The 4 server tests skipped silently, server.py fell from 93% to 11%, and the total dropped 96.67% -> 68.89%, tripping --cov-fail-under=90. No Python code changed on the dependabot branch; the only differing input between the 07-22 pass and the 07-29 fail was mcp 1.28.1 -> 2.0.0. - server.py: import MCPServer on 2.x, fall back to FastMCP on 1.x, so the declared `mcp>=1.2` range is honest again for both majors. - test_server.py: skip only when the `mcp` SDK is genuinely absent. If the SDK is installed, an import failure is a real incompatibility and must fail loudly instead of quietly removing server.py from the coverage denominator. Verified locally with the exact CI command on py3.11: mcp 2.2.0 -> 19 passed, 94.62% mcp 1.30.0 -> 19 passed, 96.77% Coverage threshold unchanged at 90; no tests removed. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
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.
Why
Dependabot #7 (actions bumps only) fails the coverage gate at 68.89% against 90. The same branch passed on 2026-07-22 and has failed since 2026-07-29. Diffing those two CI runs: identical Python 3.11.15, pytest 9.1.1, pytest-cov 7.1.0, coverage 7.15.2. The only difference is
mcp1.28.1 -> 2.0.0.mcp 2.0 removed
mcp.server.fastmcpand renamedFastMCPtoMCPServerundermcp.server.mcpserver.agent_gate/server.pystopped importing, andtests/test_server.pyconverted thatImportErrorinto aSkipTest, silently dropping the 4 server tests.server.pywent from 93% to 11% covered with every test green. Thecoveragejob passed because it runscoverage reportwith no--fail-under.This also means the published
agent-gateconsole script has been broken for anyone installing with a currentmcpsince late July, so the fix is to the package, not just to CI.What
agent_gate/server.py: try the 2.x import, fall back toFastMCPon 1.x.MCPServeris drop-in for everything this module uses (positional name,.name,.tool()returning the undecorated function,.run()default stdio). Verifiedlist_tools()and acall_tool('verify_gate', ...)round-trip produce identical output on mcp 1.30.0 and 2.2.0.tests/test_server.py: skip only whenimport mcpitself fails. With the SDK present, a brokenagent_gate.serverimport is now 4 real failures namingModuleNotFoundError, not 4 silent skips. Verified by swapping the oldserver.pyback in against the new test.--cov-fail-under=90untouched, no tests removed. The declaredmcp>=1.2stays true across both majors (mcp.server.fastmcpfirst shipped in 1.2.0).Verification (local, py3.11)
Coverage lands at ~95 rather than the old 97: the two new lines are the 1.x fallback branch, which CI (latest mcp) does not execute. Reviewer follow-ups not included here: a CI matrix leg on
mcp<2to exercise the fallback, one async test throughlist_tools/call_tool, and re-raising when the 2.x import fails for a reason other than the module being absent.🤖 Generated with Claude Code