Skip to main content
Glama
lsaavedr

MCP Duty Pharma

by lsaavedr

get_nearby_duty_pharmacies

Find the ten nearest pharmacies open today based on a given address, sorted by proximity for quick and reliable access to medication.

Instructions

Get ten closest pharmacies on duty today, sorted by distance to the given address.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYes

Implementation Reference

  • The main handler function implementing the 'get_nearby_duty_pharmacies' tool. It is decorated with @mcp.tool() for automatic registration with the FastMCP server. Fetches pharmacy data from API, filters for duty today, sorts by distance from given address, and returns top 10.
    @mcp.tool()
    async def get_nearby_duty_pharmacies(address: str) -> list[dict]:
        """Get nearby pharmacies on duty today.
    
        - sorted by distance to the given address.
        - only ten closest pharmacies are returned.
        - only pharmacies on duty today are returned.
    
        """
        headers = {"User-Agent": "MCP Duty Pharma", "Accept": "application/json"}
        async with httpx.AsyncClient() as client:
            try:
                response = await client.get(
                    "https://midas.minsal.cl/farmacia_v2/WS/getLocalesTurnos.php",
                    headers=headers,
                    timeout=30.0,
                    follow_redirects=True,
                )
                response.raise_for_status()
                all_pharmacies: list[dict] = response.json()
            except httpx.HTTPStatusError:
                return []
    
        # Filter pharmacies that are on duty today
        now = datetime.now(tz=pytz.timezone("America/Santiago"))
        fecha_hoy = now.isoformat()[0:10]
        fecha_ayer = (now - timedelta(hours=12)).isoformat()[0:10]
        all_pharmacies = list(
            filter(
                lambda f: f["fecha"] == fecha_hoy or f["fecha"] == fecha_ayer,
                all_pharmacies,
            ),
        )
    
        # Sort pharmacies by distance to the given address
        location = geocode(address)
        valid_pharmacies = []
        for pharmacy in all_pharmacies:
            try:
                lat = float(pharmacy["local_lat"].strip(","))
                lng = float(pharmacy["local_lng"].strip(","))
                valid_pharmacies.append(pharmacy)
                logging.debug(f"Processed lat/lng: {lat}, {lng}")
            except ValueError as e:
                logging.error(
                    f"Error processing lat/lng for pharmacy {pharmacy}: {e}"
                )
    
        valid_pharmacies.sort(
            key=lambda pto: distance.distance(
                (
                    float(pto["local_lat"].strip(",")),
                    float(pto["local_lng"].strip(",")),
                ),
                (location.latitude, location.longitude),
            ).km,
        )
    
        # Return the ten closest pharmacies
        return [
            {
                "name": pharmacy["local_nombre"],
                "address": pharmacy["local_direccion"],
                "phone": pharmacy["local_telefono"],
                "schedule": pharmacy["funcionamiento_hora_apertura"]
                + " - "
                + pharmacy["funcionamiento_hora_cierre"],
                "zone": pharmacy["localidad_nombre"],
            }
            for pharmacy in valid_pharmacies[:10]
        ]
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While it mentions the tool returns 'ten closest pharmacies' and sorts by distance, it fails to describe critical behaviors such as response format, error handling, data freshness, rate limits, or authentication requirements. For a location-based query tool with zero annotation coverage, this leaves significant gaps.

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 a single, well-structured sentence that efficiently conveys the core functionality: action, resource, quantity, constraints, and sorting. Every word earns its place with no redundancy or fluff, making it easy to parse and front-loaded with essential information.

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 (location-based query with filtering), lack of annotations, and no output schema, the description is minimally complete. It covers the basic purpose and parameter intent but omits details on output structure, error cases, and operational constraints. It meets the bare minimum for understanding what the tool does but not how it behaves fully.

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

Parameters3/5

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

The input schema has 0% description coverage, so the description must compensate. It adds meaning by explaining that the 'address' parameter is used to calculate distance and filter results, which goes beyond the schema's bare 'Address' title. However, it doesn't specify address format requirements, validation rules, or handling of ambiguous inputs, leaving some semantic gaps.

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: 'Get ten closest pharmacies on duty today, sorted by distance to the given address.' It specifies the verb ('Get'), resource ('pharmacies'), and key constraints ('ten closest', 'on duty today', 'sorted by distance'). However, with no sibling tools mentioned, it cannot demonstrate differentiation from alternatives.

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 explicit guidance on when to use this tool versus alternatives. It implies usage for finding nearby duty pharmacies but offers no information about prerequisites, limitations, or scenarios where other tools might be more appropriate. With no siblings listed, this is a missed opportunity for basic context.

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

Related 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/lsaavedr/mcp-duty-pharma'

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