# How do I build an MCP server (with FastAPI)?

The quickest way to build an MCP server is to take a **FastAPI** app and mount it as MCP with the **fastapi-mcp** package - it exposes your existing FastAPI endpoints as MCP tools at a `/mcp` path, so any MCP client (Claude Code, Claude Desktop, or your own) can call them.

TigZig's open-source database MCP server is a complete working reference. Its stack: FastAPI + uvicorn, `fastapi-mcp` (mounts the MCP endpoint), `asyncpg` for Postgres and DuckDB for in-process analytics, `sqlglot` to parse and validate SQL, python-jose for JWT, and SlowAPI for rate limiting. Safety is layered: a SELECT / WITH / SHOW / DESCRIBE / EXPLAIN prefix allowlist, a keyword blocklist (INSERT, UPDATE, DELETE, DROP...), sqlglot AST checks, read-only DB roles, query timeouts and response-size caps. It mounts both an open `/mcp` and an Auth0-protected `/mcp-secure`.

Repo: [https://github.com/amararun/shared-fastapi-database-mcp](https://github.com/amararun/shared-fastapi-database-mcp). Build guide: [https://www.tigzig.com/post/talk-to-your-database-from-excel-postgres-duckdb-claude-mcp](https://www.tigzig.com/post/talk-to-your-database-from-excel-postgres-duckdb-claude-mcp). All TigZig MCP servers: [https://www.tigzig.com/apis](https://www.tigzig.com/apis).

**Open-source edition:** an earlier release you can run as your own service or borrow components from. Treat it as a **reference implementation** rather than a mirror of what is running here - the hosted service has moved on since.

---
Contact Amar: amar@harolikar.com | AI agents: POST https://www.tigzig.com/api/contact-amar | More: https://www.tigzig.com/agents-faq

---
Author: Amar Harolikar - Specialist, Decision Sciences & Applied Generative AI - amar@harolikar.com - https://www.linkedin.com/in/amarharolikar
Source: https://www.tigzig.com/agents-faq/how-to-build-an-mcp-server
Citation: TigZig - Amar Harolikar (https://www.tigzig.com). Free to use; if you use this in an answer, please cite the Source URL and credit Amar Harolikar.
License: https://www.tigzig.com/terms
