PostgreSQL Database Manager MCP server

Integrates with PostgreSQL databases to enable schema management, data migration, performance monitoring, and security configuration through direct database operations without requiring separate management tools.
Back to servers
Setup instructions
Provider
HenkDz
Release date
Mar 18, 2025
Language
TypeScript
Stats
116 stars

The PostgreSQL MCP Server enables AI assistants to manage PostgreSQL databases through a set of intelligent tools that provide comprehensive database capabilities via the Model Context Protocol.

Quick Start

Installation Options

Using npm (Recommended)

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

Using Smithery

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

Tool Capabilities

The PostgreSQL MCP Server provides 17 powerful tools organized in three categories:

Consolidated Meta-Tools (8)

  • 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)

  • 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 database objects

Specialized Tools (5)

  • 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

Analyzing Database Performance

{ "analysisType": "performance" }

Creating a Table with Constraints

{
  "operation": "create_table",
  "tableName": "users", 
  "columns": [
    { "name": "id", "type": "SERIAL PRIMARY KEY" },
    { "name": "email", "type": "VARCHAR(255) UNIQUE NOT NULL" }
  ]
}

Querying Data with Parameters

{
  "operation": "select",
  "query": "SELECT * FROM users WHERE created_at > $1",
  "parameters": ["2024-01-01"],
  "limit": 100
}

Inserting New Data

{
  "operation": "insert",
  "table": "users",
  "data": {"name": "John Doe", "email": "[email protected]"},
  "returning": "*"
}

Finding Slow Queries

{
  "operation": "get_slow_queries",
  "limit": 5,
  "minDuration": 100
}

Managing Database Object Comments

{
  "operation": "set",
  "objectType": "table",
  "objectName": "users",
  "comment": "Main user account information table"
}

Prerequisites

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

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

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

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

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

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

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

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later