Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭 适合新手
#191 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@sarankumar1325 已经在做这个了。

开始于 2026年10月29日。

  • #193 来自 @sarankumar1325 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java
领域
observability

调研方向

从 InstrumentationSemConv.addAnthropicServerSideChildSpans 开始,位于 braintrust-sdk/src/main/java/dev/braintrust/instrumentation/InstrumentationSemConv.java,其中块由 type 分派;还要阅读 ANTHROPIC_SERVER_TOOL_USE_TYPE、isAnthropicToolResultType 以及 call == null 的回退逻辑。将 mcp_tool_use 注册为调用类型,以便现有的基于后缀的结果匹配将其与 mcp_tool_result 配对。在 BraintrustAnthropicServerSideSpansTest.java 中仿照现有的 server_tool_use 覆盖,并运行该测试类;完成意味着 MCP 子 span 携带真实工具名称和 input_json。

由索引模型根据 Issue 内容生成。

描述

bug java

Summary

InstrumentationSemConv.addAnthropicServerSideChildSpans dispatches Anthropic Messages response content blocks by checking each block's "type" against the literal string "server_tool_use" (see ANTHROPIC_SERVER_TOOL_USE_TYPE and the dispatch check). Anthropic's MCP connector feature emits a different, distinct pair of block types for server-executed MCP tool calls: "mcp_tool_use" (the call) and "mcp_tool_result" (the result). "mcp_tool_use" does not match the "server_tool_use" check, so it is never registered in the call-tracking map used to pair calls with results.

Meanwhile "mcp_tool_result" does match the result-type check, which is a suffix check (type.endsWith("_tool_result") && !type.equals("tool_result")). So the result proceeds through the pairing logic, never finds its matching call, and is emitted alone with call == null.

Consequence for every MCP connector tool invocation:

  • The child span is named generically "mcp_tool" (derived by stripping "_tool_result" off the result's type) instead of the real tool name, because the fallback naming path only runs when call == null.
  • input_json is never set on the span, because the input-extraction path also returns null when call == null. The tool's name, server_name, and input arguments — which live only in the dropped mcp_tool_use block — are permanently lost from the structured child span.

The raw response body is still present in the parent LLM span's full JSON passthrough, so the data isn't gone from Braintrust entirely, but the per-tool-call child span that Braintrust's UI specifically surfaces for tool calls is broken for every MCP connector invocation — call name and input are unrecoverable from that span.

Braintrust docs status: supported

Braintrust's docs at https://www.braintrust.dev/docs/integrations/ai-providers/anthropic describe this capability for the Python SDK: tool calls (including MCP connector tool calls) are captured "with its input and result ... named after the tool" as dedicated spans. This confirms the capability is documented/expected, just not delivered correctly by the Java SDK.

Why this isn't speculative

The identical bug (same mechanism: literal match on "server_tool_use", suffix-based result matching that doesn't require a paired call) was already found and fixed in Braintrust's Python SDK — see braintrustdata/braintrust-sdk-python#797 (fixed in py-sdk-v0.44.1) — and is tracked as still-open for the Go SDK in braintrustdata/braintrust-sdk-go#107. The fix was never ported to the Java SDK.

Upstream sources

Local repo files inspected

  • braintrust-sdk/src/main/java/dev/braintrust/instrumentation/InstrumentationSemConv.java — ANTHROPIC_SERVER_TOOL_USE_TYPE constant and dispatch check; addAnthropicServerSideChildSpans (call registration loop); isAnthropicToolResultType (suffix-based result matching); emitAnthropicServerToolSpan, anthropicToolSpanName, anthropicToolSpanInput (fallback behavior when call == null).
  • braintrust-sdk/instrumentation/anthropic_2_2_0/src/test/java/dev/braintrust/instrumentation/anthropic/v2_2_0/BraintrustAnthropicServerSideSpansTest.java — only exercises web_search/server_tool_use; no mcp_tool_use/mcp_tool_result test coverage exists.
  • Repo-wide search for mcp_tool_use / mcp_tool_result / "MCP connector" — zero matches outside this finding.

Suggested fix

Recognize "mcp_tool_use" as an additional call-type alongside "server_tool_use" when populating the call-tracking map (the existing suffix-based result matching already handles "mcp_tool_result" correctly once a matching call is registered), and add a test mirroring the existing server_tool_use test for the MCP connector block pair.

主要语言
Java
星标
21
派生
5
平均合并
1 天 1 小时
30 天内合并 PR
5

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

braintrustdata/braintrust-sdk-java 的其他 Issue

查看 braintrustdata/braintrust-sdk-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。