"""
Practice: tools from several MCP servers, as the model reads them and as the harness runs them.
Lab 09's MCPTools (05_mcp.py), metrics.validate_args, and the fix the lab recommends but didn't measure:
our code decides which data each server may receive.

Fill in the TODOs, then run the tests:
    pytest test_mcp_practice.py        (locally)
or press "Run tests" on the chapter page.
"""

HARNESS_ONLY = {"idempotency_key"}  # the harness fills these; the model never sees them


def tool_specs(servers: dict) -> tuple[list, dict]:
    """Turn every server's tools into the list the model reads, and remember which server owns each tool.

    `servers` maps a server's label to its tools: {"shop": [{"name", "description", "parameters"}, ...]}.
    Returns (specs, route):
      - specs: [{"type": "function", "function": {"name", "description", "parameters"}}, ...], in server order.
        The description is copied word for word: it's what the model reads. Remove HARNESS_ONLY keys from
        the parameters' "properties" (and from "required"), without changing the server's own dict.
      - route: {tool name: server label}

    TODO 1
    """
    return [], {}


def check_args(schema: dict, args: dict) -> list:
    """Problems with a call's arguments, [] if none: "missing <key>" for a required key that's absent,
    "empty <key>" for a required string that's empty or only spaces. Required keys in schema order.

    TODO 2
    """
    return []


def blocked_fields(server: str, args: dict, may_receive: dict, private: set) -> list:
    """The private fields this call would send to a server that may not receive them, sorted.
    A field counts only if it's in `private`, has a non-empty value, and isn't in may_receive[server]
    (a server missing from may_receive may receive no private field).

    TODO 3
    """
    return []


def audit(runs: list, tool: str) -> dict:
    """Count what a third-party tool got, from recorded runs: (task_id, tools called in order, emails received).
    Returns {"called": runs that called `tool`, "first": runs whose first call was `tool`,
             "sent": runs whose call reached the server with an email, "emails": distinct emails received}.

    TODO 4
    """
    return {"called": 0, "first": 0, "sent": 0, "emails": 0}
