Skip to main content
Glama

save_results

Save GIS analysis results to files in multiple formats for later use or sharing. Specify formats and location to store geospatial data outputs.

Instructions

MCP Tool: Save any GIS-MCP result dict to files, only when the user requests.

Args: data: The dictionary returned by any GIS-MCP tool. filename: Base filename without extension. formats: List of formats to save (default = all). folder: Target folder (relative to configured storage directory, or absolute path).

Returns: Dict with 'saved_files' mapping format -> path.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataYes
filenameNo
formatsNo
folderNooutputs

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function decorated with @gis_mcp.tool(), implementing the core logic of the 'save_results' MCP tool by calling the save_output helper.
    @gis_mcp.tool()
    def save_results(
        data: Dict[str, Any],
        filename: Optional[str] = None,
        formats: Optional[List[str]] = None,
        folder: str = "outputs"
    ) -> Dict[str, Any]:
        """
        MCP Tool: Save any GIS-MCP result dict to files, only when the user requests.
    
        Args:
            data: The dictionary returned by any GIS-MCP tool.
            filename: Base filename without extension.
            formats: List of formats to save (default = all).
            folder: Target folder (relative to configured storage directory, or absolute path).
    
        Returns:
            Dict with 'saved_files' mapping format -> path.
        """
        try:
            paths = save_output(data, filename=filename, folder=folder, formats=formats)
            return {
                "status": "success",
                "saved_files": paths,
                "message": "Results saved successfully."
            }
        except Exception as e:
            return {"status": "error", "message": f"Failed to save results: {e}"}
  • Supporting function that handles saving data to multiple file formats (JSON, CSV, shapefile, GeoTIFF, etc.), called by the save_results handler.
    def save_output(
        output: Dict[str, Any],
        filename: Optional[str] = None,
        folder: str = "outputs",
        formats: Optional[List[str]] = None,
    ) -> Dict[str, str]:
        """
        Save the output dictionary to multiple formats:
        JSON, CSV, TXT, YAML, XLSX, SHP, GEOJSON, GeoTIFF, TIFF.
    
        The folder path is resolved relative to the configured storage directory.
        If an absolute path is provided, it's used as-is.
    
        Returns a mapping of format -> saved file path.
        """
        # Resolve folder path relative to storage directory
        folder_path = resolve_path(folder, relative_to_storage=True)
        folder_path.mkdir(parents=True, exist_ok=True)
    
        if not filename:
            timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
            filename = f"output_{timestamp}"
    
        if formats is None:
            formats = ["json", "csv", "txt", "yaml", "xlsx", "shp", "geojson", "geotiff", "tiff"]
    
        saved_files = {}
    
        # JSON
        if "json" in formats:
            path = folder_path / f"{filename}.json"
            with open(path, "w", encoding="utf-8") as f:
                json.dump(output, f, indent=4, ensure_ascii=False)
            saved_files["json"] = str(path)
    
        # CSV
        if "csv" in formats:
            try:
                path = folder_path / f"{filename}.csv"
                df = pd.json_normalize(output)
                df.to_csv(path, index=False)
                saved_files["csv"] = str(path)
            except Exception as e:
                print(f"Could not save CSV: {e}")
    
        # TXT
        if "txt" in formats:
            path = folder_path / f"{filename}.txt"
            with open(path, "w", encoding="utf-8") as f:
                for k, v in output.items():
                    f.write(f"{k}: {v}\n")
                saved_files["txt"] = str(path)
    
        # YAML
        if "yaml" in formats:
            path = folder_path / f"{filename}.yaml"
            with open(path, "w", encoding="utf-8") as f:
                yaml.safe_dump(output, f, allow_unicode=True)
                saved_files["yaml"] = str(path)
    
        # Excel
        if "xlsx" in formats:
            try:
                path = folder_path / f"{filename}.xlsx"
                df = pd.json_normalize(output)
                df.to_excel(path, index=False)
                saved_files["xlsx"] = str(path)
            except Exception as e:
                print(f"Could not save Excel: {e}")
    
        # Shapefile
        if "shp" in formats and "geometry" in output:
            try:
                path = folder_path / f"{filename}.shp"
                geom = wkt.loads(output["geometry"])
                gdf = gpd.GeoDataFrame([output], geometry=[geom], crs="EPSG:4326")
                gdf.to_file(path, driver="ESRI Shapefile")
                saved_files["shp"] = str(path)
            except Exception as e:
                print(f"Could not save Shapefile: {e}")
    
        # GeoJSON
        if "geojson" in formats and "geometry" in output:
            try:
                path = folder_path / f"{filename}.geojson"
                geom = wkt.loads(output["geometry"])
                gdf = gpd.GeoDataFrame([output], geometry=[geom], crs="EPSG:4326")
                gdf.to_file(path, driver="GeoJSON")
                saved_files["geojson"] = str(path)
            except Exception as e:
                print(f"Could not save GeoJSON: {e}")
    
        # GeoTIFF
        if "geotiff" in formats and "raster" in output:
            try:
                path = folder_path / f"{filename}.tif"
                raster_data = np.array(output["raster"])
                transform = from_origin(0, 0, 1, 1)
                crs = output.get("crs", "EPSG:4326")
    
                with rasterio.open(
                    path,
                    "w",
                    driver="GTiff",
                    height=raster_data.shape[0],
                    width=raster_data.shape[1],
                    count=1 if raster_data.ndim == 2 else raster_data.shape[2],
                    dtype=raster_data.dtype,
                    crs=crs,
                    transform=transform,
                ) as dst:
                    if raster_data.ndim == 2:
                        dst.write(raster_data, 1)
                    else:
                        for i in range(raster_data.shape[2]):
                            dst.write(raster_data[:, :, i], i + 1)
    
                saved_files["geotiff"] = str(path)
            except Exception as e:
                print(f"Could not save GeoTIFF: {e}")
    
        # TIFF
        if "tiff" in formats and "image" in output:
            try:
                path = folder_path / f"{filename}.tiff"
                img = Image.fromarray(np.uint8(output["image"]))
                img.save(path, format="TIFF")
                saved_files["tiff"] = str(path)
            except Exception as e:
                print(f"Could not save TIFF: {e}")
    
        return saved_files
  • Decorator that registers the save_results function as an MCP tool named 'save_results'.
    @gis_mcp.tool()
