MCP Database Server — Claude Code MCP server: query SQL in plain words
An MCP server that connects PostgreSQL and MySQL to your agent and turns plain-language questions into SQL. Handy when you want to inspect data without writing queries by hand.
claude mcp add --env DATABASE_URL=<DATABASE_URL> --transport stdio mcp-database-server -- docker run -i --rm -e DATABASE_URL docker.io/souhardyak/mcp-db-server:1.3.1What MCP Database Server does
The server runs a FastAPI app and hands your agent table listings, a table's schema, sample rows, and query execution. A question like "top 5 customers by total order amount" goes through HuggingFace transformers, which produces the SQL and a structured result.
Operations are read-only, queries get validated, and result size is capped. Since version 1.4.0 the database HTTP routes require an X-API-Key header; only /health stays public. Without MCP_API_KEY set, those routes are disabled, so plan for the key up front. The same release binds to 127.0.0.1 by default, checks table names against the real schema, and supports sslmode=require for asyncpg.
Docker Compose is the shortest path: clone the repo, generate a key with openssl rand -hex 32, bring the containers up. Running locally needs Python 3.11+ and the packages from requirements.txt. A demo e-commerce database ships with the project, which is a reasonable way to test the wiring before pointing it at a real database.
What it helps with
- inspect table contents without opening psql
- pull a table schema into the agent chat
- phrase a SQL query in words and see the rows
- grab a few sample rows to sanity-check data
- wire PostgreSQL or MySQL into an agent without writing code
Example prompts for the agent
- List the tables in the database and how many columns each has
- Describe the schema of the
customerstable - Count orders grouped by status
How to install MCP Database Server
Platform CLI
claude mcp add --env DATABASE_URL=<DATABASE_URL> --transport stdio mcp-database-server -- docker run -i --rm -e DATABASE_URL docker.io/souhardyak/mcp-db-server:1.3.1Replace <…> with your own values
Platform CLI
codex mcp add mcp-database-server --env DATABASE_URL=<DATABASE_URL> -- docker run -i --rm -e DATABASE_URL docker.io/souhardyak/mcp-db-server:1.3.1Replace <…> with your own values
Config file
{
"mcpServers": {
"mcp-database-server": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"DATABASE_URL",
"docker.io/souhardyak/mcp-db-server:1.3.1"
],
"env": {
"DATABASE_URL": "<DATABASE_URL>"
}
}
}
}Replace <…> with your own values
Config file
{
"servers": {
"mcp-database-server": {
"type": "stdio",
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"DATABASE_URL",
"docker.io/souhardyak/mcp-db-server:1.3.1"
],
"env": {
"DATABASE_URL": "<DATABASE_URL>"
}
}
}
}Replace <…> with your own values
Platform CLI
gemini mcp add -e DATABASE_URL=<DATABASE_URL> mcp-database-server docker run -i --rm -e DATABASE_URL docker.io/souhardyak/mcp-db-server:1.3.1Replace <…> with your own values
Step by step, with commands for each platform: How to add an MCP server to Claude Code, Codex, Cursor, VS Code, Gemini CLI and more
Questions about MCP Database Server
How do I install MCP Database Server in Claude Code?
Run `claude mcp add --env DATABASE_URL=<DATABASE_URL> --transport stdio mcp-database-server -- docker run -i --rm -e DATABASE_URL docker.io/souhardyak/mcp-db-server:1.3.1`, replacing the placeholder with your own connection string.
What does MCP Database Server do?
It gives an agent access to PostgreSQL and MySQL: table listings, schemas, sample data, and query execution. Plain-language questions become SQL.
Which databases are supported?
PostgreSQL and MySQL. The DATABASE_URL uses the asyncpg driver for PostgreSQL and pymysql for MySQL.