Skip to content

feat(tools): show call duration in tool result header (#1284)#1426

Open
dashitongzhi wants to merge 1 commit into
modelcontextprotocol:mainfrom
dashitongzhi:feat/tool-call-duration-20260604091100
Open

feat(tools): show call duration in tool result header (#1284)#1426
dashitongzhi wants to merge 1 commit into
modelcontextprotocol:mainfrom
dashitongzhi:feat/tool-call-duration-20260604091100

Conversation

@dashitongzhi
Copy link
Copy Markdown

Closes #1284.

Displays the round-trip time taken by callTool next to the
Success/Error/Task Running badge in the Tools tab.

  • Tracks performance.now() around the callTool invocation
    and records the elapsed milliseconds in local state.
  • Resets the recorded duration when the user switches tools
    so a previous tool's timing is never shown for a new one.
  • Formats the value as <1 ms, N ms, N.NN s, or Nm N.Ns.
  • Adds Jest coverage for show / hide / reset behaviour.

…otocol#1284)

Displays the round-trip time taken by callTool next to the
Success/Error/Task Running badge in the Tools tab.

- Tracks performance.now() around the callTool invocation
  and records the elapsed milliseconds in local state.
- Resets the recorded duration when the user switches tools
  so a previous tool's timing is never shown for a new one.
- Formats the value as <1 ms, N ms, N.NN s, or Nm N.Ns.
- Adds Jest coverage for show / hide / reset behaviour.

Closes modelcontextprotocol#1284.
Copilot AI review requested due to automatic review settings June 4, 2026 01:14
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds UI support for displaying tool call duration next to tool results, and introduces tests for the duration display/reset behavior.

Changes:

  • Measure callTool wall-clock duration in ToolsTab and pass it down to ToolResults.
  • Render formatted duration text in the tool result header when available.
  • Add unit tests intended to validate duration display and reset behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
client/src/components/tests/ToolsTab.test.tsx Adds tests for duration display/reset scenarios.
client/src/components/ToolsTab.tsx Measures tool call duration and resets it on tool switch.
client/src/components/ToolResults.tsx Formats and displays duration next to the result status.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +38 to +44
if (durationMs < 60_000) {
return `${(durationMs / 1000).toFixed(2)} s`;
}
const totalSeconds = Math.floor(durationMs / 1000);
const minutes = Math.floor(totalSeconds / 60);
const seconds = (durationMs - minutes * 60_000) / 1000;
return `${minutes}m ${seconds.toFixed(1)}s`;
Comment on lines +174 to +182
{typeof durationMs === "number" && (
<span
className="ml-2 text-xs font-normal text-gray-500 dark:text-gray-400"
data-testid="tool-call-duration"
title="Time taken to run the tool (round-trip)"
>
({formatCallDuration(durationMs)})
</span>
)}
Comment on lines +1215 to +1246
it("should show the call duration next to the result after running a tool", async () => {
// Add a small but measurable delay so durationMs > 0 in jsdom.
const callToolMock = jest.fn(
() =>
new Promise<CompatibilityCallToolResult>((resolve) =>
setTimeout(() => resolve(successfulResult), 25),
),
);

renderToolsTab({
selectedTool: mockTools[0],
callTool: callToolMock,
toolResult: null,
});

const runButton = screen.getByRole("button", { name: /run tool/i });
await act(async () => {
fireEvent.click(runButton);
});

// Re-render with the now-available result so the duration surfaces.
renderToolsTab({
selectedTool: mockTools[0],
callTool: callToolMock,
toolResult: successfulResult,
});

const durationEl = await screen.findByTestId("tool-call-duration");
expect(durationEl).toBeInTheDocument();
// The formatted duration is one of "<1 ms", "N ms", "N.NN s", or "Nm N.Ns".
expect(durationEl.textContent).toMatch(/ms|s|m\s/);
});
Comment on lines +16 to +20
/**
* Wall-clock time the last `callTool` invocation took, in milliseconds.
* `undefined` means no measurement is available (e.g. legacy result path).
*/
durationMs?: number | null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show took in ms when running tools

2 participants