mcp-postgres-demo
Provides read-only access to a PostgreSQL database: lists tables and views, describes schemas, columns and keys with sample rows, runs one safe SELECT at a time, returns JSON rows and the executed SQL, and explains query plans without ANALYZE.
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.
MCP server for PostgreSQL, read only
Demo on sample data. An open-source Model Context Protocol (MCP) server that lets an AI assistant query a PostgreSQL database in plain English, without being able to change it.
What it is
An MCP server is a small program that lets an AI assistant such as Claude use your systems through tools you define. This one connects Claude Desktop, Claude Code, Cursor and other MCP clients to a sample PostgreSQL database, read only. Every query passes four separate safety layers before and while it runs.
The story: ask Claude "Which 5 film categories earned the most rental revenue in the first quarter of 2026?" Claude reads the schema through this server, writes one read-only SQL query, runs it, and answers with the numbers and the query it used.
Related MCP server: text-to-sql-mcp
Quick start
Needs Docker and Node 22.
corepack enable && pnpm install && pnpm build
pnpm db:up # Postgres 18 with the demo roles, on localhost:5433
pnpm db:seed # downloads Pagila 4.1.2, checks it, loads itThen connect your assistant: docs/claude-desktop.md has the steps for Claude Code, Claude Desktop and Cursor. Questions to try are in docs/demo-script.md.
The hosted endpoint
https://mcp-postgres-demo.vercel.app/mcp: read only, no sign-in, 30 requests a minute per visitor (over the limit, the server answers HTTP 429 for the rest of that minute). GET /healthz wakes it up after a quiet period. Only the clients tested against it are listed in docs/claude-desktop.md.
How it keeps your database safe
The database login can only read. The server connects as a role that can read the sample tables and nothing else. Its transactions are read only by default, it has a 5 second time limit, and it cannot see any other schema. Even if every check in the code were skipped, this login could not change data.
Every query is read by Postgres's own parser first. The server uses the real Postgres parser (
libpg-query) to turn the SQL into a tree and walks all of it. It refuses anything other than one plain SELECT: writes hidden in aWITH, a second statement after a semicolon or a comment,SELECT INTO, row locks, system tables, other schemas, and functions that can sleep, read files or change settings. The checked tree is turned back into SQL, so what runs is exactly what was checked.Limits on every run. Each query runs in a read-only transaction with a 5 second timeout and returns at most 200 rows (it says when a result was cut). Responses are capped at 1 MB, and very long cells are shortened.
An audit line for every query. One JSON line per query records the time, the tool, a fingerprint (sha256) of the SQL, the row count, the duration and the outcome. It never records the results or the visitor's IP address.
test/db-role.test.ts checks layer 1 on its own: each write the parser refuses also fails when sent straight to the database as the read-only role. One exception: COPY film TO STDOUT is a read that Postgres allows for any role that can SELECT the table, so only layer 2 refuses it. It returns nothing a SELECT would not.
Tools
Tool | What it does |
| Tables and views you can query, with approximate row counts and a one-line description |
| Columns, types, primary and foreign keys, and up to 5 sample rows |
| Runs one SELECT and returns the rows as JSON, the SQL that ran, and whether the result was cut |
| The query plan for a SELECT (EXPLAIN, FORMAT JSON). Never ANALYZE |
Also a resource, schema://overview (tables, columns and keys, read by the assistant first), and a prompt, analyse-table.
Configuration
Variable | Default | Meaning |
| none | Connection string for a read-only role |
|
| Schemas a query may use (comma-separated) |
|
| Most rows returned per query |
|
| Time limit per query |
|
| Longest query accepted |
|
| HTTP port (hosted mode) |
|
| Requests a minute per visitor (hosted mode) |
|
| Requests a day per instance (hosted mode) |
| none | Salt for hashing visitor IPs (hosted mode) |
|
| Database connections per server copy (2 on Vercel) |
What it does not do
It never writes, deletes or changes data.
No sign-in on this demo. OAuth is available for client builds.
No multi-tenant hosting: one server, one database.
Sample data
Pagila 4.1.2 (commit 6ea53f812254c91a602f61c0ef62beca3fa676b1), a fictional DVD rental shop ported from MySQL's Sakila sample, under the PostgreSQL License (Copyright (c) 2015-2026, Devrim Gündüz). db/seed/fetch-pagila.sh downloads it at that commit, checks its sha256, and moves it from the public schema into a pagila schema with a non-superuser owner. The load drops the film_embedding table (sample vectors this demo does not use) and blocks Pagila's own functions. No data is stored in this repo.
The staff table holds sample password hashes and the customer table sample emails. Both are part of the public sample, not real people.
Database size after loading: 36 MB (measured on local Docker, 4 Dec 2026).
Licence
MIT. Built by Apex36, a founder-led team.
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 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Query your Postgres from ChatGPT or Claude without exposing the database or handing over credentials. Run npx boltschema connect next to your database and it dials out over HTTPS — no inbound firewall rule, no open port, works with localhost and VPC-private databases. Read-only is enforced by a SQL guard, a Postgres READ ONLY transaction, and a scoped role generated for you.
Related MCP Servers
- AlicenseAqualityCmaintenanceEnables Claude Desktop and Claude Code to inspect a Postgres schema and run read-only SQL queries against a demo database through the tools describe_schema and query_readonly. Every proposed query passes the same deterministic guardrails — SELECT-only, allow-listed tables, enforced row limits, statement timeouts and a read-only role — before execution.2MIT
- AlicenseNot gradedqualityCmaintenanceEnables Claude to translate natural-language business questions into safe, read-only SQL queries by exposing tools for listing tables, inspecting schemas, and executing row-capped SELECT statements against PostgreSQL.MIT
- AlicenseNot gradedqualityCmaintenanceEnables Claude to query and safely write to a Postgres database, driven entirely by one policy file with read-only access by default, column-precise PII masking, and an append-only audit log. SQL is parsed and validated before execution, writes use parameterized queries with dry-run/confirm and transactions, and every call is rate-limited and audited so destructive or exfiltrating requests are refused.MIT
- AlicenseAqualityCmaintenanceEnables Claude to answer questions from PostgreSQL databases using read-only SQL queries, with row caps, column masking, and an audit log while preventing data changes.3MIT