Skip to content

fix(tool)!: serve each schema to the Claude Agent SDK and remove toClaudeAgentSdkTool - #406

Merged
glebedel merged 6 commits into
mainfrom
s2d2/audit-claude-agent-sdk-tools
Nov 11, 2026
Merged

glebedel merged 6 commits into
mainfrom
s2d2/audit-claude-agent-sdk-tools

Conversation

@glebedel

@glebedel glebedel commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Tools.toClaudeAgentSdk() passed the AI SDK JSON schema to the Claude Agent SDK's tool(), which takes only a Zod raw shape. createSdkMcpServer() registers it through McpServer.tool(), which treats a non-Zod object as annotations, so every tool was registered with no input schema:

  • tools/list gave Claude an empty object schema, so it called the tools with {};
  • tools/call ran 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 latest Claude Agent SDK (0.3.322) still accepts only Zod shapes. A Zod round trip would lose $defs, $ref and root keywords that the schema conformance tests keep, so the server is now built from @modelcontextprotocol/sdk (already a dependency). Its tools/list serves the same schema toAnthropic() sends, and its tools/call runs the tool with the model's arguments. Tool errors still come back as an isError result the model can read.

  • src/tool.ts: toClaudeAgentSdk() builds the McpServer and sets both handlers. It no longer needs the ai or @anthropic-ai/claude-agent-sdk packages at runtime. BaseTool.toClaudeAgentSdkTool() is removed: the SDK's tool() drops its JSON schema, so it could not work there. tools/list is 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 on main (empty schemas) and passes here. The tests of the removed method are gone, and the optional ai peer test now uses toAISDK().
  • tests/examples/claude-agent-sdk-integration.test.ts: the example test built tools by hand with the SDK's tool() and never called toClaudeAgentSdk(). 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 on main.
  • README.md: names toClaudeAgentSdk() instead of the removed method, and keeps main's non-strict toOpenAIResponses() row. MIGRATION.md: new "3.x to 4.0" section on the removal of toClaudeAgentSdkTool().

Breaking change

BaseTool.toClaudeAgentSdkTool() is removed, so the title carries ! and release-please will cut a major version. Migrate with const mcpServer = await tools.toClaudeAgentSdk() and pass it in mcpServers.

Dogfood: the Claude Agent SDK example

