@devries-cameron20 / composio Mirror · read-only / commits / 07e3cf5a0
Fork 0

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 22, 13:15 UTC

test(ts/e2e): fix potential mcp connection leak

jkomyno committed Jan 24, 2026 at 22:47 UTC 07e3cf5a0f6a8c158b1edfbeb10a7d473b6be841
1 file changed +29 -27
ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/src/index.ts
+29 -27
@@ -101,34 +101,36 @@ app.get('/test/agent', async c => {
101 },
102 });
103
104 - const tools = await mcpClient.tools();
105 - const openai = createOpenAI({ apiKey: c.env.OPENAI_API_KEY });
106 -
107 - const result = await generateText({
108 - model: openai('gpt-5.1-codex'),
109 - prompt: `Look up the HackerNews user "pg", and tell me their karma score.`,
110 - output: Output.object({
111 - schema: z.object({
112 - karma: z.number(),
104 + try {
105 + const tools = await mcpClient.tools();
106 + const openai = createOpenAI({ apiKey: c.env.OPENAI_API_KEY });
107 +
108 + const result = await generateText({
109 + model: openai('gpt-5.1-codex'),
110 + prompt: `Look up the HackerNews user "pg", and tell me their karma score.`,
111 + output: Output.object({
112 + schema: z.object({
113 + karma: z.number(),
114 + }),
115 }),
114 - }),
115 - stopWhen: stepCountIs(10),
116 - tools,
117 - });
118 -
119 - const toolCalls = result.steps.flatMap(step =>
120 - step.toolCalls.map(tc => ({ toolName: tc.toolName }))
121 - );
122 -
123 - c.executionCtx.waitUntil(mcpClient.close());
124 -
125 - return c.json({
126 - message: 'Agent executed successfully',
127 - sessionId,
128 - toolCount: Object.keys(tools).length,
129 - toolCalls,
130 - response: result.output,
131 - });
116 + stopWhen: stepCountIs(10),
117 + tools,
118 + });
119 +
120 + const toolCalls = result.steps.flatMap(step =>
121 + step.toolCalls.map(tc => ({ toolName: tc.toolName }))
122 + );
123 +
124 + return c.json({
125 + message: 'Agent executed successfully',
126 + sessionId,
127 + toolCount: Object.keys(tools).length,
128 + toolCalls,
129 + response: result.output,
130 + });
131 + } finally {
132 + c.executionCtx.waitUntil(mcpClient.close());
133 + }
134 });
135
136 export default app;