Skip to main content
Glama

remove_layer

Delete a specific layer from a QGIS project using its unique identifier to manage project layers and maintain organized workspace structure.

Instructions

Remove a layer from the project by its ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
layer_idYes

Implementation Reference

  • MCP tool handler for 'remove_layer'. Proxies the request to the QGIS plugin socket server via get_qgis_connection() and send_command().
    @mcp.tool()
    def remove_layer(ctx: Context, layer_id: str) -> str:
        """Remove a layer from the project by its ID."""
        qgis = get_qgis_connection()
        result = qgis.send_command("remove_layer", {"layer_id": layer_id})
        return json.dumps(result, indent=2)
  • Core implementation of remove_layer command in the QGIS plugin. Removes the specified layer from the current QgsProject instance.
    def remove_layer(self, layer_id, **kwargs):
        """Remove a layer from the project"""
        project = QgsProject.instance()
        
        if layer_id in project.mapLayers():
            project.removeMapLayer(layer_id)
            return {"removed": layer_id}
        else:
            raise Exception(f"Layer not found: {layer_id}")
  • Registration of command handlers in the QGIS plugin socket server, including 'remove_layer': self.remove_layer.
    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,
    }
  • Wrapper method in the socket client for sending remove_layer command.
    def remove_layer(self, layer_id):
        """Remove a layer from the project"""
        return self.send_command("remove_layer", {"layer_id": layer_id})
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the basic action without disclosing behavioral traits. It doesn't mention permissions needed, whether removal is permanent/reversible, effects on the project, error conditions, or rate limits, leaving significant gaps for a destructive operation.

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 with zero waste, front-loading the core action. It's appropriately sized for a simple tool, though brevity contributes to gaps in other dimensions.

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?

For a destructive tool with no annotations, 0% schema coverage, and no output schema, the description is incomplete. It lacks details on behavior, parameters, return values, and integration with siblings, making it inadequate for safe and effective use.

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 but adds minimal value. It mentions 'by its ID' which clarifies the parameter's role, but doesn't explain ID format, sourcing (e.g., from 'get_layers'), or validation, failing to adequately address the coverage gap.

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 ('Remove') and target resource ('a layer from the project'), providing specific verb+resource pairing. However, it doesn't differentiate from sibling tools like 'get_layers' or 'zoom_to_layer' beyond the obvious destructive nature, missing explicit sibling distinction.

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?

No guidance is provided on when to use this tool versus alternatives. The description lacks context about prerequisites (e.g., needing an existing layer ID), exclusions, or comparisons to siblings like 'save_project' or 'create_new_project' for project modifications.

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