Skip to content

feat: MCP tool execution visualization in activity history - #717

Merged
itomek merged 3 commits into
mainfrom
feat/issue-712-mcp-tool-visualization
Apr 10, 2026
Merged

itomek merged 3 commits into
mainfrom
feat/issue-712-mcp-tool-visualization

Conversation

@itomek-amd

@itomek-amd itomek-amd commented Apr 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Closes #712

  • MCP tool calls in the Agent Activity panel now show a purple "via {server}" badge identifying the MCP server
  • Latency (in ms) is displayed in the collapsed tool header, measured at the SSE handler layer via time.monotonic()
  • MCP tool cards start collapsed by default (native tools still auto-expand)
  • Filter bar appears when 2+ tool steps exist — filter by tool name text or status (All/Success/Error)
  • Server name resolved via _TOOL_REGISTRY lookup (no fragile prefix parsing)
  • No new SSE event types, no DB migration, no new API endpoints

Changes

File Change
src/gaia/ui/sse_handler.py mcp_server on tool_start, latency_ms on tool_result
src/gaia/ui/_chat_helpers.py mcpServer/latencyMs in captured steps
src/gaia/ui/models.py New fields on AgentStepResponse
src/gaia/apps/webui/src/types/index.ts Extend AgentStep + StreamEvent
src/gaia/apps/webui/src/components/ChatView.tsx Forward mcp_server/latency_ms in event handlers
src/gaia/apps/webui/src/components/AgentActivity.tsx MCP meta, badge, latency, filter bar, collapsed-by-default
src/gaia/apps/webui/src/components/AgentActivity.css Filter bar, MCP badge, latency styles
tests/unit/chat/ui/test_sse_handler.py 7 new MCP visualization tests
tests/unit/chat/ui/test_models.py 4 new AgentStepResponse tests

Test plan

  • 216 unit tests pass (python -m pytest tests/unit/chat/ui/)
  • Frontend builds clean (npm run build)
  • Lint passes (python util/lint.py --all --fix)
  • Manual: gaia chat --ui → configure MCP server → trigger tool calls → verify badge/latency/filter/collapse
  • Manual: Refresh page → verify tool traces persist in session

Images

image

@github-actions github-actions Bot added tests Test changes electron Electron app changes labels Apr 2, 2026
@itomek itomek self-assigned this Apr 2, 2026
@itomek

itomek commented Apr 2, 2026

Copy link
Copy Markdown
Collaborator

@claude review this PR

@github-actions

github-actions Bot commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @itomek's task —— View job


Reviewing PR #717

  • Read changed files and understand the implementation
  • Review backend changes (SSE handler, models, chat helpers)
  • Review frontend changes (TypeScript types, React components, CSS)
  • Review test coverage
  • Provide comprehensive feedback

Code Review Summary

This PR adds MCP tool execution visualization to the Agent Activity panel. The implementation is clean and well-structured. The changes follow existing patterns and include good test coverage.

🟢 Strengths

  1. Clean Architecture - MCP server resolution via _TOOL_REGISTRY lookup avoids fragile prefix parsing
  2. Proper Layering - Each layer handles its responsibility: SSE handler emits data, chat helpers capture it, types define contracts, frontend renders
  3. Good Test Coverage - 11 new tests covering MCP visualization (7 in test_sse_handler.py, 4 in test_models.py)
  4. No Breaking Changes - Optional fields with None defaults, no new API endpoints, no DB migration
  5. Performance Consideration - Latency measured with time.monotonic() which is correct for measuring elapsed time

🟡 Minor Suggestions

1. Consider defensive handling for missing registry entry (src/gaia/ui/sse_handler.py:211)

mcp_server = _TOOL_REGISTRY.get(tool_name, {}).get("_mcp_server")

This is already defensive with .get(), but a comment explaining the _mcp_server key would help future maintainers understand the MCP tool registration pattern.

2. Filter bar styling (src/gaia/apps/webui/src/components/AgentActivity.css:296-330)
The filter bar styles are clean. Consider adding aria-label to the filter controls for accessibility:

<input
    type="text"
    className="activity-filter-input"
   
    value={toolNameFilter}
    onChange={(e) => setToolNameFilter(e.target.value)}
     // Add this
