Logo QGIS MCP

QGIS MCP

Cộng đồng
nkarasiak

Connect QGIS to AI agent through the Model Context Protocol (MCP)

Nhà phát hànhnkarasiak
Kho mãqgis-mcp
Ngôn ngữPython
Bản fork
77
Sao
314
Công cụ có sẵn
0
Phương thức truyền tảistdio
Danh mục
Giấy phépGPL-2.0
Liên kết
  • Kết nối công cụ với quy trình làm việc AI

    QGIS MCP cung cấp các chức năng MCP cho các ứng dụng khách AI và tác nhân AI tương thích.

  • 0 công cụ có sẵn

    Xem các thao tác có thể gọi bên dưới, kèm tên và mô tả nếu máy chủ cung cấp.

  • Mẫu cấu hình có thể sao chép ngay

    Dùng các đoạn cấu hình mẫu để thiết lập máy chủ này trong ứng dụng khách MCP bạn muốn dùng.

  • Mức độ quan tâm của cộng đồng đến kho mã

    314 sao và 77 bản fork từ kho mã được liên kết.

QGIS MCP

Connect QGIS to any AI agent that speaks the Model Context Protocol (MCP), so the agent drives QGIS directly: manage layers, edit features, run processing algorithms, render maps, and more.

118 MCP tools covering layer management, feature editing, processing, rendering, styling, layout & atlas authoring, cross-layer SQL, plugin development, and system management. Compatible with QGIS 3.28–4.x. Model and client agnostic: any MCP client works, among them Claude Code, Codex CLI, Gemini CLI, Qwen Code, Kimi Code CLI, GitHub Copilot CLI, opencode, LM Studio, Claude Desktop, Cursor, VS Code, Windsurf, Zed, and more.

Architecture

AI agent ←→ MCP Server (FastMCP) ←→ TCP socket ←→ QGIS Plugin (QTimer) ←→ PyQGIS API
  1. QGIS Plugin (qgis_mcp_plugin/) - Runs inside QGIS. Non-blocking TCP socket server that processes JSON commands within QGIS's event loop.
  2. MCP Server (src/qgis_mcp/server.py) - Runs outside QGIS. Exposes QGIS operations as MCP tools via FastMCP.

Installation

No clone needed. Requires QGIS 3.28+ and uv.

1. Install the QGIS plugin

In QGIS: Plugins > Manage and Install Plugins > search QGIS MCP > Install.

Restart QGIS and click Start Server in the QGIS MCP dock widget.

2. Connect your coding agent

bash
claude mcp add -s user qgis -- uvx --from https://github.com/nkarasiak/qgis-mcp/archive/refs/heads/main.zip qgis-mcp-server

Scope reference:

FlagStored inVisible to
-s local (default).mcp.json (gitignored)You, this project
-s project.mcp.json (committed)Whole team, this project
-s user~/.claude.jsonYou, every project
bash
codex mcp add qgis -- uvx --from https://github.com/nkarasiak/qgis-mcp/archive/refs/heads/main.zip qgis-mcp-server

Or edit ~/.codex/config.toml directly:

toml
[mcp_servers.qgis]
command = "uvx"
args = ["--from", "https://github.com/nkarasiak/qgis-mcp/archive/refs/heads/main.zip", "qgis-mcp-server"]

Add to ~/.gemini/settings.json:

json
{
  "mcpServers": {
    "qgis": {
      "command": "uvx",
      "args": ["--from", "https://github.com/nkarasiak/qgis-mcp/archive/refs/heads/main.zip", "qgis-mcp-server"]
    }
  }
}

Same layout as Gemini CLI. Add to ~/.qwen/settings.json:

json
{
  "mcpServers": {
    "qgis": {
      "command": "uvx",
      "args": ["--from", "https://github.com/nkarasiak/qgis-mcp/archive/refs/heads/main.zip", "qgis-mcp-server"]
    }
  }
}

Add to ~/.kimi-code/mcp.json (or $KIMI_CODE_HOME/mcp.json). A .kimi-code/mcp.json in the working directory overrides it for that project.

