The PostgreSQL MCP Server provides AI assistants with comprehensive PostgreSQL database management through 17 intelligent tools covering schema management, security, data operations, performance optimization, and monitoring.
Core Capabilities:
Schema & Structure Management - Create/alter tables, manage ENUMs, columns, constraints (foreign keys, checks, unique), indexes (btree, hash, gist, gin, brin), functions (SQL, PL/pgSQL, PL/Python), triggers, and database object comments
Security & Access Control - Create/drop/alter users and roles with granular permissions, grant/revoke privileges on tables/schemas/databases, implement Row-Level Security (RLS) policies
Data Operations - Execute SELECT queries with parameterized statements, perform INSERT/UPDATE/DELETE/UPSERT operations with conflict resolution, run arbitrary SQL with transaction support, export/import data (JSON/CSV), and copy data between databases
Performance & Diagnostics - Generate EXPLAIN plans, identify slow queries, analyze query statistics and cache hit ratios, examine database configuration/performance/security, and troubleshoot connection, lock, and replication issues
Real-time Monitoring - Monitor active connections, queries, locks, table statistics, replication lag, and set customizable alert thresholds
Index Management - Create/drop/rebuild indexes (including concurrent operations), analyze usage patterns, and identify duplicates
Key Features: SQL injection prevention through parameterized queries, transaction wrapping for atomicity, connection pooling, flexible connection options (CLI, environment variables, per-tool strings), concurrent operations support, and production-ready error handling with Docker support.
Supports PostgreSQL installation and configuration on Linux platforms with customized setup instructions tailored to Linux environments.
Provides platform-specific PostgreSQL installation and configuration guidance for macOS systems.
Requires Node.js runtime environment for server operation, with specific version requirements (ā„ 18.0.0) for proper functionality.
Provides comprehensive PostgreSQL database management capabilities, including database analysis, schema management, data migration, and real-time monitoring. Enables analyzing configurations, debugging issues, creating and altering tables, exporting/importing data between databases, and monitoring performance metrics.
PostgreSQL MCP Server
A Model Context Protocol (MCP) server that provides comprehensive PostgreSQL database management capabilities for AI assistants.
Features
š 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.
Related MCP server: MCP PostgreSQL Server
Quick Start
Prerequisites
Node.js ā„18.0.0
Access to a PostgreSQL server
(Optional) An MCP client like Cursor or Claude for AI integration
Option 1: npm (Recommended)
Verify installation
npx @henkey/postgres-mcp-server --help
Add to your MCP client configuration:
Option 2: Install via Smithery
Option 3: Docker (Recommended for Production)
Add to your MCP client configuration:
Option 4: Manual Installation (Development)
Add to your MCP client configuration:
What's Included
17 powerful tools organized into three categories:
š Consolidation: 34 original tools consolidated into 8 intelligent meta-tools
š§ Specialized: 5 tools kept separate for complex operations
š Enhancement: 4 brand new tools (not in original 46)
š Consolidated Meta-Tools (8 tools)
Schema Management - Tables, columns, ENUMs, constraints
User & Permissions - Create users, grant/revoke permissions
Query Performance - EXPLAIN plans, slow queries, statistics
Index Management - Create, analyze, optimize indexes
Functions - Create, modify, manage stored functions
Triggers - Database trigger management
Constraints - Foreign keys, checks, unique constraints
Row-Level Security - RLS policies and management
š Enhancement Tools (4 NEW tools)
Brand new capabilities not available in the original 46 tools
Execute Query - SELECT operations with count/exists support
Execute Mutation - INSERT/UPDATE/DELETE/UPSERT operations
Execute SQL - Arbitrary SQL execution with transaction support
Comments Management - Comprehensive comment management for all database objects
š§ Specialized Tools (5 tools)
Database Analysis - Performance and configuration analysis
Debug Database - Troubleshoot connection, performance, locks
Data Export/Import - JSON/CSV data migration
Copy Between Databases - Cross-database data transfer
Real-time Monitoring - Live database metrics and alerts
Example Usage
š Documentation
š - All 18 tool parameters & examples in one place
For additional information, see the docs/ folder:
š Usage Guide - Comprehensive tool usage and examples
š ļø Development Guide - Setup and contribution guide
āļø Technical Details - Architecture and implementation
šØāš» Developer Reference - API reference and advanced usage
š Documentation Index - Complete documentation overview
Features Highlights
š Consolidation Achievements
ā
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
š Enhanced Data Capabilities
ā
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
š§ Production Ready
ā
Flexible connection - CLI args, env vars, or per-tool configuration
ā
Security focused - SQL injection prevention, parameterized queries
ā
Robust architecture - Connection pooling, comprehensive error handling
Docker Usage
The PostgreSQL MCP Server is fully Docker-compatible and can be used in production environments.
Building the Image
Running with Environment Variables
Docker Compose Example
MCP Client Configuration
For use with MCP clients like Cursor or Claude Desktop:
Prerequisites
Node.js ā„ 18.0.0 (for local development)
Docker (for containerized deployment)
PostgreSQL server access
Valid connection credentials
Contributing
Fork the repository
Create a feature branch
Commit your changes
Create a Pull Request
See Development Guide for detailed setup instructions.
License
AGPLv3 License - see LICENSE file for details.