feat(tools): show call duration in tool result header (#1284)#1426
Open
dashitongzhi wants to merge 1 commit into
Open
feat(tools): show call duration in tool result header (#1284)#1426dashitongzhi wants to merge 1 commit into
dashitongzhi wants to merge 1 commit into
Conversation
…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.
There was a problem hiding this comment.
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
callToolwall-clock duration inToolsTaband pass it down toToolResults. - 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1284.
Displays the round-trip time taken by
callToolnext to theSuccess/Error/Task Running badge in the Tools tab.
performance.now()around thecallToolinvocationand records the elapsed milliseconds in local state.
so a previous tool's timing is never shown for a new one.
<1 ms,N ms,N.NN s, orNm N.Ns.