Postgres MCP
Postgres MCP is a Model Context Protocol (MCP) implementation for PostgreSQL databases. It provides a standardized interface for AI agents to interact with PostgreSQL databases through a set of well-defined commands.
Features
-
Connection Management
- Register and unregister database connections
- Support for multiple concurrent database connections
- Connection pooling for efficient resource management
-
Database Operations
- Execute SELECT queries
- Insert new records
- Update existing records
- Delete records
- Create and drop tables
- Create and drop indexes
- Describe table structures
- List tables in a schema
-
SQL Validation
- Built-in SQL parser for validating statements
- Support for PostgreSQL-specific syntax
- Safety checks to ensure only allowed operations are performed
Installation
Usage
Configuration
Add the following to your MCP configuration file:
Once you started the postgres-mcp
server, you should see the status of the MCP config is green, like this (cursor):
And then you could interact with it via the agent, like this (cursor):
Commands
Register a Database Connection
# Returns a connection ID (UUID)
Unregister a Connection
Execute a SELECT Query
Insert Data
Update Data
Delete Data
Create a Table
Drop a Table
Create an Index
Drop an Index
Describe a Table
Dependencies
- Rust 1.70 or later
- PostgreSQL 12 or later
- Required Rust crates:
- anyhow: 1.0
- arc-swap: 1.7
- sqlx: 0.8 (with "runtime-tokio", "tls-rustls-aws-lc-rs", "postgres" features)
- rmcp: 0.1 (with "server", "transport-sse-server", "transport-io" features)
- schemars: 0.8
- sqlparser: 0.55
- tokio: 1.44
Development
To build from source:
License
MIT license. See LICENSE.md for details.
Contributing
Contributions are welcome! Please open an issue or submit a pull request.