json
{
  "mcpServers": {
    "qgis": {
      "command": "uvx",
      "args": ["--from", "https://github.com/nkarasiak/qgis-mcp/archive/refs/heads/main.zip", "qgis-mcp-server"]
    }
  }
}

Kimi has no mcp add subcommand - edit the JSON or use the /mcp-config TUI.

Add to ~/.copilot/mcp-config.json (directory overridable via $COPILOT_HOME):

json
{
  "mcpServers": {
    "qgis": {
      "command": "uvx",
      "args": ["--from", "https://github.com/nkarasiak/qgis-mcp/archive/refs/heads/main.zip", "qgis-mcp-server"]
    }
  }
}

Add to ~/.lmstudio/mcp.json (%USERPROFILE%\.lmstudio\mcp.json on Windows):

json
{
  "mcpServers": {
    "qgis": {
      "command": "uvx",
      "args": ["--from", "https://github.com/nkarasiak/qgis-mcp/archive/refs/heads/main.zip", "qgis-mcp-server"]
    }
  }
}

Add to opencode.json at your project root:

json
{
  "mcp": {
    "qgis": {
      "type": "local",
      "command": ["uvx", "--from", "https://github.com/nkarasiak/qgis-mcp/archive/refs/heads/main.zip", "qgis-mcp-server"],
      "enabled": true
    }
  }
}

Hermes stores MCP servers in config.yaml under an mcpServers block. A standalone mcp.json is ignored. You also need a small .bat launcher - running uvx directly inside Hermes causes a venv conflict (ModuleNotFoundError: No module named 'pydantic_core._pydantic_core').

Step 1 - Create %APPDATA%\Hermes\qgis-mcp-launch.bat:

batch
@echo off
REM Clears Hermes's venv vars so uvx uses a clean Python environment.
set VIRTUAL_ENV=
set PYTHONPATH=
set PYTHONHOME=
uvx --from "https://github.com/nkarasiak/qgis-mcp/archive/refs/heads/main.zip" qgis-mcp-server

Step 2 - Add to %APPDATA%\Hermes\config.yaml:

yaml
mcpServers:
  qgis:
    command: "C:\\Users\\<you>\\AppData\\Roaming\\Hermes\\qgis-mcp-launch.bat"
    args: []

Replace <you> with your Windows username. Restart Hermes, then verify with:

Call the QGIS ping tool.

Tip: The QGIS plugin's Setup & Configurator dialog has a hermes entry in the client dropdown. Select it and click Copy to get the bat file and YAML pre-filled with your local paths.

For the full guide see docs/agent-integration.md.

opencode (which runs Nous/Hermes and other models) is supported directly by the installer:

bash
python install.py --non-interactive --clients opencode

This writes the correct config block to ~/.config/opencode/config.json (%APPDATA%\opencode\config.json on Windows).

To configure manually, add to your opencode.json or global opencode config:

json
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "qgis": {
      "type": "local",
      "command": [
        "uvx",
        "--from", "https://github.com/nkarasiak/qgis-mcp/archive/refs/heads/main.zip",
        "qgis-mcp-server"
      ]
    }
  }
}

