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.

session fixes

Sushmithamalleshaf242d96f946
diff --git a/fern/pages/src/tool-router/manually-authenticating-users.mdx b/fern/pages/src/tool-router/manually-authenticating-users.mdx
index 1184ad53e..d95020070 100644
--- a/fern/pages/src/tool-router/manually-authenticating-users.mdx
+++ b/fern/pages/src/tool-router/manually-authenticating-users.mdx
@@ -15,14 +15,13 @@ Disable the `COMPOSIO_MANAGE_CONNECTIONS` meta-tool so the agent doesn't prompt
<CodeGroup>
```python
-session = await composio.create_session(
+session = await composio.create(
user="pg-user-550e8400-e29b-41d4",
manage_connections=False,
)
```
```typescript
-const session = await composio.createSession({
- user: "pg-user-550e8400-e29b-41d4",
+const session = await composio.create("pg-user-550e8400-e29b-41d4", {
manageConnections: false,
});
```
@@ -134,7 +133,7 @@ A common pattern is to verify all required connections before starting the agent
```python
required_toolkits = ["gmail", "googlecalendar", "linear", "slack"]
-session = await composio.create_session(
+session = await composio.create(
user=user_id,
manage_connections=False,
)
@@ -163,8 +162,7 @@ tools = await session.tools()
```typescript
const requiredToolkits = ["gmail", "googlecalendar", "linear", "slack"];
-const session = await composio.createSession({
- user: userId,
+const session = await composio.create(userId, {
manageConnections: false,
});
@@ -198,7 +196,7 @@ To use a specific account, pass it in the session config:
<CodeGroup>
```python
-session = await composio.create_session(
+session = await composio.create(
user=user_id,
connected_accounts={
"gmail": "ca_specific_account_id",
@@ -206,8 +204,7 @@ session = await composio.create_session(
)
```
```typescript
-const session = await composio.createSession({
- user: userId,
+const session = await composio.create(userId, {
connectedAccounts: {
gmail: "ca_specific_account_id",
},
diff --git a/fern/pages/src/tool-router/using-in-chat-authentication.mdx b/fern/pages/src/tool-router/using-in-chat-authentication.mdx
index 5dd42e91a..69c4f172b 100644
--- a/fern/pages/src/tool-router/using-in-chat-authentication.mdx
+++ b/fern/pages/src/tool-router/using-in-chat-authentication.mdx
@@ -19,14 +19,12 @@ In-chat auth is enabled by default. The `COMPOSIO_MANAGE_CONNECTIONS` meta-tool
<CodeGroup>
```python
-session = await composio.create_session(
+session = await composio.create(
user="pg-user-550e8400-e29b-41d4",
)
```
```typescript
-const session = await composio.createSession({
- user: "pg-user-550e8400-e29b-41d4",
-});
+const { mcp } = await composio.create("pg-user-550e8400-e29b-41d4");
```
</CodeGroup>
@@ -36,7 +34,7 @@ Redirect users to a specific page after authentication:
<CodeGroup>
```python
-session = await composio.create_session(
+session = await composio.create(
user="pg-user-550e8400-e29b-41d4",
manage_connections={
"callback_url": "https://yourapp.com/chat"
@@ -44,8 +42,7 @@ session = await composio.create_session(
)
```
```typescript
-const session = await composio.createSession({
- user: "pg-user-550e8400-e29b-41d4",
+const { mcp } = await composio.create("pg-user-550e8400-e29b-41d4", {
manageConnections: {
callbackUrl: "https://yourapp.com/chat",
},
@@ -59,14 +56,13 @@ To manage authentication outside of chat, disable the `COMPOSIO_MANAGE_CONNECTIO
<CodeGroup>
```python
-session = await composio.create_session(
+session = await composio.create(
user="pg-user-550e8400-e29b-41d4",
manage_connections=False,
)
```
```typescript
-const session = await composio.createSession({
- user: "pg-user-550e8400-e29b-41d4",
+const { mcp } = await composio.create("pg-user-550e8400-e29b-41d4", {
manageConnections: false,
});
```
diff --git a/fern/pages/src/tool-router/white-labeling-authentication.mdx b/fern/pages/src/tool-router/white-labeling-authentication.mdx
index 628c32f64..0576848c4 100644
--- a/fern/pages/src/tool-router/white-labeling-authentication.mdx
+++ b/fern/pages/src/tool-router/white-labeling-authentication.mdx
@@ -48,7 +48,7 @@ Pass your auth config ID in the session:
<CodeGroup>
```python
-session = await composio.create_session(
+session = await composio.create(
user="pg-user-550e8400-e29b-41d4",
auth_configs={
"github": "ac_your_github_config"
@@ -56,8 +56,7 @@ session = await composio.create_session(
)
```
```typescript
-const session = await composio.createSession({
- user: "pg-user-550e8400-e29b-41d4",
+const session = await composio.create("pg-user-550e8400-e29b-41d4", {
authConfigs: {
github: "ac_your_github_config",
},
@@ -75,7 +74,7 @@ You can white-label some toolkits while using Composio's default credentials for
<CodeGroup>
```python
-session = await composio.create_session(
+session = await composio.create(
user="pg-user-550e8400-e29b-41d4",
auth_configs={
"github": "ac_your_github_config",
@@ -85,8 +84,7 @@ session = await composio.create_session(
)
```
```typescript
-const session = await composio.createSession({
- user: "pg-user-550e8400-e29b-41d4",
+const session = await composio.create("pg-user-550e8400-e29b-41d4", {
authConfigs: {
github: "ac_your_github_config",
slack: "ac_your_slack_config",
diff --git a/fern/snippets/tool-router/python/anthropic-mcp.py b/fern/snippets/tool-router/python/anthropic-mcp.py
new file mode 100644
index 000000000..7c790d554
--- /dev/null
+++ b/fern/snippets/tool-router/python/anthropic-mcp.py
@@ -0,0 +1,18 @@
+from composio import Composio
+from anthropic_agents import Agent, run
+
+composio = Composio(api_key="your-api-key")
+
+session = composio.create(user_id="pg-user-550e8400-e29b-41d4")
+
+agent = Agent(
+ name="Personal Assistant",
+ instructions="You are a helpful personal assistant.",
+ mcp_servers=[session.mcp.url]
+)
+
+result = run(
+ agent,
+ "Summarize all the emails in my Gmail inbox today"
+)
+print(result.final_output)
diff --git a/fern/snippets/tool-router/python/in-chat-auth.py b/fern/snippets/tool-router/python/in-chat-auth.py
index 33fe07447..7ba361500 100644
--- a/fern/snippets/tool-router/python/in-chat-auth.py
+++ b/fern/snippets/tool-router/python/in-chat-auth.py
@@ -2,12 +2,12 @@ import asyncio
from composio import Composio
from agents import Agent, Runner, HostedMCPTool
-composio = Composio()
+composio = Composio(api_key="your-composio-api-key")
async def chat():
- session = await composio.create_session(
- user="pg-user-550e8400-e29b-41d4",
- )
+ print("Creating Tool Router session...")
+ session = await composio.create("pg-user-550e8400-e29b-41d4")
+ print(f"Tool Router session created: {session.mcp.url}")
agent = Agent(
name="GitHub Assistant",
@@ -19,6 +19,9 @@ async def chat():
"server_label": "composio",
"server_url": session.mcp.url,
"require_approval": "never",
+ "headers": {
+ "x-api-key": "your-composio-api-key",
+ },
}
)
],
diff --git a/fern/snippets/tool-router/python/manual-auth.py b/fern/snippets/tool-router/python/manual-auth.py
index 16653be18..363f84d8c 100644
--- a/fern/snippets/tool-router/python/manual-auth.py
+++ b/fern/snippets/tool-router/python/manual-auth.py
@@ -1,13 +1,13 @@
import asyncio
from composio import Composio
-composio = Composio()
+composio = Composio(api_key="your-composio-api-key")
user_id = "pg-user-550e8400-e29b-41d4"
required_toolkits = ["gmail", "googlecalendar", "linear", "slack"]
async def main():
- session = await composio.create_session(
+ session = await composio.create(
user=user_id,
manage_connections=False,
)
diff --git a/fern/snippets/tool-router/python/openai-agents.py b/fern/snippets/tool-router/python/openai-agents.py
new file mode 100644
index 000000000..a98b14e00
--- /dev/null
+++ b/fern/snippets/tool-router/python/openai-agents.py
@@ -0,0 +1,22 @@
+from composio import Composio
+from composio_openai_agents import OpenAIAgentsProvider
+from agents import Agent, Runner
+
+composio = Composio(
+ api_key="your-api-key",
+ provider=OpenAIAgentsProvider()
+)
+
+session = composio.create(user_id="pg-user-550e8400-e29b-41d4")
+
+agent = Agent(
+ name="Personal Assistant",
+ instructions="You are a helpful personal assistant.",
+ tools=session.tools()
+)
+
+result = Runner.run_sync(
+ agent,
+ "Summarize all the emails in my Gmail inbox today"
+)
+print(result.final_output)
diff --git a/fern/snippets/tool-router/python/quickstart.py b/fern/snippets/tool-router/python/quickstart.py
index e19621942..6fef875f7 100644
--- a/fern/snippets/tool-router/python/quickstart.py
+++ b/fern/snippets/tool-router/python/quickstart.py
@@ -1,42 +1,33 @@
-import asyncio
-import os
from composio import Composio
-from composio_openai_agents import OpenAIAgentsProvider
from agents import Agent, Runner, HostedMCPTool
-async def main() -> None:
- # Initialize Composio and create Tool Router session
- composio = Composio(
- api_key=os.getenv("COMPOSIO_API_KEY"), # Uses env var by default
- provider=OpenAIAgentsProvider()
- )
- session = composio.experimental.tool_router.create_session(
- user_id="[email protected]",
- toolkits=["gmail", "github"] # Optional: Limit available toolkits
- )
-
- # Set up OpenAI agent with Tool Router MCP endpoint
- agent = Agent(
- name="Assistant",
- instructions="You are a helpful assistant that can access Gmail and GitHub. "
- "Help users fetch emails, create issues, manage pull requests, and more.",
- tools=[
- HostedMCPTool(
- tool_config={
- "type": "mcp",
- "server_label": "tool_router",
- "server_url": session['url'],
- "require_approval": "never",
- }
- )
- ],
- )
+composio = Composio(api_key="your-composio-api-key")
- # Execute the agent
- result = await Runner.run(
- agent,
- "Fetch the contributors to composiohq/composio github repository and email the list to [email protected]"
- )
- print(result.final_output)
+print("Creating Tool Router session...")
+session = composio.create("pg-user-550e8400-e29b-41d4")
+print(f"Tool Router session created: {session.mcp.url}")
-asyncio.run(main())
\ No newline at end of file
+agent = Agent(
+ name="Personal Assistant",
+ instructions="You are a helpful personal assistant.",
+ tools=[
+ HostedMCPTool(
+ tool_config={
+ "type": "mcp",
+ "server_label": "composio",
+ "server_url": session.mcp.url,
+ "require_approval": "never",
+ "headers": {
+ "x-api-key": "your-composio-api-key",
+ },
+ }
+ )
+ ],
+)
+
+print("Running the OpenAI agent to fetch gmail inbox")
+result = Runner.run_sync(
+ agent,
+ "Summarize all the emails in my Gmail inbox today"
+)
+print(result.final_output)
diff --git a/fern/snippets/tool-router/typescript/anthropic-mcp.ts b/fern/snippets/tool-router/typescript/anthropic-mcp.ts
new file mode 100644
index 000000000..50ed44667
--- /dev/null
+++ b/fern/snippets/tool-router/typescript/anthropic-mcp.ts
@@ -0,0 +1,18 @@
+import { Composio } from "@composio/core";
+import { Agent, run } from "@anthropic-ai/agent";
+
+const composio = new Composio({ apiKey: "your-api-key" });
+
+const { mcp } = await composio.create("pg-user-550e8400-e29b-41d4");
+
+const agent = new Agent({
+ name: "Personal Assistant",
+ instructions: "You are a helpful personal assistant.",
+ mcpServers: [mcp.url],
+});
+
+const result = await run(
+ agent,
+ "Summarize all the emails in my Gmail inbox today"
+);
+console.log(result.finalOutput);
diff --git a/fern/snippets/tool-router/typescript/in-chat-auth.ts b/fern/snippets/tool-router/typescript/in-chat-auth.ts
index 13b1112d3..8e0ceaab3 100644
--- a/fern/snippets/tool-router/typescript/in-chat-auth.ts
+++ b/fern/snippets/tool-router/typescript/in-chat-auth.ts
@@ -1,19 +1,27 @@
-import { Composio } from "@composio/core";
-import { VercelProvider } from "@composio/vercel";
import { openai } from "@ai-sdk/openai";
+import { experimental_createMCPClient as createMCPClient } from "@ai-sdk/mcp";
+import { Composio } from "@composio/core";
import { generateText } from "ai";
import * as readline from "readline";
-const composio = new Composio({
- provider: new VercelProvider(),
-});
+const composio = new Composio({ apiKey: "your-composio-api-key" });
async function chat() {
- const session = await composio.createSession({
- user: "pg-user-550e8400-e29b-41d4",
+ console.log("Creating Tool Router session...");
+ const { mcp } = await composio.create("pg-user-550e8400-e29b-41d4");
+ console.log(`Tool Router session created: ${mcp.url}`);
+
+ const client = await createMCPClient({
+ transport: {
+ type: "http",
+ url: mcp.url,
+ headers: {
+ "x-api-key": "your-composio-api-key",
+ },
+ },
});
- const tools = await session.tools();
+ const tools = await client.tools();
const messages: { role: "user" | "assistant"; content: string }[] = [];
const rl = readline.createInterface({
diff --git a/fern/snippets/tool-router/typescript/manual-auth.ts b/fern/snippets/tool-router/typescript/manual-auth.ts
index 859ffafa5..e66589343 100644
--- a/fern/snippets/tool-router/typescript/manual-auth.ts
+++ b/fern/snippets/tool-router/typescript/manual-auth.ts
@@ -1,16 +1,12 @@
import { Composio } from "@composio/core";
-import { VercelProvider } from "@composio/vercel";
-const composio = new Composio({
- provider: new VercelProvider(),
-});
+const composio = new Composio({ apiKey: "your-composio-api-key" });
const userId = "pg-user-550e8400-e29b-41d4";
const requiredToolkits = ["gmail", "googlecalendar", "linear", "slack"];
async function main() {
- const session = await composio.createSession({
- user: userId,
+ const session = await composio.create(userId, {
manageConnections: false,
});
diff --git a/fern/snippets/tool-router/typescript/openai-agents.ts b/fern/snippets/tool-router/typescript/openai-agents.ts
new file mode 100644
index 000000000..177795957
--- /dev/null
+++ b/fern/snippets/tool-router/typescript/openai-agents.ts
@@ -0,0 +1,22 @@
+import { Composio } from "@composio/core";
+import { OpenAIAgentsProvider } from "@composio/openai-agents";
+import { Agent, run } from "@openai/agents";
+
+const composio = new Composio({
+ apiKey: "your-api-key",
+ provider: new OpenAIAgentsProvider(),
+});
+
+const { tools } = await composio.create("pg-user-550e8400-e29b-41d4");
+
+const agent = new Agent({
+ name: "Personal Assistant",
+ instructions: "You are a helpful personal assistant.",
+ tools: await tools(),
+});
+
+const result = await run(
+ agent,
+ "Summarize all the emails in my Gmail inbox today"
+);
+console.log(result.finalOutput);
diff --git a/fern/snippets/tool-router/typescript/quickstart.ts b/fern/snippets/tool-router/typescript/quickstart.ts
index 990ab1f04..9e5ecdc9c 100644
--- a/fern/snippets/tool-router/typescript/quickstart.ts
+++ b/fern/snippets/tool-router/typescript/quickstart.ts
@@ -1,41 +1,29 @@
-import { Composio } from '@composio/core';
-import { OpenAIAgentsProvider } from '@composio/openai-agents';
-import { Agent, hostedMcpTool, run } from '@openai/agents';
+import { Composio } from "@composio/core";
+import { Agent, hostedMcpTool, run } from "@openai/agents";
-async function main() {
- // Initialize Composio with OpenAI Agents Provider
- const composio = new Composio({
- apiKey: process.env.COMPOSIO_API_KEY,
- provider: new OpenAIAgentsProvider()
- });
+const composio = new Composio({ apiKey: "your-composio-api-key" });
- // Create a Tool Router session for your user
- const session = await composio.experimental.toolRouter.createSession(
- {
- toolkits: ['gmail', 'github'] // Optional: Limit available toolkits
- }
- );
+console.log("Creating Tool Router session...");
+const { mcp } = await composio.create("pg-user-550e8400-e29b-41d4");
+console.log(`Tool Router session created: ${mcp.url}`);
- // Create an agent with Tool Router MCP endpoint
- const agent = new Agent({
- name: 'Assistant',
- instructions: 'You are a helpful assistant that can access Gmail and GitHub. Help users fetch emails, create issues, manage pull requests, and more.',
- tools: [
- hostedMcpTool({
- serverLabel: 'tool_router',
- serverUrl: session.url,
- }),
- ],
- });
+const agent = new Agent({
+ name: "Personal Assistant",
+ instructions: "You are a helpful personal assistant.",
+ tools: [
+ hostedMcpTool({
+ serverLabel: "composio",
+ serverUrl: mcp.url,
+ headers: {
+ "x-api-key": "your-composio-api-key",
+ },
+ }),
+ ],
+});
- // Execute the agent
- const result = await run(
- agent,
- 'Fetch the contributors to composiohq/composio github repository and email the list to [email protected]'
- );
-
- console.log(result.finalOutput);
-}
-
-main();
\ No newline at end of file
+console.log("Running the OpenAI agent to fetch gmail inbox");
+const result = await run(
+ agent,
+ "Summarize all the emails in my Gmail inbox today"
+);
+console.log(result.finalOutput);
diff --git a/fern/snippets/tool-router/typescript/vercel.ts b/fern/snippets/tool-router/typescript/vercel.ts
new file mode 100644
index 000000000..05e8ce76f
--- /dev/null
+++ b/fern/snippets/tool-router/typescript/vercel.ts
@@ -0,0 +1,40 @@
+import { openai } from "@ai-sdk/openai";
+import { experimental_createMCPClient as createMCPClient } from "@ai-sdk/mcp";
+import { Composio } from "@composio/core";
+import { stepCountIs, streamText } from "ai";
+
+const composio = new Composio({ apiKey: "your-composio-api-key" });
+
+console.log("Creating Tool Router session...");
+const { mcp } = await composio.create("pg-user-550e8400-e29b-41d4");
+console.log(`Tool Router session created: ${mcp.url}`);
+
+const client = await createMCPClient({
+ transport: {
+ type: "http",
+ url: mcp.url,
+ headers: {
+ "x-api-key": "your-composio-api-key",
+ },
+ },
+});
+
+const tools = await client.tools();
+
+const stream = await streamText({
+ model: openai("gpt-4o"),
+ prompt: "Summarize all the emails in my Gmail inbox today",
+ stopWhen: stepCountIs(10),
+ onStepFinish: (step) => {
+ if (step.toolCalls.length > 0) {
+ for (const toolCall of step.toolCalls) {
+ console.log(`Executed ${toolCall.toolName}`);
+ }
+ }
+ },
+ tools,
+});
+
+for await (const textPart of stream.textStream) {
+ process.stdout.write(textPart);
+}