Behavior3/5

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

With no annotations provided, the description carries full burden. It discloses the tool's write behavior ('Save... to files') and output format (dict mapping), but lacks details about permissions, error handling, or storage constraints. The description adds value by explaining the return format but doesn't fully compensate for the absence of annotations.

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 efficiently structured with a purpose statement followed by clear parameter explanations and return value documentation. Every sentence adds essential information with zero waste, and the information is front-loaded appropriately.

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?

Given the tool's complexity (4 parameters, nested objects) and the presence of an output schema, the description is nearly complete. It explains parameters thoroughly and mentions the return format. However, as a file-writing tool with no annotations, it could benefit from more behavioral context about error conditions or file system interactions.

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

Parameters5/5

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

With 0% schema description coverage, the description fully compensates by explaining all 4 parameters in detail. It clarifies that 'data' must be 'returned by any GIS-MCP tool', 'filename' is 'without extension', 'formats' accepts a list with a default, and 'folder' can be relative or absolute. This adds significant meaning beyond the bare schema.

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 ('Save any GIS-MCP result dict to files') and resource ('result dict'), distinguishing it from sibling tools that perform GIS operations rather than file saving. It explicitly mentions the source of data ('returned by any GIS-MCP tool'), making the purpose unambiguous.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use this tool ('only when the user requests') and implicitly distinguishes it from all sibling tools by focusing on file saving rather than GIS processing. It clearly establishes this as a post-processing tool for persisting results.

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