Any other agent or client that supports the MCP stdio transport can also use this server. Generic config (exact key names vary by client - see your agent's docs):

json
{
  "mcpServers": {
    "qgis": {
      "command": "uvx",
      "args": [
        "--from", "https://github.com/nkarasiak/qgis-mcp/archive/refs/heads/main.zip",
        "qgis-mcp-server"
      ]
    }
  }
}

After starting the agent, verify by asking it to call the ping tool - it should return {"pong": true} when the QGIS plugin is running.

For a full setup guide, troubleshooting steps, and compound-tool mode configuration see docs/agent-integration.md.

Add to your client's MCP config file:

json
{
  "mcpServers": {
    "qgis": {
      "command": "uvx",
      "args": [
        "--from", "https://github.com/nkarasiak/qgis-mcp/archive/refs/heads/main.zip",
        "qgis-mcp-server"
      ]
    }
  }
}

Usage

  1. Start the plugin - In QGIS, click the MCP toolbar button (or Plugins > QGIS MCP) and click "Start Server"
  2. Talk to your agent - The MCP tools appear automatically. Ask the agent to work with your QGIS project.

Example prompt

You have access to QGIS tools. Do the following:
1. Ping to check the connection
2. Create a new project and save it at "/tmp/my_project.qgz"
3. Load the vector layer "world_map.gpkg" available in Qgis ("resources/data/world_map.gpkg")
4. Filter "USA" from the field "adm0_a3"
6. Render the map and show me the result
7. Save the project

Updating

The plugin (inside QGIS) and the MCP server (outside QGIS) must stay in sync - a newer server sending a command the older plugin doesn't know will return an error. Run diagnose after any update to verify both sides match.

ComponentRemote installLocal install (git clone)
QGIS pluginPlugins > Manage and Install Plugins > UpdateSame - Plugin Manager picks up the new version from QGIS Hub
MCP serveruvx caches the downloaded archive - force an update with uvx --refresh-package qgis-mcp --from https://github.com/nkarasiak/qgis-mcp/archive/refs/heads/main.zip qgis-mcp-server, then restart your MCP clientgit pull then restart the MCP server process

To auto-update instead, add --refresh-package qgis-mcp before --from in the configs above: uvx then re-resolves this package from GitHub on every launch. Warning: this requires network at launch - the MCP server fails to start when offline - and adds ~1–3s to startup. The plain configs above use the cached version and work offline.

After updating the plugin, click Stop / Start in the QGIS MCP dock widget (or reload via Plugins > QGIS MCP > Reload Plugin) to load the new code without restarting QGIS.

Tools (118)

CategoryTools
Projectload_project, create_new_project, save_project, get_project_info, set_project_crs
Layersget_layers, add_vector_layer, add_raster_layer, add_web_layer, remove_layer, find_layer, create_memory_layer, set_layer_visibility, zoom_to_layer, get_layer_extent, set_layer_property, get_layer_crs, set_layer_crs, get_active_layer, set_active_layer, add_table_join, export_layer
Featuresget_layer_features, add_features, update_features, update_feature_geometry, delete_features, select_features, get_selection, clear_selection, get_field_statistics, get_unique_values
Fieldsadd_field, delete_field, rename_field, field_calculator
Editingstart_editing, commit_edits, rollback_edits, get_edit_status, undo_edits, redo_edits
Stylingset_layer_style (single, categorized, graduated), set_raster_style (pseudocolor, gray, RGB, hillshade), apply_style_qml, save_style_qml, get_layer_labeling, set_layer_labeling
Connectionslist_connections, create_postgresql_connection, list_connection_tables, add_layer_from_connection, import_layer_to_connection, execute_connection_sql
Renderingrender_map, get_canvas_screenshot, get_3d_screenshot, get_canvas_extent, set_canvas_extent, get_canvas_scale, set_canvas_scale
Bookmarks & themesadd_bookmark, get_bookmarks, remove_bookmark, add_map_theme, get_map_themes, apply_map_theme, remove_map_theme
Processingexecute_processing, execute_processing_batch, list_processing_algorithms, get_algorithm_help, get_processing_providers, create_processing_model, list_processing_models, run_model
Analysisraster_calculator, zonal_statistics, sample_raster_values, spatial_join
Layoutslist_layouts, export_layout, create_layout, add_layout_map, add_layout_label, add_layout_legend, add_layout_scalebar, add_layout_picture, add_layout_table, get_layout_info, remove_layout
Atlasconfigure_atlas, export_atlas
Queryexecute_sql, evaluate_expression, identify_features
Layer treeget_layer_tree, create_layer_group, move_layer_to_group, duplicate_layer, set_layer_order
Pluginslist_plugins, get_plugin_info, reload_plugin
Systemping, diagnose, list_qgis_instances, get_qgis_info, get_raster_info, get_message_log, execute_code, batch_commands, validate_expression, get_project_variables, set_project_variable, get_setting, set_setting, transform_coordinates

All tools are async with human-readable titles and annotations (readOnly, destructive, idempotent). Destructive tools rely on your client's own confirmation gate, which reads the destructive annotation; set QGIS_MCP_AUTO_CONFIRM=0 to have the server elicit a second confirmation as well. Long-running tools report progress via MCP logging.

Compound tool mode

Set QGIS_MCP_TOOL_MODE=compound to reduce the granular tools to 27 grouped tools (every granular command stays reachable), cutting schema overhead per LLM turn. Each compound tool takes an action parameter plus a params object holding that action's parameters:

bash
QGIS_MCP_TOOL_MODE=compound uv run --no-sync src/qgis_mcp/server.py
json
{ "action": "load", "params": { "path": "/data/city.qgz" } }

Omit params for actions that take none ({"action": "ping"}).

Groups: system, project, layer, features, selection, style, canvas, render, processing, code, batch, layer_tree, plugins, variables, settings, expression, query, transform, message_log, layer_property, field, analysis, bookmarks, map_themes, active_layer.

Configuration

Environment variableDefaultDescription
QGIS_MCP_HOSTlocalhostHost for socket connection
QGIS_MCP_PORT9876Port for socket connection
QGIS_MCP_INSTANCES(unset)Address several running QGIS windows from one server. See Multiple QGIS instances.
QGIS_MCP_TOKEN(unset)Optional shared secret. When set, the plugin rejects any command without a matching token. See Authentication.
QGIS_MCP_TRANSPORTstdioMCP transport: stdio or streamable-http
QGIS_MCP_LOG_FILE~/.local/share/qgis-mcp/server.logLog file path (empty to disable)
QGIS_MCP_LOG_LEVELINFOFile log level
QGIS_MCP_TOOL_MODEgranulargranular (118 tools) or compound (27 grouped)
QGIS_MCP_AUTO_CONFIRMonConfirmation elicitation on destructive tools (execute_code, remove_layer, delete_features, ...) is skipped by default: your client already asks before running them, so it was a second prompt for the same call. Set to 0/false/no/off to elicit anyway - worth it only for a client that runs tools unattended.

Authentication

By default the socket has no authentication - it binds to localhost only, but any process on the machine that can reach the port can drive QGIS (including execute_code, which runs arbitrary PyQGIS). For shared or multi-user machines, set a shared secret so only callers that know it can connect:

  1. Set QGIS_MCP_TOKEN in the environment QGIS runs in (so the plugin enforces it), then Stop/Start the server in the dock. The QGIS log shows Token authentication ENABLED.

  2. Set the same value in the MCP server's environment - add it to the env block of your MCP client config:

    json
    {
      "mcpServers": {
        "qgis": {
          "command": "uvx",
          "args": ["--from", "https://github.com/nkarasiak/qgis-mcp/archive/refs/heads/main.zip", "qgis-mcp-server"],
          "env": { "QGIS_MCP_TOKEN": "your-long-random-secret" }
        }
      }
    }

The token is compared in constant time. When QGIS_MCP_TOKEN is unset (the default), behaviour is unchanged. This raises the bar against other local users/processes; a process running as the same user can still read the token from your config, so it is not a sandbox.

One exception: binding the plugin to a non-loopback address requires a token. Exposing arbitrary PyQGIS execution to the network without authentication is not a state you should be able to reach by accident, so the plugin refuses to start on such an address until QGIS_MCP_TOKEN is set (in QGIS and in the MCP server).

Multiple QGIS instances

One server registration can drive several running QGIS windows. Start each QGIS with the plugin on its own port, then list them in QGIS_MCP_INSTANCES as comma-separated name=port or name=host:port entries:

json
{
  "mcpServers": {
    "qgis": {
      "command": "uvx",
      "args": ["--from", "https://github.com/nkarasiak/qgis-mcp/archive/refs/heads/main.zip", "qgis-mcp-server"],
      "env": { "QGIS_MCP_INSTANCES": "default=9876,planning=9877,archive=lab-box:9878" }
    }
  }
}
  • Every tool takes an optional instance argument (get_layers(instance="planning")). Omitting it targets the entry named default, or - when no entry is called default - the first entry listed, so planning=9877,archive=9878 works without renaming anything.
  • list_qgis_instances returns the configured names with their host, port, and current reachability. An unknown name is rejected with the list of valid names.
  • Instance names match [A-Za-z0-9_-]+; entries without a host use QGIS_MCP_HOST (default localhost).
  • Each instance has its own pooled connection and its own lock, so two QGIS windows can be driven concurrently.
  • Not supported with QGIS_MCP_TOOL_MODE=compound. Compound tools carry no instance argument, so every call would silently hit one instance; configuring more than one instance in compound mode refuses to start rather than routing writes to the wrong QGIS.
  • When QGIS_MCP_INSTANCES is unset, exactly one instance named default is defined from QGIS_MCP_HOST/QGIS_MCP_PORT - existing setups are unaffected.
  • QGIS_MCP_TOKEN is shared across instances: the same secret must be set in every QGIS.

Contributing

bash
git clone https://github.com/nkarasiak/qgis-mcp.git
cd qgis-mcp
python install.py   # symlinks plugin + configures your MCP client

install.py options: --clients claude-desktop,cursor, --remote (uvx instead of uv run), --profile myprofile, --uninstall.

Known client names: claude-desktop, cursor, vscode, windsurf, zed, claude-code, codex, opencode, hermes, kimi, gemini, qwen, copilot-cli, lmstudio.

Windows (Microsoft Store / MSIX Claude Desktop): install.py uses --directory instead of cwd in generated configs. This is required for Store-installed Claude Desktop, which runs MCP servers in an MSIX sandbox that silently drops cwd. If you configure manually, use uv --directory "/path/to/qgis-mcp" run --no-sync src/qgis_mcp/server.py - this works on both MSIX and standalone installs. You can identify a Store install when the config file is under %LOCALAPPDATA%\Packages\Claude_<id>\LocalCache\Roaming\Claude\ instead of %APPDATA%\Claude\.

bash
# Unit tests (no QGIS needed - mocked socket)
uv run --no-sync pytest tests/test_mcp_tools.py -v

# Integration tests (requires QGIS plugin running)
uv run --no-sync pytest tests/test_qgis_live.py -v

License

This project is dual-licensed. Each component is distributed under its own license:

Cài đặt

TypingMind
Yêu cầu:

Node.js 18+

{
  "mcpServers": {
    "nkarasiak-qgis-mcp": {
      "command": "",
      "args": []
    }
  }
}

Dùng MCP QGIS MCP với nhiều mô hình AI

TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên sau khi kết nối QGIS MCP, bạn có thể dùng với nhiều mô hình AI khác nhau trong TypingMind thay vì phải thiết lập riêng cho từng mô hình. MCP này chạy cục bộ thông qua trình kết nối MCP của TypingMind trên thiết bị của bạn.

Hướng dẫn thiết lập để dùng trình kết nối cục bộ

Dùng cách này khi máy chủ MCP cần truy cập các tệp, ứng dụng hoặc tài nguyên riêng tư trên máy tính của bạn.

1

Mở cài đặt MCP

Trong TypingMind, vào Cài đặt, Cài đặt nâng cao, rồi đến Giao thức ngữ cảnh mô hình và chọn Thiết lập trình kết nối.

  1. Mở TypingMind trong trình duyệt của bạn.
  2. Nhấp vào biểu tượng Cài đặt.
  3. Vào Cài đặt nâng cao.
  4. Mở mục Giao thức ngữ cảnh mô hình.
  5. Nhấp vào Thiết lập trình kết nối rồi chọn Thiết bị này.
Màn hình thiết lập trình kết nối MCP của TypingMind với tùy chọn Thiết bị này được chọn
2

Chạy lệnh thiết lập trình kết nối

Chọn Thiết bị này, sao chép lệnh từ TypingMind và chạy trong Terminal. Để tiến trình tiếp tục chạy trong khi bạn dùng MCP.

  1. Sao chép lệnh thiết lập hiển thị trong TypingMind.
  2. Mở Terminal trên macOS hoặc Windows Terminal trên Windows.
  3. Dán và chạy lệnh.
  4. Xác nhận cài đặt gói nếu Terminal hỏi bạn có muốn tiếp tục không.
  5. Để tiến trình tiếp tục chạy trong cửa sổ Terminal khi bạn dùng các công cụ MCP.
3

Thêm QGIS MCP làm máy chủ

Khi trạng thái trình kết nối là Sẵn sàng, nhấp vào Sửa máy chủ và dán cấu hình máy chủ MCP.

  1. Đợi đến khi trạng thái trình kết nối hiển thị Sẵn sàng.
  2. Nhấp vào Sửa máy chủ.
  3. Dán cấu hình máy chủ MCP của QGIS MCP.
  4. Lưu danh sách máy chủ.
  5. Làm mới nếu bạn muốn xác nhận trình kết nối vẫn sẵn sàng.
Cài đặt MCP của TypingMind hiển thị máy chủ đang hoạt động và nút Sửa máy chủ
{
  "mcpServers": {
    "nkarasiak-qgis-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "qgis-mcp"
      ]
    }
  }
}
4