/>

3. Type consistency (src/gaia/apps/webui/src/components/ChatView.tsx:701)

latencyMs: event.latency_ms,

Good that snake_case from SSE is mapped to camelCase for the step. This maintains TypeScript conventions.

🟢 Verified Behaviors

  • ✅ mcp_server only attached when the tool has _mcp_server in registry
  • ✅ latency_ms resets between tool calls (via _tool_start_time = None)
  • ✅ MCP tools start collapsed by default, native tools auto-expand
  • ✅ Filter bar only appears when 2+ tool steps exist
  • ✅ Latency displayed in collapsed header only when tool is complete

📋 Test Coverage

The new tests thoroughly cover:

  • test_tool_start_includes_mcp_server - MCP server attached to tool_start events
  • test_tool_start_no_mcp_server_for_native_tools - Native tools don't get the field
  • test_tool_result_includes_latency_ms - Latency captured and emitted
  • test_latency_resets_between_tool_calls - Independent latency per tool
  • test_latency_not_present_without_tool_start - Edge case handling
  • test_tool_complete_resets_start_time - Timer cleanup
  • test_mcp_tool_full_flow - Full integration test

✅ Recommendation

LGTM - This PR is ready to merge pending manual verification of the UI behaviors listed in the test plan.


@itomek-amd
itomek-amd force-pushed the feat/issue-712-mcp-tool-visualization branch from acd7cef to fcf4b4c Compare April 2, 2026 18:38
Add MCP server name, latency, and filtering to the Agent Activity panel.
MCP tool calls show a purple "via {server}" badge, latency in ms, and
start collapsed by default. A filter bar allows filtering by tool name
and status when 2+ tool steps exist.

Backend: SSE handler emits mcp_server on tool_start (via public
get_tool_metadata accessor) and latency_ms on tool_result (measured
with time.monotonic). Step capture persists both fields in the
agent_steps JSON blob.

Frontend: getToolMeta returns MCP-specific icon/color, FlowToolCard
renders server badge and latency, ActivityFilterBar provides tool name
and status filtering with useMemo.

Co-Authored-By: Tomasz Iniewicz <[email protected]>
@itomek-amd
itomek-amd force-pushed the feat/issue-712-mcp-tool-visualization branch from fcf4b4c to c4cfb66 Compare April 2, 2026 18:57
@github-actions github-actions Bot added the agents label Apr 2, 2026
…#712)

print_tool_complete() was resetting _tool_start_time before
pretty_print_json() could compute latency_ms, so the MCP tool
latency was never emitted in SSE events or persisted in the DB.

Swap the call order at both execution paths so the result (with
latency) is emitted first, then the timer is reset.

Also guard _execute_tool against None tool_name from LLM parsing.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@itomek
itomek marked this pull request as ready for review April 6, 2026 17:25
@itomek
itomek requested a review from kovtcharov-amd as a code owner April 6, 2026 17:25
@itomek

itomek commented Apr 10, 2026

Copy link
Copy Markdown
Collaborator

@claude review this PR

@github-actions

github-actions Bot commented Apr 10, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @itomek's task —— View job


Reviewing PR #717

  • Read changed files and understand the implementation
  • Review backend changes (SSE handler, models, chat helpers)
  • Review frontend changes (TypeScript types, React components, CSS)
  • Review test coverage
  • Provide comprehensive feedback

Code Review Summary

This PR implements MCP tool execution visualization with server identification, latency metrics, filtering, and collapsed-by-default behavior. The implementation is well-architected and production-ready.

🟢 Strengths

  1. Clean API Design - New get_tool_metadata() function (src/gaia/agents/base/tools.py:113-120) provides proper encapsulation instead of exposing _TOOL_REGISTRY directly

  2. Correct Latency Measurement - Uses time.monotonic() (src/gaia/ui/sse_handler.py:204,257) which is immune to system clock adjustments — the right choice for measuring elapsed time

  3. Proper Event Ordering Fix - The change to emit tool_result before tool_complete (src/gaia/agents/base/agent.py:1688-1691,2403-2406) ensures latency is captured before the timer resets

  4. Defensive Coding - Added null check for tool_name (src/gaia/agents/base/agent.py:1162-1163) prevents crashes from malformed tool calls

  5. Good Accessibility - Filter inputs have aria-label attributes (src/gaia/apps/webui/src/components/AgentActivity.tsx:252,258)

  6. Thorough Test Coverage - 11 new tests cover all edge cases including timer resets, MCP vs native tools, and full flow integration

