Skip to content
Open
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
12 changes: 7 additions & 5 deletions src/avalan/server/routers/mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,12 +1054,14 @@ def _tool_call_event_item(event: Event) -> dict[str, JSONValue] | None:
}
if isinstance(event.payload, list) and event.payload:
call = event.payload[0]
elif isinstance(event.payload, dict):
calls = event.payload.get("calls")
if isinstance(calls, list) and calls:
call = calls[0]
else:
Comment on lines +1058 to +1061

Choose a reason for hiding this comment

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

P2 Badge Emit all tool call notifications for multi-call events

When a TOOL_PROCESS payload includes multiple calls (the tool parser can emit payload={"calls": [call1, call2, ...]} when a response contains several tool calls at once), this code only selects calls[0], so _tool_event_notifications emits a notification for the first call and silently drops the rest. That means MCP clients won’t receive tool-call notifications for subsequent calls in the same event, breaking multi-tool responses; this scenario is triggered whenever the model outputs multiple tool calls in a single chunk.

Useful? React with 👍 / 👎.

call = event.payload.get("call")
else:
call = (
event.payload.get("call")
if isinstance(event.payload, dict)
else None
)
call = None
if call is None:
return None
return {
Expand Down
7 changes: 7 additions & 0 deletions tests/server/mcp_router_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,13 @@ def test_tool_call_event_item_variants(self) -> None:
dict_item = mcp_router._tool_call_event_item(dict_event)
self.assertEqual(dict_item["name"], "run")

dict_calls_event = Event(
type=EventType.TOOL_PROCESS,
payload={"calls": [call]},
)
dict_calls_item = mcp_router._tool_call_event_item(dict_calls_event)
self.assertEqual(dict_calls_item["id"], "c1")

none_event = Event(type=EventType.TOOL_PROCESS, payload=None)
self.assertIsNone(mcp_router._tool_call_event_item(none_event))

Expand Down