Skip to main content
Glama

zoom_to_layer

Focus the map view on a specific layer's extent in QGIS to quickly center your analysis area.

Instructions

Zoom to the extent of a specified layer.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
layer_idYes

Implementation Reference

  • Core handler function that executes the zoom to layer logic by setting the layer as active and calling zoomToActiveLayer on the QGIS interface.
    def zoom_to_layer(self, layer_id, **kwargs):
        """Zoom to a layer's extent"""
        project = QgsProject.instance()
        
        if layer_id in project.mapLayers():
            layer = project.mapLayer(layer_id)
            self.iface.setActiveLayer(layer)
            self.iface.zoomToActiveLayer()
            return {"zoomed_to": layer_id}
        else:
            raise Exception(f"Layer not found: {layer_id}")
  • MCP tool registration and proxy handler that forwards the zoom_to_layer command to the QGIS socket server.
    def zoom_to_layer(ctx: Context, layer_id: str) -> str:
        """Zoom to the extent of a specified layer."""
        qgis = get_qgis_connection()
        result = qgis.send_command("zoom_to_layer", {"layer_id": layer_id})
        return json.dumps(result, indent=2)
  • Socket server command handler registration dictionary that maps 'zoom_to_layer' command to the zoom_to_layer handler method.
    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 sending the zoom_to_layer command over the socket.
    def zoom_to_layer(self, layer_id):
        """Zoom to a layer's extent"""
        return self.send_command("zoom_to_layer", {"layer_id": layer_id})
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While 'zoom to the extent' implies a view change, it doesn't specify whether this affects the project state permanently, requires specific layer types, has side effects on other layers, or what happens if the layer doesn't exist. For a tool with zero annotation coverage, this leaves significant gaps.

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

Conciseness5/5

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

The description is a single, efficient sentence that directly states the tool's function with zero wasted words. It's appropriately sized for a simple operation and front-loads the core action, making it easy to parse quickly.

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

Completeness2/5

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

Given the lack of annotations, output schema, and low schema description coverage, the description is incomplete. It doesn't address behavioral aspects like error handling, return values, or dependencies on other tools (e.g., needing a layer from 'add_raster_layer'). For a tool with one parameter but no structured documentation, more context is needed.

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?

Schema description coverage is 0%, so the description must compensate for the undocumented parameter 'layer_id'. The description only vaguely references 'a specified layer' without explaining what constitutes a valid layer ID, how to obtain one (e.g., from 'get_layers'), or format requirements. This adds minimal value beyond the schema's basic type information.

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

Purpose4/5

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

The description clearly states the action ('zoom to the extent') and the target resource ('specified layer'), making the purpose immediately understandable. However, it doesn't differentiate this tool from potential sibling tools that might also manipulate layer views or extents, preventing a perfect score.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With sibling tools like 'get_layers', 'render_map', and 'remove_layer', there's no indication of whether zooming is for visualization, analysis, or other contexts, or what prerequisites might exist.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/syauqi-uqi/qgis_mcp_modify1'

If you have feedback or need assistance with the MCP directory API, please join our Discord server