🟡 Minor Observations

1. Test registry cleanup pattern (tests/unit/chat/ui/test_sse_handler.py:1609-1610)

The _cleanup_registry method uses pop(name, None) which is correct, but the tests would be more robust with a fixture that guarantees cleanup even if assertions fail:

@pytest.fixture
def mcp_tool(handler):
    """Register an MCP tool and ensure cleanup."""
    registered = []
    def register(name, server):
        _TOOL_REGISTRY[name] = {...}
        registered.append(name)
        return name
    yield register
    for name in registered:
        _TOOL_REGISTRY.pop(name, None)

This is a minor suggestion — the current try/finally pattern works correctly.

2. MCP tool detection heuristic (src/gaia/apps/webui/src/components/AgentActivity.tsx:84-85)

The frontend uses toolName.startsWith('mcp_') as a heuristic for MCP tools. This is reasonable for display purposes since:

  • It provides correct styling even before mcpServer data arrives
  • The backend's _mcp_server field provides authoritative identification

3. Filter state persistence (src/gaia/apps/webui/src/components/AgentActivity.tsx:160-161)

Filter state (toolNameFilter, statusFilter) resets when navigating between sessions. This is appropriate behavior — filters are ephemeral UI state.

🟢 Verified Behaviors

Behavior Status
mcp_server only attached for MCP tools ✅ Verified via get_tool_metadata() lookup
latency_ms resets between tool calls ✅ Timer set in print_tool_usage, cleared in pretty_print_json
MCP tools start collapsed ✅ !s.mcpServer filter in auto-expand effect
Filter bar only shown when 2+ tools ✅ toolSteps.length >= 2 condition
Latency displayed only when complete ✅ step.latencyMs != null && !step.active

📋 Test Coverage

The tests comprehensively cover:

  • test_tool_start_includes_mcp_server - MCP server attached to tool_start
  • test_tool_start_no_mcp_server_for_native_tools - Native tools excluded
  • test_tool_result_includes_latency_ms - Latency captured and emitted
  • test_latency_resets_between_tool_calls - Independent latency per tool
  • test_latency_not_present_without_tool_start - Edge case handling
  • test_tool_complete_resets_start_time - Timer cleanup
  • test_mcp_tool_full_flow - Full integration test
  • 4 model tests for AgentStepResponse MCP fields

✅ Recommendation

LGTM - This PR is ready to merge. The implementation is clean, well-tested, and follows existing patterns. The accessibility improvements (aria-labels) and the new get_tool_metadata() API are particularly good additions.


@itomek
itomek added this pull request to the merge queue Apr 10, 2026
Merged via the queue into main with commit 83f5148 Apr 10, 2026
24 checks passed
@itomek
itomek deleted the feat/issue-712-mcp-tool-visualization branch April 10, 2026 19:22
@itomek itomek mentioned this pull request Apr 10, 2026
github-merge-queue Bot pushed a commit that referenced this pull request Apr 10, 2026
Release notes for v0.17.2. See
[docs/releases/v0.17.2.mdx](https://github.com/amd/gaia/blob/v0.17.2-release/docs/releases/v0.17.2.mdx)
for the full body.

**Headline features:**
- One-click desktop installers for Windows, macOS, and Linux (#731 +
#743)
- Customizable agents and Builder Agent (#720)
- MCP tool execution visibility in Agent Activity panel (#717)

**Security:** RAG cache integrity verification (#722, closes #447)

**Bug fixes:** drag-and-drop upload in any browser (#729), Linux install
fixes (#743)

**Release & CI:** unified publish workflow (#715), Claude review on fork
PRs (#685), npm OIDC fix (#683), webui package.json sync (#682)

Full changelog: v0.17.1...v0.17.2

---------

Co-authored-by: Tomasz Iniewicz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

electron Electron app changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent UI: MCP tool execution visualization in activity history

3 participants