A Model Context Protocol (MCP) server that provides comprehensive PostgreSQL database management capabilities for AI assistants
npm install @henkey/postgres-mcp-serverA 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 18 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.
bash
Install globally
npm install -g @henkey/postgres-mcp-serverOr run directly with npx (no installation)
npx @henkey/postgres-mcp-server --connection-string "postgresql://user:pass@localhost:5432/db"
`Add to your MCP client configuration:
`json
{
"mcpServers": {
"postgresql-mcp": {
"command": "npx",
"args": [
"@henkey/postgres-mcp-server",
"--connection-string", "postgresql://user:password@host:port/database"
]
}
}
}
`$3
`bash
npx -y @smithery/cli install @HenkDz/postgresql-mcp-server --client claude
`$3
`bash
git clone
cd postgresql-mcp-server
npm install
npm run build
`Add to your MCP client configuration:
`json
{
"mcpServers": {
"postgresql-mcp": {
"command": "node",
"args": [
"/path/to/postgresql-mcp-server/build/index.js",
"--connection-string", "postgresql://user:password@host:port/database"
]
}
}
}
`What's Included
18 powerful tools organized into three categories:
- š Consolidation: 34 original tools consolidated into 8 intelligent meta-tools
- š§ Specialized: 6 tools kept separate for complex operations
- š Enhancement: 4 brand new tools (not in original 46)
$3
- 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$3
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$3
- Database Analysis - Performance and configuration analysis
- Setup Instructions - Platform-specific PostgreSQL setup
- 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 alertsExample Usage
`typescript
// 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": "john@example.com"},
"returning": "*"
}
// Find slow queries
{
"operation": "get_slow_queries",
"limit": 5,
"minDuration": 100
}
// Manage database object comments
{
"operation": "set",
"objectType": "table",
"objectName": "users",
"comment": "Main user account information table"
}
`š Documentation
š Complete Tool Schema Reference - All 18 tool parameters & examples in one place
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
- Node.js ā„ 18.0.0
- PostgreSQL server access
- Valid connection credentials
1. Fork the repository
2. Create a feature branch
3. Commit your changes
4. Create a Pull Request
See Development Guide for detailed setup instructions.
AGPLv3 License - see LICENSE file for details.