jjsantos01_qgis_mcp

jjsantos01_qgis_mcp

by jjsantos01
Enables Claude AI to interact with and control QGIS Desktop through the Model Context Protocol (MCP).

QGIS Model Context Protocol Integration

Overview

QGISMCP connects QGIS to Claude AI through the Model Context Protocol (MCP), enabling Claude to directly interact with and control QGIS. This integration allows for prompt-assisted project creation, layer loading, code execution, and more.

Features

  • Two-way communication: Connect Claude AI to QGIS through a socket-based server.
  • Project manipulation: Create, load, and save projects in QGIS.
  • Layer manipulation: Add and remove vector or raster layers to a project.
  • Execute processing: Execute processing algorithms using the Processing Toolbox.
  • Code execution: Run arbitrary Python code in QGIS from Claude. Use with caution due to its power.

Components

The system consists of two main components:

  1. QGIS plugin: A QGIS plugin that creates a socket server within QGIS to receive and execute commands.
  2. MCP Server: A Python server that implements the Model Context Protocol and connects to the QGIS plugin.

Installation

Prerequisites

  • QGIS 3.X (only tested on 3.22)
  • Cloud desktop
  • Python 3.10 or newer
  • uv package manager:

  • Mac:
    shell brew install uv

  • Windows Powershell:
    shell powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
  • Other platforms: Follow the uv installation guide.

Download Code

Clone the repository:

git clone [email protected]:jjsantos01/qgis_mcp.git

QGIS Plugin

Copy the folder qgis_mcp_plugin to your QGIS profile plugins folder:

  1. Open QGIS and go to Settings -> User profiles -> Open active profile folder.
  2. Navigate to Python/plugins and paste the qgis_mcp_plugin folder.
  3. Restart QGIS.
  4. Go to Plugins -> Installing and Managing Plugins, select the All tab, search for "QGIS MCP", and enable it.

Claude for Desktop Integration

Edit the claude_desktop_config.json file:

  1. Go to Claude > Settings > Developer > Edit Config > claude_desktop_config.json.
  2. Add the following configuration:
{
    "mcpServers": {
        "qgis": {
            "command": "uv",
            "args": [
                "--directory",
                "/ABSOLUTE/PATH/TO/PARENT/REPO/FOLDER/qgis_mcp/src/qgis_mcp",
                "run",
                "qgis_mcp_server.py"
            ]
        }
    }
}

Usage

Starting the Connection

  1. In QGIS, go to plugins -> QGIS MCP -> QGIS MCP.
  2. Click "Start Server".

Using with Claude

Once the server is running, you will see a hammer icon with tools for the QGIS MCP.

Tools

  • ping: Check server connectivity.
  • get_qgis_info: Get QGIS installation information.
  • load_project: Load a QGIS project from the specified path.
  • create_new_project: Create and save a new project.
  • get_project_info: Get current project information.
  • add_vector_layer: Add a vector layer to the project.
  • add_raster_layer: Add a raster layer to the project.
  • get_layers: Retrieve all layers in the current project.
  • remove_layer: Remove a layer by its ID.
  • zoom_to_layer: Zoom to the extent of a specified layer.
  • get_layer_features: Retrieve features from a vector layer.
  • execute_processing: Execute a processing algorithm.
  • save_project: Save the current project.
  • render_map: Render the current map view to an image file.
  • execute_code: Execute arbitrary PyQGIS code.

Example Commands

You have access to the tools to work with QGIS. You will do the following:
    1. Ping to check the connection. If it works, continue with the following steps.
    2. Create a new project and save it at: "C:/Users/USER/GitHub/qgis_mcp/data/cdmx.qgz"
    3. Load the vector layer: "C:/Users/USER/GitHub/qgis_mcp/data/cdmx/mgpc_2019.shp" and name it "Colonias".
    4. Load the raster layer: "C:/Users/USER/GitHub/qgis_mcp/data/09014.tif" and name it "BJ"
    5. Zoom to the "BJ" layer.
    6. Execute the centroid algorithm on the "Colonias" layer. Skip the geometry check. Save the output to "colonias_centroids.geojson".
    7. Execute code to create a choropleth map using the "POB2010" field in the "Colonias" layer. Use the quantile classification method with 5 classes and the Spectral color ramp.
    8. Render the map to "C:/Users/USER/GitHub/qgis_mcp/data/cdmx.png"
    9. Save the project.

About

Model Context Protocol (MCP) that allows LLMs to use QGIS Desktop.

Resources

Stars

357 stars

Watchers

8 watching

Forks

38 forks

Report repository

Releases


No releases published

Languages

Features & Capabilities

Categories
mcp_server model_context_protocol python qgis claude api_integration gis

Implementation Details

Stats

0 Views
357 GitHub Stars

Repository Info

jjsantos01 Organization

Similar MCP Servers

continuedev_continue by continuedev
25049
21423
9300