Skip to content

Commit 89c9c20

Browse files
committed
Fixed dynamic MCP naming by pydantic
1 parent 3b0fe3d commit 89c9c20

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

src/utils/agents/tool_processor.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
logger = get_logger(__name__)
3434

3535
_FILE_SEARCH_URL_KEYS = ("doc_url", "docs_url", "url", "link", "reference_url")
36+
_MCP_SERVER_TOOL_PREFIX = f"{MCPServerTool.kind}:"
3637

3738

3839
def summarize_function_tool_call(part: ToolCallPart) -> ToolCallSummary:
@@ -80,8 +81,8 @@ def summarize_native_tool_call(
8081
args=args,
8182
type="file_search_call",
8283
)
83-
case MCPServerTool.kind:
84-
label = part.tool_name.removeprefix(f"{MCPServerTool.kind}:")
84+
case tool_name if tool_name.startswith(_MCP_SERVER_TOOL_PREFIX):
85+
label = tool_name.removeprefix(_MCP_SERVER_TOOL_PREFIX)
8586
action = args.get("action")
8687
# MCP list tools
8788
if action == "list_tools":
@@ -180,7 +181,7 @@ def process_native_tool_result(
180181
state.turn_summary.referenced_documents.extend(referenced_documents)
181182
case WebSearchTool.kind:
182183
tool_result = summarize_web_search_result(part, state.tool_round)
183-
case MCPServerTool.kind:
184+
case tool_name if tool_name.startswith(_MCP_SERVER_TOOL_PREFIX):
184185
tool_result = summarize_mcp_tool_result(part, state.tool_round)
185186
case _:
186187
logger.warning(f"Unknown tool name: {part.tool_name}")

tests/unit/utils/agents/test_tool_processor.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,19 @@ def test_mcp_list_tools_call(self) -> None:
118118
assert summary.args == {"server_label": MCPServerTool.kind}
119119
assert summary.type == "mcp_list_tools"
120120

121+
def test_mcp_list_tools_call_with_label(self) -> None:
122+
"""Test labeled MCP list-tools action uses the server label suffix."""
123+
part = NativeToolCallPart(
124+
tool_name=f"{MCPServerTool.kind}:myserver",
125+
args={"action": "list_tools"},
126+
tool_call_id="mcp-list-labeled",
127+
)
128+
129+
summary = summarize_native_tool_call(part)
130+
131+
assert summary is not None
132+
assert summary.args == {"server_label": "myserver"}
133+
121134
def test_mcp_call(self) -> None:
122135
"""Test MCP tool call summary."""
123136
part = NativeToolCallPart(
@@ -553,6 +566,19 @@ def test_records_file_search_result(self, turn_state: AgentTurnAccumulator) -> N
553566
assert len(turn_state.turn_summary.referenced_documents) == 1
554567
assert turn_state.round_increment_pending
555568

569+
def test_records_labeled_mcp_result(self, turn_state: AgentTurnAccumulator) -> None:
570+
"""Test labeled MCP tool return is processed like unlabeled MCP returns."""
571+
part = NativeToolReturnPart(
572+
tool_name=f"{MCPServerTool.kind}:srv",
573+
tool_call_id="mcp-labeled",
574+
content={"output": "labeled-output"},
575+
)
576+
577+
result = process_native_tool_result(turn_state, part)
578+
579+
assert result is not None
580+
assert result.content == "labeled-output"
581+
556582
def test_records_web_search_and_mcp_results(
557583
self, turn_state: AgentTurnAccumulator
558584
) -> None:

0 commit comments

Comments
 (0)