PostgreSQL Database Interface
STDIOModel Context Protocol implementation for PostgreSQL databases providing standardized interface for AI agents.
Model Context Protocol implementation for PostgreSQL databases providing standardized interface for AI agents.
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.
Connection Management
Database Operations
SQL Validation
cargo install postgres-mcp
Add the following to your MCP configuration file:
{ "mcpServers": { "postgres": { "command": "postgres-mcp", "args": ["stdio"] } } }
or run it in SSE mode:
First, start the postgres-mcp
server in SSE mode:
postgres-mcp sse
Then, configure the MCP config file to use the SSE mode:
{ "mcpServers": { "postgres": { "url": "http://localhost:3000/sse" } } }
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):
pg_mcp register "postgres://postgres:postgres@localhost:5432/postgres" # Returns a connection ID (UUID)
pg_mcp unregister <connection_id>
pg_mcp query <connection_id> "SELECT * FROM users"
pg_mcp insert <connection_id> "INSERT INTO users (name, email) VALUES ('John Doe', '[email protected]')"
pg_mcp update <connection_id> "UPDATE users SET name = 'Jane Doe' WHERE id = 1"
pg_mcp delete <connection_id> "users" "1"
pg_mcp create <connection_id> "CREATE TABLE users (id SERIAL PRIMARY KEY, name VARCHAR(255), email VARCHAR(255))"
pg_mcp drop <connection_id> "users"
pg_mcp create_index <connection_id> "CREATE INDEX idx_users_name ON users (name)"
pg_mcp drop_index <connection_id> "idx_users_name"
pg_mcp describe <connection_id> "users"
To build from source:
git clone https://github.com/yourusername/postgres-mcp.git cd postgres-mcp cargo build --release
MIT license. See LICENSE.md for details.
Contributions are welcome! Please open an issue or submit a pull request.