Skip to main content
Glama
mahdin75

GeoServer MCP Server

query_features

Extract vector layer data from GeoServer using CQL filters to specify query conditions, return properties, and limit results.

Instructions

Query features from a vector layer using CQL filter.

Args:
    workspace: The workspace containing the layer
    layer: The layer to query
    filter: Optional CQL filter expression
    properties: Optional list of properties to return
    max_features: Maximum number of features to return

Returns:
    GeoJSON FeatureCollection with query results

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filterNo
layerYes
max_featuresNo
propertiesNo
workspaceYes

Implementation Reference

  • Implementation of the 'query_features' tool handler. Queries features from a GeoServer vector layer via WFS GetFeature request with optional CQL filter, property selection, and max features limit. Returns a GeoJSON FeatureCollection. Registered via @mcp.tool() decorator.
    def query_features(
        workspace: str, 
        layer: str, 
        filter: Optional[str] = None,
        properties: Optional[List[str]] = None,
        max_features: Optional[int] = 10
    ) -> Dict[str, Any]:
        """Query features from a vector layer using CQL filter.
        
        Args:
            workspace: The workspace containing the layer
            layer: The layer to query
            filter: Optional CQL filter expression
            properties: Optional list of properties to return
            max_features: Maximum number of features to return
        
        Returns:
            GeoJSON FeatureCollection with query results
        """
        geo = get_geoserver()
        if geo is None:
            raise ValueError("Not connected to GeoServer")
        
        if not workspace or not layer:
            raise ValueError("Workspace and layer name are required")
        
        try:
            # Construct WFS GetFeature request URL
            url = f"{geo.service_url}/wfs"
            params = {
                "service": "WFS",
                "version": "1.0.0",
                "request": "GetFeature",
                "typeName": f"{workspace}:{layer}",
                "outputFormat": "application/json",
                "maxFeatures": max_features or 10
            }
            
            # Add CQL filter if provided
            if filter:
                params["CQL_FILTER"] = filter
                
            # Add property names if provided
            if properties:
                params["propertyName"] = ",".join(properties)
                
            # Make the request
            import requests
            response = requests.get(url, params=params, auth=(geo.username, geo.password))
            response.raise_for_status()
            
            # Parse the GeoJSON response
            features = response.json()
            
            return {
                "type": "FeatureCollection",
                "features": features.get("features", [])
            }
        except Exception as e:
            logger.error(f"Error querying features: {str(e)}")
            raise ValueError(f"Failed to query features: {str(e)}")
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 mentions the return format (GeoJSON FeatureCollection) and that parameters are optional, but lacks details on permissions, rate limits, error handling, or whether this is a read-only operation. For a query tool with zero 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 well-structured and concise, with a clear purpose statement followed by bullet-pointed Args and Returns sections. Every sentence adds value, and there's no redundant information. It's appropriately sized for the tool's complexity.

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

Completeness3/5

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

Given 5 parameters, no annotations, and no output schema, the description is moderately complete. It covers the purpose, parameters, and return format, but lacks behavioral context (e.g., read/write nature, error cases) and usage guidelines. For a query tool with moderate complexity, this is adequate but has clear gaps.

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

Parameters4/5

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

The description lists all 5 parameters with brief explanations (e.g., 'Optional CQL filter expression'), adding meaning beyond the schema, which has 0% description coverage. It clarifies optionality and purposes, though it doesn't provide examples or detailed constraints. Since schema coverage is low, the description compensates well, but not fully.

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 tool's purpose: 'Query features from a vector layer using CQL filter.' It specifies the action (query), resource (features from a vector layer), and method (CQL filter). However, it doesn't explicitly differentiate from sibling tools like 'list_layers' or 'get_layer_info', which reduces 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. It doesn't mention sibling tools like 'list_layers' (for listing layers) or 'get_layer_info' (for layer metadata), nor does it specify use cases or prerequisites. This leaves the agent without contextual 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

Related 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/mahdin75/geoserver-mcp'

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