Build a versioned, policy-checked call envelope
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
- 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.
- 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.
- 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.
- Require a nonempty string request ID or an exact integer request ID; reject booleans. Arguments must be a dictionary.
- 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.
Implement the function, then run the tests.
Ctrl / ⌘ + Enter to test · Shift + Tab leaves editor