About fastapi-mcp
A Python example that mounts an MCP server within an existing FastAPI web app and includes a sample MCP client. It is intended for developers exploring this integration pattern.
Key features
- 01Mount an MCP server in FastAPI
- 02Sample MCP client
- 03Docker-based server startup
Use cases
- 01Explore hosting an MCP server in a FastAPI app
- 02Run the included client to test MCP communication
MCP support
Mounts an MCP server on a FastAPI app and includes a sample client demonstrating communication. The README notes that the server currently only works when mounted at the root path.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEDescription
Simple example web app + client showing Model Context Protocol server mounted on an existing fastapi server
Files
./src/main.py -> main fastapi server app
./src/mcp.py -> mcp sub server app logic
./client/client.py -> sample client showing some communication logic using mcp client lib
Set up
Using Docker to start server
docker build -t fastapi-mcp .
docker run -p 8000:8000 --net=host fastapi-mcp
Set up python environment & run client
pip install -r requirements.txt
python client/client.py
# to run server as well without docker
uvicorn src.main:app
Known Issues
MCP server can only be mounted on root '/'
Limitations on MCP python sdk that currently only allows for MCP server to work when mounted on root /
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.