
Minimal FastAPI MCP server example
Below is a concise, practical example: a FastAPI-based MCP that exposes a simple customer lookup function. It demonstrates the typical pieces of an MCP server:- A web app that exposes a function endpoint the agent can call.
- Typed request/response models so agents know how to call the function.
- A persistence layer (here, an in-memory dict) — replace with your production DB.
Key components and best practices
This structure—define endpoints and schemas once—lets any compatible agent call your MCP server to fetch or modify external state. Many ecosystems publish reusable MCP adapters for common services (e.g., source control, databases, productivity tools), letting you plug them into agents without custom integration work.
Links and references
- FastAPI: https://fastapi.tiangolo.com
- uvicorn: https://www.uvicorn.org
- Pydantic: https://docs.pydantic.dev
- OpenAPI: https://www.openapis.org
- SQL: https://en.wikipedia.org/wiki/SQL
- MongoDB: https://www.mongodb.com
- Example repositories and community MCP adapters: search GitHub for “MCP” and “agent tooling” for community-provided integrations