feat: expose MCP server name on converted FunctionTool and ToolCallItem#2829
feat: expose MCP server name on converted FunctionTool and ToolCallItem#2829hashwnath wants to merge 1 commit intoopenai:mainfrom
Conversation
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
There was a problem hiding this comment.
💡 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 |
There was a problem hiding this comment.
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 👍 / 👎.
|
Thanks for you interest, but for this issue, we'll merge #2654 in future releases. |
Summary
When MCP tools are converted to
FunctionToolviaMCPUtil.to_function_tool(), the originating server name is captured in theon_invoke_toolclosure but not exposed on the tool object itself. With multiple MCP servers, callers inspectingToolCallItemorFunctionToolinstances cannot determine which server provided a given tool.This PR adds a
_mcp_server_namefield toFunctionTooland a publicmcp_server_namefield toToolCallItem, following the existing pattern established by_mcp_title/title. The server name is populated duringMCPUtil.to_function_tool()and propagated toToolCallItemin both the non-streaming (turn_resolution.py) and streaming (run_loop.py) paths, including hosted MCP tools whereserver_labelis 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
test_to_function_tool_stores_mcp_server_name: verifies_mcp_server_nameis set onFunctionToolafter conversion.test_to_function_tool_default_mcp_server_name: verifies non-MCPFunctionTooldefaults toNone.test_get_all_function_tools_preserve_server_name: verifies server name is preserved across multiple MCP servers.make format,make lint,make typecheckall pass clean.Issue number
Closes #2228
Checks
make lintandmake format