Skip to main content

A Model Context Protocol server for PostgreSQL databases with SSL support

Project description

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

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

postgres_mcp_server-1.0.1.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

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

postgres_mcp_server-1.0.1-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file postgres_mcp_server-1.0.1.tar.gz.

File metadata

  • Download URL: postgres_mcp_server-1.0.1.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.9

File hashes

Hashes for postgres_mcp_server-1.0.1.tar.gz
Algorithm Hash digest
SHA256 7d7b3c604110bf89e1c060604bb1e3c67268786edabc24f4ddcc36bfc633c741
MD5 96b24430085fd4b38dff3c27f80d8020
BLAKE2b-256 1dcf73afe9d8fca19af27160712c50da7f55cf63006f8f4bce11cb75f3af8449

See more details on using hashes here.

File details

Details for the file postgres_mcp_server-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for postgres_mcp_server-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9850972afc6f5e061122db700b5173ea690f33c47e0a318c8bca3ea14d65ec3a
MD5 f4297420953f4ee04b69a3a48f91bdcb
BLAKE2b-256 b00666802f46c59a398925617ca4db705eaa4dce75cf5d761b240567c8c77cac

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