Skip to main content
Glama
PostgreSQL MCP Server

PostgreSQL MCP Server

PostgreSQL MCP Server

A Model Context Protocol (MCP) server that provides tools for interacting with PostgreSQL databases.

Tools

  • read_query - Execute SELECT queries to read data from the database

  • list_tables - Get a list of all tables in the database

  • describe_table - View schema information for a specific table

Related MCP server: PostgreSQL MCP Server

Installation

1. Create and activate a virtual environment

cd <path-to-project>
python3 -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

2. Install the package

pip install -e .

Usage

The server supports two transport modes:

  • stdio (default) - Standard input/output, for direct MCP client integration

  • http - HTTP with streamable transport, for standalone server mode

Command Line

postgres-mcp --host <host> --port <port> --database <database> --user <user> --password <password> [--transport stdio|http]

Arguments:

Argument

Required

Default

Description

--host

Yes

-

PostgreSQL host

--port

No

5432

PostgreSQL port

--database

Yes

-

Database name

--user

Yes

-

Database user

--password

Yes

-

Database password

--transport

No

stdio

Transport type: stdio or http

--http-host

No

127.0.0.1

Host for HTTP server

--http-port

No

8080

Port for HTTP server

Example (stdio mode):

postgres-mcp --host localhost --port 5432 --database mydb --user admin --password secret

Example (HTTP mode):

postgres-mcp --host localhost --database mydb --user admin --password secret --transport http --http-port 8080

As a Python module

python -m postgres_mcp --host localhost --database mydb --user admin --password secret

Using run.sh (for AWS RDS with IAM authentication)

The run.sh script handles AWS RDS IAM authentication and SSL configuration:

./run.sh

This script:

  • Sets up SSL certificates for RDS

  • Generates a temporary IAM auth token via aws-vault

  • Launches the MCP server in HTTP mode on http://127.0.0.1:8080/mcp

  • You need to configure the environment variables for credentials and RDS connection details before running the script.

MCP Client Configuration

  1. Start the server in a terminal with the correct environment:

    ./run.sh
  2. Configure your MCP client:

    For clients that support HTTP directly (e.g., Cursor):

    {
      "mcpServers": {
        "postgres": {
          "type": "streamable-http",
          "url": "http://127.0.0.1:8080/mcp"
        }
      }
    }

    For clients that only support stdio (e.g., Claude Code):

    Use the stdio-to-HTTP proxy:

    {
      "mcpServers": {
        "postgres": {
          "command": "<path-to-project>/.venv/bin/postgres-mcp-proxy",
          "args": ["--server-url", "http://127.0.0.1:8080/mcp"]
        }
      }
    }

Stdio Mode (for simple setups)

Direct execution

Claude Desktop (~/Library/Application Support/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "postgres": {
      "command": "<path-to-project>/.venv/bin/postgres-mcp",
      "args": [
        "--host", "localhost",
        "--port", "5432",
        "--database", "mydb",
        "--user", "admin",
        "--password", "secret"
      ]
    }
  }
}

Claude Code:

{
  "mcpServers": {
    "postgres": {
      "command": "<path-to-project>/.venv/bin/postgres-mcp",
      "args": [
        "--host", "localhost",
        "--port", "5432",
        "--database", "mydb",
        "--user", "admin",
        "--password", "secret"
      ]
    }
  }
}

Development

Install in development mode

pip install -e .

Project structure

db-mcp/
├── pyproject.toml
├── README.md
├── run.sh                   # AWS RDS launcher script
└── src/
    └── postgres_mcp/
        ├── __init__.py
        ├── __main__.py      # CLI entry point
        ├── database.py      # Connection pool management
        ├── server.py        # MCP server implementation
        └── proxy.py         # Stdio-to-HTTP proxy for Claude Code

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      Enables secure querying of PostgreSQL databases through MCP-compatible clients. Supports read-only SQL execution, table exploration, and connection management with built-in security validation.
      3
      56 npm
      9
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables interaction with PostgreSQL databases through both HTTP and stdio transports. Supports executing read-only SQL queries, listing tables, and retrieving schema information with stateful session management.
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables interaction with PostgreSQL databases through MCP, allowing users to explore database structures, inspect table schemas, and execute read-only SQL queries.
      -
    • A
      license
      C
      quality
      D
      maintenance
      Enables querying PostgreSQL database metadata including table lists and schema information through the MCP protocol. Supports stdio transport for Cursor/IDE integration as well as HTTP transport with health check endpoints.
      2
      MIT