Dùng kết nối với nhiều mô hình

Lưu danh sách máy chủ, mở Plugin, bật các công cụ MCP của QGIS MCP, sau đó chọn bất kỳ mô hình AI nào được hỗ trợ trong TypingMind và dùng các công cụ trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.

  1. Mở trang Plugin trong TypingMind.
  2. Bật các công cụ MCP của QGIS MCP.
  3. Bắt đầu cuộc trò chuyện và chọn mô hình AI bạn muốn dùng.
  4. Dùng các công cụ MCP trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.
  5. Chuyển sang mô hình AI khác bất cứ khi nào cần mà không phải kết nối lại MCP.
Cuộc trò chuyện trên TypingMind dùng các công cụ MCP đã bật với mô hình AI đã chọn
Bạn có thể dùng QGIS MCP giúp tôi làm việc này không?
QGIS MCP
Được. Tôi đọc rồi.
Đây là kết quả tôi tìm được bằng QGIS MCP.

Câu hỏi thường gặp

Máy chủ MCP QGIS MCP dùng để làm gì?

QGIS MCP là máy chủ MCP cho phép các ứng dụng AI tương thích kết nối với công cụ và ngữ cảnh bên ngoài. Trong TypingMind, bạn chỉ cần thêm máy chủ MCP này một lần để các công cụ của nó có sẵn trong không gian làm việc AI của bạn.

