Skip to main content

mcp-postgis

CI PyPI Python License: MIT

A Model Context Protocol server that exposes PostGIS to MCP-aware clients (Claude Desktop, Claude Code).

Lets Claude introspect your spatial database, run safe spatial queries, and publish results as views that QGIS picks up automatically — so an analyst can describe a layer in plain language and have it land in their QGIS browser.

Install

pip install mcp-postgis     # or `uv tool install mcp-postgis`

Quick start (Docker PostGIS + Claude Desktop)

  1. Run PostGIS:
    docker run --name postgis -e POSTGRES_PASSWORD=postgres \
      -p 5432:5432 -d postgis/postgis:16-3.4
    
  2. Create a dedicated read-only role (see docs/security.md for read_write and admin variants):
    CREATE ROLE mcp_postgis_ro LOGIN PASSWORD 'change-me';
    GRANT CONNECT ON DATABASE mydb TO mcp_postgis_ro;
    GRANT USAGE ON SCHEMA public, app TO mcp_postgis_ro;
    GRANT SELECT ON ALL TABLES IN SCHEMA public, app TO mcp_postgis_ro;
    ALTER DEFAULT PRIVILEGES IN SCHEMA public, app
        GRANT SELECT ON TABLES TO mcp_postgis_ro;
    
  3. Add to your claude_desktop_config.json:
    {
      "mcpServers": {
        "postgis": {
          "command": "uvx",
          "args": ["mcp-postgis"],
          "env": {
            "MCP_POSTGIS_DATABASE_URL": "postgresql://mcp_postgis_ro:change-me@localhost:5432/mydb",
            "MCP_POSTGIS_MODE": "read_only"
          }
        }
      }
    }
    
  4. Restart Claude Desktop. The server's tools appear in the model picker.

Using with Claude Code (Linux/macOS/Windows)

Claude Desktop is macOS/Windows only — on Linux (or anywhere you use the CLI), register the server with Claude Code instead:

claude mcp add --transport stdio \
  --env MCP_POSTGIS_DATABASE_URL="postgresql://mcp_postgis_ro:change-me@localhost:5432/mydb" \
  --env MCP_POSTGIS_MODE=read_only \
  --scope user \
  postgis \
  -- uvx mcp-postgis

Restart claude, then /mcp lists the server and its tools. Use --scope user (not project) so your connection string isn't committed to a repo.

Modes

Mode What it can do
read_only Default. Introspection + SELECT + spatial analysis. No writes, no DDL.
read_write Above + create/refresh/drop views in MCP_POSTGIS_LAYER_SCHEMA (mcp_layers by default).
admin Anything the connected role can do. Use only for one-off admin tasks; the role still gates.

Tools

Introspection: list_schemas, list_tables, describe_table, list_geometry_columns, list_spatial_indexes, list_extensions

Query: execute_sql, explain, sample_table

Spatial analysis: features_in_bbox, features_in_polygon, nearest_features, within_distance, buffer, intersect_layers

Geometry operations: transform_srid, centroid, point_on_surface, area, length, simplify, is_valid, make_valid, bbox

Data quality: check_geometry_validity

Import / export: import_geojson (load a GeoJSON FeatureCollection into a table), export_geojson, export_wkt

Layer publishing (QGIS bridge): create_layer (with geometry_type filter), refresh_layer, list_layers, describe_layer, drop_layer

Resources: postgis://schemas, postgis://schema/{schema}/{table}, postgis://layers · Prompts: analyze-layer, nearest-things, within-radius, compare-layers

QGIS integration

After running the server in read_write mode and asking Claude to "publish that as a layer named hotels_near_coast", point QGIS at the same database (or use the same role). In the QGIS Browser → PostGIS → your connection, right-click → Refresh; the mcp_layers schema appears with hotels_near_coast inside it.

See docs/qgis-setup.md for screenshots.

License

MIT. Contributions welcome — please open an issue first to discuss bigger changes.

Metadata

Release files for mcp-postgis 0.3.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-postgis 0.3.0
File Size Uploaded
mcp_postgis-0.3.0.tar.gz 143.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mcp-postgis 0.3.0
File Interpreter ABI Platform
mcp_postgis-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 182.3 kB

Release files / mcp_postgis-0.3.0.tar.gz

Download URL mcp_postgis-0.3.0.tar.gz
Size 143.5 kB
Tags Source
SHA-256 checksum
How to use checksums
926c55ea9fc07cbe4c13e34f81b17bd785850f1acfb1efe22659e6a1d1472633
BLAKE2b-256 checksum
How to use checksums
c325c6838ad5fea4f20c46b972e592e72bcf3a6848bd182a0f789da026abe7b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 29, 2026.

Transparency log

Release files / mcp_postgis-0.3.0-py3-none-any.whl

Download URL mcp_postgis-0.3.0-py3-none-any.whl
Size 38.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e2e1fdb7c4a6537a70e5cb8f1737a8fa740f24c67fe424341ce32288cfe080d6
BLAKE2b-256 checksum
How to use checksums
abc5d7cd894db2ac5e6fee0e647ecbba8341f0fb79c242da425cc4908165a720
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 29, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

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