Skip to content
Conduit

mcp server

postgres-mcp-server

irsyadjpp/postgres-mcp-servercommunitylistedunreviewed

Set up

Runs on your computer. Pick your agent and operating system.

Before you start

  • Node.js 20 or newer
~/Library/Application Support/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "irsyadjpp-postgres-mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "@irsyadjpp/postgres-mcp-server"
      ]
    }
  }
}

same format Cursor, GitHub Copilot CLI, Junie, JetBrains AI Assistant, Augment (Auggie CLI), Factory Droid, Kiro, Devin CLI +12

Values in angle brackets are placeholders. Restart Claude Desktop after editing its config.Claude Desktop docs

README

synced Oct 26, 2026

PostgreSQL MCP Server

A secure Model Context Protocol (MCP) Server for PostgreSQL built with Kysely ORM. It enables AI assistants such as Claude Desktop, GitHub Copilot, Cline, and others to interact with PostgreSQL databases using natural language.

npm version Tests GitHub issues

A secure Model Context Protocol (MCP) server for PostgreSQL built with Kysely ORM. It provides AI assistants with secure, read-only (by default) access to PostgreSQL databases using natural language.


Table of Contents


Features

Database Features

  • ✅ PostgreSQL 12–18 support
  • ✅ Multi-database support
  • ✅ Lazy database initialization
  • ✅ Connection pooling
  • ✅ Query timeout configuration
  • ✅ Read-only mode by default
  • ✅ Parameterized queries (SQL Injection protection)
  • ✅ Type-safe validation using Zod

MCP Capabilities

More than 40 MCP tools covering:

  • SQL Query Execution
  • Schema Inspection
  • Table Explorer
  • Index Explorer
  • Query Explain Plan
  • Database Diagnostics
  • Performance Monitoring
  • PostgreSQL DBA Utilities
  • Java Backend Monitoring

PostgreSQL Advanced Monitoring

Supports PostgreSQL modern features including:

  • Partitioning
  • WAL Monitoring
  • Replication
  • Parallel Query
  • JSONB Analysis
  • Generated Columns
  • Extended Statistics
  • Autovacuum Advisor
  • Backup Monitoring
  • Huge Pages
  • Extensions
  • Foreign Key Analysis

Java Backend Support

Built specifically for Java backend engineers.

Supports monitoring for:

  • Spring Boot
  • Quarkus
  • Hibernate
  • Spring Data JPA
  • HikariCP
  • Flyway
  • Liquibase
  • JDBC Batch
  • Transaction Monitoring
  • Connection Leak Detection

Installation

Run directly with NPX:

npx @irsyadjpp/postgres-mcp-server

Configuration

The server supports three configuration methods.

Option 1 — Environment Variables (Recommended)

Default Database

DB_HOST=127.0.0.1
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=your_password
DB_NAME=postgres
DB_SSL=true

Additional Databases

DB_PROD_HOST=prod.example.com
DB_PROD_PORT=5432
DB_PROD_USER=app_user
DB_PROD_PASSWORD=secret
DB_PROD_DATABASE=production
DB_PROD_SSL=true

DB_STAGING_HOST=staging.example.com
DB_STAGING_PORT=5432
DB_STAGING_USER=app_user
DB_STAGING_PASSWORD=secret
DB_STAGING_DATABASE=staging
DB_STAGING_SSL=true

Option 2 — JSON Configuration

Set:

DB_CONFIG_PATH=/path/to/db-config.json

Example:

{
  "databases": [
    {
      "name": "default",
      "host": "127.0.0.1",
      "port": 5432,
      "user": "postgres",
      "password": "password",
      "database": "postgres",
      "maxConnections": 5,
      "ssl": true
    },
    {
      "name": "production",
      "host": "prod.example.com",
      "port": 5432,
      "user": "app_user",
      "password": "secret",
      "database": "production",
      "maxConnections": 10,
      "ssl": true
    }
  ]
}

Option 3 — Dynamic Database Selection

Every MCP tool accepts an optional parameter:

{
  "database_name": "production"
}

Example:

{
  "sql": "SELECT * FROM users",
  "database_name": "production"
}

Available Tools

Core Tools

