Skip to main content
Glama

clip_vector

Extract vector geometries within specified boundaries by clipping spatial data files. Use this tool to isolate geographic features for focused analysis in GIS workflows.

Instructions

Clip vector geometries using geopandas.clip. Args: gdf_path: Path to the input geospatial file. clip_path: Path to the clipping geometry file. output_path: Optional path to save the result. Returns: Dictionary with status, message, and output info.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
gdf_pathYes
clip_pathYes
output_pathNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core implementation of the clip_vector tool. Loads GeoDataFrames from input paths, aligns CRS if necessary, performs geometric clipping using gpd.clip, optionally saves output, and returns metadata with a preview.
    @gis_mcp.tool()
    def clip_vector(gdf_path: str, clip_path: str, output_path: str = None) -> Dict[str, Any]:
        """
        Clip vector geometries using geopandas.clip.
        Args:
            gdf_path: Path to the input geospatial file.
            clip_path: Path to the clipping geometry file.
            output_path: Optional path to save the result.
        Returns:
            Dictionary with status, message, and output info.
        """
        try:
            gdf = gpd.read_file(gdf_path)
            clip_gdf = gpd.read_file(clip_path)
            if gdf.crs != clip_gdf.crs:
                clip_gdf = clip_gdf.to_crs(gdf.crs)
            result = gpd.clip(gdf, clip_gdf)
            if output_path:
                output_path_resolved = resolve_path(output_path, relative_to_storage=True)
                output_path_resolved.parent.mkdir(parents=True, exist_ok=True)
                result.to_file(str(output_path_resolved))
                output_path = str(output_path_resolved)
            # Convert geometry to WKT for serialization
            preview_df = result.head(5).copy()
            if 'geometry' in preview_df.columns:
                preview_df['geometry'] = preview_df['geometry'].apply(lambda g: g.wkt if g is not None else None)
            preview = preview_df.to_dict(orient="records")
            return {
                "status": "success",
                "message": "Clip completed successfully.",
                "num_features": len(result),
                "crs": str(result.crs),
                "columns": list(result.columns),
                "preview": preview,
                "output_path": output_path,
            }
        except Exception as e:
            logger.error(f"Error in clip_vector: {str(e)}")
            return {"status": "error", "message": str(e)}
  • The @gis_mcp.tool() decorator registers the clip_vector function as an MCP tool.
    @gis_mcp.tool()
  • The gis://geopandas/io resource lists 'clip_vector' among available GeoPandas operations, serving as tool discovery/schema.
    @gis_mcp.resource("gis://geopandas/io")
    def get_geopandas_io() -> Dict[str, List[str]]:
        """List available GeoPandas I/O operations."""
        return {
            "operations": [
                "read_file_gpd",
                "to_file_gpd",
                "overlay_gpd",
                "dissolve_gpd",
                "explode_gpd",
                "clip_vector",
                "write_file_gpd"
            ]
        }
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. While it mentions the geopandas implementation and describes the return format, it doesn't cover important behavioral aspects: whether this is a read-only or destructive operation, what happens if files don't exist, what coordinate reference systems are required, whether the operation modifies input files, or any performance/limitation considerations for large datasets.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (Args, Returns) and front-loaded purpose statement. Every sentence adds value: the first states what the tool does, the Args explain parameters, and Returns describes output. It could be slightly more concise by integrating the purpose with parameter explanations, but overall it's efficient.

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?

For a 3-parameter spatial operation tool with no annotations but with output schema (implied by Returns documentation), the description is minimally adequate. It covers the basic purpose and parameters but lacks important context: no guidance on when to use versus siblings, no behavioral constraints, and no mention of prerequisites like required libraries or file formats. The output documentation helps but doesn't fully compensate for missing operational context.

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?

With 0% schema description coverage, the description compensates well by explaining all three parameters in the Args section: 'gdf_path: Path to the input geospatial file.', 'clip_path: Path to the clipping geometry file.', and 'output_path: Optional path to save the result.' This adds meaningful context beyond the bare schema types, though it doesn't specify file format requirements or path validation rules.

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: 'Clip vector geometries using geopandas.clip.' It specifies the verb ('clip'), resource ('vector geometries'), and implementation method ('using geopandas.clip'). However, it doesn't explicitly differentiate from sibling tools like 'clip_raster_with_shapefile' or 'difference', which perform similar but distinct spatial operations.

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 many sibling tools for spatial operations (e.g., 'clip_raster_with_shapefile', 'difference', 'intersection'), there's no indication of when this vector clipping tool is appropriate versus other clipping or overlay operations. The description only documents parameters and returns.

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

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