postgres-mcp-server
An MCP server for safely querying PostgreSQL from an LLM, with read-only default mode, multi-connection aliases, and session-enforced safety.
README
postgres-mcp-server
An MCP server for safely querying PostgreSQL from an LLM. Read-only by default, multi-connection with named aliases, Postgres-session-enforced safety.
Quickstart
Create ~/.config/postgres-mcp/config.json:
{
"connections": {
"local": {
"url_env": "LOCAL_DATABASE_URL",
"mode": "read"
}
}
}
Add to your MCP client config (Claude Desktop, Cursor, Windsurf, Zed):
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "@arieffian/postgres-mcp-server"],
"env": { "LOCAL_DATABASE_URL": "postgres://user:pw@localhost/db" }
}
}
}
Restart the client and ask: "Ping the local Postgres and list its tables."
Modes
Every connection declares its mode statically in config. Escalation requires editing config and restarting.
| Mode | SELECT | INSERT/UPDATE/DELETE | DDL | Notes |
|---|---|---|---|---|
| read | ✓ | ✗ | ✗ | Default. SET default_transaction_read_only = on at the session level. |
| write | ✓ | ✓ | ✗ | Writes must go through begin_transaction → execute → commit. |
| admin | ✓ | ✓ | ✓ | Same tx flow as write; DDL also permitted. |
Tools
Meta
ping,list_connections
SQL
query— read-only SELECT via server-side cursorbegin_transaction,commit,rollback— tx lifecycleexecute— INSERT/UPDATE/DELETE/DDL inside an open tx
Schema introspection (Phase 2, new in 0.2.0)
list_databases,list_schemaslist_tables— includes regular, partitioned, and foreign tables (viakindfield); row count is clamped to 0 for never-analyzed tableslist_indexes,list_constraints— per-table catalog listingslist_functions— excludes functions installed by extensionsdescribe_table— composite: columns, PK, FKs, indexes, constraints in one call
Observability — ships in Phase 3.
Safety
Five layers — see docs/safety.md. Highlights:
- Read-only enforced by the Postgres session, not by parsing SQL — we do not trust our own parser.
- Statement timeout per connection (default 30s).
- Every SELECT wrapped in a server-side cursor; results capped by row count and byte size.
- Writes require an explicit transaction; no autocommit.
- Bound parameter values are never logged. Credentials in URLs are redacted.
Configuration
Discovery order (first hit wins):
--config <path>CLI flag$POSTGRES_MCP_CONFIGenv var$XDG_CONFIG_HOME/postgres-mcp/config.json(fallback~/.config/postgres-mcp/config.json)./postgres-mcp.config.json
Contributing
Requires Node ≥ 20. Local dev: npm install, npm test. Integration tests use testcontainers and need a working Docker daemon.
Publishing
Set NPM_TOKEN in the repo's GitHub Actions secrets. Changesets automatically opens a release PR on push to main; merging it publishes to npm with provenance.
License
MIT
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.