Skip to content

fix(tracing): capture completed McpToolCall items as named tool calls - #106

Open
lakshya-dhariwal wants to merge 1 commit into
langfuse:mainfrom
lakshya-dhariwal:fix/completed-mcp-tool-call-items
Open

lakshya-dhariwal wants to merge 1 commit into
langfuse:mainfrom
lakshya-dhariwal:fix/completed-mcp-tool-call-items

Conversation

@lakshya-dhariwal

Copy link
Copy Markdown

Fixes langfuse/langfuse#17969

What

Desktop code-mode turns emit nested MCP calls only as completed McpToolCall items on item_completed - there are no mcp_tool_call_begin/end events for them and no model-visible tool call to enrich. parse.ts only handled item_completed for UserMessage, so those calls never became observations: traces showed the outer TOOL exec but nothing for the MCP call inside it.

Change

Handle item_completed with item.type === "McpToolCall" in the parser:

  • New tool call named server.tool (the existing mcp naming path in trace.ts renders it the same way) with arguments as input and result as output.
  • status: "failed" records an error instead of an output, unwrapping Err/string error shapes.
  • Deduplicates by call ID: if a model-visible call with the same ID exists (the ordinary CLI path), the item enriches it with MCP identity instead of creating a duplicate - same role as mcp_tool_call_begin/end.
  • startTime uses the completion timestamp. The item carries a duration, but its serialized shape/units are not documented, so this does not guess from it; the span is zero-length rather than wrong.

Testing

  • Two new parser tests with synthetic payloads, matching the shapes in the issue: a code-mode-style completed McpToolCall becomes one codex_app.list_projects tool call with input/output; a completed item whose ID matches a model-visible function_call enriches it (MCP identity + failure error) without duplicating it. Both fail without the parser change.
  • pnpm test - 122/122 pass. pnpm run lint (format + tsc + build) clean.

Notes

Desktop code-mode turns surface nested MCP calls only as item_completed McpToolCall items - no mcp_tool_call_begin/end events and no model-visible call to enrich - so they never became observations. Map them to server.tool tool calls with arguments/result, record failures as errors, and deduplicate by call ID against existing calls.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@CLAassistant

CLAassistant commented Sep 26, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@lakshya-dhariwal

Copy link
Copy Markdown
Author

Friendly bump. This captures completed McpToolCall items as native tool spans, and the CLA is signed. Could a maintainer take a look when you have time? Happy to adjust.

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.

bug: Codex Desktop code-mode MCP calls omitted from tracing plugin

2 participants