The same query as examples/claude-agent-sdk-integration.ts ran against a local StackOne MCP stand-in built from mocks/mcp-server.ts, which logs every request it gets. The model is real Claude (Sonnet 4.5) through an Anthropic-compatible endpoint. Both runs pass allowedTools: ['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 only tools/list reaches StackOne.

Tool use: mcp__stackone-tools__bamboohr_list_employees Input: {}
tool_result: "Arguments for \"bamboohr_list_employees\" could not be encoded as JSON: an instance of AbortSignal is not a JSON value (at \"signal\")"
Tool use: mcp__stackone-tools__workday_list_workers Input: {}
tool_result: "Arguments for \"workday_list_workers\" could not be encoded as JSON: an instance of AbortSignal is not a JSON value (at \"signal\")"
Assistant: I apologize, but I'm encountering a technical issue ...
[stackone] POST /mcp account=your-bamboohr-account-id tools/list -> 200

This PR:

Tool use: mcp__stackone-tools__bamboohr_list_employees Input: {"query":{"limit":5}}
tool_result: [{"type":"text","text":"{\"data\":[{\"id\":\"w1\",\"name\":\"Ada Lovelace\"},{\"id\":\"w2\",\"name\":\"Alan Turing\"}, ...
Assistant: Here are the first 5 employees: ...
[stackone] POST /mcp account=your-bamboohr-account-id tools/list -> 200
[stackone] POST /mcp account=your-bamboohr-account-id tools/call bamboohr_list_employees {"query":{"limit":5}} -> 200

All seven examples then ran on Node 24.22.1 (the repo's pinned engine) on main merged 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}}). On main before #408 the same run failed the OpenAI Responses example (400, strict schema) and showed Arguments: undefined for the AI SDK example and Input: {} 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 errors
  • pnpm vitest run tests/examples: 10 passed
  • New test fails against main's src/tool.ts and passes here
  • pnpm run lint:oxlint (type-aware, type-check): pass. pnpm build and publint: pass, and the dist output is the same size as on main

Rate limit and failure

No new calls, retries or timers. Each tools/call makes one execute(), as before, with the toolset's existing timeout and 429 handling. An unknown tool name is an MCP InvalidParams error, the same code the previous server used.

Gates

Gate Result Head
Repo skills None in repo (Nix-managed, gitignored). Read .claude/rules/*. release-please not applied: no release in scope f06ad4f
/forge:forge Ran on f06ad4f: static imports in place of a dynamic import, doc reflowed. Meter vs main: 8 added comment lines (2 constraint comments, JSDoc correction), longest block 3, type escapes 0, copies 0, findings none f06ad4f
Security scan (security-reviewer agent + Aikido) f06ad4f and again on the removal (6ba4d0f): no findings at threshold 70. Two notes below threshold: any thrown message reaches the model, as it did through the SDK's server before; and there is no argument validation, the same as every other adapter. Aikido: none of the open critical/high issues is in a changed file f06ad4f
Codex security pass No findings f06ad4f, 6ba4d0f
/security-review Pass (injection, secrets, DoS: Map lookup, error text carries no credentials, one call per request) f06ad4f
/code-review f06ad4f: no findings. 6ba4d0f: 9 findings. Fixed in 73493d8: stale PR body, MIGRATION.md mention, tools/list rebuilt per request, example test not covering toClaudeAgentSdk(). Not changed, with evidence: loading server/mcp.js statically costs 3.6 ms on top of the client the SDK already loads; the return type is the agent SDK's own McpSdkServerConfigWithInstance and the SDK only calls instance.connect(); zod stays in the install line because it is the agent SDK's peer dependency; cancellation (extra.signal) is not passed to execute(), which takes no signal, the same as the SDK's server before; the raw handlers on McpServer match the type the agent SDK requires f06ad4f, 6ba4d0f
Dogfood Above, local stand-in with real Claude, main vs this head; all seven examples again with every audit PR combined f06ad4f, f2314ee
Removal and review fixes Forge meter vs f2314ee on the removal: +6 -57, 0 comment lines, findings none; on the review fixes: +39 -105, longest comment block 2, findings none. Lint (oxlint type-aware), tool and example tests: 169 passed 6ba4d0f, 73493d8
CI Green (25 pass, 5 skipped by design, 1 neutral) 73493d8
Review threads 0 unresolved 73493d8

Post-merge validation

Library: ships with the next release-please release. After publishing, run examples/claude-agent-sdk-integration.ts with the published package. The signal that it works is a tools/call with the model's arguments in the request log and a tool result in the stream. The regression signal is Input: {}, or a tool result that mentions AbortSignal.

Requested by guillaume@stackone.com in Slack (repo audit thread).

🤖 Generated with Claude Code

…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>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T01:39:14.985057Z f06ad4f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/StackOneHQ/stackone-ai-node/@stackone/ai@406

commit: 6be7301

s2d2-s1 and others added 2 commits November 11, 2026 09:37
…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>
@glebedel glebedel changed the title fix(tool): serve each schema to the Claude Agent SDK and pass it the model arguments fix(tool)!: serve each schema to the Claude Agent SDK and remove toClaudeAgentSdkTool Nov 11, 2026
s2d2-s1 and others added 3 commits November 11, 2026 09:52
…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>
@glebedel
glebedel requested a review from StuBehan November 11, 2026 14:07
@glebedel
glebedel merged commit 81e1586 into main Nov 11, 2026
31 checks passed
@glebedel
glebedel deleted the s2d2/audit-claude-agent-sdk-tools branch November 11, 2026 14:48
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.

2 participants