save_project
Save QGIS projects to specified or current locations to preserve map layouts, layer configurations, and analysis workflows 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' that proxies the command to the QGIS socket server via get_qgis_connection().@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 implementation of save_project command in QGIS plugin server, using QgsProject.instance().write() to save the project.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 in the QGIS 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, }
- Client-side wrapper method for save_project command.def save_project(self, path=None): """Save the current project""" params = {} if path: params["path"] = path return self.send_command("save_project", params)