Skip to main content
Glama

concat_bands

Combine multiple single-band raster files into a multi-band raster, automatically aligning mismatched coordinate systems, resolutions, and dimensions for geospatial analysis.

Instructions

Concatenate multiple single-band raster files into one multi-band raster, handling alignment issues automatically.

Parameters:

  • folder_path: Path to folder containing input raster files (e.g. GeoTIFFs).

  • destination: Path to output multi-band raster file.

Notes:

  • Files are read in sorted order by filename.

  • If rasters have mismatched CRS, resolution, or dimensions, they are aligned automatically.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
folder_pathYes
destinationYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The concat_bands tool handler that concatenates multiple single-band TIFF files from a folder into one multi-band raster file, automatically aligning mismatched rasters using reprojection.
    def concat_bands(
        folder_path: str,
        destination: str
    ) -> Dict[str, Any]:
        """
        Concatenate multiple single-band raster files into one multi-band raster, 
        handling alignment issues automatically.
    
        Parameters:
        - folder_path:   Path to folder containing input raster files (e.g. GeoTIFFs).
        - destination:   Path to output multi-band raster file.
    
        Notes:
        - Files are read in sorted order by filename.
        - If rasters have mismatched CRS, resolution, or dimensions, they are aligned automatically.
        """
        try:
            import rasterio
            import numpy as np
            from rasterio.warp import reproject, calculate_default_transform, Resampling
            from glob import glob
    
            folder_path = os.path.expanduser(folder_path.replace("`", ""))
            dst_path = os.path.expanduser(destination.replace("`", ""))
    
            # Collect single-band TIFF files in folder
            files = sorted(glob(os.path.join(folder_path, "*.tif")))
    
            if len(files) == 0:
                raise ValueError("No .tif files found in folder.")
    
            # Read properties of the first file for reference
            with rasterio.open(files[0]) as ref:
                meta = ref.meta.copy()
                height, width = ref.height, ref.width
                crs = ref.crs
                transform = ref.transform
                dtype = ref.dtypes[0]
    
            meta.update(count=len(files), dtype=dtype)
    
            os.makedirs(os.path.dirname(dst_path) or ".", exist_ok=True)
    
            with rasterio.open(dst_path, "w", **meta) as dst:
                for idx, fp in enumerate(files, start=1):
                    with rasterio.open(fp) as src:
                        band = src.read(1)
    
                        # Auto-align raster if size or CRS mismatch occurs
                        if src.height != height or src.width != width or src.crs != crs or src.transform != transform:
                            new_transform, new_width, new_height = calculate_default_transform(
                                src.crs, crs, src.width, src.height, *src.bounds
                            )
                            aligned_band = np.zeros((new_height, new_width), dtype=dtype)
                            reproject(
                                source=band,
                                destination=aligned_band,
                                src_transform=src.transform,
                                src_crs=src.crs,
                                dst_transform=new_transform,
                                dst_crs=crs,
                                resampling=Resampling.bilinear
                            )
                            band = aligned_band
    
                        dst.write(band, idx)
    
            return {
                "status": "success",
                "destination": str(dst_path),
                "message": f"{len(files)} single-band rasters concatenated into '{dst_path}'."
            }
    
        except Exception as e:
            raise ValueError(f"Failed to concatenate rasters: {e}")
  • Resource listing available rasterio operations, including 'concat_bands', serving as tool discovery/registration.
    @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"
            ]
        }
  • src/gis_mcp/mcp.py:1-6 (registration)
    Creation of the FastMCP instance 'gis_mcp' to which tools are registered via decorators.
    # MCP imports using the new SDK patterns
    from fastmcp import FastMCP
    
    
    gis_mcp = FastMCP("GIS MCP")
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by disclosing key behavioral traits: automatic alignment handling for mismatched CRS/resolution/dimensions, file reading order (sorted by filename), and the transformation nature (single-band to multi-band). It doesn't cover error conditions or performance characteristics.

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?

Perfectly structured with a clear purpose statement followed by organized parameter explanations and notes. Every sentence adds value with zero redundancy. The three-section format (description, parameters, notes) is efficient and scannable.

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

Completeness4/5

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

For a 2-parameter tool with no annotations but an output schema, the description provides solid coverage of the operation's purpose, parameters, and key behaviors. It could benefit from mentioning typical use cases or performance considerations, but the presence of an output schema reduces the need to describe return values.

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 for 2 parameters, the description compensates well by explaining both parameters' purposes ('folder containing input raster files' and 'output multi-band raster file') and providing format examples (GeoTIFFs). It doesn't specify file naming conventions or path validation rules.

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

Purpose5/5

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

The description clearly states the specific action ('concatenate multiple single-band raster files into one multi-band raster') and resource ('raster files'), distinguishing it from siblings like 'extract_band' or 'raster_band_statistics' which handle individual bands differently. It precisely defines the transformation being performed.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context about when to use this tool ('handling alignment issues automatically'), but doesn't explicitly state when NOT to use it or name specific alternatives among siblings. The 'Notes' section gives operational guidance but not comparative usage advice.

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