Workspace/Coding labs
Loading progress

Build a versioned, policy-checked call envelope

Intermediate60 min

Implement plan_tool_call(server, tool_name, arguments, client_versions, granted_scopes, request_id). A local manifest describes versions and tools; the function checks a deliberately narrow schema and produces a pinned modern request plus matching plain ASCII headers.

Your task

  1. The local server manifest has versions and a tools mapping. Each tool has required scopes and fields mapping argument names to string or integer. These are local teaching fields, not an MCP wire catalog.
  2. This exercise implements only revision 2026-07-28. Select it when both peers advertise it; raise ValueError otherwise. Other advertised revisions are outside this implementation.
  3. Raise PermissionError if the selected tool scopes are not a subset of granted scopes. Raise ValueError for an unknown tool, wrong argument names, wrong exact Python types, or a tool name that contains spaces, control characters, or non-ASCII characters.
  4. Require a nonempty string request ID or an exact integer request ID; reject booleans. Arguments must be a dictionary.
  5. Return {request, headers} with JSON-RPC 2.0, tools/call, name, copied arguments, metadata containing the selected version and empty client capabilities, plus matching protocol, method, and name headers. No actual credentials or network calls are performed.

Examples

EXAMPLE 1

Inputlookup with {'sku':'A','limit':2}, revision 2026-07-28, scope read

OutputA tools/call request and matching MCP-Protocol-Version, Mcp-Method, and Mcp-Name headers.

The manifest scope and fields keys are local teaching conventions.
solution.pyPython 3.12