Repository navigation
fix(tool)!: serve each schema to the Claude Agent SDK and remove toClaudeAgentSdkTool - #406
Merged
Merged
Conversation
…model arguments toClaudeAgentSdk() handed the AI SDK JSON schema to the Claude Agent SDK's tool(), which takes only a Zod raw shape. createSdkMcpServer() then registered every tool without an input schema, so: - tools/list gave the model an empty object schema, and Claude called the tools with no arguments; - tools/call invoked the handler with the MCP request context instead of the arguments, and execute() failed with "an instance of AbortSignal is not a JSON value (at signal)". No call reached StackOne. The MCP server is now built from the MCP SDK the package already depends on, with tools/list serving the same schema toAnthropic() sends (no Zod round trip, so $defs, $ref and root keywords survive) and tools/call running the tool with the model's arguments. Tool errors still come back as an isError result the model can read. The new test connects an MCP client to the returned server: it fails on main (empty schemas) and passes here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour 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. |
commit: |
…eAgentSdk The Claude Agent SDK's tool() takes only Zod raw shapes, so the JSON schema this method returns is dropped when passed to it. Tools.toClaudeAgentSdk() serves the schema itself. Mark the method deprecated, to be removed in the next major. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>
The Claude Agent SDK's tool() takes only Zod raw shapes, so the JSON schema this
method returned was dropped and the tool ran without its parameters.
Tools.toClaudeAgentSdk() serves the schema itself and replaces it.
- Delete the method and its schema-adapter and serialisation tests
- Check base64 serialisation of file bytes through the toClaudeAgentSdk() MCP server
- Point the optional `ai` peer test at toAISDK(), the remaining tryImport('ai') caller
- README: list toClaudeAgentSdk() in the schema folding table
BREAKING CHANGE: BaseTool.toClaudeAgentSdkTool() is removed. Serve tools to the
Claude Agent SDK with `await tools.toClaudeAgentSdk()` and pass the result in
`mcpServers`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>
…uses The example e2e test built tools by hand with the SDK's tool() and a Zod shape, so it never exercised Tools.toClaudeAgentSdk(), the call the example makes. - The test now connects an MCP client to the server toClaudeAgentSdk() returns, checks the served schema and runs a tool call against the mock StackOne API. The schema and tool call tests fail on main - toClaudeAgentSdk() builds the tools/list response once instead of per request - MIGRATION.md names toClaudeAgentSdk() instead of the removed method Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Tools.toClaudeAgentSdk()passed the AI SDK JSON schema to the Claude Agent SDK'stool(), which takes only a Zod raw shape.createSdkMcpServer()registers it throughMcpServer.tool(), which treats a non-Zod object as annotations, so every tool was registered with no input schema:tools/listgave Claude an empty object schema, so it called the tools with{};tools/callran the handler with the MCP request context instead of the arguments, andexecute()failed withan instance of AbortSignal is not a JSON value (at "signal"). No call reached StackOne.The latest Claude Agent SDK (0.3.322) still accepts only Zod shapes. A Zod round trip would lose
$defs,$refand root keywords that the schema conformance tests keep, so the server is now built from@modelcontextprotocol/sdk(already a dependency). Itstools/listserves the same schematoAnthropic()sends, and itstools/callruns the tool with the model's arguments. Tool errors still come back as anisErrorresult the model can read.src/tool.ts:toClaudeAgentSdk()builds theMcpServerand sets both handlers. It no longer needs theaior@anthropic-ai/claude-agent-sdkpackages at runtime.BaseTool.toClaudeAgentSdkTool()is removed: the SDK'stool()drops its JSON schema, so it could not work there.tools/listis built once per server.src/tool.test.ts: new test that connects an MCP client to the returned server and checks the served schemas, the arguments the tool receives, file bytes as base64, and an error result. It fails onmain(empty schemas) and passes here. The tests of the removed method are gone, and the optionalaipeer test now usestoAISDK().tests/examples/claude-agent-sdk-integration.test.ts: the example test built tools by hand with the SDK'stool()and never calledtoClaudeAgentSdk(). It now connects to the server the example uses, checks the schema and runs a tool call against the mock API. Two of its three tests fail onmain.README.md: namestoClaudeAgentSdk()instead of the removed method, and keeps main's non-stricttoOpenAIResponses()row.MIGRATION.md: new "3.x to 4.0" section on the removal oftoClaudeAgentSdkTool().Breaking change
BaseTool.toClaudeAgentSdkTool()is removed, so the title carries!and release-please will cut a major version. Migrate withconst mcpServer = await tools.toClaudeAgentSdk()and pass it inmcpServers.Dogfood: the Claude Agent SDK example
The same query as
examples/claude-agent-sdk-integration.tsran against a local StackOne MCP stand-in built frommocks/mcp-server.ts, which logs every request it gets. The model is real Claude (Sonnet 4.5) through an Anthropic-compatible endpoint. Both runs passallowedTools: ['mcp__stackone-tools'](from #405), without which a headless query never runs the tool, and print each tool result.main: Claude sees no parameters, every call fails, and onlytools/listreaches StackOne.This PR:
All seven examples then ran on Node 24.22.1 (the repo's pinned engine) on
mainmerged with every open audit PR (#401, #402, #404, #405 and this one) against the same stand-in, with real OpenAI and Claude models. All seven exit 0, and each tool call reaches StackOne with the model's arguments ({"query":{"limit":5}}). Onmainbefore #408 the same run failed the OpenAI Responses example (400, strict schema) and showedArguments: undefinedfor the AI SDK example andInput: {}for this one; #408 (now merged) fixes the first and #405 the second.Test plan
pnpm vitest run src/tool.test.ts src/tool-optional-ai.test.ts src/toolsets.test.ts: 378 passed, no type errorspnpm vitest run tests/examples: 10 passedmain'ssrc/tool.tsand passes herepnpm run lint:oxlint(type-aware, type-check): pass.pnpm buildand publint: pass, and thedistoutput is the same size as onmainRate limit and failure
No new calls, retries or timers. Each
tools/callmakes oneexecute(), as before, with the toolset's existing timeout and 429 handling. An unknown tool name is an MCPInvalidParamserror, the same code the previous server used.Gates
.claude/rules/*.release-pleasenot applied: no release in scope/forge:forgemain: 8 added comment lines (2 constraint comments, JSDoc correction), longest block 3, type escapes 0, copies 0, findings none/security-review/code-reviewtools/listrebuilt per request, example test not coveringtoClaudeAgentSdk(). Not changed, with evidence: loadingserver/mcp.jsstatically costs 3.6 ms on top of the client the SDK already loads; the return type is the agent SDK's ownMcpSdkServerConfigWithInstanceand the SDK only callsinstance.connect();zodstays in the install line because it is the agent SDK's peer dependency; cancellation (extra.signal) is not passed toexecute(), which takes no signal, the same as the SDK's server before; the raw handlers onMcpServermatch the type the agent SDK requiresmainvs this head; all seven examples again with every audit PR combinedtooland example tests: 169 passedPost-merge validation
Library: ships with the next release-please release. After publishing, run
examples/claude-agent-sdk-integration.tswith the published package. The signal that it works is atools/callwith the model's arguments in the request log and a tool result in the stream. The regression signal isInput: {}, or a tool result that mentionsAbortSignal.Requested by guillaume@stackone.com in Slack (repo audit thread).
🤖 Generated with Claude Code