Skip to content

[bot] Anthropic Messages API: container and mcp_servers params not captured in span metadata #195

Description

@braintrust-bot

Summary

The official anthropic Ruby gem's Messages and Beta Messages APIs support two significant, currently-documented fields that this SDK's instrumentation silently drops from span metadata: container (code execution tool sandbox reuse) and mcp_servers (the MCP connector, which lets Claude call tools on remote MCP servers directly during generation). Both directly affect what happens during model execution — which tools were actually available/reused, which sandbox state persisted across turns — yet neither appears in any span this SDK produces.

What is missing

  • mcp_servers (request param, beta Messages API): configures remote MCP servers Claude can call tools on mid-generation. Official Ruby example from Anthropic's own docs:

    client.beta.messages.create(
      model: "claude-opus-4-8",
      max_tokens: 1000,
      messages: [...],
      mcp_servers: [{type: "url", url: "...", name: "example-mcp", authorization_token: "..."}],
      tools: [{type: "mcp_toolset", mcp_server_name: "example-mcp"}],
      betas: ["mcp-client-2025-11-20"]
    )

    Also usable inside Message Batches requests.

  • container (request param + response field, both stable and beta Messages APIs): identifies/reuses the sandboxed code-execution container across requests so state (e.g. Python variable bindings) persists. Documented on Anthropic::Models::Message in the official Ruby SDK docs as "Information about the container used in the request (for the code execution tool)."

Neither field is in METADATA_FIELDS (lib/braintrust/contrib/anthropic/instrumentation/messages.rb:25-28) or BETA_METADATA_FIELDS/METADATA_FIELDS (lib/braintrust/contrib/anthropic/instrumentation/beta_messages.rb:29-37), and finalize_metadata/set_output in both files never read response.container. So a user running a code-execution or MCP-connector workflow through this SDK gets a Braintrust trace with no record of which container was reused or which MCP servers/tools were actually wired up — a debugging-critical omission for exactly the kind of agentic tool-execution traces Braintrust is meant to surface.

Braintrust docs status

not_found for Ruby — https://www.braintrust.dev/docs/integrations/ai-providers/anthropic does not mention container or mcp_servers anywhere in the Ruby-specific section. Notably, the Go section of the same page explicitly lists both as captured request parameters ("each span captures ... container, mcp_servers ..."), showing Braintrust already treats these as first-class fields for another language SDK — Ruby is the outlier.

Upstream sources

Local repo files inspected

  • lib/braintrust/contrib/anthropic/instrumentation/messages.rbMETADATA_FIELDS (lines 25-28) and finalize_metadata (lines 141-146) omit container; no mcp_servers handling anywhere
  • lib/braintrust/contrib/anthropic/instrumentation/beta_messages.rbMETADATA_FIELDS/BETA_METADATA_FIELDS (lines 29-37) and capture_beta_fields (lines 146-166) capture only betas and output_format; no container or mcp_servers
  • lib/braintrust/contrib/anthropic/instrumentation/common.rb — token usage parser only; no incidental capture of container/mcp_servers
  • Grep for container, mcp_servers, mcp_server across lib/braintrust/ returns zero relevant matches (one unrelated hit in lib/braintrust/server/services/list_service.rb)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Fields

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions