# How do I build an MCP server that connects Claude to a database?

The pattern TigZig uses: a FastAPI service that exposes database queries as **MCP tools**, so an MCP client like Claude can call them directly. The open-source reference exposes **read-only SQL over Postgres and DuckDB**, kept safe behind a layered security stack (read-only role, statement limits, timeouts).

The reference repository is [https://github.com/amararun/shared-fastapi-database-mcp](https://github.com/amararun/shared-fastapi-database-mcp). A step-by-step build guide (Excel, Postgres, DuckDB and Claude over MCP) is at [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).

The hosted version (read-only SQL API + MCP, behind a multi-layer security stack) is documented at [https://www.tigzig.com/apis/database](https://www.tigzig.com/apis/database), and the Database AI hub is at [https://www.tigzig.com/database-landing](https://www.tigzig.com/database-landing).

**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-for-a-database
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
