Skip to main content

PostgreSQL MCP Server

A Model Context Protocol (MCP) server for PostgreSQL databases. This server provides read-only access to PostgreSQL databases through the MCP protocol, allowing AI assistants to query database schemas and execute SELECT queries safely.

Features

  • Schema Exploration: Browse database tables and their column information
  • Read-only Queries: Execute SELECT queries safely with transaction isolation
  • SSL Support: Handles SSL connections with proper fallback options
  • Connection Pooling: Efficient database connection management
  • Security: Only allows SELECT queries to prevent data modification

Installation

Install with pip:

pip install postgres-mcp-server

Or run directly with uvx (recommended):

uvx postgres-mcp-server "postgresql://username:password@hostname:port/database"

MCP Client Configuration

To use this server with MCP clients, configure it in your MCP settings:

Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "postgres": {
      "command": "uvx",
      "args": [
        "postgres-mcp-server",
        "postgresql://username:password@localhost:5432/database"
      ]
    }
  }
}

Configuration file locations:

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

Environment Variables

For security, avoid hardcoding credentials:

{
  "mcpServers": {
    "postgres": {
      "command": "uvx",
      "args": [
        "postgres-mcp-server",
        "postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
      ],
      "env": {
        "POSTGRES_HOST": "localhost",
        "POSTGRES_PORT": "5432", 
        "POSTGRES_DB": "database",
        "POSTGRES_USER": "username",
        "POSTGRES_PASSWORD": "password"
      }
    }
  }
}

SSL Configuration Examples

Development (SSL disabled):

{
  "mcpServers": {
    "postgres-dev": {
      "command": "uvx",
      "args": [
        "postgres-mcp-server",
        "postgresql://postgres:password@localhost:5432/mydb?sslmode=disable"
      ]
    }
  }
}

Production (SSL required):

{
  "mcpServers": {
    "postgres-prod": {
      "command": "uvx", 
      "args": [
        "postgres-mcp-server",
        "postgresql://user:pass@prod-db.example.com:5432/mydb?sslmode=require"
      ]
    }
  }
}

Multiple Databases

Configure multiple PostgreSQL connections:

{
  "mcpServers": {
    "postgres-main": {
      "command": "uvx",
      "args": [
        "postgres-mcp-server",
        "postgresql://user:pass@main-db:5432/main_database"
      ]
    },
    "postgres-analytics": {
      "command": "uvx",
      "args": [
        "postgres-mcp-server",
        "postgresql://user:pass@analytics-db:5432/analytics_database" 
      ]
    }
  }
}

SSL Support

The server automatically handles SSL connections with these modes:

  • disable: No SSL
  • allow: Try non-SSL, then SSL
  • prefer: Try SSL, then non-SSL (default)
  • require: SSL required
  • verify-ca: SSL with CA verification
  • verify-full: SSL with full verification

Usage in MCP Clients

Once configured, interact with your PostgreSQL database through natural language:

"What tables are available in the database?" - Lists all tables with their schemas

"Show me the first 10 users" - Executes: SELECT * FROM users LIMIT 10

"Find recent orders with customer info" - Builds complex JOINs automatically

All queries are restricted to SELECT statements for security.

License

MIT

Metadata

Release files for postgres-mcp-server 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for postgres-mcp-server 1.0.1
File Size Uploaded Provenance
postgres_mcp_server-1.0.1.tar.gz 10.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for postgres-mcp-server 1.0.1
File Interpreter ABI Platform
postgres_mcp_server-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 16.8 kB

Release files / postgres_mcp_server-1.0.1.tar.gz

Download URL postgres_mcp_server-1.0.1.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7d7b3c604110bf89e1c060604bb1e3c67268786edabc24f4ddcc36bfc633c741
BLAKE2b-256 checksum
How to use checksums
1dcf73afe9d8fca19af27160712c50da7f55cf63006f8f4bce11cb75f3af8449
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.9

Release files / postgres_mcp_server-1.0.1-py3-none-any.whl

Download URL postgres_mcp_server-1.0.1-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9850972afc6f5e061122db700b5173ea690f33c47e0a318c8bca3ea14d65ec3a
BLAKE2b-256 checksum
How to use checksums
b00666802f46c59a398925617ca4db705eaa4dce75cf5d761b240567c8c77cac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.9

Security for postgres-mcp-server 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page