Skip to main content
Glama

raster_histogram

Analyze pixel value distributions in raster data bands to understand data patterns and quality for geospatial analysis.

Instructions

Compute histogram of pixel values for each band.

Parameters:

  • source: path to input raster.

  • bins: number of histogram bins.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceYes
binsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the 'raster_histogram' MCP tool. It reads the input raster, computes histograms for each band using numpy.histogram, and returns the results per band including bin edges.
    @gis_mcp.tool()
    def raster_histogram(
        source: str,
        bins: int = 256
    ) -> Dict[str, Any]:
        """
        Compute histogram of pixel values for each band.
    
        Parameters:
        - source: path to input raster.
        - bins:   number of histogram bins.
        """
        try:
            import rasterio
            import numpy as np
            import os
    
            src_path = os.path.expanduser(source.replace("`", ""))
            histograms = {}
    
            with rasterio.open(src_path) as src:
                for i in range(1, src.count + 1):
                    band = src.read(i, masked=True)
                    hist, bin_edges = np.histogram(band.compressed(), bins=bins)
                    histograms[f"Band {i}"] = {
                        "histogram": hist.tolist(),
                        "bin_edges": bin_edges.tolist()
                    }
    
            return {
                "status": "success",
                "histograms": histograms,
                "message": f"Histogram computed for all bands."
            }
    
        except Exception as e:
            raise ValueError(f"Failed to compute histogram: {e}")
  • MCP resource that lists all available rasterio operations, including 'raster_histogram', serving as a tool discovery/registration point.
    @gis_mcp.resource("gis://operation/rasterio")
    def get_rasterio_operations() -> Dict[str, List[str]]:
        """List available rasterio operations."""
        return {
            "operations": [
                "metadata_raster",
                "get_raster_crs",
                "clip_raster_with_shapefile",
                "resample_raster",
                "reproject_raster",
                "weighted_band_sum",
                "concat_bands",
                "raster_algebra",
                "compute_ndvi",
                "raster_histogram",
                "tile_raster",
                "raster_band_statistics",
                "extract_band",
                "zonal_statistics",
                "reclassify_raster",
                "focal_statistics",
                "hillshade",
                "write_raster"
            ]
        }
Behavior2/5

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

No annotations are provided, so the description must fully disclose behavioral traits. It states the action ('compute histogram') but does not cover critical aspects like performance implications (e.g., memory usage for large rasters), output format (though an output schema exists), error handling, or permissions required. This leaves significant gaps in understanding the tool's behavior.

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 concise and well-structured, with a clear purpose statement followed by parameter explanations in a bulleted format. Every sentence adds value, and there is no redundant information. It could be slightly improved by integrating the parameter details more seamlessly, but it's highly 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?

Given the tool's moderate complexity (2 parameters, no annotations, but with an output schema), the description is minimally adequate. It covers the basic purpose and parameters but lacks usage guidelines, behavioral details, and output explanation (though the output schema mitigates this). For a tool with no annotations, it should provide more context to be fully complete.

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 adds meaningful semantics beyond the input schema, which has 0% description coverage. It explains that 'source' is a 'path to input raster' and 'bins' is the 'number of histogram bins,' clarifying their purposes. However, it does not detail constraints (e.g., valid file formats for 'source' or range for 'bins'), so it's not fully comprehensive.

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: 'Compute histogram of pixel values for each band.' This specifies the verb ('compute'), resource ('pixel values'), and scope ('each band'), making it easy to understand. However, it does not explicitly differentiate from sibling tools like 'raster_band_statistics' or 'metadata_raster', which might offer overlapping functionality, so it falls short of 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 lacks context about prerequisites (e.g., input raster format), exclusions, or comparisons to siblings such as 'raster_band_statistics' for other statistical analyses. This omission leaves the agent without clear 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/mahdin75/gis-mcp'

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