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, 18:15 UTC
fix quickstart snippets
Sushmithamallesh committed
Dec 8, 2025 at 18:29 UTC
209f382b0af12b05398fdf15d20cf97178281548
3 files changed
+85
-85
fern/pages/src/tool-router/quickstart.mdx
+10
-85
@@ -22,57 +22,25 @@ npm install @composio/core @openai/agents
22
[Sessions](/tool-router/users-and-sessions) are ephemeral, user-scoped and manage connections and tools for that user.
23
24
<Info>
25
-Replace `your-composio-api-key` with your Composio API key from the [settings](https://platform.composio.dev/?next_page=/settings) page.
25
+- Set your `COMPOSIO_API_KEY` environment variable with your API key from [Settings](https://platform.composio.dev/?next_page=/settings).
26
+- Set your `OPENAI_API_KEY` environment variable with your [OpenAI API key](https://platform.openai.com/api-keys).
27
+- `userId` is your user's unique identifier. See [User Management](/docs/user-management) for details.
28
</Info>
29
30
When the agent needs authentication, it will prompt the user with a link to connect their account. If you want to customise the authentication flow and have more control over the user experience, see [Manual Authentication](/tool-router/manually-authenticating-users).
31
30
-```typescript
31
-import { Composio } from "@composio/core";
32
-import { Agent, run, hostedMcpTool } from "@openai/agents";
33
-
34
-const composio = new Composio({ apiKey: "your-composio-api-key" });
35
-
36
-console.log("Creating Tool Router session...");
37
-const { mcp } = await composio.create("pg-user-550e8400-e29b-41d4");
38
-console.log(`Tool Router session created: ${mcp.url}`);
39
-
40
-const agent = new Agent({
41
- name: "Personal Assistant",
42
- instructions: "You are a helpful personal assistant.",
43
- tools: [
44
- hostedMcpTool({
45
- serverLabel: "composio",
46
- serverUrl: mcp.url,
47
- headers: {
48
- "x-api-key": "your-composio-api-key",
49
- },
50
- }),
51
- ],
52
-});
53
-
54
-console.log("Running the Open AI agent to fetch gmail inbox")
55
-const result = await run(
56
- agent,
57
- "Summarize all the emails in my Gmail inbox today"
58
-);
59
-console.log(result.finalOutput);
60
-```
61
-
62
-<Info>
63
-`pg-user-550e8400-e29b-41d4` is a placeholder for your user's ID. See [User Management](/docs/user-management) for details.
64
-</Info>
32
+<SnippetCode src="fern/snippets/tool-router/typescript/quickstart-openai.ts" />
33
</Step>
34
</Steps>
35
36
</Tab>
37
70
-<Tab title="Vercel AI SDK">
38
+<Tab title="Vercel AI SDK (Anthropic)">
39
40
<Steps>
41
<Step title="Install Composio SDK">
42
```bash
75
-npm install @composio/core ai @ai-sdk/openai @ai-sdk/mcp
43
+npm install @composio/core ai @ai-sdk/anthropic @ai-sdk/mcp
44
```
45
</Step>
46
@@ -80,57 +48,14 @@ npm install @composio/core ai @ai-sdk/openai @ai-sdk/mcp
48
[Sessions](/tool-router/users-and-sessions) are ephemeral, user-scoped and manage connections and tools for that user.
49
50
<Info>
83
-Replace `your-composio-api-key` with your Composio API key from the [settings](https://platform.composio.dev/?next_page=/settings) page.
51
+- Set your `COMPOSIO_API_KEY` environment variable with your API key from [Settings](https://platform.composio.dev/?next_page=/settings).
52
+- Set your `ANTHROPIC_API_KEY` environment variable with your [Anthropic API key](https://platform.claude.com/settings/keys).
53
+- `userId` is your user's unique identifier. See [User Management](/docs/user-management) for details.
54
</Info>
55
56
When the agent needs authentication, it will prompt the user with a link to connect their account. If you want to customise the authentication flow and have more control over the user experience, see [Manual Authentication](/tool-router/manually-authenticating-users).
57
88
-```typescript
89
-import { openai } from "@ai-sdk/openai";
90
-import { experimental_createMCPClient as createMCPClient } from "@ai-sdk/mcp";
91
-import { Composio } from "@composio/core";
92
-import { stepCountIs, streamText } from "ai";
93
-
94
-const composio = new Composio({ apiKey: "your-composio-api-key" });
95
-
96
-console.log("Creating Tool Router session...");
97
-const { mcp } = await composio.create("pg-user-550e8400-e29b-41d4");
98
-console.log(`Tool Router session created: ${mcp.url}`);
99
-
100
-const client = await createMCPClient({
101
- transport: {
102
- type: "http",
103
- url: mcp.url,
104
- headers: {
105
- "x-api-key": "your-composio-api-key",
106
- },
107
- },
108
-});
109
-
110
-const tools = await client.tools();
111
-
112
-const stream = await streamText({
113
- model: openai("gpt-5"),
114
- prompt: "Summarize all the emails in my Gmail inbox today",
115
- stopWhen: stepCountIs(10),
116
- onStepFinish: (step) => {
117
- if (step.toolCalls.length > 0) {
118
- for (const toolCall of step.toolCalls) {
119
- console.log(`Executed ${toolCall.toolName}`);
120
- }
121
- }
122
- },
123
- tools,
124
-});
125
-
126
-for await (const textPart of stream.textStream) {
127
- process.stdout.write(textPart);
128
-}
129
-```
130
-
131
-<Info>
132
-`pg-user-550e8400-e29b-41d4` is a placeholder for your user's ID. See [User Management](/docs/user-management) for details.
133
-</Info>
58
+<SnippetCode src="fern/snippets/tool-router/typescript/quickstart-vercel.ts" />
59
</Step>
60
</Steps>
61
fern/snippets/tool-router/typescript/quickstart-openai.ts
new
+34
@@ -0,0 +1,34 @@
1
+import { Composio } from "@composio/core";
2
+import { Agent, run, hostedMcpTool } from "@openai/agents";
3
+const composioApiKey = process.env.COMPOSIO_API_KEY;
4
+const userId = "550e8400-e29b-41d4-a716-446655440000"; // Your user's unique identifier
5
+
6
+const composio = new Composio({ apiKey: composioApiKey });
7
+
8
+const { mcp } = await composio.create(userId);
9
+console.log(`Tool Router session created: ${mcp.url}`);
10
+
11
+const agent = new Agent({
12
+ name: "Personal Assistant",
13
+ instructions: "You are a helpful personal assistant.",
14
+ model: 'gpt-5.1',
15
+ modelSettings: {
16
+ reasoning: { effort: 'low' },
17
+ },
18
+ tools: [
19
+ hostedMcpTool({
20
+ serverLabel: "composio",
21
+ serverUrl: mcp.url,
22
+ headers: {
23
+ 'x-api-key': composioApiKey,
24
+ },
25
+ }),
26
+ ],
27
+});
28
+
29
+console.log("Running the Open AI agent to fetch gmail inbox")
30
+const result = await run(
31
+ agent,
32
+ "Summarize all the emails in my Gmail inbox today"
33
+);
34
+console.log(result.finalOutput);
fern/snippets/tool-router/typescript/quickstart-vercel.ts
new
+41
@@ -0,0 +1,41 @@
1
+import { anthropic } from "@ai-sdk/anthropic";
2
+import { experimental_createMCPClient as createMCPClient } from "@ai-sdk/mcp";
3
+import { Composio } from "@composio/core";
4
+import { stepCountIs, streamText } from "ai";
5
+const composioApiKey = process.env.COMPOSIO_API_KEY;
6
+const userId = "550e8400-e29b-41d4-a716-446655440000"; // Your user's unique identifier
7
+
8
+const composio = new Composio({ apiKey: composioApiKey });
9
+
10
+const { mcp } = await composio.create(userId);
11
+console.log(`Tool Router session created: ${mcp.url}`);
12
+
13
+const client = await createMCPClient({
14
+ transport: {
15
+ type: "http",
16
+ url: mcp.url,
17
+ headers: {
18
+ "x-api-key": composioApiKey,
19
+ },
20
+ },
21
+});
22
+
23
+const tools = await client.tools();
24
+
25
+const stream = await streamText({
26
+ model: anthropic("claude-sonnet-4-5"),
27
+ prompt: "Summarize all the emails in my Gmail inbox today",
28
+ stopWhen: stepCountIs(10),
29
+ onStepFinish: (step) => {
30
+ if (step.toolCalls.length > 0) {
31
+ for (const toolCall of step.toolCalls) {
32
+ console.log(`Executed ${toolCall.toolName}`);
33
+ }
34
+ }
35
+ },
36
+ tools,
37
+});
38
+
39
+for await (const textPart of stream.textStream) {
40
+ process.stdout.write(textPart);
41
+}