Skip to main content

MCP server for PostgreSQL with read-only guardrails, row caps, and statement timeouts

Project description

database-mcp-postgres

PyPI CI License: MIT

MCP server giving AI clients safe, structured access to a PostgreSQL database. Two tools, guardrails on by default.

Quick start (Claude Desktop / Claude Code / Cursor)

{
  "mcpServers": {
    "postgres": {
      "command": "uvx",
      "args": ["database-mcp-postgres"],
      "env": {
        "POSTGRES_HOST": "127.0.0.1",
        "POSTGRES_USER": "youruser",
        "POSTGRES_PASSWORD": "yourpassword",
        "POSTGRES_DATABASE": "yourdb"
      }
    }
  }
}

Configuration

Sources, highest precedence first: flags, --config YAML, environment variables, defaults.

Environment variables

POSTGRES_HOST, POSTGRES_PORT, POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DATABASE, or a full DATABASE_URL (postgres://user:pass@host:5432/db, inline credentials discouraged). libpq's native PGHOST/PGUSER/PGPASSWORD/PGDATABASE also work.

Password without plaintext

  • POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password (Docker/Kubernetes secrets convention)
  • In YAML: connection.password: ${POSTGRES_PASSWORD} (env expansion, never a literal)

The password is held in a non-printable type and redacted from all output.

Tools

  • execute_sql: run a single SQL statement. Returns a summary line and compact JSON {columns, rows}.
  • search_objects: list tables with estimated row counts, or describe one table (columns, indexes, foreign keys).

Guardrails

  • Read-only by default, enforced twice: a SQL guard plus the default_transaction_read_only=on startup parameter at the server. Pass --allow-write to enable writes.
  • Results capped at maxRows (default 1000, MAX_ROWS).
  • Statements exceeding queryTimeoutMs (default 30000, QUERY_TIMEOUT_MS) are aborted server-side via statement_timeout.

Full contract: docs/tool-contract.md


mcp-name: io.github.arifulislamat/database-mcp-postgres

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

database_mcp_postgres-0.1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

database_mcp_postgres-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file database_mcp_postgres-0.1.0.tar.gz.

File metadata

  • Download URL: database_mcp_postgres-0.1.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for database_mcp_postgres-0.1.0.tar.gz
Algorithm Hash digest
SHA256 521280c4a845541c75889f8149a26901de8311349786f0126166964b20cc751e
MD5 10d91ce60afbdd4198d3ce2111cb7e06
BLAKE2b-256 159919914cd23b4c6ff01aa36138a3a12d04e51d02f83a8d178356ca40796e08

See more details on using hashes here.

File details

Details for the file database_mcp_postgres-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: database_mcp_postgres-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for database_mcp_postgres-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0b97fa6339ea36f8843e9315ed72ea9ad5be874a3bff4d4f255dc8c124f67ecd
MD5 390eccff11a14838c0c78465430f07e1
BLAKE2b-256 2d1ccfc5aacad367aae9281ff023be8c9499bc5a3a59a7409c260d9fb1692e44

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