
Build an MCP Server in Python: FastMCP vs FastAPI-MCP vs Python SDK
Short answer: To build an MCP server in Python from scratch, use the official MCP Python SDK (from mcp.server import MCPServer) if you want the reference implementation with the fewest extras. Use the standalone FastMCP package (from fastmcp import FastMCP) if you want more batteries included. Use FastAPI-MCP if you already have a FastAPI app and want its endpoints exposed as MCP tools.
The tricky part is the names. "FastMCP" can mean two different things now, and many older tutorials use an import that no longer works. Here's how I keep them straight.
Why the names are confusing
In 2024, the official MCP Python SDK took in a high-level server API called FastMCP. That API came from the FastMCP project, which kept going as its own package [4]. So for a while, "FastMCP" meant both a class inside the official SDK and a separate library.
Version 2 of the official SDK settles part of that. The class is now called MCPServer, and the old import path, mcp.server.fastmcp, was removed outright rather than deprecated [1][2]. If a tutorial tells you to write from mcp.server.fastmcp import FastMCP, it was written for SDK v1.
I tested this today (Nov 5, 2026) in a clean virtual environment. With mcp 2.3.0 installed, from mcp.server import MCPServer works and import mcp.server.fastmcp raises ModuleNotFoundError.
Option 1: The official MCP Python SDK (MCPServer)
This is the SDK published by the Model Context Protocol project (PyPI package mcp) [1][3]. Its docs say pip install mcp now installs 2.x, and the latest release on PyPI today is 2.3.0 [5].
from mcp.server import MCPServer
mcp = MCPServer("Demo")
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers."""
return a + b
What else changed in v2 [1][2]:
- Everything that used to live under
mcp.server.fastmcp.*is now undermcp.server.mcpserver.*. - Settings like host, port, and
stateless_httpmoved from the constructor torun().MCPServer("x", port=9000)now raises an error. - v2 supports the 2026-07-28 protocol revision, which drops the session handshake, while still serving older clients.
- Synchronous
deftools now run on a worker thread.
Pick it if: you want the reference implementation, minimal dependencies, and docs that match the spec. If you publish a library that isn't ready for v2, the SDK docs suggest a cap like mcp>=1.28,<2 [1]. v1 still gets critical fixes and security patches.
Option 2: Standalone FastMCP (from fastmcp import FastMCP)
This is a separate project, maintained by Prefect at PrefectHQ/fastmcp, with docs at gofastmcp.com [4][6]. It's on major version 4. PyPI shows 4.1.6 as of today [7].
from fastmcp import FastMCP
mcp = FastMCP("Demo")
@mcp.tool
def add(a: int, b: int) -> int:
"""Add two numbers."""
return a + b
It looks a lot like the SDK, but it's a different library with its own API. Even the decorator differs here: @mcp.tool vs @mcp.tool(). Its docs cover features beyond the core server, such as server composition, proxying other MCP servers, tool transforms, and a client [6]. According to its package metadata, the MCP-related extras build on the official SDK 2.x (mcp>=2.3.0,<3).
Pick it if: you want higher-level extras like composition, proxying, or auth helpers, and you're happy to follow its own release cycle. Don't assume code moves unchanged between fastmcp.FastMCP and the SDK's MCPServer. They're related, but they aren't interchangeable.
Option 3: FastAPI-MCP (from fastapi_mcp import FastApiMCP)
FastAPI-MCP, by Tadata, does a different job. You don't write MCP tools by hand. It takes the endpoints of an existing FastAPI app and exposes them as MCP tools [8].
from fastapi import FastAPI
from fastapi_mcp import FastApiMCP
app = FastAPI()
# ... your existing routes ...
mcp = FastApiMCP(app)
mcp.mount()
Pick it if: you already have a FastAPI service and want an agent to call it quickly. A word of caution: the latest PyPI release is 0.4.0 from July 28, 2025 [9], and it declares mcp>=1.12.0 with no upper bound. It installed and imported fine alongside mcp 2.3.0 in my test. I didn't run a server, so I can't confirm it works at runtime with SDK v2. Pin versions and test before you depend on it.
Quick comparison
| Official SDK | Standalone FastMCP | FastAPI-MCP | |
|---|---|---|---|
| Install | pip install mcp | pip install fastmcp | pip install fastapi-mcp |
| Import | from mcp.server import MCPServer | from fastmcp import FastMCP | from fastapi_mcp import FastApiMCP |
| Maintainer | MCP project | Prefect | Tadata |
| Best for | Spec-faithful servers | Feature-rich servers | Existing FastAPI apps |
| Latest (PyPI, Nov 5, 2026) | 2.3.0 | 4.1.6 | 0.4.0 (Jul 2025) |
My take
For a new solo project, I'd start with the official SDK's MCPServer. Move to standalone FastMCP if you need a feature it has. Use FastAPI-MCP only when the API already exists. Whichever you choose, check the import line in any tutorial you copy, because that's the quickest way to tell which library (and which version) it was written for.
Ready to write one? Follow How to Create a Simple MCP Server. When you're deciding how to ship it, see Remote MCP vs Local MCP.
References
- Model Context Protocol, "What's new in v2," MCP Python SDK docs. https://py.sdk.modelcontextprotocol.io/whats-new/
- Model Context Protocol, "Migration Guide," MCP Python SDK docs. https://py.sdk.modelcontextprotocol.io/migration/
- modelcontextprotocol/python-sdk, GitHub. https://github.com/modelcontextprotocol/python-sdk
- FastMCP, "Welcome to FastMCP," FastMCP docs. https://gofastmcp.com/getting-started/welcome
- "mcp," PyPI. https://pypi.org/project/mcp/
- PrefectHQ/fastmcp, GitHub. https://github.com/PrefectHQ/fastmcp
- "fastmcp," PyPI. https://pypi.org/project/fastmcp/
- tadata-org/fastapi_mcp, GitHub. https://github.com/tadata-org/fastapi_mcp
- "fastapi-mcp," PyPI. https://pypi.org/project/fastapi-mcp/