mcp postgres full access
A Model Context Protocol server that provides LLMs with full read-write access to PostgreSQL databases, allowing both querying and modifying database content with transaction management and safety controls.
A Model Context Protocol server that provides LLMs with full read-write access to PostgreSQL databases, allowing both querying and modifying database content with transaction management and safety controls.
A powerful Model Context Protocol server providing full read-write access to PostgreSQL databases. Unlike the read-only official MCP PostgreSQL server, this enhanced implementation allows Large Language Models (LLMs) to both query and modify database content with proper transaction management and safety controls.
execute_query
Execute read-only SQL queries (SELECT statements)
sql
(string): The SQL query to executeResults include execution time metrics and field information
execute_dml_ddl_dcl_tcl
Execute data modification operations (INSERT, UPDATE, DELETE) or schema changes (CREATE, ALTER, DROP)
sql
(string): The SQL statement to executeImportant safety feature: The conversation will end after execution, allowing the user to review the results before deciding to commit or rollback
execute_commit
Explicitly commit a transaction by its ID
transaction_id
(string): ID of the transaction to commitPermanently applies changes to the database
execute_rollback
Explicitly rollback a transaction by its ID
transaction_id
(string): ID of the transaction to rollbackUseful when reviewing changes and deciding not to apply them
list_tables
Get a comprehensive list of all tables in the database
No input parameters required
describe_table
table_name
(string): Name of the table to describeThe server provides enhanced schema information for database tables:
postgres://<host>/<table>/schema
)To use this server with Claude Desktop, follow these steps:
Install the package using npx or add it to your project
Configure Claude Desktop by editing claude_desktop_config.json
(typically found at ~/Library/Application Support/Claude/
on macOS):
{
"mcpServers": {
"postgres-full": {
"command": "npx",
"args": [
"-y",
"mcp-postgres-full-access",
"postgresql://username:password@localhost:5432/database"
],
"env": {
"TRANSACTION_TIMEOUT_MS": "60000",
"MAX_CONCURRENT_TRANSACTIONS": "5",
"PG_STATEMENT_TIMEOUT_MS": "30000"
}
}
}
}
When Claude attempts to commit changes to your database, Claude Desktop will prompt you for approval:
Always review the SQL changes carefully before approving them!
Best practices for safety:
This "Allow once" approach gives you full control to prevent unwanted changes to your database while still enabling Claude to help with data management tasks when needed.
You can customize the server behavior with environment variables in your Claude Desktop config:
"env": {
"TRANSACTION_TIMEOUT_MS": "60000",
"MAX_CONCURRENT_TRANSACTIONS": "5"
}
Key environment variables:
TRANSACTION_TIMEOUT_MS
: Transaction timeout in milliseconds (default: 15000)
Increase this if your transactions need more time
Transactions exceeding this time will be automatically rolled back for safety
MAX_CONCURRENT_TRANSACTIONS
: Maximum concurrent transactions (default: 10)
Lower this number for more conservative operation
Higher values allow more simultaneous write operations
ENABLE_TRANSACTION_MONITOR
: Enable/disable transaction monitor ("true" or "false", default: "true")
Monitors and automatically rolls back abandoned transactions
Rarely needs to be disabled
PG_STATEMENT_TIMEOUT_MS
: SQL query execution timeout in ms (default: 30000)
Limits how long any single SQL statement can run
Important safety feature to prevent runaway queries
PG_MAX_CONNECTIONS
: Maximum PostgreSQL connections (default: 20)
Important to stay within your database's connection limits
MONITOR_INTERVAL_MS
: How often to check for stuck transactions (default: 5000)
This server enables Claude to both read from and write to your PostgreSQL database with your approval. Here are some example conversation flows:
You: "I need a new products table with columns for id, name, price, and inventory"
Claude: Analyzes your database and creates a query
CREATE TABLE products (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
price DECIMAL(10,2) NOT NULL,
inventory INTEGER DEFAULT 0
);
Claude Desktop will prompt you to approve this operation
You: Review and click "Allow once"
Claude: "I've created the products table. Would you like me to add some sample data?"
You: "Yes, please add 5 sample products"
Claude: Creates INSERT statements and prompts for approval You review and approve with "Allow once"
You: "What are my top 3 products by price?"
Claude: Executes a read-only query automatically Shows you the results
The key safety feature is the two-step approach for any operation that modifies your database:
This gives you multiple opportunities to verify changes before they're permanently applied to the database.
When connecting Claude to your database with write access:
IMPORTANT: Create a dedicated database user with appropriate permissions:
-- Example of creating a restricted user (adjust as needed)
CREATE USER claude_user WITH PASSWORD 'secure_password';
GRANT SELECT ON ALL TABLES IN SCHEMA public TO claude_user;
GRANT INSERT, UPDATE, DELETE ON TABLE table1, table2 TO claude_user;
-- Only grant specific permissions as needed
Always use "Allow once" to review each write operation
Never select "Always allow" for database modifications
Take time to review the SQL carefully
Connect to a testing database when first exploring this tool
Consider using a database copy/backup for initial testing
Limit database user permissions to only what's necessary
Avoid using a superuser or admin account
Grant table-specific permissions when possible
Implement database backups before extensive use
Never share sensitive data that shouldn't be exposed to LLMs
Verify all SQL operations before approving them
The server can be easily run in a Docker container:
# Build the Docker image
docker build -t mcp-postgres-full-access .
# Run the container
docker run -i --rm mcp-postgres-full-access "postgresql://username:password@host:5432/database"
For Docker on macOS, use host.docker.internal to connect to the host network:
docker run -i --rm mcp-postgres-full-access "postgresql://username:[email protected]:5432/database"
This MCP server is licensed under the MIT License.
Feature | This Server | Official MCP PostgreSQL Server |
---|---|---|
Read Access | ✅ | ✅ |
Write Access | ✅ | ❌ |
Schema Details | Enhanced | Basic |
Transaction Support | Explicit with timeouts | Read-only |
Index Information | ✅ | ❌ |
Foreign Key Details | ✅ | ❌ |
Row Count Estimates | ✅ | ❌ |
Table Descriptions | ✅ | ❌ |
Created by Syahiid Nur Kamil (@syahiidkamil)
Copyright © 2024 Syahiid Nur Kamil. All rights reserved.