postgres-mcp-server
Provides safe, read-only access to PostgreSQL databases, enabling agents to list tables, describe schemas, execute capped read-only queries, and retrieve domain-specific campaign summaries.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
postgres-mcp-server
A small, production-minded Model Context Protocol (MCP) server that gives LLM agents
safe, read-only access to PostgreSQL. Built with the official Python MCP SDK (FastMCP)
and psycopg3.
Use it from Claude Desktop, Cursor, Claude Code, or any MCP-compatible agent to let the model explore a schema and answer questions over live data, without the ability to change it.
Why
Agents are good at writing SQL and bad at knowing when not to. This server makes the "not" part structural:
Layer | Protection |
Database session | every connection runs with |
Query validation | only a single |
Row cap | results are wrapped in |
Least privilege | README and |
Errors as data | DB errors return as JSON the agent can reason about, not stack traces |
Related MCP server: PostgreSQL MCP Server
Tools
Tool | What it does |
| tables + approximate row counts |
| columns, types, nullability |
| one read-only statement, capped at |
| example domain tool: KPIs for a voice-AI call campaign (answer rate, booking rate, avg duration, cost, latency) |
campaign_summary shows the pattern for turning a recurring analyst question into a typed
tool the agent can call directly, instead of guessing SQL every time.
Quick start
git clone https://github.com/makkarss929/postgres-mcp-server
cd postgres-mcp-server
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
cp .env.example .env # set DATABASE_URL to a READ-ONLY role
psql "$DATABASE_URL" -f sql/schema.sql # optional sample schema
psql "$DATABASE_URL" -f sql/seed.sql # optional sample data
pytest # safety tests
postgres-mcp # stdio serverInteractive inspector:
mcp dev src/postgres_mcp/server.pyConnect to Claude Desktop / Cursor
Add to claude_desktop_config.json (or Cursor's MCP settings):
{
"mcpServers": {
"postgres": {
"command": "postgres-mcp",
"env": {
"DATABASE_URL": "postgresql://readonly_user:password@localhost:5432/nextdialog",
"MAX_ROWS": "200"
}
}
}
}Then ask: "Which campaign had the best booking rate this week, and what was its average latency?"
The agent will call list_tables → describe_table → run_query (or campaign_summary) on its own.
Remote / HTTP mode
postgres-mcp --http # streamable HTTP on http://localhost:8000/mcpProject layout
src/postgres_mcp/
server.py # FastMCP app, tools, connection pool lifespan
safety.py # read-only validation + row cap (unit tested)
sql/
schema.sql # sample voice-AI calls schema + read-only role
seed.sql # sample data
tests/
test_safety.pyIdeas to extend
Add tracing (Langfuse / OpenTelemetry) around each tool call: prompt, SQL, rows, latency, cost.
Add a
explain_querytool so the agent can check cost before running heavy queries.Add an allow-list of schemas/tables for multi-tenant deployments.
Add a
run_queryeval set: natural-language question → expected SQL/result, to catch regressions.
License
MIT © Tarun Makkar
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Deterministic safety, correctness & cost gate that vets Postgres SQL before your AI agent runs it.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to safely interact with PostgreSQL databases through read-only operations, providing schema discovery, table inspection, and query execution capabilities with structured context awareness.MIT
- AlicenseNot gradedqualityDmaintenanceEnables LLMs to interact with PostgreSQL databases by providing tools to inspect table schemas and execute read-only SQL queries. It ensures data safety by running all operations within read-only transactions.MIT
- FlicenseAqualityDmaintenanceEnables AI agents to inspect and query PostgreSQL databases safely, with features like listing tables, retrieving schemas, and running read-only SQL queries.3-
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to query a PostgreSQL database through a small set of controlled, read-only tools for schema inspection, row lookup, and aggregate statistics.1MIT