Skip to main content
Glama
tharlestsa

OpenLandMap MCP Server

by tharlestsa

build_r_snippet

Generate R code snippets to access and process raster datasets from OpenLandMap's environmental data catalog for geospatial analysis.

Instructions

Generate a ready-to-use R code snippet for accessing a raster asset.

Uses terra, sf, and rstac packages.

Args: collection_id: Collection identifier. item_id: Item identifier. asset_key: Asset key within the item. operation: Code operation: 'open' — open with terra::rast() 'info' — print metadata 'plot' — plot the raster 'clip_bbox' — crop to bounding box 'stats' — compute statistics 'export_csv' — export to CSV

Returns: R code snippet as a string.

Example: build_r_snippet("organic.carbon_usda.6a1c", "organic.carbon_usda.6a1c_20180101_20181231", "organic.carbon_usda.6a1c_m_1km_b30cm_s", "plot")

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collection_idYes
item_idYes
asset_keyYes
operationNoopen

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The function `build_r_snippet` implements the tool logic to generate R code snippets based on collection, item, asset keys, and an operation type. It is annotated with `@mcp.tool()` which registers it as an MCP tool.
    async def build_r_snippet(
        collection_id: str,
        item_id: str,
        asset_key: str,
        operation: str = "open",
    ) -> str:
        """Generate a ready-to-use R code snippet for accessing a raster asset.
    
        Uses terra, sf, and rstac packages.
    
        Args:
            collection_id: Collection identifier.
            item_id: Item identifier.
            asset_key: Asset key within the item.
            operation: Code operation:
                'open' — open with terra::rast()
                'info' — print metadata
                'plot' — plot the raster
                'clip_bbox' — crop to bounding box
                'stats' — compute statistics
                'export_csv' — export to CSV
    
        Returns:
            R code snippet as a string.
    
        Example:
            build_r_snippet("organic.carbon_usda.6a1c",
                            "organic.carbon_usda.6a1c_20180101_20181231",
                            "organic.carbon_usda.6a1c_m_1km_b30cm_s",
                            "plot")
        """
        data = await client.get_item_raw(collection_id, item_id)
        assets = data.get("assets", {})
    
        if asset_key not in assets:
            return f"# Error: asset '{asset_key}' not found. Available: {list(assets.keys())}"
    
        url = assets[asset_key].get("href", "")
    
        snippets = {
            "open": (
                f'library(terra)\n\n'
                f'url <- "{url}"\n'
                f'r <- rast(url)\n'
                f'print(r)\n'
                f'cat("CRS:", crs(r, describe=TRUE)$code, "\\n")\n'
                f'cat("Resolution:", res(r), "\\n")\n'
                f'cat("Extent:", as.vector(ext(r)), "\\n")'
            ),
            "info": (
                f'library(terra)\n\n'
                f'url <- "{url}"\n'
                f'r <- rast(url)\n'
                f'cat("Dimensions:", nrow(r), "x", ncol(r), "\\n")\n'
                f'cat("Layers:", nlyr(r), "\\n")\n'
                f'cat("CRS:", crs(r, describe=TRUE)$code, "\\n")\n'
                f'cat("Resolution:", res(r), "\\n")\n'
                f'cat("Extent:", as.vector(ext(r)), "\\n")\n'
                f'cat("Min:", minmax(r)[1], "\\n")\n'
                f'cat("Max:", minmax(r)[2], "\\n")\n'
                f'cat("Data type:", datatype(r), "\\n")'
            ),
            "plot": (
                f'library(terra)\n\n'
                f'url <- "{url}"\n'
                f'r <- rast(url)\n'
                f'plot(r, main="{collection_id} — {item_id}",\n'
                f'     col=hcl.colors(50, "viridis"))'
            ),
            "clip_bbox": (
  • The `@mcp.tool()` decorator on line 410 registers the `build_r_snippet` function as an MCP tool. The module `openlandmap_mcp.tools.analysis` is imported in `src/openlandmap_mcp/server.py` to ensure registration.
    @mcp.tool()
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses that the tool generates code (not executes it), mentions the R packages used (terra, sf, rstac), and lists possible operations, but does not cover behavioral aspects like error handling, rate limits, or authentication needs. It adds some value but lacks comprehensive behavioral context.

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 front-loaded with the main purpose, followed by details on packages, parameters, returns, and an example. Every sentence adds value without redundancy, making it efficient and easy to parse.

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, 0% schema coverage, no annotations) and the presence of an output schema (implied by 'Returns: R code snippet as a string'), the description is mostly complete. It covers parameters and operations well but could include more on behavioral aspects like dependencies or limitations to be fully comprehensive.

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?

Schema description coverage is 0%, so the description must compensate. It adds significant meaning beyond the schema by explaining each parameter's role (e.g., 'collection_id: Collection identifier') and detailing the 'operation' parameter with specific enum-like values and their purposes. This clarifies what inputs are needed and how they affect the output.

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 tool's purpose: 'Generate a ready-to-use R code snippet for accessing a raster asset.' It specifies the verb ('generate'), resource ('R code snippet'), and target ('accessing a raster asset'), and distinguishes from siblings like 'build_python_snippet' by focusing on R specifically.

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 for when to use this tool—for generating R code to access raster assets—and implies usage through the example. However, it does not explicitly state when not to use it or name alternatives (e.g., when Python code is needed instead of R).

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/tharlestsa/openlandmap_mcp'

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