fix: support MCP Python SDK 2.0 (FastMCP import moved) - #4
Open
jf3300 wants to merge 1 commit into
Open
Conversation
mcp-server-bwt depends on an unpinned "mcp[cli]" dependency. As of
mcp==2.0.0, mcp.server.fastmcp.FastMCP was removed/relocated, so any
fresh install (e.g. via uvx) now crashes on startup:
Traceback (most recent call last):
File "mcp_server_bwt/main.py", line 2, in <module>
from mcp.server.fastmcp import FastMCP
ModuleNotFoundError: No module named "mcp.server.fastmcp"
In mcp>=2.0.0 the class lives at mcp.server.mcpserver.MCPServer and
exposes the same .tool() decorator and .run(transport=...) API used
here, so this adds a small compatibility shim
(mcp_server_bwt/_mcp_compat.py) that imports FastMCP from the old
location when available and falls back to MCPServer under the new
location, and updates the two call sites to import from the shim.
No dependency pin change needed since the shim supports both SDK
generations.
Tested: pip-installed this package with mcp<2.0.0 and with mcp==2.0.0
in separate venvs; ran `python -m mcp_server_bwt.main` with
BING_WEBMASTER_API_KEY=dummy under both and confirmed the process
starts and idles on stdio instead of crashing. Reverting the fix
reproduces the exact ModuleNotFoundError above under mcp==2.0.0.
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.
Problem
Under
mcp>=2.0.0the server crashes at startup:(traceback observed via a
uvxinstall, sincepyproject.tomldepends on unpinnedmcp[cli]anduvresolves to the 2.x line.) This breaks the server for any fresh install as of the SDK 2.0.0 release.Cause
SDK 2.0 moved/renamed
mcp.server.fastmcp.FastMCPtomcp.server.mcpserver.MCPServer(same.tool()decorator and.run(transport=...)API).Fix
Small compatibility shim
_mcp_compat.pythat imports whichever is available; the two call sites (main.pyandtools/bing_webmaster.py) now import from the shim. Works on SDK 1.x and 2.x, no dependency pin needed.Testing
Editable installs in clean venvs with
mcp1.29.0 andmcp2.0.0 — server starts and idles on stdio in both. Reverting the fix and testing under 2.0.0 reproduces the crash.