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 | /** Run the actual MCP example client against staging without a model. */ |
| 2 | import assert from 'node:assert/strict'; |
| 3 | import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'; |
| 4 | import { CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js'; |
| 5 | import { createApprovalClient } from './mcp-client'; |
| 6 | import { approvalTools, createComposio, multiArguments } from './session'; |
| 7 | import { assertBatch, assertDenied } from './verification'; |
| 8 | |
| 9 | const composio = createComposio(); |
| 10 | for (const elicitation of [true, false]) { |
| 11 | const session = await composio.create(`approvals-mcp-ci-${crypto.randomUUID()}`, { |
| 12 | mcp: true, |
| 13 | toolkits: ['hackernews'], |
| 14 | tools: { hackernews: { enable: approvalTools, requireApproval: approvalTools } }, |
| 15 | sandbox: { enable: false }, |
| 16 | experimental: { noElicitationSupportFallback: 'deny' }, |
| 17 | }); |
| 18 | let prompts = 0; |
| 19 | const client = createApprovalClient( |
| 20 | elicitation |
| 21 | ? async () => { |
| 22 | assert.ok(++prompts <= 2, 'MCP approval did not resolve'); |
| 23 | return { action: 'accept', content: { decision: 'approve' } }; |
| 24 | } |
| 25 | : undefined |
| 26 | ); |
| 27 | try { |
| 28 | await client.connect( |
| 29 | new StreamableHTTPClientTransport(new URL(session.mcp.url), { |
| 30 | requestInit: { headers: session.mcp.headers }, |
| 31 | }) |
| 32 | ); |
| 33 | const result = CallToolResultSchema.parse( |
| 34 | await client.callTool({ name: 'COMPOSIO_MULTI_EXECUTE_TOOL', arguments: multiArguments }) |
| 35 | ); |
| 36 | assert.equal(prompts, elicitation ? 2 : 0); |
| 37 | const text = result.content |
| 38 | .filter(block => block.type === 'text') |
| 39 | .map(block => block.text) |
| 40 | .join('\n'); |
| 41 | if (!elicitation && result.isError) { |
| 42 | assertDenied(text); |
| 43 | } else { |
| 44 | assertBatch( |
| 45 | result.structuredContent ?? JSON.parse(text), |
| 46 | elicitation ? 2 : 0, |
| 47 | elicitation ? 0 : 2 |
| 48 | ); |
| 49 | } |
| 50 | console.log(`PASS MCP ${elicitation ? 'elicitation' : 'deny fallback'}`); |
| 51 | } finally { |
| 52 | try { |
| 53 | await client.close(); |
| 54 | } finally { |
| 55 | await composio.sessions.delete(session.sessionId); |
| 56 | } |
| 57 | } |
| 58 | } |