Skip to content

Support mcp 2.x (FastMCP -> MCPServer); stop skipping a broken server import - #8

Merged
Jott2121 merged 1 commit into
mainfrom
fix/ci-coverage-drop
Sep 15, 2026
Merged

Jott2121 merged 1 commit into
mainfrom
fix/ci-coverage-drop

Conversation

@Jott2121

Copy link
Copy Markdown
Owner

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 mcp 1.28.1 -> 2.0.0.

mcp 2.0 removed mcp.server.fastmcp and renamed FastMCP to MCPServer under mcp.server.mcpserver. agent_gate/server.py stopped importing, and tests/test_server.py converted that ImportError into a SkipTest, silently dropping the 4 server tests. server.py went from 93% to 11% covered with every test green. The coverage job passed because it runs coverage report with no --fail-under.

This also means the published agent-gate console script has been broken for anyone installing with a current mcp since 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 to FastMCP on 1.x. MCPServer is drop-in for everything this module uses (positional name, .name, .tool() returning the undecorated function, .run() default stdio). Verified list_tools() and a call_tool('verify_gate', ...) round-trip produce identical output on mcp 1.30.0 and 2.2.0.
  • tests/test_server.py: skip only when import mcp itself fails. With the SDK present, a broken agent_gate.server import is now 4 real failures naming ModuleNotFoundError, not 4 silent skips. Verified by swapping the old server.py back in against the new test.
  • --cov-fail-under=90 untouched, no tests removed. The declared mcp>=1.2 stays true across both majors (mcp.server.fastmcp first shipped in 1.2.0).

Verification (local, py3.11)

state result
before, mcp 2.2.0 15 passed, 4 skipped, 68.89% FAIL
after, mcp 2.2.0 19 passed, 94.62% PASS
after, mcp 1.30.0 19 passed, 96.77% PASS

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<2 to exercise the fallback, one async test through list_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

… 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>
@github-actions

Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  agent_gate
  server.py 16-17
Project Total  

This report was generated by python-coverage-comment-action

@Jott2121
Jott2121 merged commit ef91c37 into main Sep 15, 2026
6 checks passed
@Jott2121
Jott2121 deleted the fix/ci-coverage-drop branch September 15, 2026 03:51
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