Skip to main content
Glama

PostgreSQL MCP Server

AGPL 3.0
582
99
  • Linux
  • Apple

PostgreSQL MCP Server

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.

Quick Start

# Install globally npm install -g @henkey/postgres-mcp-server # Or 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:

{ "mcpServers": { "postgresql-mcp": { "command": "npx", "args": [ "@henkey/postgres-mcp-server", "--connection-string", "postgresql://user:password@host:port/database" ] } } }

Option 2: Install via Smithery

npx -y @smithery/cli install @HenkDz/postgresql-mcp-server --client claude

Option 3: Manual Installation (Development)

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" ] } } }

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

// 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

For additional information, see the docs/ folder:

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

Prerequisites

  • Node.js ≥ 18.0.0
  • PostgreSQL server access
  • Valid connection credentials

Contributing

  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.

License

AGPLv3 License - see LICENSE file for details.

Install Server
A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

Сервер Model Context Protocol, который обеспечивает мощные возможности управления базами данных PostgreSQL, включая анализ, управление схемами, миграцию данных и мониторинг посредством взаимодействия на естественном языке.

  1. Версия 0.2.0
    1. Функции
      1. 1. Анализ и настройка базы данных
      2. 2. Управление схемой
      3. 3. Миграция данных
      4. 4. Мониторинг
      5. 5. Функции
      6. 6. Безопасность на уровне строк (RLS)
      7. 7. Триггеры
    2. Предпосылки
      1. Установка
        1. Установка через Smithery
        2. Ручная установка
      2. Конфигурация инструмента
        1. Разработка
          1. Соображения безопасности
            1. Лучшие практики
              1. Обработка ошибок
                1. Внося вклад
                  1. Лицензия

                    Related MCP Servers

                    • -
                      security
                      F
                      license
                      -
                      quality
                      A Model Context Protocol server providing both read and write access to PostgreSQL databases, enabling LLMs to query data, modify records, and manage database schemas.
                      Last updated -
                      144
                      7
                      JavaScript
                    • -
                      security
                      F
                      license
                      -
                      quality
                      A Model Context Protocol server that enables performing PostgreSQL database operations (create, read, update, delete) on User and Post entities through MCP tools.
                      Last updated -
                      TypeScript
                    • -
                      security
                      A
                      license
                      -
                      quality
                      A Model Context Protocol server that enables interaction with PostgreSQL databases to list tables, retrieve schemas, and execute read-only SQL queries.
                      Last updated -
                      20
                      JavaScript
                      MIT License
                      • Linux
                      • Apple
                    • A
                      security
                      A
                      license
                      A
                      quality
                      A Model Context Protocol server that enables interaction with PostgreSQL databases for analyzing setups, debugging issues, managing schemas, migrating data, and monitoring performance.
                      Last updated -
                      1
                      0
                      TypeScript
                      MIT License

                    View all related MCP servers

                    MCP directory API

                    We provide all the information about MCP servers via our MCP API.

                    curl -X GET 'https://glama.ai/api/mcp/v1/servers/HenkDz/postgresql-mcp-server'

                    If you have feedback or need assistance with the MCP directory API, please join our Discord server