load_project
Load a QGIS project from a specified file path to access and work with geographic data, layers, and configurations within the GIS environment.
Instructions
Load a QGIS project from the specified path.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- src/qgis_mcp/qgis_mcp_server.py:160-165 (handler)This is the primary MCP tool handler for the 'load_project' tool. It establishes a connection to the QGIS MCP plugin server via socket and sends the load_project command with the provided path parameter, returning the JSON-formatted response from QGIS.@mcp.tool() def load_project(ctx: Context, path: str) -> str: """Load a QGIS project from the specified path.""" qgis = get_qgis_connection() result = qgis.send_command("load_project", {"path": path}) return json.dumps(result, indent=2)
- qgis_mcp_plugin/qgis_mcp_plugin.py:133-149 (registration)Registration of socket command handlers in the QGIS plugin, mapping the 'load_project' command string to the plugin's load_project method, which the MCP server forwards to.handlers = { "ping": self.ping, "get_qgis_info": self.get_qgis_info, "load_project": self.load_project, "get_project_info": self.get_project_info, "execute_code": self.execute_code, "add_vector_layer": self.add_vector_layer, "add_raster_layer": self.add_raster_layer, "get_layers": self.get_layers, "remove_layer": self.remove_layer, "zoom_to_layer": self.zoom_to_layer, "get_layer_features": self.get_layer_features, "execute_processing": self.execute_processing, "save_project": self.save_project, "render_map": self.render_map, "create_new_project": self.create_new_project, }
- The underlying QGIS plugin handler that performs the actual project loading using QgsProject.read(path), refreshes the map canvas, and returns success info with layer count.def load_project(self, path, **kwargs): """Load a project""" project = QgsProject.instance() if project.read(path): self.iface.mapCanvas().refresh() return { "loaded": path, "layer_count": len(project.mapLayers()) } else: raise Exception(f"Failed to load project from {path}")