Skip to content

MCP examples are broken with the mcp version installed by the SDK (mcp.server.fastmcp removed in mcp 2.x) #175

Description

@maux99

Summary

examples/getting_started/mcp_tools.py fails at import time on a clean install
from PyPI. The MCP example resource imports mcp.server.fastmcp, which no
longer exists in mcp 2.x — it was renamed to mcp.server.mcpserver
(FastMCPMCPServer).

Because pyproject.toml declares mcp>=1.0 with no upper bound, a fresh
pip install google-antigravity resolves to mcp==2.0.0, so the shipped MCP
examples cannot run on any platform with a clean environment.

Environment

  • google-antigravity 0.1.12 (installed from PyPI)
  • mcp 2.0.0 (resolved automatically as a transitive dependency)
  • Python 3.12.10
  • Windows 11 — but the failure is platform-independent, it happens at import

Reproduction

python -m venv .venv
.venv/bin/pip install google-antigravity        # pulls mcp==2.0.0
export GEMINI_API_KEY="..."
python ./examples/getting_started/mcp_tools.py

Actual result

Traceback (most recent call last):
  File "examples/getting_started/mcp_tools.py", line 40, in <module>
    from resources import mcp_server
  File "examples/resources/mcp_server.py", line 25, in <module>
    from mcp.server.fastmcp import server
ModuleNotFoundError: No module named 'mcp.server.fastmcp'

Expected result

The example runs and demonstrates the stdio / SSE / streamable-HTTP transports.

Root cause

  • pyproject.toml:40 declares "mcp>=1.0" — unbounded, so 2.x is selected.
  • examples/resources/mcp_server.py:25 imports mcp.server.fastmcp, and
    :31/:35 reference server.FastMCP. Both were removed in mcp 2.0.

This affects all three transports in mcp_tools.py, since they all import
the same helper module.

Suggested fix

Either cap the dependency (mcp>=1.0,<2) or, preferably, update the example to
the 2.x API:

from mcp.server.mcpserver import MCPServer

mcp = MCPServer(name="Pirate Math")

@mcp.tool()
def pirate_multiply(a: int, b: int) -> str:
    ...

I verified the 2.x API works with the SDK: an in-process MCPServer served over
streamable HTTP connects fine via types.McpStreamableHttpServer, tool calls
execute, and policy.allow(server, [...]) / policy.deny(server, [...]) behave
as documented. So only the example needs porting — the SDK's MCP support itself
is fine.

Secondary issue in the same file

examples/getting_started/mcp_tools.py hardcodes command="python3" (lines 52,
92, 123) to spawn the stdio server. On Windows python3 is typically absent, and
when present as a Store alias it points at the system interpreter rather than the
virtualenv running the example — which will not have mcp installed. Using
sys.executable would make the stdio transport portable.

Minor observation

MCPServer calls logging.basicConfig(level=INFO)
(mcp/server/mcpserver/utilities/logging.py:39), which raises the root log
level for the whole process. That makes the SDK's
logging.info("RAW WS MSG: %s", raw_msg) (local_connection.py:521) flood
stdout for anyone using MCP. Not an SDK bug, but demoting that line to DEBUG
would spare users a lot of noise.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions