Skip to content
mengfung.com
til

In the MCP Python SDK 2.x, FastMCP is called MCPServer

 ·  1 min read

In version 2 of the MCP Python SDK, FastMCP is called MCPServer, and it moved to a new module. Most MCP tutorials still start with the old import, and on mcp 2.x it fails straight away:

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 module is still there, but all it does is raise that error, so v1 code gets a hint instead of a bare import failure. For a simple server the fix is two lines:

# mcp 1.x
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("kb")

# mcp 2.x
from mcp.server.mcpserver import MCPServer
mcp = MCPServer("kb")

In my server, @mcp.tool(), @mcp.prompt() and mcp.run() all worked unchanged after the rename. The error message warns that other APIs changed too, so read the migration guide before porting anything bigger.

One change in behavior: for an error you expect, like a bad argument, raise ToolError from mcp.server.mcpserver.exceptions. The client then sees your message. Any other exception is treated as a crash: the client only gets “Error executing tool read_document”, and the server logs a full traceback.

Not ready to port? Pin "mcp<2" in your dependencies.