关于 QGISMCP - QGIS Model Context Protocol Integration
QGISMCP 是一个将 QGIS 桌面软件连接到 Claude 的 MCP 集成项目。它通过 QGIS 插件内的套接字服务器接收命令,允许 LLM 创建项目、加载图层、执行处理算法并运行 PyQGIS 代码。项目基于 BlenderMCP 开发,面向 GIS 用户。
主要功能
- 01创建、加载和保存 QGIS 项目
- 02添加和移除矢量及栅格图层
- 03执行 Processing 工具箱中的算法
- 04渲染地图视图并导出为图像
- 05运行任意 PyQGIS 代码(需谨慎使用)
- 06基于套接字的 QGIS 插件与 MCP 服务通信
适用场景
- 01通过自然语言在 QGIS 中执行质心计算等空间分析
- 02根据字段生成分级统计地图
- 03自动化加载和整理图层数据
MCP 相关
该项目包含一个 MCP 服务,通过 QGIS 插件的套接字服务器与 QGIS 通信,向 Claude Desktop 等 MCP 客户端提供项目、图层、处理算法与代码执行等工具。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
QGISMCP - QGIS 模型上下文协议集成
QGISMCP 通过 Model Context Protocol (MCP) 将 QGIS 连接到 Claude AI,让 Claude 能够直接与 QGIS 交互并对其进行控制。此集成支持借助提示词创建项目、加载图层、执行代码等操作。
本项目主要基于 Siddharth Ahuja 的 BlenderMCP 项目。
功能
- 双向通信:通过基于套接字的服务将 Claude AI 连接到 QGIS。
- 项目操作:在 QGIS 中创建、加载和保存项目。
- 图层操作:向项目中添加和移除矢量或栅格图层。
- 执行处理:执行处理算法(处理工具箱)。
- 代码执行:通过 Claude 在 QGIS 中运行任意 Python 代码。功能强大,但使用此工具时也务必谨慎。
组件
系统由两个主要组件构成:
- QGIS 插件:在 QGIS 内创建套接字服务,以接收并执行命令的 QGIS 插件。
- MCP 服务:实现 Model Context Protocol 并连接到 QGIS 插件的 Python 服务。
安装
先决条件
- QGIS 3.X(仅在 3.22 上测试过)
- Claude 桌面应用
- Python 3.10 或更高版本
- uv 包管理器:
如果你使用 Mac,请按以下方式安装 uv:
brew install uv
在 Windows Powershell 上:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
其他安装说明请参阅其网站:安装 uv
⚠️ 安装 UV 前请勿继续
下载代码
将此仓库下载到你的电脑。你可以使用以下命令克隆:
git clone [email protected]:jjsantos01/qgis_mcp.git
QGIS 插件
你需要将文件夹 qgis_mcp_plugin 及其内容复制到 QGIS 配置文件的插件文件夹中。
在 QGIS 中依次选择菜单 Settings -> User profiles -> Open active profile folder,即可找到配置文件夹。然后进入 Python/plugins,粘贴文件夹 qgis_mcp_plugin。
在 Windows 电脑上,插件文件夹通常位于:
C:\Users\USER\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins
在 MacOS 上则位于:~/Library/Application\ Support/QGIS/QGIS3/profiles/default/python/plugins
然后关闭并重新打开 QGIS。依次选择菜单项 Plugins > Installing and Managing Plugins,选择 All 选项卡并搜索 "QGIS MCP",然后勾选 QGIS MCP 复选框。
Claude 桌面应用集成
依次选择 Claude > Settings > Developer > Edit Config > claude_desktop_config.json,添加以下内容:
如果找不到“Developers”选项卡或
claude_desktop_config.json,请参阅此文档。
{
"mcpServers": {
"qgis": {
"command": "uv",
"args": [
"--directory",
"/ABSOLUTE/PATH/TO/PARENT/REPO/FOLDER/qgis_mcp/src/qgis_mcp",
"run",
"qgis_mcp_server.py"
]
}
}
}
使用方法
启动连接
- 在 QGIS 中,依次选择
plugins>QGIS MCP>QGIS MCP
- 点击“Start Server”

与 Claude 搭配使用
在 Claude 中设置好配置文件且 QGIS 中的服务正在运行后,你会看到一个锤子图标,其中包含 QGIS MCP 的工具。

工具
ping- 简单的 ping 命令,用于检查服务器连接性get_qgis_info- 获取当前安装的 QGIS 信息load_project- 从指定路径加载 QGIS 项目create_new_project- 创建新项目并保存get_project_info- 获取当前项目信息add_vector_layer- 向项目添加矢量图层add_raster_layer- 向项目添加栅格图层get_layers- 检索当前项目中的所有图层remove_layer- 按 ID 从项目中移除图层zoom_to_layer- 缩放到指定图层的范围get_layer_features- 从矢量图层检索要素,可选限制数量execute_processing- 使用给定参数执行处理算法save_project- 将当前项目保存到给定路径render_map- 将当前地图视图渲染为图像文件execute_code- 执行作为字符串提供的任意 PyQGIS 代码
示例命令
这是我用于演示的示例:
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.
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。