[bot] Anthropic MCP connector tool calls (mcp_tool_use/mcp_tool_result) produce broken, input-less child spans
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 82/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- java
- Lĩnh vực
- observability
Hướng nghiên cứu
Bắt đầu trong InstrumentationSemConv.addAnthropicServerSideChildSpans trong braintrust-sdk/src/main/java/dev/braintrust/instrumentation/InstrumentationSemConv.java, nơi các khối được dispatch bởi type; cũng đọc ANTHROPIC_SERVER_TOOL_USE_TYPE, isAnthropicToolResultType và các fallback call == null. Đăng ký mcp_tool_use như một call type để phần khớp kết quả dựa trên hậu tố hiện có ghép nó với mcp_tool_result. Phản chiếu phạm vi bao phủ server_tool_use hiện có trong BraintrustAnthropicServerSideSpansTest.java và chạy lớp test đó; hoàn tất nghĩa là MCP child span mang tên công cụ thật và input_json.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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 whencall == null. input_jsonis never set on the span, because the input-extraction path also returnsnullwhencall == null. The tool'sname,server_name, andinputarguments — which live only in the droppedmcp_tool_useblock — 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
- https://docs.anthropic.com/en/docs/agents-and-tools/mcp-connector — documents the
mcp_tool_use/mcp_tool_resultcontent block shapes (e.g.{"type":"mcp_tool_use","id":"mcptoolu_...","name":"<tool>","server_name":"<server>","input":{...}}), distinct fromserver_tool_use. - https://github.com/anthropics/anthropic-sdk-java/blob/v2.2.0/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaContentBlock.kt — confirms these block types were already modeled in the Anthropic Java SDK at the version this repo pins (2.2.0). This instrumentation parses raw JSON directly rather than typed SDK objects, so the gap is a pure string-literal dispatch miss, not an SDK-version-currency issue.
- https://github.com/braintrustdata/braintrust-sdk-python/issues/797 — identical bug, already fixed in the Python SDK.
- https://github.com/braintrustdata/braintrust-sdk-go/issues/107 — same class of bug, open in the Go SDK.
Local repo files inspected
braintrust-sdk/src/main/java/dev/braintrust/instrumentation/InstrumentationSemConv.java—ANTHROPIC_SERVER_TOOL_USE_TYPEconstant and dispatch check;addAnthropicServerSideChildSpans(call registration loop);isAnthropicToolResultType(suffix-based result matching);emitAnthropicServerToolSpan,anthropicToolSpanName,anthropicToolSpanInput(fallback behavior whencall == null).braintrust-sdk/instrumentation/anthropic_2_2_0/src/test/java/dev/braintrust/instrumentation/anthropic/v2_2_0/BraintrustAnthropicServerSideSpansTest.java— only exercisesweb_search/server_tool_use; nomcp_tool_use/mcp_tool_resulttest 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.
- Ngôn ngữ chính
- Java
- Star
- 21
- Fork
- 5
- Merge trung bình
- 1 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 5
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của braintrustdata/braintrust-sdk-java
-
java
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
java
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Tất cả issue của braintrustdata/braintrust-sdk-java
Issue tương tự
-
Update samples to Citrus 5.1.0Có thể đã có người làm @asuruceanu đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
snowflakedb/snowflake-kafka-connector#1610 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
add multipart/form-data exampleĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
swagger-api/swagger-petstore#245 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
liquid-java/liquidjava#443 ·
Maintainer thường phản hồi trong vòng 2 ngày