Repository navigation
AB#3134 Migrate to the mcp 2.0 SDK (FastMCP -> MCPServer) - #3
Merged
Merged
Conversation
Lifts the mcp<2 cap added alongside AB#3132. mcp 2.0 removed `mcp.server.fastmcp` outright and renamed the high-level server class FastMCP -> MCPServer, now exported from `mcp.server`. That rename is essentially the whole migration: the @mcp.tool / @mcp.resource / @mcp.prompt decorators keep their signatures AND still return the plain undecorated function, so the 25 tool bodies, their descriptions and their generated schemas are untouched, and the tests that call tools directly keep working. Two real API changes: - HTTP transports take host/port as run() keyword arguments, forwarded to run_streamable_http_async / run_sse_async. Under 1.x you mutated mcp.settings before calling run(). __main__.py updated; the CLI flags are unchanged. - MCPServer accepts `version`, which FastMCP had no equivalent for, so the server now reports its own version in serverInfo instead of leaving it blank. Verified beyond the test suite, because pytest here runs against a fake bridge and never exercises the protocol layer: - Registration compared name-for-name against the 1.x baseline in a detached worktree at origin/main: 25 tools, 4 resources, 2 prompts, identical names, descriptions and schemas (including the AB#3123 `generator` output schema). - Live MCP initialize handshake over stdio - the same check release.yml runs against the packed .exe - returns a serverInfo block identifying modelchoice-mcp 0.0.31. - streamable-http boots and honours a custom --host/--port, covering the one code path that changed and that neither pytest nor the stdio check touches. - ruff + mypy + pytest green (79 passed, 2 skipped). uv.lock re-locked to mcp 2.0.0; CI's --locked sync keeps it honest. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Lifts the
mcp<2cap added alongside AB#3132.mcp 2.0 removed
mcp.server.fastmcpoutright and renamed the high-level server classFastMCP→MCPServer, now exported frommcp.server. That rename is essentially the whole migration: the@mcp.tool/@mcp.resource/@mcp.promptdecorators keep their signatures and still return the plain undecorated function, so the 25 tool bodies, their descriptions and their generated schemas are untouched — and the tests that call tools directly keep working.Two real API changes
from mcp.server.fastmcp import FastMCPfrom mcp.server import MCPServermcp.settingsbeforerun()run(transport=..., host=..., port=...)MCPServeralso acceptsversion, whichFastMCPhad no equivalent for, so the server now reports its own version inserverInfoinstead of leaving it blank. CLI flags (--transport,--host,--port) are unchanged.Verification
pytest here runs against a fake bridge and never exercises the protocol layer, so the suite passing is necessary but nowhere near sufficient. Also checked:
origin/main: 25 tools, 4 resources, 2 prompts — identical names, descriptions and schemas, including the AB#3123generatoroutput schema. (25/4/2 matches the decorator count exactly; an earlier 27/5/4 grep was counting docstring mentions.)initializehandshake over stdio — the same checkrelease.ymlruns against the packed.exe:--host/--port(Uvicorn running on http://127.0.0.1:8931) — the one code path that changed and that neither pytest nor the stdio check touches.uv.lockre-locked to mcp 2.0.0; CI's--lockedsync keeps it honest.Note
The major-version cap stays, now as
mcp>=2,<3. mcp 2.0 arriving unannounced is exactly what brokemainin the first place.