- Home
- MCP servers
- FastAPI
FastAPI
- python
0
GitHub Stars
python
Language
5 months ago
First Indexed
2 months ago
Catalog Refreshed
Documentation & install
Readme and setup notes from the catalogue, plus a client-ready config you can copy for your MCP host.
You set up a FastAPI-based MCP server that exposes mathematical operations over a Model Context Protocol (MCP) interface. This server combines a Python web framework with MCP to offer real-time communication and Easy tool registration patterns for extending capabilities. You can connect an MCP client to perform calculations and receive updates via Server-Sent Events (SSE).
How to use
Connect your MCP client to the mounted server to access the mathematical tools. The MCP interface is exposed at the SSE endpoint for real-time communication and the MCC server is mounted at a dedicated path. You can call the available operations and receive structured results through the MCP protocol. Use the provided client configuration to discover available tools and their results in your application flow.
How to install
Prerequisites you need before starting:
-
Python 3.12 or newer
-
A compatible environment manager (recommended: uv) to run the server
Step by step setup
# 1) Prepare project directory
# Create a virtual environment and activate it
uv venv
source .venv/bin/activate # On Windows use .venv\Scripts\activate
# 2) Install dependencies in editable mode (or as required)
uv pip install -e .
# 3) Run the MCP-enabled FastAPI server
uvicorn fastapi_mcp:app --reload --port 8000
Configuration reference
The MCP client can connect to the server using a defined MCP endpoint. Use the following configuration snippet to point your client to the MCP server SSE endpoint and to identify the server name in your client configuration.
MCP server connection example
{
"mcpServers": {
"math_tools": {
"type": "http",
"url": "http://localhost:8000/mcp-server/sse",
"env": {}
}
}
}
Additional notes
The server provides three mathematical operations to demonstrate tool usage over MCP, including Add, Multiply, and Subtract. Real-time updates are delivered via the SSE channel, and you can integrate these tools into your application using your MCP client of choice.
Troubleshooting
Common issues include port conflicts, Python version mismatches, and missing dependencies. Ensure port 8000 is available or adjust the startup command accordingly. Verify your Python version is 3.12+ and that dependencies are installed in the active environment. If the MCP SSE endpoint is not reachable, confirm the server is running and accessible at the configured URL.
Security and best practices
Keep your server behind appropriate network boundaries and limit access to trusted MCP clients. Use standard security practices for FastAPI deployments, such as enabling TLS if exposed publicly, and monitor logs for unusual activity.
Notes
You can extend the server by adding more tools through MCP tool registration patterns demonstrated in the project. The example focuses on decorator-based and function-based registrations, showing how to wire tools into FastAPI endpoints while exposing them via the MCP protocol.
Available tools
add
Add two numbers by creating a pandas DataFrame and returning the sum.
multiply
Multiply two numbers by creating a pandas DataFrame and returning the product.
subtract
Subtract two numbers by creating a pandas DataFrame and returning the difference.