Objective
Migrate your existing FastAPI services to the Model Context Protocol (MCP) using two different implementations:
- Official MCP SDK (
mcp
on PyPI) - Jeremiah Lowin’s FastMCP 2.0 (
fastmcp
on PyPI)
Evaluate each on performance, LangChain integration, and production readiness.
- Existing FastAPI Code (REPLACE WITH YOUR REAL CODE):
from fastapi import FastAPI app = FastAPI() @app.post("/query") async def query_engine(text: str): # Your actual retrieval/RAG logic here return {"response": f"Processed {text}"}
- Project Constraints:
- Scale: e.g.
5 endpoints, 100+ QPS
- Non-negotiables: e.g.
OAuth2
,latency <8 ms
,Kubernetes
- LangChain Usage: e.g.
LCEL chain with OpenAI + pgvector
- Baseline Metric: e.g.
Current latency: 15 ms @ 50 QPS
- Scale: e.g.
- Environment:
- Python version (e.g.
3.11
) - FastAPI version (e.g.
0.98
) - OS/container details if relevant
- Python version (e.g.
A. Code Conversion
- Produce side-by-side FastAPI → FastMCP examples for your endpoint, including:
- ASGI mounting & lifespan events
@tool
definitions- Full runnable snippets with robust error handling (retries, circuit-breakers)
B. Architecture Analysis
Comparison Point | Official MCP SDK (mcp ) |
FastMCP 2.0 (fastmcp ) |
---|---|---|
Cold start | [benchmark vs. baseline] | [benchmark vs. baseline] |
Async throughput | [req/s @ 50 concurrent] | [req/s @ 50 concurrent] |
License Risk | Apache 2.0 (✅) | MIT (✅) |
PyPI Downloads (30 d) | [data] | [data] |
Evidence Rule: Cite PyPI/GitHub stats; if unavailable, explain how to measure (e.g. locust or k6).
C. LangChain Integration
- Show how to wrap your LangChain chain using
langchain-mcp-adapters
- Provide a compatibility matrix for both MCP implementations
D. Production Practices
# IMPLEMENT IN CODE:
# 1. OAuth2 middleware ▶ WHY: SSO compliance
# 2. OpenTelemetry hooks ▶ WHY: distributed tracing
# 3. Async resource cleanup ▶ WHY: prevent connection leaks
# 4. Retry & circuit-breaker ▶ WHY: resilience under load
E. Decision & Rollback
- Final recommendation with one-sentence justification
- 3-step rollback plan to revert to FastAPI
- Max 1,200 words
- Prioritize: Code > Tables > Bullet lists
- Annotate every code snippet with
▶ WHY
comments - Zero fluff—focus on actionable, evidence-backed guidance
Missing benchmarks? Provide ready-to-run
locust
ork6
scripts to gather the required metrics.
# Example locust task
from locust import FastHttpUser, task, between
class TestUser(FastHttpUser):
wait_time = between(1, 2)
@task
def query(self):
self.client.post("/query", json={"text": "test"}, name="/query")
# Example k6 script
import http from 'k6/http';
import { sleep } from 'k6s';
export default function () {
http.post('https://your-host/query', JSON.stringify({ text: 'test' }), { headers: { 'Content-Type': 'application/json' } });
sleep(1);
}