Skip to main content
Glama

get_layer_features

Retrieve features from vector layers in QGIS for analysis and visualization, with optional result limits to manage data output.

Instructions

Retrieve features from a vector layer with an optional limit.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
layer_idYes
limitNo

Implementation Reference

  • Core handler implementation that executes the logic to fetch layer features from QGIS project, including attributes and geometry.
    def get_layer_features(self, layer_id, limit=10, **kwargs):
        """Get features from a vector layer"""
        project = QgsProject.instance()
        
        if layer_id in project.mapLayers():
            layer = project.mapLayer(layer_id)
            
            if layer.type() != QgsMapLayer.VectorLayer:
                raise Exception(f"Layer is not a vector layer: {layer_id}")
            
            features = []
            for i, feature in enumerate(layer.getFeatures()):
                if i >= limit:
                    break
                    
                # Extract attributes
                attrs = {}
                for field in layer.fields():
                    attrs[field.name()] = feature.attribute(field.name())
                
                # Extract geometry if available
                geom = None
                if feature.hasGeometry():
                    geom = {
                        "type": feature.geometry().type(),
                        "wkt": feature.geometry().asWkt(precision=4)
                    }
                
                features.append({
                    "id": feature.id(),
                    "attributes": attrs,
                    "geometry": geom
                })
            
            return {
                "layer_id": layer_id,
                "feature_count": layer.featureCount(),
                "features": features,
                "fields": [field.name() for field in layer.fields()]
            }
        else:
            raise Exception(f"Layer not found: {layer_id}")
  • Registers the get_layer_features handler in the QGIS MCP server's command handlers dictionary.
    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,
    }
    
    handler = handlers.get(cmd_type)
    if handler:
  • MCP protocol tool handler that proxies get_layer_features calls to the QGIS plugin socket server.
    @mcp.tool()
    def get_layer_features(ctx: Context, layer_id: str, limit: int = 10) -> str:
        """Retrieve features from a vector layer with an optional limit."""
        qgis = get_qgis_connection()
        result = qgis.send_command("get_layer_features", {"layer_id": layer_id, "limit": limit})
        return json.dumps(result, indent=2)
  • Socket client proxy method for sending get_layer_features command to QGIS plugin.
    def get_layer_features(self, layer_id, limit=10):
        """Get features from a vector layer"""
        return self.send_command("get_layer_features", {"layer_id": layer_id, "limit": limit})
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. It mentions 'retrieve' and an 'optional limit', but doesn't cover critical aspects like whether this is a read-only operation, potential rate limits, error conditions, or what 'features' entail (e.g., geometry, attributes). For a tool with no annotation coverage, this is insufficient.

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 front-loads the core action ('retrieve features') and includes the key constraint ('optional limit'). There is no wasted verbiage, making it appropriately sized and easy to parse.

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 (retrieving features from a vector layer), lack of annotations, no output schema, and low schema description coverage, the description is incomplete. It doesn't explain what 'features' include, potential side effects, or return format, leaving significant gaps for the agent to understand the tool's full context.

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

Parameters3/5

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

The description adds minimal meaning beyond the input schema: it implies 'layer_id' identifies the vector layer and 'limit' controls the number of features retrieved. However, with 0% schema description coverage, the schema provides no details on parameter semantics. The description compensates slightly but doesn't fully address the gap, such as explaining what 'layer_id' format is expected or how 'limit' interacts with pagination.

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 states the verb 'retrieve' and resource 'features from a vector layer', which clarifies the basic action. However, it doesn't distinguish this from sibling tools like 'get_layers' or 'get_project_info', leaving ambiguity about what specifically makes this tool unique. The purpose is clear but lacks sibling differentiation.

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 siblings like 'get_layers' (which might list layers) and 'zoom_to_layer' (which might focus on a layer), there's no indication of context, prerequisites, or exclusions for 'get_layer_features'. This leaves the agent without usage direction.

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