Skip to main content

PostgreSQL MCP server for Model Context Protocol

Project description

PostgreSQL MCP Server

Python MCP License: MIT PyPI

A Model Context Protocol (MCP) server for PostgreSQL databases. Query, explore, and analyze your PostgreSQL databases directly from any MCP-compatible AI client.

Features

  • Execute SQL — Run any SQL query with automatic result formatting
  • Natural Language Queries — Ask questions in plain English or Turkish
  • Schema Exploration — List tables, describe columns, view statistics
  • Execution Plans — EXPLAIN / EXPLAIN ANALYZE with buffer stats
  • Query History — Review past queries scoped to your database and workspace
  • Read-Only Mode — Optional write protection via READ_ONLY=true
  • Zero Install — Works with uvx, no virtual environment needed

Quick Start

Claude Code

claude mcp add postgres \
  -e DB_HOST=localhost \
  -e DB_PORT=5432 \
  -e DB_NAME=mydb \
  -e DB_USER=postgres \
  -e DB_PASSWORD=secret \
  -- uvx mapeg-postgres-mcp

Claude Desktop

Add to your config file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "postgres": {
      "command": "uvx",
      "args": ["mapeg-postgres-mcp"],
      "env": {
        "DB_HOST": "localhost",
        "DB_PORT": "5432",
        "DB_NAME": "mydb",
        "DB_USER": "postgres",
        "DB_PASSWORD": "secret"
      }
    }
  }
}

Cursor

Add to ~/.cursor/mcp.json:

{
  "mcpServers": {
    "postgres": {
      "command": "uvx",
      "args": ["mapeg-postgres-mcp"],
      "env": {
        "DB_HOST": "localhost",
        "DB_PORT": "5432",
        "DB_NAME": "mydb",
        "DB_USER": "postgres",
        "DB_PASSWORD": "secret"
      }
    }
  }
}

Windsurf

Add to Windsurf MCP config:

{
  "mcpServers": {
    "postgres": {
      "command": "uvx",
      "args": ["mapeg-postgres-mcp"],
      "env": {
        "DB_HOST": "localhost",
        "DB_PORT": "5432",
        "DB_NAME": "mydb",
        "DB_USER": "postgres",
        "DB_PASSWORD": "secret"
      }
    }
  }
}

VS Code

Add to your VS Code settings (JSON):

"mcp": {
  "servers": {
    "postgres": {
      "type": "stdio",
      "command": "uvx",
      "args": ["mapeg-postgres-mcp"],
      "env": {
        "DB_HOST": "localhost",
        "DB_PORT": "5432",
        "DB_NAME": "mydb",
        "DB_USER": "postgres",
        "DB_PASSWORD": "secret"
      }
    }
  }
}

Gemini CLI

Add to ~/.gemini/settings.json:

{
  "mcpServers": {
    "postgres": {
      "command": "uvx",
      "args": ["mapeg-postgres-mcp"],
      "env": {
        "DB_HOST": "localhost",
        "DB_PORT": "5432",
        "DB_NAME": "mydb",
        "DB_USER": "postgres",
        "DB_PASSWORD": "secret"
      }
    }
  }
}

GitHub Copilot

Add to ~/.copilot/mcp-config.json:

{
  "mcpServers": {
    "postgres": {
      "command": "uvx",
      "args": ["mapeg-postgres-mcp"],
      "env": {
        "DB_HOST": "localhost",
        "DB_PORT": "5432",
        "DB_NAME": "mydb",
        "DB_USER": "postgres",
        "DB_PASSWORD": "secret"
      }
    }
  }
}

OpenAI Codex

Add to ~/.codex/config.toml:

[mcp_servers.postgres]
command = "uvx"
args = ["mapeg-postgres-mcp"]

[mcp_servers.postgres.env]
DB_HOST = "localhost"
DB_PORT = "5432"
DB_NAME = "mydb"
DB_USER = "postgres"
DB_PASSWORD = "secret"

Install from Source

cd mapeg-postgres-mcp
pip install -e .

Configuration

Environment Variable Required Default Description
DB_HOST No localhost PostgreSQL host
DB_PORT No 5432 PostgreSQL port
DB_NAME Yes Database name
DB_USER No postgres Database user
DB_PASSWORD Yes Database password
READ_ONLY No false Block write operations (INSERT, UPDATE, DELETE, DROP, etc.)

Tools

execute_sql — Run SQL queries

Execute any SQL query on the connected PostgreSQL database.

Parameter Type Required Description
sql string Yes SQL query to execute
limit integer No Max rows to return (default: 100)
natural_language_query — Query in plain language

Convert natural language to SQL and execute. Supports Turkish and English.

Parameter Type Required Description
query string Yes Natural language query

Examples: "show all tables", "tabloları listele", "show database info"

describe_table — Table structure details

Get column definitions, row count, and table size.

Parameter Type Required Description
table_name string Yes Table name (schema.table or table)
smart_query — AI-powered query assistant

Analyzes your schema and suggests queries based on your question.

Parameter Type Required Description
question string Yes Question about your data
explain_query — Execution plan analysis

Show the EXPLAIN plan for a SQL query.

Parameter Type Required Description
sql string Yes SQL query to explain
analyze boolean No Run EXPLAIN ANALYZE (default: false)
format string No Output format: text, json, yaml (default: text)
buffers boolean No Include buffer usage (requires analyze=true)
get_query_history — Review past queries

Retrieve recent query history scoped to this database and workspace.

Parameter Type Required Description
limit integer No Number of entries (default: 20)
status string No Filter: success or error
tool_name string No Filter by tool name

Resources

URI Description
postgresql://tables List all user tables
postgresql://schema Detailed schema with columns
postgresql://stats Database version and statistics

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mapeg_postgres_mcp-1.0.0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mapeg_postgres_mcp-1.0.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file mapeg_postgres_mcp-1.0.0.tar.gz.

File metadata

  • Download URL: mapeg_postgres_mcp-1.0.0.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for mapeg_postgres_mcp-1.0.0.tar.gz
Algorithm Hash digest
SHA256 48748639a3e32dea5235510e97c4237bc71f41925f3cc1c474a8cf657c110cf3
MD5 70cfc3ebf7744517a3fd65fddce345e3
BLAKE2b-256 71ea72528510ceedf476766acf20a1b79d08327dd7b60b86fd30f2b806bf55cc

See more details on using hashes here.

File details

Details for the file mapeg_postgres_mcp-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mapeg_postgres_mcp-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63627bc5baf81bae4c0360ac065e7fde76ae41874ab2c664ae2ca3bbc7540a5a
MD5 5d71c4bbec141202f4f21e0bf44728c3
BLAKE2b-256 400f549f6f1dac141df5093c49f04401dd72a2ae0391c6c30fd4cf7b211fda32

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page