PGAutoPilot
Provides tools to query, aggregate, insert, update, delete, and manage PostgreSQL databases using natural language, with schema-aware generation and safety controls.
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., "@PGAutoPilotShow me customers that spent more than $500."
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.
PGAutoPilot
Model-agnostic PostgreSQL access for AI assistants, plus a hardened web dashboard.
PGAutoPilot lets any AI assistant safely explore, query, and manage a PostgreSQL database in natural language through an MCP server, and gives you a full management UI through an optional dashboard. Both entry points share the exact same safety model (redaction, blocked tables, read-only mode, the dangerous-function gate), so every action, whether from an editor or the web UI, is subject to the same guarantees.
Model-agnostic PostgreSQL-optimized Safe writes Read-only mode
Minimal config Single executable Docker Cloud databases
Connection pool Production-ready SSL Schema inspectionContents
Related MCP server: Postgres Scout MCP
What is PGAutoPilot?
Most database MCP servers expose raw SQL directly and leave destructive operations largely unguarded. PGAutoPilot takes the opposite stance:
Schema-aware: every identifier is validated against your live database.
Production-first: every write path is guarded by multiple configurable safety layers.
Model-agnostic: works identically with Claude, GPT-4o, Gemini, DeepSeek, Copilot, and open-source models.
Two surfaces, one safety model: the MCP server and the dashboard share the same redaction, blocked-tables, and read-only guarantees.
You: "Show me customers that spent more than $500."
-> db_aggregate(table="orders", by="customer_id", _sum="total",
orderBy={"_sum/total": "desc"}, take=5)
<- 23 customers foundRepository layout
The repo is a monorepo with two independent halves, the MCP server and the dashboard, each with its own toolchain, kept separate but unified under one repo and one shared safety model.
root/
│
├─ server/ MCP core, PostgreSQL MCP server (npm, single executable)
│ ├─ src/
│ │ ├─ index.ts MCP server entry point / initialization
│ │ ├─ config.ts Env loading + validation
│ │ ├─ db.ts PostgreSQL connection pool
│ │ ├─ schema.ts Live schema introspection (information_schema)
│ │ ├─ sqlBuilder.ts Parameterized, safe SQL builder
│ │ ├─ safety.ts Redaction, write access, warnings
│ │ ├─ toolDefinitions.ts Zod schemas for all 14 tools
│ │ ├─ toolHandlers.ts Tool implementations
│ │ ├─ sqlDump.ts Backups via pg_dump
│ │ └─ *test.ts Colocated vitest tests
│ ├─ dist/ Compiled + bundled artifact (pgautopilot.bundle.cjs)
│ ├─ config/ Ready-to-use MCP configs for every editor/CLI (one folder per client)
│ ├─ scripts/ bundle / sign / verify installers
│ ├─ docker-compose.yml PostgreSQL 16 + MCP server
│ └─ package.json npm package `pgautopilot`
│
└─ web/ Dashboard, pnpm/Turborepo workspace
├─ apps/
│ ├─ api/ Express API (auth, tool gateway, schema, migrations, snapshots)
│ └─ web/ React + Vite + Tailwind v4 single-page app
└─ packages/
├─ contracts/ Zod schemas + DTOs shared across the wire
├─ api-client/ Typed fetch client generated against contracts
├─ ui/ Presentational component library (design system)
├─ core/ HTTP-friendly port of the MCP tool/safety layer
└─ config/ Shared tsconfig + eslint presetsTwo halves, one safety model. The web/ workspace is isolated (its own
pnpm-lock.yaml, Turborepo, packages) and depends strictly inward
(apps/* -> packages/*; packages never depend on apps). web/packages/core
is an HTTP-friendly port of the MCP core's safety layer (server/src/safety.ts),
so both entry points enforce identical guarantees. A change to one safety layer
must be mirrored in the other, or the two surfaces diverge.
Each half has its own README stub pointing here, and each has its own verification gate, see Development and Verification before shipping.
The two entry points
Entry point | What it is | Built for |
MCP server ( | A single-executable MCP server ( | Running queries/tools from your editor (VS Code, Cursor, Claude Desktop, Zed, …) |
Dashboard ( | A hardened web UI (React + Express) with tables, tools, SQL editor, schema, migrations, snapshots | Managing the database in a browser, on top of the same safety layer |
The MCP server is the primary, fully self-contained artifact. The dashboard is an optional extension that connects to a database through the same gatekeeping logic.
Install
Requirements: Node.js 18+ · PostgreSQL 12+ (local, remote, Docker, or cloud) · any MCP-compatible client (for the server) or a modern browser (for the dashboard).
MCP server (server/)
npm:
npm install -g pgautopilotNo npm, one-line installer (clones, adds to PATH; re-run to update):
Platform | Command |
Linux/mac |
|
Windows |
|
Download & run: node pgautopilot.bundle.cjs
Clone & run: git clone https://github.com/cyberreinxy/pgautopilot.git && cd pgautopilot && node server/dist/pgautopilot.bundle.cjs
Uninstall:
Platform | Command |
Linux/mac |
|
Windows |
|
Dashboard (web/)
pnpm installInstalls are idempotent and signed; see Software Signing.
Quick Start
1. MCP server (AI assistants)
Create a .env anywhere on your machine (PGAutoPilot finds it automatically):
DATABASE_URL=postgresql://user:password@localhost:5432/yourdbConnect your AI assistant, identical config for VS Code, Cursor, Windsurf, Claude Desktop, Zed, JetBrains, Neovim, opencode, Cline, Kilo, Roo Code, Gemini CLI, Codex CLI, Copilot CLI, and more:
{ "mcpServers": { "postgres": { "command": "pgautopilot" } } }Ready-to-copy config files for every supported client live in
server/config/, each folder has a README showing where to
put the file in your project.
Then just ask: "Show me all tables." · "How many users signed up this month?" · "Find orders over $500 by customer." · "Add a product called 'Widget Pro' at $29.99."
2. Dashboard (web UI)
From web/:
pnpm install
cp .env.example .env # set DATABASE_URL, PORT, HOST, DASHBOARD_TOKEN
pnpm dev # API on 127.0.0.1:3000 + Vite on :5173 (hot reload)After pnpm build, the API also serves the built SPA directly, so the full app
runs monolithically on the API port.
Without Docker? Get a local database running in minutes with Run your own PostgreSQL (no Docker).
Architecture
AI Assistant
(Claude / Cursor / GPT / Gemini)
|
v
MCP Protocol
|
v
+----------------------------------+
| PGAutoPilot |
| |
| Schema Discovery |
| Identifier Validation |
| Safety Policy Engine <----+ |
| SQL Builder | |
| Connection Pool | |
| Tool Handlers (14 tools) | |
+---------------------------------+ |
| |
v |
PostgreSQL Everything passes through safetyEvery MCP request flows: natural language → MCP tool call → Zod parameter validation → live schema lookup → identifier validation → safety policy evaluation → parameterized SQL generation → time-limited execution → formatted response. Deterministic at every step. No hidden state, no side effects.
The dashboard follows the same flow through its API: browser → Express →
tool gateway → packages/core (a port of the same safety layer) → PostgreSQL.
Safety & Security
Threat model
PGAutoPilot runs on your machine and connects over the PostgreSQL wire
protocol. The AI assistant communicates only through MCP, and every request
passes the safety layer before reaching PostgreSQL. The DATABASE_URL
credential is the sole authentication boundary for the MCP server; the
dashboard adds optional bearer-token auth and binds to 127.0.0.1 by default.
The safety model is shared by both entry points (server/src/safety.ts and
web/packages/core/src/safety.ts); a change to one must be mirrored in the
other, or the two surfaces diverge.
Safety features
Threat | Protection |
SQL injection | Parameterized queries (never string interpolation) |
Accidental delete-all |
|
Full table update | Warning on >10 rows affected |
Secret exposure | Automatic redaction on read + strip on write |
Unknown table/column | Live schema validation before query build |
Slow queries | Configurable statement timeout (default 10s) |
Connection exhaustion | Configurable pool limit |
Arbitrary SQL |
|
Dangerous Postgres fns | Blocked: |
Bulk data loss | Dry-run support on every write tool |
Operational guarantees
Never logs
DATABASE_URL(hostname only in the startup banner)Never exposes redacted fields (passwords, tokens, keys →
***REDACTED***)Never runs multiple SQL statements in one call
Never
UPDATEs without live identifier validationNever
DELETEs all rows withoutconfirmAll: trueNever runs raw
INSERT/UPDATE/DELETE(use the structured tools)Never bypasses schema validation or exceeds the pool max
Sensitive columns
Columns matching password, token, secret, api_key, private_key, ssn,
credit_card, cvv (and variants) are auto-redacted on read and stripped on
write. Extend via SENSITIVE_COLUMNS.
Least-privilege database role
Do not connect with a superuser or the application's primary role. Create a
dedicated role per connection mode and point DATABASE_URL at it. The Postgres
role is the security boundary, not the client.
CREATE ROLE mcp_readonly LOGIN PASSWORD 'generate-a-strong-password';
GRANT CONNECT ON DATABASE yourdb TO mcp_readonly;
GRANT USAGE ON SCHEMA public TO mcp_readonly;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO mcp_readonly;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO mcp_readonly;For a read/write connection, additionally grant INSERT, UPDATE, DELETE on
the tables the agent may touch. Never grant SUPERUSER. For non-loopback hosts,
prefer PGSSLMODE=verify-full.
Dashboard security
Localhost-first: the API binds to
127.0.0.1by default; setDASHBOARD_TOKENto requireAuthorization: Bearer <token>on all/api/*routes.Same safety model as the MCP server: every tool call passes through
packages/core.No CORS by default: the web app is served same-origin through the Vite proxy.
Masked errors: production mode returns generic errors so schema details never leak.
Rate limiting: tool execution, migrations, and failed authentication are throttled when configured.
Security
Responsible disclosure: report vulnerabilities privately via GitHub Security Advisories.
Signed releases: every release is SHA-256 checksummed and GPG-signed.
Zero runtime dependencies in the bundled MCP server build.
Logging policy: connection strings are never logged; per-request logs off in
--mode=production.
Tools (MCP server)
Read tools
Tool | Use when... | Returns |
| "What's in this database?" | All tables, row counts, relationships |
| "What columns does each table have?" | Full column/type/constraint map |
| "Is the connection working?" | Pool usage, uptime, latency |
| "Tell me about the orders table" | Columns, indexes, row estimates, size |
| "Show recent orders", "Find inactive users" | Filtered, sorted, paginated rows |
| "Get user with ID 42" | Single matching row |
| "How many users signed up this week?" | Row count (all or filtered) |
| "Total sales by category", "Average order value" | Grouped aggregates (count, sum, avg, min, max) |
| "I need a custom SELECT" | Raw query results (SELECT-only, limited to 5000 rows) |
Write tools
Tool | Use when... | Safety |
| "Add a new user" | Dry-run supported, schema-validated |
| "Create or update this product" | Dry-run supported, conflict-safe |
| "Update all shipped orders" | Warns on >10 rows, dry-run supported |
| "Delete old logs" | Warns on >10 rows, |
Maintenance tools
Tool | Use when... | Output |
| "Back up the database" | Full SQL dump via |
Examples
Find recent orders for a customer:
Prompt: "Show me the last 10 orders for customer 42"
Tool: db_find_many(table="orders", where={"customer_id": 42}, select=["id","total","status","created_at"], orderBy={"created_at":"desc"}, take=10)Count products by category:
Prompt: "How many products in each category?"
Tool: db_aggregate(table="products", by="category", _count="*", take=5, orderBy={"_count": "desc"})
-> Electronics: 142, Clothing: 89, Books: 54, ...Add a record (dry run first, then commit):
Prompt: "Add Jane Doe with email jane@example.com"
Tool: db_create(table="users", data={"email":"jane@example.com","name":"Jane Doe"}, dryRun=true)
-> "Dry run: valid. Proceed?" -> Row inserted with id 105Bulk delete with confirmation:
Prompt: "Delete logs from before 2025"
Tool: db_delete_many(table="logs", where={"created_at":{"lt":"2025-01-01"}}, dryRun=true)
-> "1,204 rows would be deleted. Confirm? [yes/no]"Every write tool is dry-run capable, and every query produces the exact parameterized SQL that runs, nothing touches your database silently.
API (dashboard)
All endpoints are mounted under /api. Token auth, rate limiting, and error masking apply when configured.
Method | Path | What it does |
GET |
| API + database diagnostics |
GET |
| List the safe MCP tools |
POST |
| Execute a tool with validated params |
GET |
| Live schema introspection |
GET |
| List applied + pending migrations |
POST |
| Apply all pending migrations |
POST |
| Apply specific migrations by version |
POST |
| Apply a single migration |
GET |
| Current safety/read-only/version state |
Tool execution passes through packages/core: sensitive-column redaction,
blocked-table checks, read-only enforcement, the raw-query dangerous-function
gate, and write confirmation requirements.
Migrations (dashboard)
Versioned SQL migrations live in web/apps/api/migrations (default
MIGRATIONS_DIR). Applied versions are tracked in the schema_migrations table.
File | What it does |
| Base schema: organizations, users, orders, invoices |
| Demo dataset for the dashboard views |
Apply pending migrations through the UI, the API (POST /api/migrations/apply),
or the migration runner in packages/core. In read-only mode, all apply
endpoints are blocked. 001_initial_schema.sql is idempotent; 002_seed_demo_data.sql
is not, so never assume both are safely re-runnable.
Docker
Run PGAutoPilot alongside a fresh PostgreSQL instance, or point it at a database you already have:
cd server
docker compose up --build # PostgreSQL 16 + MCP server together
docker run -e DATABASE_URL=... pgautopilot # Connect to an existing DBRun your own PostgreSQL (no Docker)
Don't use Docker for your database? Install PostgreSQL directly on your machine
and manage it yourself with psql or pgAdmin.
1. Install
Platform | How |
Windows | EDB installer. Note the superuser password it prompts for. |
macOS |
|
Linux (Debian/Ubuntu) |
|
Linux (Fedora) |
|
2. Set the postgres password
(Needed for TCP login; Windows/macOS set it at install time, so skip to step 3 if set):
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'mypass';"3. Create a database
createdb mydb (or CREATE DATABASE mydb; via psql).
4. Verify
pg_isready -h localhost -p 5432 should say accepting connections. Then:
DATABASE_URL=postgresql://postgres:mypass@localhost:5432/mydb5. Inspect with pgAdmin (optional)
New server: Host localhost · Port 5432 · Maintenance DB postgres · Username postgres · your password. Browse tables and run queries while PGAutoPilot works against the same database.
Backups need
pg_dump, bundled with PostgreSQL on Windows; install the client tools (postgresql-client/libpq) on macOS/Linux. See Troubleshooting.Tip: for production, create a dedicated least-privilege role for PGAutoPilot (see Safety & Security) and keep your
postgreslogin for pgAdmin/psql.
Configuration
MCP server (server/)
pgautopilot --readonly # block every write
pgautopilot --mode=production # suppress per-request logs
pgautopilot --readonly --mode=productionVariable | Default | What it does |
| (required) | PostgreSQL connection string |
| auto | SSL mode: |
|
| Maximum simultaneous database connections |
|
| Connection timeout (ms) |
|
| Idle-connection timeout (ms) |
|
| Max single-query time (ms) |
|
| Where |
| - | Docker container name for |
| - | Tables to block writes on (comma-separated) |
| - | Tables that warn but allow writes (comma-separated) |
| - | Extra columns to redact (comma-separated) |
| - | Set |
| - | Tools to disable entirely (comma-separated) |
|
| PostgreSQL schemas to introspect (comma-separated) |
|
|
|
Dashboard API (web/apps/api)
Variable | Default | What it does |
| (required) | PostgreSQL connection string |
|
| Port the API binds to |
|
| Bind address (localhost by default) |
| - | Bearer token required on all |
|
| Allow production start without a token |
|
| Max time for a single query (ms) |
|
| Directory holding versioned SQL migrations |
|
| Where |
| - | Docker container name for |
| - | Tables to block writes on (comma-separated) |
| - | Tables that warn but allow writes (comma-separated) |
| - | Extra columns to redact (comma-separated) |
| - | Set |
| - | Tools to disable entirely (comma-separated) |
|
|
|
|
|
|
| - | Requests per window for tool/migration endpoints |
|
| Rate-limit window |
|
| Failed-auth throttle when token auth is on |
|
| Failed-auth throttle window |
| - | Proxy trust when deployed behind a reverse proxy |
Dashboard Web (web/apps/web)
Variable | Default | What it does |
|
| Base URL for the API (same-origin proxy by default) |
| - | Bearer token sent on every request (match the API token) |
Connection string examples:
Where | URL |
Localhost |
|
Remote server |
|
Docker (port-mapped) |
|
Neon |
|
Supabase |
|
AWS RDS |
|
Render |
|
Cloud SSL: cloud providers (Neon, Supabase, RDS, Render) need SSL; set
PGSSLMODE=require (stronger: verify-full); auto-detected for most providers.
Performance
PGAutoPilot adds minimal overhead over a direct connection, latency depends on your database and network, with a zero-dependency single-file executable for the MCP server and configurable pool sizes and statement timeouts. Full benchmarks will be published once the project reaches a stable release.
Compatibility
Platform | Support |
Windows | Yes (native) |
macOS | Yes (native) |
Linux | Yes (native) |
Docker | Yes |
WSL | Yes |
ARM64 | Yes |
x64 | Yes |
Node 18 | Yes |
Node 20 | Yes |
Node 22 | Yes |
Software Signing
Method | How to verify |
SHA-256 hashes |
|
GPG signature |
|
cd server
npm run sign:gpg # signs dist/checksums.txt -> dist/checksums.txt.sig
npm run verify:gpg # verifies the signature + all checksumsInstall scripts verify checksums.txt automatically after cloning. On mismatch,
installation aborts. Bypass with --skip-verify (not recommended).
FAQ
Do I need to restart after schema changes? No, identifiers are validated against the live schema on every request.
Can PGAutoPilot modify my database automatically? Only through explicit tool calls; every write is deliberate, and dry-run-before-write is the default.
Does it work with Supabase? Yes, use the Supabase connection string and PGSSLMODE=require.
Does it require npm? No, npm, the one-line installer, or the single-file bundle all work.
Does it support SSL? Yes, auto-detected or via PGSSLMODE.
Can I disable writes entirely? Yes, pgautopilot --readonly.
Can I expose it publicly? No, the MCP server is designed for local/private network use (no auth layer or HTTP server); the dashboard binds to 127.0.0.1 by default.
Is it safe for production? Yes, every write path is guarded. See Safety & Security.
Troubleshooting
Error | Likely cause | How to verify | Fix |
|
|
| Create |
| PostgreSQL not running or wrong URL |
| Check host/port, Docker port mapping |
| Cloud DB requires SSL | Check provider docs | Set |
| Typo or wrong schema | Run | Use exact names from schema |
| Using | N/A | Use |
|
|
| Install |
Development
MCP server (server/), source layout
server/src/
index.ts Entry point, MCP server initialization
config.ts Environment variable loading and validation
db.ts PostgreSQL connection pool management
schema.ts Live schema introspection via information_schema
sqlBuilder.ts Parameterized, safe SQL query builder
safety.ts Redaction engine, write access control, warnings
toolDefinitions.ts Zod schemas for all 14 tools
toolHandlers.ts Tool implementations, one handler per toolCommand | What it does |
| Start the dev server with hot-reload |
| Compile TypeScript and bundle into a single executable |
| Run the compiled version |
| Full TypeScript type checking |
| TypeScript type-check + ESLint |
| Unit tests (vitest) |
| Auto-format source files with Prettier |
Dashboard (web/)
Command | What it does |
| Free conflicting ports, then run API + web with hot reload (Turborepo) |
| Check the API/web ports and kill processes using them |
| Build all workspace packages |
| Build, then run the bundled API ( |
| Full TypeScript type checking across the workspace |
| ESLint across the workspace |
| Unit tests across the workspace |
| Playwright E2E smoke test (from |
| Format all source with Prettier |
Dashboard source layout:
web/apps/api/src/ Express API (routes, middleware, services)
web/apps/web/src/ React SPA (app, components, features, routes)
web/packages/contracts/ zod schemas + DTOs
web/packages/core/ HTTP-friendly port of the MCP safety layer
web/packages/ui/ design system components
web/packages/config/ shared tsconfig + eslint presetsVerification before shipping
Run the full gate before merging or publishing:
# MCP core
cd server
npm run typecheck && npm run lint && npm run test && npm run build && npm run verify:gpg
# Dashboard
cd ../web
pnpm typecheck && pnpm lint && pnpm test && pnpm build
cd apps/web && pnpm test:e2eThe E2E smoke test (web/apps/web/e2e/smoke.spec.ts) boots the app and asserts
the tool runner renders. Run a full integration test against a live API +
Postgres if you need deeper coverage, since the smoke test starts only the web
server.
Roadmap
Authentication plugins / session management UI (API key, JWT)
SQL editor with syntax highlighting and safe-query checks
Backups UI (trigger and download
pg_dumpoutput)AI-assisted workflows (natural language to safe SQL, explain/optimize)
Role-based access control and audit log
Realtime monitoring (pool stats, slow queries, active sessions)
Contributing & License
See server/CONTRIBUTING.md for contribution guidelines.
MIT © 2026 Cyber Reinxy
This server cannot be installed
Maintenance
Related MCP Servers
- FlicenseAqualityDmaintenanceEnables AI assistants to interact with PostgreSQL databases using natural language queries, providing secure read-only access to database schemas and SQL translation capabilities.67
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to safely explore, analyze, and maintain PostgreSQL databases with read-only mode by default, SQL injection prevention, query performance analysis, and optional write operations.90Apache 2.0
- AlicenseNot gradedqualityNot gradedmaintenanceProvides AI assistants with safe, controlled access to PostgreSQL databases with read-only defaults, granular permissions, query safety features, and schema introspection capabilities.1
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to interact with PostgreSQL databases through natural language queries, schema inspection, and safe SQL execution.91
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.
The grounded data layer for any LLM: governed SQL, metrics, lineage and catalog over your data.
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/cyberreinxy/pgautopilot'
If you have feedback or need assistance with the MCP directory API, please join our Discord server