Skip to main content

mcp-pgsql-query

MCP server for read-only PostgreSQL queries. Only SELECT statements are allowed — all other operations are rejected at the SQL validation layer.

Features

  • SELECT-only enforcement (INSERT/UPDATE/DELETE/DDL/COPY all blocked)
  • AST-level SQL analysis via sqlglot to catch injection and embedded write operations
  • Blocks dangerous functions: pg_read_file, pg_write_file, lo_export, dblink, etc.
  • Stacked statement prevention (; separated statements)
  • Returns results as JSON with column names, rows, and truncation indicator

Configuration

Set these environment variables:

Variable Description Default
PG_HOST PostgreSQL hostname localhost
PG_PORT Port 5432
PG_DATABASE Database name
PG_USERNAME Login username
PG_PASSWORD Login password

Claude Desktop configuration

{
  "mcpServers": {
    "pgsql": {
      "command": "uvx",
      "args": ["mcp-pgsql-query@latest"],
      "env": {
        "PG_HOST": "your-server",
        "PG_DATABASE": "your-db",
        "PG_USERNAME": "your-user",
        "PG_PASSWORD": "your-password"
      }
    }
  }
}

Tool

query_pgsql

Run a read-only SELECT query against the configured PostgreSQL database.

Parameters:

  • sql (required) — PostgreSQL SELECT statement
  • max_rows (optional) — Maximum rows to return, default 100, max 1000

Release files for mcp-pgsql-query 0.1.0

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

Source distribution (sdist)

Source distribution for mcp-pgsql-query 0.1.0
File Size Uploaded
mcp_pgsql_query-0.1.0.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mcp-pgsql-query 0.1.0
File Interpreter ABI Platform
mcp_pgsql_query-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.8 kB

Release files / mcp_pgsql_query-0.1.0.tar.gz

Download URL mcp_pgsql_query-0.1.0.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d2f965bc851b8e1a07f8fe489c8d7a749ad3d6b47ab76b9ff9ab3f1aa6e909dd
BLAKE2b-256 checksum
How to use checksums
c3534b486ce40b0591da43f67ec8f839959360ba03464159a91e258c3001856b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 31, 2026.

Transparency log

Release files / mcp_pgsql_query-0.1.0-py3-none-any.whl

Download URL mcp_pgsql_query-0.1.0-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
286a306dbf4614c9b1016630e79dedb8db5771b96b4303aedcbd6fd4211a5776
BLAKE2b-256 checksum
How to use checksums
b03d39b7143aa1b9ac1a1f4daaa31cb8eb45ea9aca944226d2d55841d6ca1954
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 31, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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