Skip to content

feat: expose MCP server name on converted FunctionTool and ToolCallItem#2829

Closed
hashwnath wants to merge 1 commit intoopenai:mainfrom
hashwnath:feat/2228-mcp-server-name-on-tool
Closed

feat: expose MCP server name on converted FunctionTool and ToolCallItem#2829
hashwnath wants to merge 1 commit intoopenai:mainfrom
hashwnath:feat/2228-mcp-server-name-on-tool

Conversation

@hashwnath
Copy link
Copy Markdown

Summary

When MCP tools are converted to FunctionTool via MCPUtil.to_function_tool(), the originating server name is captured in the on_invoke_tool closure but not exposed on the tool object itself. With multiple MCP servers, callers inspecting ToolCallItem or FunctionTool instances cannot determine which server provided a given tool.

This PR adds a _mcp_server_name field to FunctionTool and a public mcp_server_name field to ToolCallItem, following the existing pattern established by _mcp_title / title. The server name is populated during MCPUtil.to_function_tool() and propagated to ToolCallItem in both the non-streaming (turn_resolution.py) and streaming (run_loop.py) paths, including hosted MCP tools where server_label is used directly.

This follows the approach suggested by @seratch in the issue discussion — using specific named fields rather than a generic metadata dict.

Test plan

  • Added test_to_function_tool_stores_mcp_server_name: verifies _mcp_server_name is set on FunctionTool after conversion.
  • Added test_to_function_tool_default_mcp_server_name: verifies non-MCP FunctionTool defaults to None.
  • Added test_get_all_function_tools_preserve_server_name: verifies server name is preserved across multiple MCP servers.
  • Full test suite passes (2670 tests, 0 failures).
  • make format, make lint, make typecheck all pass clean.

Issue number

Closes #2228

Checks

  • I've added new tests (if relevant)
  • I've added/updated the relevant documentation
  • I've run make lint and make format
  • I've made sure tests pass

Add `_mcp_server_name` field to `FunctionTool` so callers can identify
which MCP server provided a tool after conversion. Populate the field
during `MCPUtil.to_function_tool()` and propagate it to `ToolCallItem`
via `mcp_server_name` for both streaming and non-streaming paths.

Closes openai#2228
@github-actions github-actions bot added enhancement New feature or request feature:mcp labels Apr 2, 2026
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: 8937f876e1

ℹ️ 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".

title: str | None = None
"""Optional short display label if known at item creation time."""

mcp_server_name: str | None = None
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 Persist MCP server metadata in run state

ToolCallItem now exposes mcp_server_name, but run-state persistence still only handles description/title in RunState._serialize_item and _deserialize_items, so this field is lost whenever a run is saved and reloaded. In interruption or session-resume flows, MCP-originated tool calls will come back with mcp_server_name=None, which breaks the new server-disambiguation behavior for restored runs.

Useful? React with 👍 / 👎.

@seratch
Copy link
Copy Markdown
Member

seratch commented Apr 2, 2026

Thanks for you interest, but for this issue, we'll merge #2654 in future releases.

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

Labels

enhancement New feature or request feature:mcp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable to access MCP server name via its converted function tool object

2 participants