save_project
Save QGIS projects to specified or current paths, preserving all layers, settings, and configurations for future use.
Instructions
Save the current project to the given path, or to the current project path if not specified.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No |
Implementation Reference
- src/qgis_mcp/qgis_mcp_server.py:237-245 (handler)MCP tool handler for 'save_project'. Proxies the command to the underlying QGIS socket server via send_command.@mcp.tool() def save_project(ctx: Context, path: str = None) -> str: """Save the current project to the given path, or to the current project path if not specified.""" qgis = get_qgis_connection() params = {} if path: params["path"] = path result = qgis.send_command("save_project", params) return json.dumps(result, indent=2)
- Core QGIS handler implementation for saving the current project using QgsProject.write().def save_project(self, path=None, **kwargs): """Save the current project""" project = QgsProject.instance() if not path and not project.fileName(): raise Exception("No project path specified and no current project path") save_path = path if path else project.fileName() if project.write(save_path): return {"saved": save_path} else: raise Exception(f"Failed to save project to {save_path}")
- qgis_mcp_plugin/qgis_mcp_plugin.py:133-149 (registration)Registration of the 'save_project' handler (line 146) in the QGIS MCP socket server's command handlers dictionary.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, }