by mlzoo
Provides a professional Python framework that standardizes MCP server development, automatically converting FastAPI endpoints into AI-callable tools while supporting interface‑implementation separation and flexible dependency injection.
MCP Server Development Framework is a Python‑based development kit that streamlines the creation of enterprise‑grade MCP servers. It bridges traditional FastAPI APIs with AI‑callable MCP tools, enabling rapid, maintainable, and testable service construction.
make install
make dev
The API docs will be available at http://localhost:5000/docs and the MCP endpoint at http://localhost:5000/mcp.Depends system for clean, decoupled component wiring.parking_service.py) demonstrates best practices.Q: Do I need Docker to run the framework?
A: No. The framework runs directly with Python 3.10+ and can be started via make dev.
Q: How can I switch between mock and real implementations?
A: Implement a provider function (e.g., get_data_service) that returns the appropriate class based on environment variables or settings.
Q: Can I expose only a subset of FastAPI routes as MCP tools?
A: Yes. Supply the include_operations list when creating the FastApiMCP instance to select specific operation_ids.
Q: What testing commands are available?
A: Use make check for linting/quality checks and make test to run the full test suite.
A professional framework designed for enterprise-level Model Context Protocol (MCP) tool development, standardizing the MCP server development process to help developers rapidly build high-quality AI tools. By integrating FastAPI with FastAPI-MCP, this framework enables seamless transformation from traditional APIs to AI-callable tools.
This framework is particularly suitable for:
┌─────────────┐ ┌───────────────┐ ┌─────────────────┐
│ API Layer │ ──→ │ Service Layer │ ──→ │ Implementation │
└─────────────┘ └───────────────┘ └─────────────────┘
↓
┌─────────────┐
│ MCP Endpoint│ ←── FastAPI-MCP Auto-Conversion
└─────────────┘
This framework uses uv as its package manager, providing faster dependency resolution and virtual environment management. For installation instructions, see the uv official documentation.
# Install dependencies and set up the development environment
make install
# Start the development server
make dev
Once the service is running, you can:
http://localhost:5000/docshttp://localhost:5000/mcp using an MCP client (e.g., Cursor, Claude Desktop).
├── main.py # Application entry point and route definitions
├── services/ # Service layer implementations
│ └── parking_service.py # Example service (replaceable with custom services)
├── pyproject.toml # Project configuration and dependency definitions
└── Makefile # Development and build tasks
# 1. Service Interface Definition
from abc import ABC, abstractmethod
from typing import Dict, Any
class DataService(ABC):
@abstractmethod
def get_data(self, id: str) -> Dict[str, Any]:
"""Data retrieval interface"""
pass
# 2A. Mock Implementation - for development and testing
class DataServiceMockImpl(DataService):
def get_data(self, id: str) -> Dict[str, Any]:
return {"id": id, "name": "Test Data", "mock": True}
# 2B. Real Implementation - for production environment
class DataServiceImpl(DataService):
def __init__(self, database_url: str):
self.db = Database(database_url)
def get_data(self, id: str) -> Dict[str, Any]:
return self.db.query("SELECT * FROM data WHERE id = :id", {"id": id})
# 3. Dependency Injection Configuration
def get_data_service() -> DataService:
# Choose implementation based on environment
return DataServiceMockImpl() # or return DataServiceImpl(settings.DATABASE_URL)
from fastapi import FastAPI, Depends
from fastapi_mcp import FastApiMCP
from pydantic import BaseModel, Field
app = FastAPI()
# Request model
class ItemRequest(BaseModel):
query: str = Field(..., description="Search query parameter")
limit: int = Field(10, description="Result limit")
# API endpoint - automatically converted to an MCP tool
@app.post("/items/search", operation_id="search_items")
async def search_items(
request: ItemRequest,
service: DataService = Depends(get_data_service)
):
result = service.search_items(request.query, request.limit)
return {"items": result["items"], "total": len(result["items"])}
# Create and mount MCP service
mcp = FastApiMCP(
app,
name="example-service",
description="Example MCP service",
base_url="http://localhost:5000",
include_operations=["search_items"]
)
# Mount MCP service at specified path
mcp.mount(mount_path="/mcp")
FastAPI's dependency injection system is an integral part of this framework, providing powerful and flexible dependency management capabilities.
Dependency injection is a design pattern that allows dependencies (such as services, database connections, etc.) to be injected into components that use them, rather than having components create and manage dependencies themselves. In FastAPI, dependency injection is implemented through the Depends function.
from fastapi import Depends
def get_db():
"""Database connection provider"""
db = connect_to_db()
try:
yield db # Using yield enables lifecycle management of dependencies
finally:
db.close()
@app.get("/items/")
async def get_items(db = Depends(get_db)):
return db.query(Item).all()
FastAPI supports several types of dependency injection:
class DatabaseDependency:
def __init__(self, settings = Depends(get_settings)):
self.settings = settings
def __call__(self):
db = connect_to_db(self.settings.db_url)
try:
yield db
finally:
db.close()
@app.get("/users/")
async def get_users(db = Depends(DatabaseDependency())):
return db.query(User).all()
In this framework, dependency injection is primarily used for:
FastAPI-MCP can automatically convert FastAPI endpoints into MCP tools:
from fastapi import FastAPI
from fastapi_mcp import FastApiMCP
app = FastAPI()
# Define a standard FastAPI endpoint
@app.post("/predict", operation_id="predict_sentiment")
async def predict_sentiment(text: str):
return {"sentiment": "positive", "confidence": 0.92}
# Create and mount MCP service - automatically converts the above endpoint to an MCP tool
mcp = FastApiMCP(
app,
name="sentiment-analysis",
description="Sentiment analysis service",
base_url="http://localhost:5000",
include_operations=["predict_sentiment"]
)
# Mount MCP service at specified path
mcp.mount(mount_path="/mcp")
MCP tool names default to the API endpoint's operation_id. We recommend following these naming conventions:
predict_sentiment, find_nearby_parking)operation_id rather than relying on auto-generation# Recommended: Explicitly set operation_id
@app.post("/parking/nearby", operation_id="find_nearby_parking")
async def find_nearby(request: NearbyRequest):
# Implementation logic...
pass
# Not recommended: Relying on auto-generated operation_id (generates something like "find_nearby_parking_nearby_post")
@app.post("/parking/nearby")
async def find_nearby(request: NearbyRequest):
# Implementation logic...
pass
This framework supports multi-level testing strategies:
# Run code quality checks
make check
# Run test suite
make test
To ensure high performance of MCP tools, we recommend:
Contributions to this framework are welcome:
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)Please log in to share your review and rating for this MCP.
Explore related MCPs that share similar capabilities and solve comparable challenges
by modelcontextprotocol
A Model Context Protocol server for Git repository interaction and automation.
by zed-industries
A high‑performance, multiplayer code editor designed for speed and collaboration.
by modelcontextprotocol
Model Context Protocol Servers
by modelcontextprotocol
A Model Context Protocol server that provides time and timezone conversion capabilities.
by cline
An autonomous coding assistant that can create and edit files, execute terminal commands, and interact with a browser directly from your IDE, operating step‑by‑step with explicit user permission.
by upstash
Provides up-to-date, version‑specific library documentation and code examples directly inside LLM prompts, eliminating outdated information and hallucinated APIs.
by daytonaio
Provides a secure, elastic infrastructure that creates isolated sandboxes for running AI‑generated code with sub‑90 ms startup, unlimited persistence, and OCI/Docker compatibility.
by continuedev
Enables faster shipping of code by integrating continuous AI agents across IDEs, terminals, and CI pipelines, offering chat, edit, autocomplete, and customizable agent workflows.
by github
Connects AI tools directly to GitHub, enabling natural‑language interactions for repository browsing, issue and pull‑request management, CI/CD monitoring, code‑security analysis, and team collaboration.