mcp Python SDK 2.x: "ModuleNotFoundError: No module named 'mcp.server.fastmcp'" for old FastMCP code: it was renamed to MCPServer (from mcp.server.mcpserver import MCPServer)
Fix: either change the imports to the 2.x names or pin mcp<2. The rename is mechanical:
# mcp 1.x
from mcp.server.fastmcp import FastMCP
from mcp.server.fastmcp.exceptions import ToolError
mcp = FastMCP("nessie-banking")
# mcp 2.x
from mcp.server.mcpserver import MCPServer
from mcp.server.mcpserver.exceptions import ToolError
mcp = MCPServer("nessie-banking")@mcp.tool() / @mcp.resource(...) decorators and mcp.run() keep working after the rename.
Symptom: a requirements.txt with mcp>=1.0.0 installed mcp 2.3.0 into a fresh python:3.12-slim image, and a server written from 1.x tutorials (an MCP wrapper around the Nessie banking API) died at import:
ModuleNotFoundError: No module named 'mcp.server.fastmcp'. This is mcp 2.x, where FastMCP was renamed to MCPServer (from mcp.server.mcpserver import MCPServer) and other APIs changed; see the migration guide at https://py.sdk.modelcontextprotocol.io/v2/migration/#fastmcp-renamed-to-mcpserver or pin 'mcp<2' to keep running v1 code.The test client then only reported MCPError: Connection closed, because the stdio server process exited before initialize.
Cause: an open-ended mcp>=1.0.0 floats to the 2.x major, which renamed FastMCP and changed other APIs. After fixing this import, expect the other 2.x breaks next: the decorator API on the low-level Server (@server.list_tools()) is gone, client result models use snake_case (input_schema, is_error), MCPServer(host=...) is rejected, and streamable_http_app() takes keyword-only options.
Verify: python -c "import mcp.server.mcpserver as m; print(m.MCPServer)" inside the image, and pip show mcp to see which major you actually got. If you keep 1.x code, pin mcp>=1.2,<2 so a rebuild doesn't break.