ask-your-database
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@ask-your-databaseWhich customers churned last month, and what plan were they on?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Ask Your Database — MCP Server
A local MCP server that lets Claude Desktop or Claude Code answer plain-English questions against a Postgres database — e.g. "which customers spent less than $2,000 in the last year?" — by calling real tools, not by guessing.
Tested end-to-end: schema discovery, multi-step joins, and a blocked write all verified against a live Postgres instance.
What's here
mcp-demo/
├── server.py # MCP server — exposes list_tables, describe_table, query
├── db.py # connection + safety layer (read-only role, timeout, write-block)
├── seed.sql # schema + sample data + read-only role setup
├── docker-compose.yml # spins up Postgres with the seed data pre-loaded
├── requirements.txt # mcp[cli], psycopg2-binary
└── README.mdRelated MCP server: Postgres MCP Server
1. Start Postgres
cd mcp-demo
docker compose up -dThis starts Postgres on localhost:5432, creates the demo database, loads
the sample schema (customers, subscriptions, support_tickets), and
creates a mcp_readonly role that can only SELECT.
No Docker? Run psql against any local Postgres instance and load seed.sql
directly: psql -U postgres -d demo -f seed.sql (creates the database first
if needed).
2. Set up Python
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt3. Point the server at your database
The server reads connection details from environment variables (defaults
shown match seed.sql and docker-compose.yml, so you likely don't need to
change anything for local testing):
Variable | Default |
|
|
|
|
|
|
|
|
|
|
4. Smoke-test it standalone (optional but recommended)
export PGHOST=localhost PGPORT=5432 PGDATABASE=demo PGUSER=mcp_readonly PGPASSWORD=readonlypass
python3 server.pyIt should sit there quietly waiting on stdio — that's correct, it's not meant to print anything until a client (like Claude Desktop) talks to it. Ctrl+C to stop.
5. Connect it to Claude Desktop
Open Claude Desktop's config file:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.json
Add this server (use the absolute path to server.py on your machine):
{
"mcpServers": {
"ask-your-database": {
"command": "/absolute/path/to/mcp-demo/venv/bin/python3",
"args": ["/absolute/path/to/mcp-demo/server.py"],
"env": {
"PGHOST": "localhost",
"PGPORT": "5432",
"PGDATABASE": "demo",
"PGUSER": "mcp_readonly",
"PGPASSWORD": "readonlypass"
}
}
}
}Restart Claude Desktop. You should see "ask-your-database" listed under the 🔌 tools/connectors icon in a new chat.
6. Connect it to Claude Code
From the project directory:
claude mcp add ask-your-database \
--env PGHOST=localhost --env PGPORT=5432 --env PGDATABASE=demo \
--env PGUSER=mcp_readonly --env PGPASSWORD=readonlypass \
-- /absolute/path/to/mcp-demo/venv/bin/python3 /absolute/path/to/mcp-demo/server.py7. Try it
Ask Claude, in plain English:
"Which customers churned last month, and what plan were they on?"
"Which customers spent less than $2,000 total in the last year?"
Claude will call list_tables and describe_table on its own to learn the
schema (nothing about it is hardcoded in the prompt), then write and run the
SQL itself via the query tool.
Try a write, too — it's blocked on purpose:
"Delete all customers with status 'churned'."
Adapting this to your real database
Swap the seed data for your actual schema, and point PGHOST/PGDATABASE at
your real Postgres instance — using a read-only role, same as here. Never
point this server at a production database with a role that can write.
db.py's query logic doesn't need to change at all.
Troubleshooting
Server doesn't show up in Claude Desktop — check the path in
claude_desktop_config.jsonis absolute, not relative, and that you restarted the app after editing the config.permission deniedon every query, even simple ones — check themcp_readonlyrole's grants ran (last block ofseed.sql); rerun that block if you dropped and recreated the database.Connection refused — confirm Postgres is actually running (
docker compose ps) and the port matchesPGPORT.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- -license-quality-maintenanceEnables secure read-only interactions with PostgreSQL databases through natural language. Provides database inspection, table listing, and SQL query execution with built-in security validation.
- Flicense-qualityCmaintenanceEnables querying and modifying PostgreSQL databases through MCP tools with read/write operations, schema inspection, and write-safety constraints that limit modifications to the mcp schema.1
- Flicense-qualityDmaintenanceEnables natural language querying of PostgreSQL databases through the Model Context Protocol. It translates user questions into validated SQL, executes read-only queries safely, and returns results to MCP-compatible clients like Claude Desktop.
- Alicense-qualityCmaintenanceEnables read-only interaction with PostgreSQL databases, allowing natural language queries for listing schemas, tables, describing columns, and executing SELECT/WITH statements.70MIT
Related MCP Connectors
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Analytical memory for AI agents: a real Postgres queried in plain English over MCP. One command.
GibsonAI MCP server: manage your databases with natural language
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/HardikSim2025/postgres_mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server