Files
Giles Odigwe c6a0e90250 Python: correct MCP tool argument filtering documentation (#7801)
* Python: correct MCP tool argument filtering documentation

The documentation for MCPTool's outbound argument filtering did not match
its behavior. The comment on _prepare_call_kwargs stated that framework
runtime kwargs are "stripped so it is never forwarded to the MCP server",
and packages/core/AGENTS.md repeated the same claim.

In practice, runtime kwargs (FunctionInvocationContext.kwargs, seeded from
function_invocation_kwargs) are merged with the model-supplied arguments in
_call_tool_with_runtime_kwargs before the filter runs, so provenance is no
longer distinguishable at that point. The allowlist is built from the tool's
declared inputSchema.properties as advertised by the server, plus names opted
in through additional_tool_argument_names. A runtime kwarg is therefore
forwarded whenever the server declares a property of the same name, without
the model supplying it.

Update the comments, docstrings and docs to describe the actual rule, and
point each transport at its appropriate channel for values that should not
become tool arguments (env for stdio, header_provider for streamable HTTP).

Also narrow the docstring of test_call_tool_forwards_only_declared_arguments,
which claimed more than it asserts (it covers undeclared names only), and add
a companion test pinning the declared-name behavior so the documented rule
stays verifiable.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Python: address review feedback on MCP argument filtering docs

Corrects and tightens the documentation added in the previous commit.

- header_provider does not withhold values from the outbound argument
  filter; it reads the runtime kwargs without consuming them. The earlier
  wording recommended it as a way to keep a value out of tool arguments,
  which is wrong. Replaced in four places with the pattern that does work:
  source the credential outside function_invocation_kwargs, for example by
  reading a ContextVar inside the provider, which still allows a different
  value per request.
- Note the _meta key and the framework denylist as exceptions wherever the
  docs say server-declared names are forwarded.
- Rework test_call_tool_forwards_runtime_kwargs_the_server_declares to
  invoke the generated FunctionTool with a FunctionInvocationContext, so it
  exercises the real runtime-kwargs path instead of calling call_tool
  directly. Verified by mutation: removing the merge in
  _call_tool_with_runtime_kwargs now fails the test.
- Add a test covering the recommended ContextVar pattern.
- Condense the transport docstring notes, which had grown into three
  near-duplicate blocks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-08-21 18:00:58 +00:00
..
2026-07-14 06:44:26 +00:00