FastMCP changed in mcp 2.3.0
In our sandbox runs up to 2026-10-27, claude-sonnet-5-5, gemini-3.8-flash and gpt-6.1-sol wrote from mcp.server.fastmcp import Context, FastMCP for mcp. It fails on 2.3.0 with ModuleNotFoundError (changed between 1.26.0 and 2.3.0). Use from mcp.server.mcpserver import Context, MCPServer instead.
- What to do
- replace the line
- Output
- same on one example
- Patch
- incomplete: old names remain
- Auto-apply
- not allowed
- Seen in
- 3 models
- Worked / failed
- 10 / 0
- Last verified
- 2026-10-27
What to do
Not for automatic application — after the patch the example still uses FastMCP, which the verified example does not: the patch covers part of the change. Show this correction to the user as a lead. Replace the old line with the new one; the rest of the code can stay.
Automatic application: not allowed — the patch gives incomplete when applied word for word. Automatic application is allowed only when proof.equivalent is true and proof.applicability.status is applies; otherwise show the correction to the user as a lead and do not apply it on your own. The change itself is described by kind (changed); the checks are in proof; neither follows from the other.
How to tell this applies to your code
- mcp version 2.3.0 or newer is installed (checked on 2.3.0; changed between 1.26.0 and 2.3.0).
- Your code uses:
FastMCP,mcp.server.fastmcp - Or it already failed with:
ModuleNotFoundError: No module named 'mcp.server.fastmcp'. This is mcp 2.x, where FastMCP was renamed to MCPServer (from mcp.server.mcpserver(every correction for this error)
Old and new code
from mcp.server.fastmcp import Context, FastMCPfrom mcp.server.mcpserver import Context, MCPServer
Error on 2.3.0:
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 runni
| Script | mcp version | Result |
|---|---|---|
| Code the models wrote | 1.26.0 | works |
| Code the models wrote | 2.3.0 | fails: ModuleNotFoundError |
| Verified example below | 2.3.0 | works |
| Output of the verified example | 2.3.0 | same as the original's on 1.26.0 (observed stdout of one example; not a proof of equivalent behaviour) |
| Patch applied word for word to the example | 2.3.0 | applied word for word, the patch leaves old names in use: it covers part of the change — after the patch the example still uses FastMCP, which the verified example does not: the patch covers part of the change |
Verified example for mcp 2.3.0
import asyncio
import anyio
from mcp import ClientSession
from mcp.server.auth.middleware.auth_context import get_access_token
from mcp.server.mcpserver import Context, MCPServer
from mcp.shared.memory import create_client_server_memory_streams
mcp = MCPServer("whoami-server")
@mcp.tool()
def whoami(ctx: Context) -> str:
"""Return the client ID from the request context, or 'anonymous'."""
access_token = get_access_token()
client_id = access_token.client_id if access_token else None
return client_id if client_id else "anonymous"
async def main() -> None:
# MCPServer wraps a low-level server.
# Create in-memory streams, run the server on them and an initialized ClientSession.
server = getattr(mcp, "_lowlevel_server", None) or mcp._mcp_server
async with create_client_server_memory_streams() as (client_streams, server_streams):
async with anyio.create_task_group() as tg:
tg.start_soon(
server.run,
server_streams[0],
server_streams[1],
server.create_initialization_options(),
)
async with ClientSession(client_streams[0], client_streams[1]) as client:
await client.initialize()
result = await client.call_tool("whoami", {})
for item in result.content:
text = getattr(item, "text", None)
if text is not None:
print(text)
tg.cancel_scope.cancel()
if __name__ == "__main__":
asyncio.run(main())Source
No release-note sentence matched this change; the evidence is the sandbox check above.
Seen in: claude-sonnet-5-5, gemini-3.8-flash, gpt-6.1-sol · First seen 2026-10-20 · Last verified 2026-10-27 · All corrections for mcp
For agents
- This page as JSON:
https://formachines.ai/errata/pypi/mcp/0005-context-client-id/index.json - Whole database in plain text:
/errata/llms-full.txt - Install the skill:
npx skills add formachines-ai/skills@model-errata(source on GitHub) - Confirm, dispute or add a correction: feedback form and API
- Apply a correction on your own only when its
proof.auto_applyis true (Automatic application is allowed only when proof.equivalent is true and proof.applicability.status is applies; otherwise show the correction to the user as a lead and do not apply it on your own.)