Bạn có thể dùng MCP QGIS MCP với nhiều mô hình AI trong TypingMind không?

Có. TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên bạn có thể dùng QGIS MCP với nhiều mô hình AI như Claude, ChatGPT, Gemini hoặc các mô hình khác đã cấu hình trong TypingMind mà không cần thiết lập máy chủ MCP riêng cho từng mô hình.

Vì sao nên dùng MCP QGIS MCP với TypingMind?

TypingMind là một trong những giao diện trò chuyện với LLM tốt nhất vì tập hợp nhiều mô hình AI, prompt, plugin, tác nhân AI, khóa API và công cụ MCP vào một không gian làm việc. Khi kết nối QGIS MCP, bạn có thể dùng các công cụ MCP của dịch vụ này với những mô hình ưa thích, đồng thời giữ quy trình trò chuyện gọn gàng trong TypingMind.

Làm cách nào để kết nối MCP QGIS MCP với TypingMind?

QGIS MCP hoạt động thông qua trình kết nối MCP cục bộ của TypingMind. Đây là lựa chọn phù hợp nhất khi máy chủ MCP cần truy cập tệp cục bộ, ứng dụng máy tính, công cụ dòng lệnh hoặc tài nguyên riêng trên máy tính của bạn.

MCP QGIS MCP cung cấp những công cụ nào trong TypingMind?

QGIS MCP cung cấp các chức năng MCP mà bạn có thể bật từ trang Plugin của TypingMind để dùng trong trò chuyện hoặc gán cho tác nhân AI.

Bạn có cần chia sẻ khóa API với TypingMind để dùng MCP QGIS MCP không?

Không. TypingMind ưu tiên xử lý cục bộ và cho phép bạn kiểm soát nhà cung cấp mô hình, khóa API, prompt và cấu hình MCP. Nếu QGIS MCP yêu cầu xác thực, hãy thêm các header, cài đặt OAuth hoặc cấu hình cục bộ cần thiết cho máy chủ MCP đó khi tạo kết nối.

Máy chủ MCP liên quan

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