Understanding MCP transport methods and how to choose between them
FastAPI-MCP supports two MCP transport methods for client-server communication: HTTP transport (recommended) and SSE transport (backwards compatibility).
HTTP transport is the recommended transport method as it implements the latest MCP Streamable HTTP specification. It provides better session management, more robust connection handling, and aligns with standard HTTP practices.
from fastapi import FastAPIfrom fastapi_mcp import FastApiMCPapp = FastAPI()mcp = FastApiMCP(app)# Mount using HTTP transport (recommended)mcp.mount_http()
from fastapi import FastAPIfrom fastapi_mcp import FastApiMCPapp = FastAPI()mcp = FastApiMCP(app)# Mount using SSE transport (backwards compatibility)mcp.mount_sse()
Both transport methods support the same FastAPI integration features like custom routing and authentication:
Copy
from fastapi import FastAPI, APIRouterfrom fastapi_mcp import FastApiMCPapp = FastAPI()router = APIRouter(prefix="/api/v1")mcp = FastApiMCP(app)# Mount to custom path with HTTP transportmcp.mount_http(router, mount_path="/my-http")# Or with SSE transportmcp.mount_sse(router, mount_path="/my-sse")