Skip to main content
Glama

add_raster_layer

Add raster data layers to QGIS projects for spatial analysis and visualization. Specify file paths and providers to integrate geospatial imagery into your GIS workflow.

Instructions

Add a raster layer to the project.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
providerNogdal
nameNo

Implementation Reference

  • Core QGIS handler that implements add_raster_layer by creating a QgsRasterLayer instance, validating it, adding it to the project, and returning layer metadata.
    def add_raster_layer(self, path, name=None, provider="gdal", **kwargs):
        """Add a raster layer to the project"""
        if not name:
            name = os.path.basename(path)
            
        # Create the layer
        layer = QgsRasterLayer(path, name, provider)
        
        if not layer.isValid():
            raise Exception(f"Layer is not valid: {path}")
        
        # Add to project
        QgsProject.instance().addMapLayer(layer)
        
        return {
            "id": layer.id(),
            "name": layer.name(),
            "type": "raster",
            "width": layer.width(),
            "height": layer.height()
        }
  • MCP tool definition and handler for 'add_raster_layer' that forwards parameters to the QGIS socket server via send_command.
    def add_raster_layer(ctx: Context, path: str, provider: str = "gdal", name: str = None) -> str:
        """Add a raster layer to the project."""
        qgis = get_qgis_connection()
        params = {"path": path, "provider": provider}
        if name:
            params["name"] = name
        result = qgis.send_command("add_raster_layer", params)
        return json.dumps(result, indent=2)
  • Registers all command handlers including 'add_raster_layer' in the handlers dictionary used by execute_command to dispatch socket commands.
    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,
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states 'Add' implies a mutation operation but doesn't disclose any behavioral traits: no information on permissions required, whether the addition is reversible, side effects on the project, error conditions, or response format. For a mutation tool with zero annotation coverage, this is a significant gap in transparency.

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, direct sentence with zero waste: 'Add a raster layer to the project.' It's front-loaded and efficiently conveys the core purpose without unnecessary words. Every part of the sentence earns its place by specifying the action and target, making it maximally concise and well-structured.

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 tool's complexity (a mutation operation with 3 parameters), lack of annotations, and no output schema, the description is incomplete. It doesn't explain what a raster layer is, how parameters interact, what happens upon addition, or potential errors. For a tool that modifies project state, this minimal description leaves critical gaps in understanding for an AI agent.

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 undocumented parameters. It adds no meaning beyond the schema: no explanation of what 'path', 'provider', or 'name' represent, their formats, or typical values. With 3 parameters (1 required) and no parameter information in the description, it fails to provide necessary context, scoring low due to inadequate compensation.

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 ('Add') and resource ('a raster layer to the project'), making the purpose immediately understandable. It distinguishes from sibling 'add_vector_layer' by specifying 'raster' rather than 'vector', providing basic differentiation. However, it doesn't specify what a raster layer is or how it differs functionally from vector layers, keeping it from 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 like 'add_vector_layer' or 'load_project'. It doesn't mention prerequisites (e.g., needing an open project) or typical use cases, leaving the agent to infer usage from context alone. This lack of explicit when-to-use or alternative references results in minimal guidance.

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