Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 06:00 UTC
| 1 | import { ClaudeAgentSDKProvider } from '@composio/claude-agent-sdk'; |
| 2 | import { createSdkMcpServer, query } from '@anthropic-ai/claude-agent-sdk'; |
| 3 | |
| 4 | const TOOL_SLUG = 'COMPOSIO_E2E_SENTINEL'; |
| 5 | const SENTINEL = 'COMPOSIO_CLAUDE_AGENT_SDK_NODE_CURRENT_OK'; |
| 6 | |
| 7 | const provider = new ClaudeAgentSDKProvider(); |
| 8 | const calls = []; |
| 9 | |
| 10 | const tools = provider.wrapTools( |
| 11 | [ |
| 12 | { |
| 13 | slug: TOOL_SLUG, |
| 14 | name: 'Composio E2E Sentinel', |
| 15 | description: |
| 16 | 'Returns the exact Composio Claude Agent SDK e2e sentinel. Use this tool when asked for the sentinel.', |
| 17 | version: 'e2e', |
| 18 | availableVersions: ['e2e'], |
| 19 | inputParameters: { |
| 20 | type: 'object', |
| 21 | properties: { |
| 22 | label: { |
| 23 | type: 'string', |
| 24 | enum: ['node-current'], |
| 25 | description: 'The e2e runtime label.', |
| 26 | }, |
| 27 | shout: { |
| 28 | type: 'boolean', |
| 29 | description: 'Whether to return the uppercase sentinel.', |
| 30 | default: true, |
| 31 | }, |
| 32 | }, |
| 33 | required: ['label'], |
| 34 | additionalProperties: false, |
| 35 | }, |
| 36 | tags: ['e2e'], |
| 37 | }, |
| 38 | ], |
| 39 | async (toolSlug, input) => { |
| 40 | calls.push({ toolSlug, input }); |
| 41 | |
| 42 | if (toolSlug !== TOOL_SLUG) { |
| 43 | throw new Error(`Unexpected tool slug: ${toolSlug}`); |
| 44 | } |
| 45 | if (input.label !== 'node-current') { |
| 46 | throw new Error(`Unexpected label: ${JSON.stringify(input.label)}`); |
| 47 | } |
| 48 | |
| 49 | return input.shout === false ? SENTINEL.toLowerCase() : SENTINEL; |
| 50 | } |
| 51 | ); |
| 52 | |
| 53 | if (tools.length !== 1) { |
| 54 | throw new Error(`Expected exactly one wrapped tool, got ${tools.length}`); |
| 55 | } |
| 56 | |
| 57 | const mcpServer = createSdkMcpServer({ |
| 58 | name: 'composio', |
| 59 | version: '1.0.0', |
| 60 | tools, |
| 61 | }); |
| 62 | |
| 63 | let queryResult = ''; |
| 64 | |
| 65 | for await (const message of query({ |
| 66 | prompt: [ |
| 67 | `Use the ${TOOL_SLUG} tool with label "node-current" and shout true.`, |
| 68 | `Reply with exactly the tool result: ${SENTINEL}`, |
| 69 | 'Do not use any built-in tools.', |
| 70 | ].join('\n'), |
| 71 | options: { |
| 72 | mcpServers: { composio: mcpServer }, |
| 73 | tools: [], |
| 74 | allowedTools: [`mcp__composio__${TOOL_SLUG}`], |
| 75 | permissionMode: 'bypassPermissions', |
| 76 | allowDangerouslySkipPermissions: true, |
| 77 | maxTurns: 4, |
| 78 | maxBudgetUsd: 0.25, |
| 79 | persistSession: false, |
| 80 | settingSources: [], |
| 81 | }, |
| 82 | })) { |
| 83 | if (message.type === 'result') { |
| 84 | if (message.subtype !== 'success') { |
| 85 | throw new Error(`Claude query failed: ${JSON.stringify(message.errors ?? message)}`); |
| 86 | } |
| 87 | queryResult = message.result; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | const sdkCalls = calls.filter(call => call.toolSlug === TOOL_SLUG); |
| 92 | |
| 93 | if (sdkCalls.length < 1) { |
| 94 | throw new Error(`Expected Claude Agent SDK to call ${TOOL_SLUG}, got ${sdkCalls.length} calls`); |
| 95 | } |
| 96 | |
| 97 | if (!queryResult.includes(SENTINEL)) { |
| 98 | throw new Error(`Expected query result to include ${SENTINEL}, got ${JSON.stringify(queryResult)}`); |
| 99 | } |
| 100 | |
| 101 | console.log('claude query executed wrapped tool'); |