ToolDescription
queryExecute SQL queries with pagination
describe_tableDescribe table structure
list_objectsList tables, views, or functions
list_schemasList schemas
list_indexesList indexes
search_objectsSearch database objects
explain_queryExplain execution plan
get_connectionsShow active connections
diagnose_databaseDatabase health check
get_slow_queriesAnalyze slow queries

PostgreSQL Advanced Tools

ToolDescription
list_partitionsPartition monitoring
replication_statusReplication monitoring
progress_reportVACUUM / CREATE INDEX progress
wal_monitorWAL monitoring
extended_statsExtended statistics
index_dedupIndex deduplication analysis
generated_columnsGenerated column analysis
jsonb_analysisJSONB recommendations
parallel_queryParallel worker monitoring
autovacuum_advisorAutovacuum recommendations
huge_pagesHuge pages monitoring
statements_enhancedEnhanced pg_stat_statements
foreign_keyForeign key analysis
backup_monitorBackup monitoring
extensionsInstalled extensions

Java Backend Tools

ToolDescription
connection_poolHikariCP monitoring
jpa_mappingValidate JPA mappings
orm_performanceORM performance analysis
transaction_monitorTransaction monitoring
prepared_statementPrepared statement analysis
migration_trackingFlyway/Liquibase monitoring
orm_index_coverageORM index recommendations
jsonb_entityJSONB entity analysis
batch_operationJDBC batch monitoring
sequence_monitorSequence monitoring
timeseries_partitionPartition recommendations
connection_leakConnection leak detection
deadlock_analysisDeadlock analysis
jpa_schema_validationValidate JPA annotations
orm_performance_baselineCRUD performance baseline

Key Capabilities

  • Multi-database support
  • Automatic pagination
  • SQL Injection protection
  • PostgreSQL diagnostics
  • Query performance analysis
  • Database health monitoring
  • DBA utilities
  • Spring Boot optimization
  • Quarkus optimization
  • Hibernate optimization

Claude Desktop Configuration

Example:

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "@irsyadjpp/postgres-mcp-server@latest"
      ],
      "env": {
        "DB_HOST": "127.0.0.1",
        "DB_PORT": "5432",
        "DB_USER": "postgres",
        "DB_PASSWORD": "password",
        "DB_NAME": "postgres",
        "DB_SSL": "true"
      }
    }
  }
}

Other Supported AI Assistants

Configuration examples are included for:

  • Claude Desktop
  • GitHub Copilot Chat
  • Cline
  • Antigravity IDE

See CONFIG-GUIDES.md for detailed setup instructions.


Claude Configuration Locations

macOS

~/Library/Application Support/Claude/claude_desktop_config.json

Windows

%APPDATA%\Claude\claude_desktop_config.json

Development

Clone the repository:

git clone https://github.com/irsyadjpp/postgres-mcp-server.git

cd postgres-mcp-server

npm install

Run development server:

npm run dev

Build:

npm run build

Run all tests:

npm test

Run unit tests:

npm run test:unit

Run integration tests:

npm run test:integration

Environment Variables

VariableDefaultDescription
DB_HOST127.0.0.1PostgreSQL host
DB_PORT5432PostgreSQL port
DB_USERpostgresDatabase user
DB_PASSWORD—Database password
DB_NAMEpostgresDatabase name
DB_SSLtrueEnable SSL
DB_CONFIG_PATH—JSON configuration path
READ_ONLYtrueRestrict to SELECT/EXPLAIN
QUERY_TIMEOUT30000Query timeout (ms)
MAX_PAGE_SIZE500Maximum page size
DEFAULT_PAGE_SIZE100Default page size

Additional databases:

DB_<NAME>_HOST
DB_<NAME>_PORT
DB_<NAME>_USER
DB_<NAME>_PASSWORD
DB_<NAME>_DATABASE
DB_<NAME>_SSL

Migration Guide

Existing users require no configuration changes.

The server maintains full backward compatibility.

To add another database:

DB_PROD_HOST=prod.example.com
DB_PROD_PORT=5432
DB_PROD_USER=app_user
DB_PROD_PASSWORD=secret
DB_PROD_DATABASE=production

Use it in any MCP tool:

{
  "database_name": "prod"
}

Alternatively, migrate to a JSON configuration by setting:

DB_CONFIG_PATH=/path/to/db-config.json

License

ISC

↑↓ navigate openesc close