Skip to main content
Glama

solve_beach_code

Search and retrieve beach data by name, province, or municipality using AEMET-MCP server to access Spain's State Meteorological Agency API.

Instructions

Search beaches by name, province, or municipality.

Args: nombre: Search string (accent-insensitive) tipo: One of 'playa', 'provincia', or 'municipio'

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nombreYes
tipoNoplaya

Implementation Reference

  • The handler function for the 'solve_beach_code' MCP tool. It performs fuzzy matching on beach names, provinces, or municipalities using a preloaded JSON dataset and the normalize helper function.
    @mcp.tool()
    def solve_beach_code(nombre: str, tipo: Literal["playa", "provincia", "municipio"] = "playa"):
        """
        Search beaches by name, province, or municipality.
    
        Args:
            nombre: Search string (accent-insensitive)
            tipo: One of 'playa', 'provincia', or 'municipio'
        """
        entrada = normalize(nombre.strip())
        coincidencias = []
    
        for playa in CODIGOS_PLAYAS:
            if tipo == "playa":
                campo = normalize(playa.get("NOMBRE_PLAYA", ""))
            elif tipo == "provincia":
                campo = normalize(playa.get("NOMBRE_PROVINCIA", ""))
            elif tipo == "municipio":
                campo = normalize(playa.get("NOMBRE_MUNICIPIO", ""))
            else:
                return {"error": f"Invalid type '{tipo}'. Use 'playa', 'provincia' or 'municipio'."}
    
            if entrada in campo or difflib.SequenceMatcher(None, entrada, campo).ratio() > 0.75:
                coincidencias.append(playa)
    
        if not coincidencias:
            return {"error": f"No beaches found with {tipo} matching '{nombre}'."}
        return coincidencias
  • Loads the static JSON data file containing beach codes, names, provinces, and municipalities used by the solve_beach_code tool.
    CODIGOS_PLAYAS = json.loads(
        files("aemet_mcp.res").
        joinpath("Beaches_code.json").
        read_text(encoding="utf-8")
    )
  • Helper function to normalize text for accent-insensitive and case-insensitive matching, used in solve_beach_code.
    def normalize(text: str) -> str:
        return unicodedata.normalize("NFKD", text).encode("ascii", "ignore").decode("ascii").lower()
  • The @mcp.tool() decorator registers the solve_beach_code function as an MCP tool.
    @mcp.tool()
  • Function signature with type hints and docstring defining the input schema for the tool.
    def solve_beach_code(nombre: str, tipo: Literal["playa", "provincia", "municipio"] = "playa"):
        """
        Search beaches by name, province, or municipality.
    
        Args:
            nombre: Search string (accent-insensitive)
            tipo: One of 'playa', 'provincia', or 'municipio'
        """

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/AnCode666/aemet-mcp'

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