Skip to main content

Model Context Protocol server for PostGIS

Project description

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.

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.

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

mcp_postgis-0.1.0.tar.gz (130.1 kB view details)

Uploaded Source

Built Distribution

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

mcp_postgis-0.1.0-py3-none-any.whl (27.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mcp_postgis-0.1.0.tar.gz
  • Upload date:
  • Size: 130.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mcp_postgis-0.1.0.tar.gz
Algorithm Hash digest
SHA256 34fae4b18c6eba8ddb2f2c18b835c374099665ad1f91dcf7ccd1d2e5b6e2384c
MD5 21e3a5c0bc7a98aecad3c0da84669985
BLAKE2b-256 531385599678ca0bd63b76243f159009eab2d98fcf07751b9c12d271240c52dd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mcp_postgis-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 27.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mcp_postgis-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b4e075d18694b6668fd4af0af9472442c75d92f51e07fba02fbc26cb2601d21
MD5 860d5047302322b9889d1bd103e5c842
BLAKE2b-256 62d51c30a882dd739815fbd7e2121dc5439299276874d36e851fc8e60cde1f19

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