Skip to main content
Glama

load_project

Load a QGIS project from a specified file path to access and work with geographic data and maps within the GIS software.

Instructions

Load a QGIS project from the specified path.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes

Implementation Reference

  • Primary MCP tool handler for 'load_project'. Proxies the request to the QGIS plugin server via socket connection and returns JSON response.
    @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)
  • Backend socket server registration of 'load_project' handler in QGIS plugin.
    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,
    }
  • Backend QGIS plugin handler that executes the actual project loading using QgsProject.instance().read(path).
    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}")
  • Helper function used by MCP tools to send commands to the QGIS plugin socket server.
    def send_command(self, command_type, params=None):
        """Send a command to the server and get the response"""
        if not self.socket:
            print("Not connected to server")
            return None
        
        # Create command
        command = {
            "type": command_type,
            "params": params or {}
        }
        
        try:
            # Send the command
            self.socket.sendall(json.dumps(command).encode('utf-8'))
            
            # Receive the response
            response_data = b''
            while True:
                chunk = self.socket.recv(4096)
                if not chunk:
                    break
                response_data += chunk
                
                # Try to decode as JSON to see if it's complete
                try:
                    json.loads(response_data.decode('utf-8'))
                    break  # Valid JSON, we have the full message
                except json.JSONDecodeError:
                    continue  # Keep receiving
            
            # Parse and return the response
            return json.loads(response_data.decode('utf-8'))
            
        except Exception as e:
            print(f"Error sending command: {str(e)}")
            return None

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

B3.2/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden. It does not disclose what happens to the current project (e.g., replaces it?), potential side effects, or error states. For example, does it close the current project without saving?

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence is concise but overly brief, lacking necessary detail. It is not front-loaded with key information beyond the basic action.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (one parameter, no output schema), the description covers the basic purpose but lacks behavioral and parameter details. It is minimally complete but could be improved.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema has 0% description coverage; the description only mentions 'from the specified path' without adding meaning about path format, existence requirements, or supported URI schemes.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it loads a QGIS project from a path, using a specific verb and resource. It effectively distinguishes from sibling tools like create_new_project or save_project.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance on when to use this tool versus alternatives, or prerequisites like file existence. The purpose is clear enough, but guidelines are missing.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.