Skip to content

fix: pair Anthropic MCP connector tool calls with their results - #193

Merged
Andrew Kent (realark) merged 1 commit into
braintrustdata:mainfrom
sarankumar1325:fix/anthropic-mcp-tool-use-spans
Oct 30, 2026
Merged

Andrew Kent (realark) merged 1 commit into
braintrustdata:mainfrom
sarankumar1325:fix/anthropic-mcp-tool-use-spans

Conversation

@sarankumar1325

Copy link
Copy Markdown
Contributor

Fixes #191

Anthropic's MCP connector returns a mcp_tool_use block for the call and a mcp_tool_result block for the result. addAnthropicServerSideChildSpans only registered server_tool_use as a call. Because the suffix check still matched mcp_tool_result, the result was emitted with no paired call. The child span ended up named mcp_tool, and the tool's input was missing.

The fix treats mcp_tool_use as a call type next to server_tool_use. Pairing, naming, input, metadata and output then work the same way they do for web search. This matches the fix in the Python SDK (braintrust-sdk-python#797).

Tests

  • Added InstrumentationSemConvTest.pairsMcpToolUseWithMcpToolResult. It fails on main and passes with this change.
  • ./gradlew :braintrust-sdk:test --tests 'dev.braintrust.instrumentation.*' passes.
  • ./gradlew :braintrust-sdk:instrumentation:anthropic_2_2_0:test (VCR replay) passes.
  • ./gradlew :braintrust-sdk:spotlessCheck passes.

Anthropic's MCP connector emits mcp_tool_use / mcp_tool_result blocks.
Only server_tool_use was registered as a call, so mcp_tool_result spans
were emitted unpaired, named "mcp_tool" and missing input.

Fixes braintrustdata#191

Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-29T14:29:56.965859Z
We couldn’t complete this review. Comment @codex review to try again.
e69b72c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@realark
Andrew Kent (realark) merged commit 8ff9be8 into braintrustdata:main Oct 30, 2026
2 of 4 checks passed
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.

[bot] Anthropic MCP connector tool calls (mcp_tool_use/mcp_tool_result) produce broken, input-less child spans

2 participants