Skip to content

Commit dff5a29

Browse files
committed
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/version
1 parent 098ff0a commit dff5a29

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

src/tool.test.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,25 @@ describe('StackOneTool', () => {
171171
expect(schema.properties?.id.type).toBe('string');
172172
});
173173

174+
it('should convert to Claude Agent SDK tool format', async () => {
175+
const tool = createMockTool();
176+
177+
const claudeTool = await tool.toClaudeAgentSdkTool();
178+
179+
expect(claudeTool).toBeDefined();
180+
expect(claudeTool.name).toBe('test_tool');
181+
expect(claudeTool.description).toBe('Test tool');
182+
expect(claudeTool.inputSchema).toBeDefined();
183+
expect(typeof claudeTool.handler).toBe('function');
184+
185+
// Test the handler returns content in the expected format
186+
const result = await claudeTool.handler({ id: 'test-123' });
187+
expect(result).toHaveProperty('content');
188+
expect(Array.isArray(result.content)).toBe(true);
189+
expect(result.content[0]).toHaveProperty('type', 'text');
190+
expect(result.content[0]).toHaveProperty('text');
191+
});
192+
174193
it('should include execution metadata by default in AI SDK conversion', async () => {
175194
const tool = createMockTool();
176195

@@ -693,6 +712,58 @@ describe('Tools', () => {
693712
expect(typeof aiSdkTools.another_tool.execute).toBe('function');
694713
});
695714

715+
it('should convert all tools to Claude Agent SDK MCP server', async () => {
716+
const tool1 = createMockTool();
717+
const tool2 = new StackOneTool(
718+
'another_tool',
719+
'Another tool',
720+
{
721+
type: 'object',
722+
properties: { name: { type: 'string' } },
723+
},
724+
{
725+
kind: 'http',
726+
method: 'POST',
727+
url: 'https://api.example.com/test',
728+
bodyType: 'json',
729+
params: [
730+
{
731+
name: 'name',
732+
location: ParameterLocation.BODY,
733+
type: 'string',
734+
},
735+
],
736+
},
737+
{
738+
authorization: 'Bearer test_key',
739+
},
740+
);
741+
742+
const tools = new Tools([tool1, tool2]);
743+
744+
const mcpServer = await tools.toClaudeAgentSdk();
745+
746+
expect(mcpServer).toBeDefined();
747+
expect(mcpServer.type).toBe('sdk');
748+
expect(mcpServer.name).toBe('stackone-tools');
749+
expect(mcpServer.instance).toBeDefined();
750+
});
751+
752+
it('should convert all tools to Claude Agent SDK MCP server with custom options', async () => {
753+
const tool1 = createMockTool();
754+
const tools = new Tools([tool1]);
755+
756+
const mcpServer = await tools.toClaudeAgentSdk({
757+
serverName: 'my-custom-server',
758+
serverVersion: '2.0.0',
759+
});
760+
761+
expect(mcpServer).toBeDefined();
762+
expect(mcpServer.type).toBe('sdk');
763+
expect(mcpServer.name).toBe('my-custom-server');
764+
expect(mcpServer.instance).toBeDefined();
765+
});
766+
696767
it('should be iterable', () => {
697768
const tool1 = createMockTool();
698769
const tool2 = new StackOneTool(

0 commit comments

Comments
 (0)