Commit f02644b
authored
feat(tool): add toClaudeAgentSdk() method for Claude Agent SDK integration [ENG-11770] (#283)
* chore(deps): add @anthropic-ai/claude-agent-sdk as peer dependency
Add Claude Agent SDK as an optional peer dependency to support the new
toClaudeAgentSdk() method. This allows users to convert StackOne tools
to Claude Agent SDK format without manual wrapping.
The package is marked as optional in peerDependenciesMeta, so users
only need to install it when using Claude Agent SDK integration.
* feat(utils): add JSON Schema to Zod conversion utility
Add jsonSchemaToZod() function that converts JSON Schema definitions
to Zod schemas at runtime. This is required for Claude Agent SDK
integration, which expects Zod schemas for tool definitions.
Supports converting:
- Primitive types (string, number, boolean, null)
- Complex types (object, array)
- String formats (email, url, uuid, datetime)
- Numeric constraints (min, max, integer)
- Length constraints for strings and arrays
- Enum values
- Required/optional properties
* feat(types): add Claude Agent SDK types
Add ClaudeAgentSdkMcpServer interface and ClaudeAgentSdkOptions type
to support the new toClaudeAgentSdk() method.
ClaudeAgentSdkMcpServer represents the MCP server configuration that
can be passed to the Claude Agent SDK query() function's mcpServers
option.
* feat(tool): add toClaudeAgentSdk() method to Tools class
Add toClaudeAgentSdk() method that converts all tools in a collection
to Claude Agent SDK format, automatically creating an MCP server.
This simplifies integration with Claude Agent SDK from requiring
manual Zod schema definitions and MCP server setup to a single method
call. The method:
- Converts JSON Schema parameters to Zod schemas dynamically
- Creates Claude Agent SDK tool definitions with handlers
- Wraps tools in an MCP server via createSdkMcpServer()
- Supports configurable server name and version
Also adds toClaudeAgentSdkTool() helper method on BaseTool for
converting individual tools.
* refactor(examples): use toClaudeAgentSdk() in Claude Agent SDK example
Simplify the Claude Agent SDK example by using the new toClaudeAgentSdk()
method instead of manual tool wrapping with Zod schemas.
Before: Required importing tool(), createSdkMcpServer(), z from
dependencies and manually defining Zod schemas for each tool.
After: Single method call tools.toClaudeAgentSdk() handles all
conversion and MCP server creation automatically.
Also updates account ID placeholder to use generic 'hris' prefix
for consistency with other examples.
* docs(readme): simplify Claude Agent SDK integration example
Update the README to showcase the simplified toClaudeAgentSdk() API.
The new example is much shorter and easier to follow:
- Removed manual tool wrapping with Zod schemas
- Removed createSdkMcpServer() setup code
- Single method call now handles all conversion
* refactor(utils): use Zod's native z.fromJSONSchema() for JSON Schema conversion
- Replace custom JSON Schema to Zod conversion with Zod v4.3+ native method
- Update Zod peer dependency to require >=4.3.0 for fromJSONSchema support
- Simplify json-schema-to-zod.ts from ~210 lines to ~50 lines
* chore: use jsonSchema from ai
* chore(deps): relax zod peer dependency to support v3.25.0+
Since we no longer use z.fromJSONSchema(), we can support Zod v3.25.0+
instead of requiring v4.3.0+. This matches the main branch and allows
users with older Zod versions to use this package.
* refactor(types): use McpSdkServerConfigWithInstance from Claude Agent SDK
Import the return type directly from @anthropic-ai/claude-agent-sdk
instead of maintaining our own ClaudeAgentSdkMcpServer interface.
This removes code duplication and ensures type compatibility.
* test(tool): add tests for toClaudeAgentSdk and toClaudeAgentSdkTool
- Add unit test for BaseTool.toClaudeAgentSdkTool() conversion
- Add unit tests for Tools.toClaudeAgentSdk() with default options
- Add unit test for Tools.toClaudeAgentSdk() with custom server name/version1 parent 6e61fd3 commit f02644b
File tree
8 files changed
+247
-100
lines changed- examples
- src
8 files changed
+247
-100
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
284 | | - | |
285 | | - | |
| 284 | + | |
286 | 285 | | |
287 | 286 | | |
288 | 287 | | |
289 | 288 | | |
290 | 289 | | |
291 | 290 | | |
292 | 291 | | |
| 292 | + | |
293 | 293 | | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
| 294 | + | |
313 | 295 | | |
314 | 296 | | |
315 | 297 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
6 | 9 | | |
7 | 10 | | |
8 | 11 | | |
9 | 12 | | |
10 | | - | |
11 | | - | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | | - | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
30 | | - | |
| 32 | + | |
31 | 33 | | |
| 34 | + | |
32 | 35 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
| 36 | + | |
| 37 | + | |
60 | 38 | | |
61 | 39 | | |
62 | 40 | | |
63 | 41 | | |
64 | 42 | | |
65 | | - | |
| 43 | + | |
| 44 | + | |
66 | 45 | | |
67 | 46 | | |
68 | 47 | | |
| |||
75 | 54 | | |
76 | 55 | | |
77 | 56 | | |
78 | | - | |
| 57 | + | |
79 | 58 | | |
80 | 59 | | |
81 | 60 | | |
82 | 61 | | |
83 | 62 | | |
84 | 63 | | |
85 | | - | |
| 64 | + | |
86 | 65 | | |
87 | 66 | | |
88 | 67 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
90 | 94 | | |
91 | 95 | | |
92 | 96 | | |
| |||
0 commit comments