Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | /** |
| 2 | * The schema the provider shows the model through the Claude Agent SDK, and |
| 3 | * the validation the SDK runs on tool-call arguments, both driven through the |
| 4 | * real SDK over an in-memory MCP transport. |
| 5 | */ |
| 6 | import { describe, expect, it, vi } from 'vitest'; |
| 7 | import { Client } from '@modelcontextprotocol/sdk/client/index.js'; |
| 8 | import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js'; |
| 9 | import { createSdkMcpServer } from '@anthropic-ai/claude-agent-sdk'; |
| 10 | import type { Tool, GlobalExecuteToolFn } from '@composio/core'; |
| 11 | import { ClaudeAgentSDKProvider } from '../src'; |
| 12 | import { |
| 13 | acceptedFor, |
| 14 | loadObjectCases, |
| 15 | } from '../../../core/test/fixtures/json-schema-conversion/corpus'; |
| 16 | |
| 17 | type Json = Record<string, unknown>; |
| 18 | |
| 19 | const buildTool = (inputParameters: Json): Tool => |
| 20 | ({ |
| 21 | slug: 'TEST_TOOL', |
| 22 | name: 'Test Tool', |
| 23 | description: 'A tool under test', |
| 24 | version: '20260901_00', |
| 25 | availableVersions: ['20260901_00'], |
| 26 | tags: [], |
| 27 | inputParameters, |
| 28 | }) as unknown as Tool; |
| 29 | |
| 30 | const register = async (composioTool: Tool) => { |
| 31 | const executeToolFn = vi.fn().mockResolvedValue({ |
| 32 | data: {}, |
| 33 | error: null, |
| 34 | successful: true, |
| 35 | }) as unknown as GlobalExecuteToolFn; |
| 36 | const provider = new ClaudeAgentSDKProvider(); |
| 37 | const server = createSdkMcpServer({ |
| 38 | name: 'composio-test', |
| 39 | version: '1.0.0', |
| 40 | tools: [provider.wrapTool(composioTool, executeToolFn)], |
| 41 | }); |
| 42 | const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); |
| 43 | const client = new Client({ name: 'test-client', version: '1.0.0' }); |
| 44 | await server.instance.server.connect(serverTransport); |
| 45 | await client.connect(clientTransport); |
| 46 | const { tools } = await client.listTools(); |
| 47 | return { |
| 48 | client, |
| 49 | inputSchema: tools[0].inputSchema as Json, |
| 50 | accepts: async (args: unknown) => { |
| 51 | const result = (await client.callTool({ |
| 52 | name: composioTool.slug, |
| 53 | arguments: args as Record<string, unknown>, |
| 54 | })) as { isError?: boolean }; |
| 55 | return !(result.isError ?? false); |
| 56 | }, |
| 57 | }; |
| 58 | }; |
| 59 | |
| 60 | describe('ClaudeAgentSDKProvider schema sent to the model', () => { |
| 61 | it('sends the source keywords a v3 Zod schema could not carry', async () => { |
| 62 | const { client, inputSchema } = await register( |
| 63 | buildTool({ |
| 64 | type: 'object', |
| 65 | properties: { |
| 66 | file: { type: 'string', format: 'binary' }, |
| 67 | hex: { |
| 68 | type: 'string', |
| 69 | contentEncoding: 'base16', |
| 70 | contentMediaType: 'application/octet-stream', |
| 71 | }, |
| 72 | count: { type: 'integer', minimum: 0 }, |
| 73 | }, |
| 74 | required: ['file'], |
| 75 | }) |
| 76 | ); |
| 77 | await client.close(); |
| 78 | const properties = inputSchema.properties as Record<string, Json>; |
| 79 | |
| 80 | expect(properties.file).toEqual({ type: 'string', format: 'binary' }); |
| 81 | expect(properties.hex).toEqual({ |
| 82 | type: 'string', |
| 83 | contentEncoding: 'base16', |
| 84 | contentMediaType: 'application/octet-stream', |
| 85 | }); |
| 86 | expect(properties.count).toMatchObject({ type: 'integer', minimum: 0 }); |
| 87 | }); |
| 88 | |
| 89 | it('keeps a defaulted field optional and shows its default', async () => { |
| 90 | const { client, inputSchema, accepts } = await register( |
| 91 | buildTool({ |
| 92 | type: 'object', |
| 93 | properties: { |
| 94 | query: { type: 'string' }, |
| 95 | page: { type: 'integer', default: 1 }, |
| 96 | }, |
| 97 | required: ['query'], |
| 98 | }) |
| 99 | ); |
| 100 | const acceptsWithoutPage = await accepts({ query: 'q' }); |
| 101 | await client.close(); |
| 102 | |
| 103 | expect(inputSchema.required).toEqual(['query']); |
| 104 | expect((inputSchema.properties as Record<string, Json>).page).toMatchObject({ |
| 105 | type: 'integer', |
| 106 | default: 1, |
| 107 | }); |
| 108 | expect(acceptsWithoutPage).toBe(true); |
| 109 | }); |
| 110 | }); |
| 111 | |
| 112 | describe('ClaudeAgentSDKProvider tool-call validation', () => { |
| 113 | for (const testCase of loadObjectCases()) { |
| 114 | it(`matches the shared corpus on ${testCase.id}`, async () => { |
| 115 | const { client, accepts } = await register(buildTool(testCase.schema)); |
| 116 | |
| 117 | for (const instance of testCase.instances) { |
| 118 | expect(await accepts(instance.input), JSON.stringify(instance.input)).toBe( |
| 119 | acceptedFor(instance, 'zod') |
| 120 | ); |
| 121 | } |
| 122 | await client.close(); |
| 123 | }); |
| 124 | } |
| 125 | }); |