Enables querying and analyzing PostgreSQL databases through SQL execution, table schema inspection, and sample data retrieval with optional write operations support
Postgres MCP Server
A Model Context Protocol server for PostgreSQL databases. Enables LLMs to query and analyze PostgreSQL databases through a controlled interface.
https://github.com/user-attachments/assets/6571c20c-91c9-4a6e-8332-13b587b79fbf
Installation
Add to your MCP client settings:
Configuration
DATABASE_URL- PostgreSQL connection string (required)DANGEROUSLY_ALLOW_WRITE_OPS- Enable writes (default:false)DEBUG- Enable debug logging (default:false)PG_SSL_ROOT_CERT- Optional path to a TLS CA bundle (e.g., AWS RDS global bundle)
Usage
Transports
Default transport is stdio. Switch to HTTP with the
--transportflag.HTTP mode serves the MCP Streamable HTTP endpoint at
/mcponPORT(default3000).Clients that support Streamable HTTP should connect to
http://localhost:3000/mcp.
Start commands:
Tools
query- Execute SQL queries{ "sql": "SELECT * FROM users WHERE active = true LIMIT 10" }
Resources
postgres://tables- List all tablespostgres://table/{schema}/{table}- Get table schema and sample data
Example Prompts
Here's an example prompt to test if your MCP server is working:
Data Analysis & Notebooks
For data analysis and exploration, I've added a Cursor rule for using the MCP server together with notebooks in .cursor/rules/notebooks.mdc:
Quick Start with Docker
Sample tables included: users, products, orders, order_items
Development
Use local build in MCP client settings:
Releases
This repo auto-creates a GitHub Release when you push a tag that matches the version in package.json:
Update
CHANGELOG.mdand bump the version inpackage.json.Commit the changes on
main(or your release branch).Create and push a matching tag:
The GitHub Actions workflow will validate that the tag (e.g. v0.1.0) matches package.json, then use gh to create a release with generated notes, and publish to npm.
License
MIT - see LICENSE
This server cannot be installed
Related Resources
Related MCP Servers
- -security-license-qualityA Model Context Protocol server providing LLMs read-only access to PostgreSQL databases for inspecting schemas and executing queries.Last updated -22,30423MIT License
- Asecurity-licenseAqualityFacilitates management and optimization of PostgreSQL databases, offering analysis, setup guidance, and debugging, while ensuring secure and efficient database operations.Last updated -3116AGPL 3.0
- -security-license-qualityEnables LLMs to interact with MySQL databases by inspecting schemas and executing safe, read-only queries within transactions.Last updated -09MIT License
- -security-license-qualityProvides read-only access to PostgreSQL databases, enabling LLMs to inspect database schemas and execute read-only SQL queries within a secure transaction context.Last updated -22,3041