Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
manual authenitcate fixes
Sushmithamallesh75bd7bbb8f7d
diff --git a/fern/pages/src/tool-router/manually-authenticating-users.mdx b/fern/pages/src/tool-router/manually-authenticating-users.mdxindex 535aa0b13..a7ec99272 100644--- a/fern/pages/src/tool-router/manually-authenticating-users.mdx+++ b/fern/pages/src/tool-router/manually-authenticating-users.mdx@@ -9,125 +9,83 @@ Manual authentication lets you connect users to toolkits outside of the chat flo- Pre-authenticate users before they start chatting- Build a custom connections UI in your app-## Create session+## Authorize a toolkit-Disable the `COMPOSIO_MANAGE_CONNECTIONS` meta-tool so the agent doesn't prompt for auth during chat:+Use `session.authorize()` to generate a [Connect Link](/docs/authenticating-tools#hosted-authentication-connect-link) URL, redirect the user, and wait for them to complete:<CodeGroup>```python-session = composio.create(- user_id="user_123",- manage_connections=False,-)+session = composio.create(user_id="user_123")++connection_request = session.authorize("gmail")++print(connection_request.redirect_url)+# https://connect.composio.dev/link/ln_abc123++connected_account = connection_request.wait_for_connection(60000)+print(f"Connected: {connected_account.id}")``````typescript-const session = await composio.create("user_123", {- manageConnections: false,-});+const session = await composio.create("user_123");++const connectionRequest = await session.authorize("gmail");++console.log(connectionRequest.redirectUrl);+// https://connect.composio.dev/link/ln_abc123++const connectedAccount = await connectionRequest.waitForConnection(60000);+console.log(`Connected: ${connectedAccount.id}`);```</CodeGroup>+Redirect the user to the redirect URL. After they authenticate, they'll return to your callback URL. The connection request polls until the user completes authentication (default timeout: 60 seconds).++<Note>+If the user closes the Connect Link without completing auth, the connection remains in `INITIATED` status until it expires.+</Note>+## Check connection status-Use `session.toolkits()` to see which apps the user has connected:+Use `session.toolkits()` to see all toolkits in the session and their connection status:<CodeGroup>```pythontoolkits = session.toolkits()-for toolkit in toolkits:- status = toolkit.connected_account.status if toolkit.connected_account else "Not connected"+for toolkit in toolkits.items:+ status = toolkit.connection.connected_account.id if toolkit.connection.is_active else "Not connected"print(f"{toolkit.name}: {status}")``````typescriptconst toolkits = await session.toolkits();-for (const toolkit of toolkits) {- const status = toolkit.connectedAccount?.status || "Not connected";- console.log(`${toolkit.name}: ${status}`);-}-```-</CodeGroup>--Each toolkit includes:-- `name`, `slug`, `logo`, `description`-- `connectedAccount` - present if user is connected, includes `id`, `status`, `createdAt`--### Filter and sort--Use filters to show relevant toolkits in your UI:--<CodeGroup>-```python-toolkits = session.toolkits(- order_by="popularity", # Sort by most used- order_direction="desc",- category="developer-tools", # Filter by category- is_connected=True, # Only show connected apps-)-```-```typescript-const toolkits = await session.toolkits({- orderBy: "popularity", // Sort by most used- orderDirection: "desc",- category: "developer-tools", // Filter by category- isConnected: true, // Only show connected apps+toolkits.items.forEach((toolkit) => {+ console.log(`${toolkit.name}: ${toolkit.connection.connectedAccount?.id ?? "Not connected"}`);});```</CodeGroup>-## Generate auth URL+## Disabling in-chat auth-Use `session.authorize()` to generate a [Connect Link](/docs/authenticating-tools#hosted-authentication-connect-link) URL:+By default, Tool Router includes the `COMPOSIO_MANAGE_CONNECTIONS` meta-tool that prompts users to authenticate during chat. To disable this and handle auth entirely in your UI:<CodeGroup>```python-connection_request = session.authorize(- "gmail",- callback_url="https://yourapp.com/callback"+session = composio.create(+ user_id="user_123",+ manage_connections=False,)--print(connection_request.redirect_url)-# https://connect.composio.dev/link/ln_abc123``````typescript-const connectionRequest = await session.authorize("gmail", {- callbackUri: "https://yourapp.com/callback",+const session = await composio.create("user_123", {+ manageConnections: false,});--console.log(connectionRequest.redirectUrl);-// https://connect.composio.dev/link/ln_abc123```</CodeGroup>-Redirect the user to `redirectUrl`. After they authenticate, they'll be redirected to your `callbackUrl`.--## Wait for connection--Use `waitForConnection()` to poll until the user completes authentication:--<CodeGroup>-```python-connected_account = connection_request.wait_for_connection(60000)-print(f"Connected: {connected_account.id}")-```-```typescript-const connectedAccount = await connectionRequest.waitForConnection(60000);-console.log(`Connected: ${connectedAccount.id}`);-```-</CodeGroup>--- Default timeout: 60 seconds (60000ms)-- Throws `ConnectionRequestTimeoutError` if timeout expires-- Throws `ConnectionRequestFailedError` if connection fails or expires--<Note>-If the user closes the Connect Link without completing auth, the connection remains in `INITIATED` status until it expires.-</Note>-## Putting it together-A common pattern is to verify all required connections before starting the agent. For example, a personal assistant might need Gmail, Calendar, Linear, and Slack:+A common pattern is to verify all required connections before starting the agent:<CodeGroup><SnippetCode src="fern/snippets/tool-router/python/manual-auth.py" title="Python" />diff --git a/fern/snippets/tool-router/python/manual-auth.py b/fern/snippets/tool-router/python/manual-auth.pyindex c09b61b60..2d51e1fd4 100644--- a/fern/snippets/tool-router/python/manual-auth.py+++ b/fern/snippets/tool-router/python/manual-auth.py@@ -1,46 +1,25 @@from composio import Composio-from agents import Agent, Runner, HostedMCPTool-composio = Composio()+composio = Composio(api_key="your-api-key")-required_toolkits = ["gmail", "googlecalendar", "linear", "slack"]+required_toolkits = ["gmail", "github"]session = composio.create(- user_id=user_id,- manage_connections=False,+ user_id="user_123",+ manage_connections=False, # Disable in-chat auth prompts)toolkits = session.toolkits()-def is_connected(slug):- toolkit = next((t for t in toolkits if t.slug == slug), None)- return toolkit and toolkit.connected_account--pending = [slug for slug in required_toolkits if not is_connected(slug)]--if pending:- for slug in pending:- connection_request = session.authorize(- slug,- callback_url="https://yourapp.com/onboarding"- )- print(f"Connect {slug}: {connection_request.redirect_url}")- connection_request.wait_for_connection()--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",- }- )- ],-)+connected = {t.slug for t in toolkits.items if t.connection.is_active}+pending = [slug for slug in required_toolkits if slug not in connected]++print(f"Connected: {connected}")+print(f"Pending: {pending}")++for slug in pending:+ connection_request = session.authorize(slug)+ print(f"Connect {slug}: {connection_request.redirect_url}")+ connection_request.wait_for_connection()-result = Runner.run_sync(agent, "Summarize my emails from today")-print(result.final_output)+print(f"All toolkits connected! MCP URL: {session.mcp.url}")diff --git a/fern/snippets/tool-router/typescript/manual-auth.ts b/fern/snippets/tool-router/typescript/manual-auth.tsindex b37b41161..a226dbdf9 100644--- a/fern/snippets/tool-router/typescript/manual-auth.ts+++ b/fern/snippets/tool-router/typescript/manual-auth.ts@@ -1,39 +1,28 @@import { Composio } from "@composio/core";-import { Agent, run, hostedMcpTool } from "@openai/agents";-const composio = new Composio();+const composio = new Composio({ apiKey: "your-api-key" });-const requiredToolkits = ["gmail", "googlecalendar", "linear", "slack"];+const requiredToolkits = ["gmail", "github"];-const session = await composio.create(userId, {- manageConnections: false,+const session = await composio.create("user_123", {+ manageConnections: false, // Disable in-chat auth prompts});const toolkits = await session.toolkits();-const pending = requiredToolkits.filter((slug) => {- const toolkit = toolkits.find((t) => t.slug === slug);- return !toolkit?.connectedAccount;-});+const connected = toolkits.items+ .filter((t) => t.connection.connectedAccount)+ .map((t) => t.slug);++const pending = requiredToolkits.filter((slug) => !connected.includes(slug));++console.log("Connected:", connected);+console.log("Pending:", pending);for (const slug of pending) {- const connectionRequest = await session.authorize(slug, {- callbackUri: "https://yourapp.com/onboarding",- });+ const connectionRequest = await session.authorize(slug);console.log(`Connect ${slug}: ${connectionRequest.redirectUrl}`);await connectionRequest.waitForConnection();}-const agent = new Agent({- name: "Personal Assistant",- instructions: "You are a helpful personal assistant.",- tools: [- hostedMcpTool({- serverLabel: "composio",- serverUrl: session.mcp.url,- }),- ],-});--const result = await run(agent, "Summarize my emails from today");-console.log(result.finalOutput);+console.log(`All toolkits connected! MCP URL: ${session.mcp.url}`);