Skip to content

feat(claude-agent-sdk): surface raw MCP tool name via metadata - #2638

Open
boyuan-fh wants to merge 1 commit into
ag-ui-protocol:mainfrom
boyuan-fh:fh-10254/pr4-raw-tool-name
Open

feat(claude-agent-sdk): surface raw MCP tool name via metadata#2638
boyuan-fh wants to merge 1 commit into
ag-ui-protocol:mainfrom
boyuan-fh:fh-10254/pr4-raw-tool-name

Conversation

@boyuan-fh

Copy link
Copy Markdown

Fixes #2633

Problem

stripMcpPrefix removes the mcp__<server>__ prefix from tool names before
the adapter emits TOOL_CALL_START events and before it builds assistant
message tool calls. This makes built-in and MCP tool calls indistinguishable
in the event stream and message history.

Changes (integration package only -- no @ag-ui/core change)

  • Emit metadata: { rawName } on TOOL_CALL_START in both the streaming path
    (adapter.ts) and the non-streaming path (handlers.ts), carrying the raw
    prefixed name while toolCallName stays the stripped display name.
  • Carry metadata: { rawName } on tool calls built by buildAguiAssistantMessage
    (utils.ts) and on the in-flight message accumulator (adapter.ts).
  • For built-in tools, metadata.rawName equals the display name.

The raw name uses the metadata map that both BaseEventSchema (events) and
ToolCallSchema (messages) already declare, so no shared-schema edit is
required and the field survives .parse() on both surfaces.

Tests (new adapter.raw-tool-name.test.ts + schema-survival.test.ts)

  • MCP tool emits metadata.rawName with the full prefix on the streaming path;
    built-in tool emits metadata.rawName equal to the display name.
  • Non-streaming (complete assistant message) path emits metadata.rawName.
  • MCP and built-in tool calls in MESSAGES_SNAPSHOT carry metadata.rawName.
  • schema-survival.test.ts parses through the real ToolCallStartEventSchema
    and ToolCallSchema from @ag-ui/core and asserts metadata.rawName
    survives .parse() on both -- proving the design premise against the real
    schemas rather than a mock.

stripMcpPrefix makes a built-in Bash call and an mcp__server__Bash call byte-identical in the event stream and message history. Carry the original prefixed name in the existing metadata map (metadata.rawName) on both TOOL_CALL_START events and assistant-message tool calls, keeping toolCallName/function.name as the stripped display name. No @ag-ui/core schema change.

Fixes #<issue>
@boyuan-fh
boyuan-fh requested a review from a team as a code owner September 4, 2026 10:24
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.

[Feature]: @ag-ui/claude-agent-sdk: surface the raw MCP tool name so consumers can distinguish MCP vs built-in calls

1 participant