part…
Building governance for MCP?
The gateway applies what the guide teaches: policies on discovery, invocation and authorisation.
The gateway applies what the guide teaches: policies on discovery, invocation and authorisation.
When a host connects to dozens of servers with hundreds or thousands of tools, loading every definition into the model's context wastes tokens, adds latency and degrades selection. The official Client Best Practices guide proposes two patterns: progressive discovery (when definitions enter the context) and programmatic tool calling (how they are invoked).
The host obtains the definitions with tools/list but defers injecting them into the context; it offers the model a lightweight search_tools meta-tool; and it loads full definitions only when they are needed.
search_tools → names and brief descriptions), inspection (get_tool_details → full schema of one tool), execution.enable_server → server/discover → tools/list); disconnect when done to free context. It fits with agent skills that declare which servers they need.list_changed; group by server.ttlMs/cacheScope; invalidate on receiving list_changed.call_tool({name, args}) meta-tool; treat server disconnection as a conversation-boundary operation.Instead of one call per tool, the model writes code that calls tools; it runs in a sandbox and only the final result returns to the model.
outputSchema gives precise return types; without it, a generic type or extraction with a fast model, validated afterwards).tools/call; only the console output or the final value returns to the model.Sandboxes (examples, not recommendations): Deno / isolated-vm (JS), Monty (experimental Python), pctx (TS), Wasmtime (any language via Wasm). Common pattern: injected stubs, interception over an internal channel (no network permissions), dispatch to servers.
Security: the broker is still the host for the purposes of the spec: the same human-confirmation policy per call (approving the script does not approve each call; categorical per-run approvals are allowed, evaluated call by call); results from one server are untrusted input for another; no network in the sandbox; credentials only in the host; time and memory limits; filter and truncate the output. Errors: isError: true is turned into an exception so the code can use try/catch; an uncaught error is returned as the script's result.
Discover with search, load the schemas of what is needed and run a single script that chains several tools: it minimises both definition tokens and result tokens.
search_tools/get_tool_details as its own tools and maintain the index (with access control in the ranking).tools/call originated by a script with its identifier.1. When does the guide recommend switching to progressive discovery?
With few tools, loading everything is reasonable.
2. In code mode, does approving the script amount to approving all of its tool calls?
The broker is the host for the purposes of the spec.
3. What does the guide recommend to avoid invalidating prompt caching when discovering new tools?
Changing the prompt prefix invalidates the cache.