PostgreSQL
STDIOMCP server providing comprehensive PostgreSQL database management with 17 intelligent tools for AI assistants
MCP server providing comprehensive PostgreSQL database management with 17 intelligent tools for AI assistants
A Model Context Protocol (MCP) server that provides comprehensive PostgreSQL database management capabilities for AI assistants.
🚀 What's New: This server has been completely redesigned from 46 individual tools to 17 intelligent tools through consolidation (34→8 meta-tools) and enhancement (+4 new tools), providing better AI discovery while adding powerful data manipulation and comment management capabilities.
# Install globally npm install -g @henkey/postgres-mcp-server # Or run directly with npx (no installation) # Use env var for connection string (optional) export POSTGRES_CONNECTION_STRING="postgresql://user:pass@localhost:5432/db" npx @henkey/postgres-mcp-server # Or pass directly: npx @henkey/postgres-mcp-server --connection-string "postgresql://user:pass@localhost:5432/db"
npx @henkey/postgres-mcp-server --help
Add to your MCP client configuration:
{ "mcpServers": { "postgresql-mcp": { "command": "npx", "args": [ "@henkey/postgres-mcp-server", "--connection-string", "postgresql://user:password@host:port/database" ] } } }
npx -y @smithery/cli install @HenkDz/postgresql-mcp-server --client claude
# Build the Docker image docker build -t postgres-mcp-server . # Run with environment variable docker run -i --rm \ -e POSTGRES_CONNECTION_STRING="postgresql://user:password@host:port/database" \ postgres-mcp-server
Add to your MCP client configuration:
{ "mcpServers": { "postgresql-mcp": { "command": "docker", "args": [ "run", "-i", "--rm", "henkey/postgres-mcp:latest", "-e", "POSTGRES_CONNECTION_STRING" ], "env": { "POSTGRES_CONNECTION_STRING": "postgresql://user:password@host:port/database" } } } }
git clone <repository-url> cd postgresql-mcp-server npm install npm run build
Add to your MCP client configuration:
{ "mcpServers": { "postgresql-mcp": { "command": "node", "args": [ "/path/to/postgresql-mcp-server/build/index.js", "--connection-string", "postgresql://user:password@host:port/database" ] } } }
17 powerful tools organized into three categories:
Brand new capabilities not available in the original 46 tools
// Analyze database performance { "analysisType": "performance" } // Create a table with constraints { "operation": "create_table", "tableName": "users", "columns": [ { "name": "id", "type": "SERIAL PRIMARY KEY" }, { "name": "email", "type": "VARCHAR(255) UNIQUE NOT NULL" } ] } // Query data with parameters { "operation": "select", "query": "SELECT * FROM users WHERE created_at > $1", "parameters": ["2024-01-01"], "limit": 100 } // Insert new data { "operation": "insert", "table": "users", "data": {"name": "John Doe", "email": "[email protected]"}, "returning": "*" } // Find slow queries { "operation": "get_slow_queries", "limit": 5, "minDuration": 100 } // Execute a parameterized SELECT query { "operation": "select", "query": "SELECT * FROM users WHERE id = $1", "parameters": [1] } // Perform an INSERT mutation { "operation": "insert", "table": "products", "data": {"name": "New Product", "price": 99.99}, "returning": "id" } // Manage database object comments { "operation": "set", "objectType": "table", "objectName": "users", "comment": "Main user account information table" }
📋 Complete Tool Schema Reference - All 18 tool parameters & examples in one place
For additional information, see the docs/ folder:
✅ 34→8 meta-tools - Intelligent consolidation for better AI discovery
✅ Multiple operations per tool - Unified schemas with operation parameters
✅ Smart parameter validation - Clear error messages and type safety
✅ Complete CRUD operations - INSERT/UPDATE/DELETE/UPSERT with parameterized queries
✅ Flexible querying - SELECT with count/exists support and safety limits
✅ Arbitrary SQL execution - Transaction support for complex operations
✅ Flexible connection - CLI args, env vars, or per-tool configuration
✅ Security focused - SQL injection prevention, parameterized queries
✅ Robust architecture - Connection pooling, comprehensive error handling
The PostgreSQL MCP Server is fully Docker-compatible and can be used in production environments.
# Build locally docker build -t postgres-mcp-server . # Or pull from Docker Hub docker pull henkey/postgres-mcp:latest
# Basic usage (using Docker Hub image) docker run -i --rm \ -e POSTGRES_CONNECTION_STRING="postgresql://user:password@host:port/database" \ henkey/postgres-mcp:latest # Or with locally built image docker run -i --rm \ -e POSTGRES_CONNECTION_STRING="postgresql://user:password@host:port/database" \ postgres-mcp-server # With tools configuration docker run -i --rm \ -e POSTGRES_CONNECTION_STRING="postgresql://user:password@host:port/database" \ -e POSTGRES_TOOLS_CONFIG="/app/config/tools.json" \ -v /path/to/config:/app/config \ postgres-mcp-server
version: '3.8' services: postgres-mcp: build: . environment: - POSTGRES_CONNECTION_STRING=postgresql://user:password@postgres:5432/database depends_on: - postgres stdin_open: true tty: true postgres: image: postgres:15 environment: - POSTGRES_DB=database - POSTGRES_USER=user - POSTGRES_PASSWORD=password ports: - "5432:5432"
For use with MCP clients like Cursor or Claude Desktop:
{ "mcpServers": { "postgresql-mcp": { "command": "docker", "args": [ "run", "-i", "--rm", "henkey/postgres-mcp:latest", "-e", "POSTGRES_CONNECTION_STRING" ], "env": { "POSTGRES_CONNECTION_STRING": "postgresql://user:password@host:port/database" } } } }
See Development Guide for detailed setup instructions.
AGPLv3 License - see LICENSE file for details.