-
Notifications
You must be signed in to change notification settings - Fork 0
Quick Start
Version 1.1.0
Get up and running with PostgreSQL MCP Server in 30 seconds!
Before starting, ensure you have:
-
PostgreSQL Database (version 13-17)
- Running and accessible instance
- Valid connection credentials
- Network connectivity
-
Environment Variable
export DATABASE_URI="postgresql://username:password@localhost:5432/dbname"
-
MCP Client
- Claude Desktop, Cursor, or other MCP-compatible client
Pull the latest image:
docker pull neverinfamous/postgres-mcp:latest
Run with environment variable:
docker run -i --rm \
-e DATABASE_URI="postgresql://username:password@localhost:5432/dbname" \
neverinfamous/postgres-mcp:latest \
--access-mode=restricted
Install from PyPI:
pip install postgres-mcp
Run the server:
postgres-mcp --access-mode=restricted
Clone the repository:
git clone https://github.com/neverinfamous/postgres-mcp.git
cd postgres-mcp
Install dependencies:
uv sync
Run tests to verify:
uv run pytest -v
Using your MCP client, try:
mcp_postgres-mcp_list_schemas()
Expected output: List of all database schemas
mcp_postgres-mcp_analyze_db_health(health_type="all")
Expected output: Comprehensive health report
mcp_postgres-mcp_get_top_queries(sort_by="total_time", limit=5)
Expected output: Top 5 queries (requires pg_stat_statements)
The server requires some PostgreSQL extensions for full functionality:
CREATE EXTENSION IF NOT EXISTS pg_stat_statements; -- Query tracking
CREATE EXTENSION IF NOT EXISTS pg_trgm; -- Text similarity
CREATE EXTENSION IF NOT EXISTS fuzzystrmatch; -- Fuzzy matching
CREATE EXTENSION IF NOT EXISTS hypopg; -- Hypothetical indexes
CREATE EXTENSION IF NOT EXISTS vector; -- Vector similarity (pgvector)
CREATE EXTENSION IF NOT EXISTS postgis; -- Geospatial operations
Note: Tools gracefully degrade with informative errors if optional extensions are missing.
See Extension Setup for detailed installation instructions.
Now that you're set up, explore:
- MCP Resources & Prompts - NEW! AI-native intelligence features
- Core Database Tools - Essential database operations
- JSON Operations - Work with JSONB data
- Performance Intelligence - Optimize queries
- MCP Configuration - Configure your MCP client
postgres-mcp --access-mode=restricted
- ✅ Read-only operations
- ✅ Advanced SQL validation
- ✅ Query timeout protection
- ✅ Resource usage limits
postgres-mcp --access-mode=unrestricted
⚠️ Full read/write access- ✅ Parameter binding protection
⚠️ Use only in trusted environments
Recommendation: Always use restricted
mode for production databases.
# List all schemas
list_schemas()
# Execute secure SQL
execute_sql(
sql="SELECT * FROM users WHERE id = %s",
params=[123]
)
# Explain query plan
explain_query(
sql="SELECT * FROM orders WHERE customer_id = %s",
params=[456]
)
# Get database health
analyze_db_health(health_type="all")
# Monitor real-time metrics
monitor_real_time(
include_queries=True,
include_locks=True
)
# Verify PostgreSQL is running
pg_isready -h localhost -p 5432
# Check connection string
echo $DATABASE_URI
-- Install missing extension
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
-- Verify installation
SELECT extname, extversion FROM pg_extension;
- Verify MCP client configuration syntax
- Check that DATABASE_URI is set correctly
- Ensure server is running
See Troubleshooting for more solutions.
You now have PostgreSQL MCP Server running. Explore the tool categories to see what you can do!
Need help? Check out the Troubleshooting page or open an issue.