awesome mcp fastapi
A production-ready MCP server built with FastAPI, providing an enhanced tool registry for creating, managing, and documenting AI tools for Large Language Models (LLMs).
A production-ready MCP server built with FastAPI, providing an enhanced tool registry for creating, managing, and documenting AI tools for Large Language Models (LLMs).
A powerful FastAPI-based implementation of the Model Context Protocol (MCP) with enhanced tool registry capabilities, leveraging the mature FastAPI ecosystem.
Awesome MCP FastAPI is a production-ready implementation of the Model Context Protocol that enhances and extends the standard MCP functionality by integrating it with FastAPI's robust ecosystem. This project provides an improved tool registry system that makes it easier to create, manage, and document AI tools for Large Language Models (LLMs).
While the Model Context Protocol provides a solid foundation for connecting AI models with tools and data sources, our implementation offers several significant advantages:
Our implementation improves upon the standard MCP tool registry by:
# Clone the repository
git clone https://github.com/yourusername/awesome-mcp-fastapi.git
cd awesome-mcp-fastapi
# Create a virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venvScriptsactivate
# Install dependencies
pip install -e .
uvicorn src.main:app --reload
Visit http://localhost:8000/docs to see the OpenAPI documentation.
from fastapi import FastAPI
from src.utils.tools import auto_tool, bind_app_tools
app = FastAPI()
bind_app_tools(app)
@auto_tool(
name="calculator",
description="Perform basic arithmetic operations",
tags=["math"]
)
@app.post("/api/calculator")
async def calculator(operation: str, a: float, b: float):
"""
Perform basic arithmetic operations.
Parameters:
- operation: The operation to perform (add, subtract, multiply, divide)
- a: First number
- b: Second number
Returns:
The result of the operation
"""
if operation == "add":
return {"result": a + b}
elif operation == "subtract":
return {"result": a - b}
elif operation == "multiply":
return {"result": a * b}
elif operation == "divide":
if b == 0:
return {"error": "Cannot divide by zero"}
return {"result": a / b}
else:
return {"error": f"Unknown operation: {operation}"}
LLMs can discover and use your tools through the Model Context Protocol. Example using Claude:
You can perform calculations using the calculator tool. Try calculating 42 * 13.
Claude will automatically find and use your calculator tool to perform the calculation.
Our application follows a modular architecture:
src/
├── api/ # API endpoints
│ └── v1/ # API version 1
├── core/ # Core functionality
│ └── settings.py # Application settings
├── db/ # Database connections
│ └── models/ # Database models
├── main.py # Application entry point
└── utils/ # Utility functions
└── tools.py # Enhanced tool registry
Build and run with Docker:
docker build -t awesome-mcp-fastapi .
docker run -p 8000:8000 --env-file .env awesome-mcp-fastapi
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.