Creating a basic MCP server
To create a basic MCP server, import or create a FastAPI app, wrap it with theFastApiMCP
class and mount the MCP to your existing application:
Running the server
By running your FastAPI, your MCP will run athttps://app.base.url/mcp
.
For example, by using uvicorn, add to your code:
python fastapi_mcp_server.py
, which will serve you the MCP at http://localhost:8000/mcp
.
Connecting a client to the MCP server
Once your FastAPI app with MCP integration is running, you would want to connect it to an MCP client.Connecting to the MCP Server using SSE
For any MCP client supporting SSE, you will simply need to provide the MCP url. All the most popular MCP clients (Claude Desktop, Cursor & Windsurf) use the following config format:Connecting to the MCP Server using mcp-remote
If you want to support authentication, or your MCP client does not support SSE, we recommend usingmcp-remote
as a bridge.