Understanding MCP Transports
FastAPI-MCP supports two methods for communication between the MCP client and your server, known as transports: Streamable HTTP and Server-Sent Events (SSE).
HTTP Transport (Recommended)
HTTP transport is the recommended method. It aligns with the latest MCP specification, which positions standard HTTP as the primary communication protocol. This transport offers several advantages:
- Stateful Session Management: Robust handling of client sessions over standard HTTP requests.
- Specification Compliance: Follows the official MCP Streamable HTTP specification.
- Standard Tooling: Works seamlessly with standard HTTP clients, proxies, and debugging tools.
To use HTTP transport, call the mount_http()
method:
from fastapi import FastAPI
from fastapi_mcp import FastApiMCP
app = FastAPI()
mcp = FastApiMCP(app)
# Mount using the recommended HTTP transport
mcp.mount_http()
# By default, this is available at /mcp
SSE Transport (Backwards Compatibility)
Server-Sent Events (SSE) transport is maintained for backwards compatibility with older MCP clients and implementations that may not yet support the Streamable HTTP specification.
To use SSE transport, call the mount_sse()
method:
from fastapi import FastAPI
from fastapi_mcp import FastApiMCP
app = FastAPI()
mcp = FastApiMCP(app)
# Mount using SSE transport for backwards compatibility
mcp.mount_sse()
# By default, this is available at /sse
Deprecated
mount()
MethodPrevious versions of
fastapi-mcp
had a singlemount()
method which defaulted to SSE transport. This method is now deprecated and will be removed in a future version. Please update your code to use eithermount_http()
ormount_sse()
explicitly.
Choosing a Transport
- For new projects or when your client supports it, always choose
mount_http()
. - Use
mount_sse()
only if you need to support older clients that rely on SSE transport.