Skip to content

Feature/support mcp function meta extentions#2764

Closed
jaw9c wants to merge 5 commits into
openai:mainfrom
jaw9c:feature/support-mcp-function-meta-extentions
Closed

Feature/support mcp function meta extentions#2764
jaw9c wants to merge 5 commits into
openai:mainfrom
jaw9c:feature/support-mcp-function-meta-extentions

Conversation

@jaw9c
Copy link
Copy Markdown

@jaw9c jaw9c commented Mar 24, 2026

No description provided.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 863c3aaa61

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/agents/mcp/util.py
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 👍 / 👎.

Comment thread src/agents/tool.py
Comment on lines +294 to 297
meta: dict[str, Any] | None = None
"""Optional metadata for the tool."""

defer_loading: bool = False
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 👍 / 👎.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 19c4e79c61

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/agents/tool.py
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 👍 / 👎.

@felmonon
Copy link
Copy Markdown
Contributor

I traced this locally and the smaller fix looks like it belongs in MCPUtil.to_function_tool(), not on the public FunctionTool dataclass.

invoke_function_tool() only ever calls function_tool.on_invoke_tool(context, arguments), so adding meta / _meta fields to FunctionTool still doesn't carry static MCP metadata into execution by itself.

The narrow path that worked locally was to bind the static MCP tool metadata at conversion time, e.g. by partially applying invoke_mcp_tool with the tool's _meta / meta payload when building the FunctionTool. That keeps the existing invoke_mcp_tool() merge behavior intact, so static tool metadata and tool_meta_resolver output still combine correctly before server.call_tool(...).

That also avoids changing FunctionTool's positional constructor layout, which looks important given the source-compat constructor coverage already in the repo.

I validated that direction locally with focused regressions for:

  • preserving static MCP _meta through to_function_tool() invocation
  • merging static MCP metadata with resolver-produced metadata
  • keeping the constructor compatibility slice green

@seratch seratch marked this pull request as draft March 24, 2026 23:21
@seratch
Copy link
Copy Markdown
Member

seratch commented Mar 24, 2026

@felmonon You're right. I came up with an alternative at #2769

@seratch
Copy link
Copy Markdown
Member

seratch commented Mar 25, 2026

Closing this in favor off #2769 Thanks again for sharing this patch!

@seratch seratch closed this Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants