Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/agents/mcp/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ def to_function_tool(
failure_error_function=effective_failure_error_function,
strict_json_schema=is_strict,
needs_approval=needs_approval,
mcp_title=resolve_mcp_tool_title(tool),
meta=tool.meta,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove unsupported meta kwarg from MCP tool builder call

This call passes meta=tool.meta into _build_wrapped_function_tool, but that helper’s signature does not accept a meta parameter, so MCP tool conversion will raise TypeError at runtime when to_function_tool is executed. In practice, this breaks MCP tool registration/execution for any code path that converts tools through this helper.

Useful? React with 👍 / 👎.

mcp_title=resolve_mcp_tool_title(tool)
)
return function_tool

Expand Down
8 changes: 8 additions & 0 deletions src/agents/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ class FunctionTool:
timeout_error_function: ToolErrorFunction | None = None
"""Optional formatter for timeout errors when timeout_behavior is "error_as_result"."""

meta: dict[str, Any] | None = None
"""Optional metadata for the tool."""

defer_loading: bool = False
Comment on lines +294 to 297
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve FunctionTool positional constructor compatibility

Adding meta before defer_loading changes the positional argument mapping for FunctionTool, so existing callers that passed defer_loading positionally will now populate meta instead and silently leave defer_loading at its default. Because FunctionTool is a public dataclass API, this is a backward-incompatible behavioral change and should be avoided by appending new optional fields at the end (or making them keyword-only).

Useful? React with 👍 / 👎.

"""Whether the Responses API should hide this tool definition until tool search loads it."""

Expand Down Expand Up @@ -325,6 +328,9 @@ class FunctionTool:

_mcp_title: str | None = field(default=None, kw_only=True, repr=False)
"""Internal MCP display title used for ToolCallItem metadata."""

_meta: dict[str, Any] | None = field(default=None, kw_only=True, repr=False)
"""Internal metadata used for ToolCallItem metadata."""

@property
def qualified_name(self) -> str:
Expand Down Expand Up @@ -428,6 +434,7 @@ def _build_wrapped_function_tool(
defer_loading: bool = False,
sync_invoker: bool = False,
mcp_title: str | None = None,
meta: dict[str, Any] | None = None,
) -> FunctionTool:
"""Create a FunctionTool with copied-tool-aware failure handling bound in one place."""
on_invoke_tool = with_function_tool_failure_error_handler(
Expand All @@ -453,6 +460,7 @@ def _build_wrapped_function_tool(
timeout_error_function=timeout_error_function,
defer_loading=defer_loading,
_mcp_title=mcp_title,
_meta=meta,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Bind MCP meta into tool invoker

to_function_tool now passes meta=tool.meta, but _build_wrapped_function_tool only stores it on FunctionTool._meta and never binds it into invoke_tool_impl. Since invoke_function_tool calls on_invoke_tool(context, arguments) with no meta kwarg, MCPUtil.invoke_mcp_tool always sees meta=None and drops static MCP _meta from list-tools entries before server.call_tool(...). This breaks MCP servers/tools that depend on request metadata (for example auth/session hints) because converted tools silently omit that metadata at execution time.

Useful? React with 👍 / 👎.

),
failure_error_function,
)
Expand Down