Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

test(ts/e2e): add cloudflare/cf-workers-tool-router-ai test suite

jkomyno277c29273e1d
diff --git a/.github/workflows/ts.test-e2e.yml b/.github/workflows/ts.test-e2e.yml
index c685b5336..179219be6 100644
--- a/.github/workflows/ts.test-e2e.yml
+++ b/.github/workflows/ts.test-e2e.yml
@@ -62,6 +62,7 @@ jobs:
permissions: read-all
env:
COMPOSIO_API_KEY: ${{ secrets.COMPOSIO_API_KEY }}
+ OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
steps:
- name: Checkout Code
@@ -85,6 +86,11 @@ jobs:
exit 1
fi
echo "✅ COMPOSIO_API_KEY is configured"
+ if [ -z "$OPENAI_API_KEY" ]; then
+ echo "::error::OPENAI_API_KEY is not set"
+ exit 1
+ fi
+ echo "✅ OPENAI_API_KEY is configured"
- name: Run Cloudflare Workers E2E Tests
run: pnpm run test:e2e:cloudflare
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index e8432e67f..f2bf69d31 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -298,6 +298,46 @@ importers:
specifier: 'catalog:'
version: 4.37.1(@cloudflare/[email protected])
+ ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai:
+ dependencies:
+ '@ai-sdk/mcp':
+ specifier: ^1.0.1
+ version: 1.0.5([email protected])
+ '@ai-sdk/openai':
+ specifier: ^3.0.11
+ version: 3.0.12([email protected])
+ '@composio/core':
+ specifier: workspace:*
+ version: link:../../../../packages/core
+ '@composio/vercel':
+ specifier: workspace:*
+ version: link:../../../../packages/providers/vercel
+ ai:
+ specifier: 'catalog:'
+ version: 6.0.27([email protected])
+ hono:
+ specifier: ^4.10.3
+ version: 4.11.4
+ devDependencies:
+ '@cloudflare/vitest-pool-workers':
+ specifier: 'catalog:'
+ version: 0.9.2(@cloudflare/[email protected])(@vitest/[email protected])(@vitest/[email protected])([email protected])
+ '@cloudflare/workers-types':
+ specifier: 'catalog:'
+ version: 4.20250917.0
+ dotenv:
+ specifier: ^17.2.3
+ version: 17.2.3
+ typescript:
+ specifier: 'catalog:'
+ version: 5.9.3
+ vitest:
+ specifier: 'catalog:'
+ wrangler:
+ specifier: 'catalog:'
+ version: 4.37.1(@cloudflare/[email protected])
+
ts/e2e-tests/runtimes/node/cjs-basic:
devDependencies:
'@composio/core':
@@ -570,16 +610,16 @@ importers:
version: link:../../packages/providers/llamaindex
'@llamaindex/openai':
specifier: ^0.4.20
- version: 0.4.20(@llamaindex/[email protected])(@llamaindex/[email protected])([email protected])([email protected])
+ version: 0.4.20(@llamaindex/[email protected])(@llamaindex/[email protected])([email protected])([email protected])
'@llamaindex/workflow':
specifier: ^1.1.24
dotenv:
specifier: ^16.4.1
version: 16.6.1
llamaindex:
specifier: ^0.12.0
devDependencies:
'@types/bun':
specifier: ^1.2.9
@@ -1205,7 +1245,7 @@ importers:
dependencies:
llamaindex:
specifier: ^0.12.0
devDependencies:
'@composio/core':
specifier: workspace:*
@@ -4999,6 +5039,10 @@ packages:
resolution: {integrity: sha512-uBq4egWHTcTt33a72vpSG0z3HnPuIl6NqYcTrKEg2azoEyl2hpW0zqlxysq2pK9HlDIHyHyakeYaYnSAwd8bow==}
engines: {node: '>=12'}
+ resolution: {integrity: sha512-JVUnt+DUIzu87TABbhPmNfVdBDt18BLOWjMUFJMSi/Qqg7NTYtabbvSNJGOJ7afbRuv9D/lngizHtP7QyLQ+9w==}
+ engines: {node: '>=12'}
+
resolution: {integrity: sha512-bihc7jPC90VrosXNzK0LTE2cuLP6jr0Ro8jk+kMugHReJVLIpHz/xadeq3MhuwyO4TD4OA3L1Q8pBBFRc08Tsw==}
engines: {node: '>=20.19.0'}
@@ -9435,15 +9479,6 @@ snapshots:
tree-sitter: 0.22.4
web-tree-sitter: 0.24.7
- dependencies:
- '@llamaindex/core': 0.6.22
- '@llamaindex/env': 0.1.30
- transitivePeerDependencies:
- - ws
- - zod
-
dependencies:
'@llamaindex/core': 0.6.22
@@ -9453,27 +9488,27 @@ snapshots:
- ws
- zod
optionalDependencies:
- '@modelcontextprotocol/sdk': 1.25.2(@cfworker/[email protected])([email protected])([email protected])
+ '@modelcontextprotocol/sdk': 1.25.2(@cfworker/[email protected])([email protected])([email protected])
hono: 4.11.4
rxjs: 7.8.2
- zod: 3.25.76
+ zod: 4.3.5
optionalDependencies:
'@modelcontextprotocol/sdk': 1.25.2(@cfworker/[email protected])([email protected])([email protected])
hono: 4.11.4
rxjs: 7.8.2
zod: 4.3.5
dependencies:
'@llamaindex/core': 0.6.22
'@llamaindex/env': 0.1.30
transitivePeerDependencies:
- '@modelcontextprotocol/sdk'
- hono
@@ -9482,11 +9517,11 @@ snapshots:
- rxjs
- zod
dependencies:
'@llamaindex/core': 0.6.22
'@llamaindex/env': 0.1.30
transitivePeerDependencies:
- '@modelcontextprotocol/sdk'
- hono
@@ -11473,6 +11508,14 @@ snapshots:
chai: 5.2.0
tinyrainbow: 2.0.0
+ dependencies:
+ '@vitest/spy': 3.2.4
+ estree-walker: 3.0.3
+ magic-string: 0.30.21
+ optionalDependencies:
+
dependencies:
'@vitest/spy': 3.2.4
@@ -11481,6 +11524,22 @@ snapshots:
optionalDependencies:
+ dependencies:
+ '@vitest/spy': 3.2.4
+ estree-walker: 3.0.3
+ magic-string: 0.30.21
+ optionalDependencies:
+
+ dependencies:
+ '@vitest/spy': 3.2.4
+ estree-walker: 3.0.3
+ magic-string: 0.30.21
+ optionalDependencies:
+
'@vitest/[email protected]':
dependencies:
tinyrainbow: 2.0.0
@@ -11510,7 +11569,7 @@ snapshots:
sirv: 3.0.1
tinyglobby: 0.2.15
tinyrainbow: 2.0.0
'@vitest/[email protected]':
dependencies:
@@ -12166,6 +12225,8 @@ snapshots:
+
@@ -13239,34 +13300,12 @@ snapshots:
rfdc: 1.4.1
wrap-ansi: 9.0.0
dependencies:
'@llamaindex/core': 0.6.22
'@llamaindex/env': 0.1.30
'@llamaindex/node-parser': 2.0.22(@llamaindex/[email protected])(@llamaindex/[email protected])([email protected])([email protected])
- '@types/lodash': 4.17.20
- '@types/node': 24.6.2
- lodash: 4.17.21
- magic-bytes.js: 1.12.1
- transitivePeerDependencies:
- - '@huggingface/transformers'
- - '@modelcontextprotocol/sdk'
- - gpt-tokenizer
- - hono
- - next
- - p-retry
- - rxjs
- - tree-sitter
- - web-tree-sitter
- - zod
-
- dependencies:
- '@llamaindex/core': 0.6.22
- '@llamaindex/env': 0.1.30
- '@llamaindex/node-parser': 2.0.22(@llamaindex/[email protected])(@llamaindex/[email protected])([email protected])([email protected])
'@types/lodash': 4.17.20
'@types/node': 24.6.2
lodash: 4.17.21
@@ -13639,11 +13678,6 @@ snapshots:
transitivePeerDependencies:
- encoding
- optionalDependencies:
- ws: 8.18.2
- zod: 3.25.76
-
optionalDependencies:
ws: 8.18.2
@@ -15069,7 +15103,7 @@ snapshots:
dependencies:
'@types/chai': 5.2.2
'@vitest/expect': 3.2.4
'@vitest/pretty-format': 3.2.4
'@vitest/runner': 3.2.4
'@vitest/snapshot': 3.2.4
@@ -15155,7 +15189,7 @@ snapshots:
dependencies:
'@types/chai': 5.2.2
'@vitest/expect': 3.2.4
'@vitest/pretty-format': 3.2.4
'@vitest/runner': 3.2.4
'@vitest/snapshot': 3.2.4
@@ -15198,7 +15232,7 @@ snapshots:
dependencies:
'@types/chai': 5.2.2
'@vitest/expect': 3.2.4
'@vitest/pretty-format': 3.2.4
'@vitest/runner': 3.2.4
'@vitest/snapshot': 3.2.4
diff --git a/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/.env.example b/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/.env.example
new file mode 100644
index 000000000..e8009245c
--- /dev/null
+++ b/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/.env.example
@@ -0,0 +1,2 @@
+COMPOSIO_API_KEY=ak_*
+OPENAI_API_KEY=sk-*
diff --git a/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/README.md b/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/README.md
new file mode 100644
index 000000000..b689c05d5
--- /dev/null
+++ b/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/README.md
@@ -0,0 +1,50 @@
+# Tool Router AI - Cloudflare Workers E2E Test
+
+Verifies that the Tool Router AI pattern (MCP session + Vercel AI SDK) works correctly in the Cloudflare Workers runtime environment.
+
+## Why This Exists
+
+This test validates that the full Tool Router workflow works in Cloudflare Workers:
+
+1. Creating MCP sessions via Composio
+2. Connecting to MCP servers using `@ai-sdk/mcp`
+3. Retrieving tools from the MCP client
+4. Using tools with Vercel AI SDK's `streamText`
+
+## What It Tests
+
+| Test | Description |
+| --------------------- | --------------------------------------------------------------- |
+| MCP Session Creation | Creates a toolrouter session with specified toolkits |
+| MCP Client Connection | Connects to the MCP server URL returned from session creation |
+| Tool Retrieval | Retrieves tools from the MCP client |
+| Agent Execution | Executes an AI agent using the retrieved tools |
+| Uses LLMs? | ✅ (OpenAI GPT) |
+
+## Isolation Tool
+
+- `wrangler`: Cloudflare's CLI that runs a local workerd instance
+- `@cloudflare/vitest-pool-workers`: Runs Vitest tests inside the Workers runtime, not Node.js
+
+This combination provides true runtime isolation—tests execute in the same environment as production Workers.
+
+## Setup
+
+1. Copy `.env.example` to `.env` and add your API keys:
+ - `COMPOSIO_API_KEY`: Your Composio API key
+ - `OPENAI_API_KEY`: Your OpenAI API key
+2. Install dependencies: `pnpm install`
+
+## Running
+
+```bash
+# Via pnpm (recommended)
+pnpm test:e2e
+```
+
+## Configuration
+
+| File | Purpose |
+| ------------------- | ---------------------------------------------------- |
+| `wrangler.jsonc` | Worker configuration (bindings, compatibility flags) |
+| `vitest.config.mts` | Vitest setup with Workers pool and env bindings |
diff --git a/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/package.json b/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/package.json
new file mode 100644
index 000000000..e02a310e6
--- /dev/null
+++ b/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/package.json
@@ -0,0 +1,28 @@
+{
+ "name": "@test-e2e/cf-workers-tool-router-ai",
+ "version": "0.0.0",
+ "private": true,
+ "type": "module",
+ "scripts": {
+ "test:e2e": "vitest run",
+ "test:e2e:cloudflare": "vitest run",
+ "dev": "wrangler dev",
+ "cf-typegen": "wrangler types"
+ },
+ "devDependencies": {
+ "@cloudflare/vitest-pool-workers": "catalog:",
+ "@cloudflare/workers-types": "catalog:",
+ "dotenv": "^17.2.3",
+ "typescript": "catalog:",
+ "vitest": "catalog:",
+ "wrangler": "catalog:"
+ },
+ "dependencies": {
+ "@ai-sdk/mcp": "^1.0.1",
+ "@ai-sdk/openai": "^3.0.11",
+ "@composio/core": "workspace:*",
+ "@composio/vercel": "workspace:*",
+ "ai": "catalog:",
+ "hono": "^4.10.3"
+ }
+}
diff --git a/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/src/index.ts b/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/src/index.ts
new file mode 100644
index 000000000..a23b887fd
--- /dev/null
+++ b/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/src/index.ts
@@ -0,0 +1,134 @@
+/**
+ * E2E test worker for Tool Router AI pattern with Composio.
+ * Tests MCP session creation, tool retrieval, and Vercel AI SDK integration
+ * in the Cloudflare Workers runtime environment.
+ */
+import { createOpenAI } from '@ai-sdk/openai';
+import { createMCPClient } from '@ai-sdk/mcp';
+import { Composio } from '@composio/core';
+import { VercelProvider } from '@composio/vercel';
+import { generateText, Output, stepCountIs } from 'ai';
+import { Hono } from 'hono';
+import { z } from 'zod/v4';
+
+type Bindings = {
+ COMPOSIO_API_KEY: string;
+ OPENAI_API_KEY: string;
+};
+
+const app = new Hono<{ Bindings: Bindings }>();
+
+/**
+ * Default route - lists available test endpoints
+ */
+app.get('/', c => {
+ return c.json({
+ message: 'Tool Router AI E2E Test Worker',
+ endpoints: [
+ '/test/mcp-client',
+ '/test/agent',
+ ],
+ });
+});
+
+/**
+ * Test: MCP Client Connection
+ * Tests that we can connect to the MCP server using @ai-sdk/mcp
+ */
+app.get('/test/mcp-client', async c => {
+ const composio = new Composio({
+ apiKey: c.env.COMPOSIO_API_KEY,
+ provider: new VercelProvider(),
+ });
+
+ const session = await composio.create('default', {
+ toolkits: ['hackernews'],
+ manageConnections: true,
+ tools: {
+ hackernews: {
+ enable: ['HACKERNEWS_GET_USER'],
+ },
+ },
+ });
+
+ const { mcp } = session;
+
+ const mcpClient = await createMCPClient({
+ transport: {
+ type: 'http',
+ url: mcp.url,
+ headers: mcp.headers,
+ },
+ });
+
+ c.executionCtx.waitUntil(mcpClient.close());
+
+ return c.json({
+ message: 'MCP client connected successfully',
+ mcpUrl: mcp.url,
+ });
+});
+
+/**
+ * Test: Agent Execution
+ * Tests the full workflow: create session, get tools, run agent with generateText.
+ *
+ * Note: this takes ~40s locally.
+ */
+app.get('/test/agent', async c => {
+ const composio = new Composio({
+ apiKey: c.env.COMPOSIO_API_KEY,
+ provider: new VercelProvider(),
+ });
+
+ const session = await composio.create('default', {
+ toolkits: ['hackernews'],
+ manageConnections: true,
+ tools: {
+ hackernews: {
+ enable: ['HACKERNEWS_GET_USER'],
+ },
+ },
+ });
+
+ const { mcp, sessionId } = session;
+
+ const mcpClient = await createMCPClient({
+ transport: {
+ type: 'http',
+ url: mcp.url,
+ headers: mcp.headers,
+ },
+ });
+
+ const tools = await mcpClient.tools();
+ const openai = createOpenAI({ apiKey: c.env.OPENAI_API_KEY });
+
+ const result = await generateText({
+ model: openai('gpt-5.1-codex'),
+ prompt: `Look up the HackerNews user "pg", and tell me their karma score.`,
+ output: Output.object({
+ schema: z.object({
+ karma: z.number(),
+ }),
+ }),
+ stopWhen: stepCountIs(10),
+ tools,
+ });
+
+ const toolCalls = result.steps.flatMap(step =>
+ step.toolCalls.map(tc => ({ toolName: tc.toolName }))
+ );
+
+ c.executionCtx.waitUntil(mcpClient.close());
+
+ return c.json({
+ message: 'Agent executed successfully',
+ sessionId,
+ toolCount: Object.keys(tools).length,
+ toolCalls,
+ response: result.output,
+ });
+});
+
+export default app;
diff --git a/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/test/tool-router-ai.spec.ts b/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/test/tool-router-ai.spec.ts
new file mode 100644
index 000000000..c7536407f
--- /dev/null
+++ b/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/test/tool-router-ai.spec.ts
@@ -0,0 +1,78 @@
+import { env, createExecutionContext, waitOnExecutionContext } from 'cloudflare:test';
+import { describe, it, expect } from 'vitest';
+import app from '../src/index';
+
+const IncomingRequest = Request<unknown, IncomingRequestCfProperties>;
+
+describe('Tool Router AI - Cloudflare Workers compatibility', () => {
+ it('should list the available endpoints', async () => {
+ const request = new IncomingRequest('http://localhost/');
+ const ctx = createExecutionContext();
+ const response = await app.fetch(request, env, ctx);
+ await waitOnExecutionContext(ctx);
+
+ expect(response.status).toBe(200);
+
+ const body = (await response.json()) as {
+ message: string;
+ endpoints: string[];
+ };
+
+ expect(body.message).toContain('Tool Router AI E2E Test Worker');
+ expect(body.endpoints).toMatchInlineSnapshot(`
+ [
+ "/test/mcp-client",
+ "/test/agent",
+ ]
+ `);
+ });
+
+ it('should connect to MCP server', async () => {
+ const request = new IncomingRequest('http://localhost/test/mcp-client');
+ const ctx = createExecutionContext();
+ const response = await app.fetch(request, env, ctx);
+ await waitOnExecutionContext(ctx);
+
+ const body = (await response.json()) as {
+ success: boolean;
+ message?: string;
+ error?: string;
+ mcpUrl?: string;
+ };
+
+ expect(response.status).toBe(200);
+ expect(body.message).toContain('MCP client connected');
+ expect(body.mcpUrl).toBeDefined();
+ });
+
+ it('should execute agent with Vercel AI SDK', async () => {
+ const request = new IncomingRequest('http://localhost/test/agent');
+ const ctx = createExecutionContext();
+ const response = await app.fetch(request, env, ctx);
+ await waitOnExecutionContext(ctx);
+
+ const body = (await response.json()) as {
+ success: boolean;
+ message?: string;
+ error?: string;
+ sessionId?: string;
+ toolCount?: number;
+ toolCalls?: Array<{ toolName: string }>;
+ response: {
+ karma: number;
+ };
+ };
+
+ expect(response.status).toBe(200);
+ expect(body.message).toContain('Agent executed successfully');
+ expect(body.sessionId).toBeDefined();
+ expect(body.toolCount).toBeGreaterThan(0);
+ expect(body.toolCalls).toBeDefined();
+ expect(body.response).toBeDefined();
+ expect(body.response.karma).toBeDefined();
+ expect(typeof body.response.karma).toEqual('number');
+ expect(body.response.karma).toBeGreaterThan(150_000);
+
+ expect(body.toolCalls).toContainEqual({ toolName: 'COMPOSIO_SEARCH_TOOLS' });
+ });
+});
diff --git a/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/tsconfig.json b/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/tsconfig.json
new file mode 100644
index 000000000..2dc131ca3
--- /dev/null
+++ b/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/tsconfig.json
@@ -0,0 +1,18 @@
+{
+ "compilerOptions": {
+ "target": "es2022",
+ "lib": ["es2022"],
+ "module": "es2022",
+ "moduleResolution": "Bundler",
+ "resolveJsonModule": true,
+ "allowJs": true,
+ "noEmit": true,
+ "isolatedModules": true,
+ "allowSyntheticDefaultImports": true,
+ "forceConsistentCasingInFileNames": true,
+ "strict": true,
+ "skipLibCheck": true,
+ "types": ["@cloudflare/workers-types"]
+ },
+ "include": ["src/**/*.ts", "test/**/*.ts"]
+}
diff --git a/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/vitest.config.mts b/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/vitest.config.mts
new file mode 100644
index 000000000..f118d0900
--- /dev/null
+++ b/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/vitest.config.mts
@@ -0,0 +1,21 @@
+import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config';
+import { config } from 'dotenv';
+
+config();
+
+export default defineWorkersConfig({
+ test: {
+ poolOptions: {
+ workers: {
+ wrangler: { configPath: './wrangler.jsonc' },
+ miniflare: {
+ bindings: {
+ COMPOSIO_API_KEY: process.env.COMPOSIO_API_KEY!,
+ OPENAI_API_KEY: process.env.OPENAI_API_KEY!,
+ },
+ },
+ },
+ },
+ testTimeout: 60_000,
+ },
+});
diff --git a/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/wrangler.jsonc b/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/wrangler.jsonc
new file mode 100644
index 000000000..a16bbce31
--- /dev/null
+++ b/ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/wrangler.jsonc
@@ -0,0 +1,12 @@
+{
+ "$schema": "node_modules/wrangler/config-schema.json",
+ "name": "composio-tool-router-ai-test",
+ "main": "src/index.ts",
+ "compatibility_date": "2025-01-10",
+
+ /**
+ * Note: this is needed because `ts/packages/core/src/utils/constants.ts` is wrapped in a `__exportsAll` function by
+ * the rolldown bundler, which imports `node:module` explicitly.
+ */
+ "compatibility_flags": ["nodejs_compat"]
+}