Skip to content

fix: support MCP Python SDK 2.0 (FastMCP import moved) - #4

Open
jf3300 wants to merge 1 commit into
zizzfizzix:mainfrom
jf3300:fix/mcp-sdk-2-compat
Open

fix: support MCP Python SDK 2.0 (FastMCP import moved)#4
jf3300 wants to merge 1 commit into
zizzfizzix:mainfrom
jf3300:fix/mcp-sdk-2-compat

Conversation

@jf3300

@jf3300 jf3300 commented Aug 3, 2026

Copy link
Copy Markdown

Problem

Under mcp>=2.0.0 the server crashes at startup:

ModuleNotFoundError: No module named 'mcp.server.fastmcp'

(traceback observed via a uvx install, since pyproject.toml depends on unpinned mcp[cli] and uv resolves 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.FastMCP to mcp.server.mcpserver.MCPServer (same .tool() decorator and .run(transport=...) API).

Fix

Small compatibility shim _mcp_compat.py that imports whichever is available; the two call sites (main.py and tools/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 mcp 1.29.0 and mcp 2.0.0 — server starts and idles on stdio in both. Reverting the fix and testing under 2.0.0 reproduces the crash.

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.
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