Skip to main content
Glama

add_vector_layer

Add vector data layers to QGIS projects from file paths, enabling spatial analysis and visualization through direct integration with GIS software.

Instructions

Add a vector layer to the project.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
providerNoogr
nameNo

Implementation Reference

  • Core handler function that creates a QgsVectorLayer from the given path, validates it, adds it to the QGIS project, and returns layer information including ID, name, type, and feature count.
    def add_vector_layer(self, path, name=None, provider="ogr", **kwargs):
        """Add a vector layer to the project"""
        if not name:
            name = os.path.basename(path)
            
        # Create the layer
        layer = QgsVectorLayer(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": self._get_layer_type(layer),
            "feature_count": layer.featureCount()
        }
  • Registers the add_vector_layer method as a handler for socket commands in the QgisMCPServer's execute_command 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,
    }
  • MCP tool handler decorated with @mcp.tool(). Proxies the call to the QGIS plugin server via socket using get_qgis_connection().send_command, providing input schema via type hints and docstring.
    def add_vector_layer(ctx: Context, path: str, provider: str = "ogr", name: str = None) -> str:
        """Add a vector layer to the project."""
        qgis = get_qgis_connection()
        params = {"path": path, "provider": provider}
        if name:
            params["name"] = name
        result = qgis.send_command("add_vector_layer", params)
        return json.dumps(result, indent=2)
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action ('Add') but doesn't explain what happens during addition (e.g., whether it modifies the project state, requires specific permissions, or has side effects like overwriting existing layers). This leaves critical behavioral traits unaddressed.

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. It's appropriately sized and front-loaded, clearly stating the tool's purpose without unnecessary elaboration, earning its place as 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 complexity of adding a layer (a mutation operation), no annotations, no output schema, and low schema coverage, the description is incomplete. It doesn't cover behavioral aspects, parameter meanings, or usage context, making it inadequate for informed tool selection and invocation.

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 mentions no parameters at all, failing to explain the meaning of 'path', 'provider', or 'name' beyond what the schema titles imply. This adds no value over the schema, leaving parameters semantically unclear.

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

Purpose3/5

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

The description 'Add a vector layer to the project' clearly states the verb ('Add') and resource ('vector layer'), but it's vague about what a 'vector layer' entails and doesn't distinguish it from sibling tools like 'add_raster_layer' or 'load_project'. It provides a basic purpose but lacks specificity.

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 such as 'add_raster_layer' for raster data or 'load_project' for loading existing layers. The description implies usage for adding vector layers but offers no context on prerequisites, timing, or exclusions.

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