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, 04:45 UTC
| 1 | import * as readline from 'node:readline/promises'; |
| 2 | import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'; |
| 3 | import { askForApproval } from './approval'; |
| 4 | import { createApprovalClient } from './mcp-client'; |
| 5 | import { approvalTools, createComposio, multiArguments } from './session'; |
| 6 | |
| 7 | const composio = createComposio(); |
| 8 | const session = await composio.create(`approvals-mcp-${crypto.randomUUID()}`, { |
| 9 | mcp: true, |
| 10 | toolkits: ['hackernews'], |
| 11 | tools: { hackernews: { enable: approvalTools, requireApproval: approvalTools } }, |
| 12 | sandbox: { enable: false }, |
| 13 | experimental: { noElicitationSupportFallback: 'deny' }, |
| 14 | }); |
| 15 | const terminal = readline.createInterface({ input: process.stdin, output: process.stdout }); |
| 16 | // Omit the handler and capability to demonstrate the deny fallback. |
| 17 | const client = createApprovalClient( |
| 18 | process.argv.includes('--no-elicitation') |
| 19 | ? undefined |
| 20 | : question => askForApproval(question, prompt => terminal.question(prompt)) |
| 21 | ); |
| 22 | try { |
| 23 | await client.connect( |
| 24 | new StreamableHTTPClientTransport(new URL(session.mcp.url), { |
| 25 | requestInit: { headers: session.mcp.headers }, |
| 26 | }) |
| 27 | ); |
| 28 | const result = await client.callTool({ |
| 29 | name: 'COMPOSIO_MULTI_EXECUTE_TOOL', |
| 30 | arguments: multiArguments, |
| 31 | }); |
| 32 | console.log(JSON.stringify(result, null, 2)); |
| 33 | } finally { |
| 34 | terminal.close(); |
| 35 | try { |
| 36 | await client.close(); |
| 37 | } finally { |
| 38 | await composio.sessions.delete(session.sessionId); |
| 39 | } |
| 40 | } |