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
feat: update mcp flow in ts sdk
Utkarsh Dixitf1a7e0f9ca35
diff --git a/fern/pages/src/mcp/developers.mdx b/fern/pages/src/mcp/developers.mdxindex 8c3202d3c..fcc54d9ca 100644--- a/fern/pages/src/mcp/developers.mdx+++ b/fern/pages/src/mcp/developers.mdx@@ -155,7 +155,7 @@ const updatedServer = await composio.mcp.update(allowedTools: ["GMAIL_FETCH_EMAILS", "GMAIL_SEND_EMAIL"]}],- { useComposioManagedAuth: true }+ { isChatAuth: true });```@@ -203,20 +203,18 @@ Pre-authentication is recommended for production applications as it provides bet## Best Practices-1. **Use meaningful server names** - This helps with organization and makes servers easier to find-2. **Limit tools appropriately** - Only include the tools your users actually need-3. **Check connection status** - Always verify user authentication before using server URLs-4. **Handle authentication gracefully** - Provide clear instructions when users need to authenticate-5. **Use the convenience methods** - The `getServer` method on create responses simplifies URL generation+1. **Use meaningful server names** - This helps with organization and makes servers easier to find.+2. **Limit tools appropriately** - Only include the tools your users actually need.+3. **Check connection status** - Always verify user authentication before using server URLs.+4. **Handle authentication gracefully** - Provide clear instructions when users need to authenticate.+5. **Use the convenience methods** - The `getServer` method on create responses simplifies URL generation.<Warning>SSE support is deprecated. If you're using `/sse` endpoints or `transport=sse` query parameters, migrate to the standard `/mcp` endpoints.</Warning>-### Configuring authentication-You or your users need to authenticate against an app to use its MCP server through Composio!-This can be done in two ways:+### Configuring Authentication+You or your users need to authenticate against an app to use its MCP server through Composio. This can be done in two ways:* Authenticate users upfront via the Composio SDK/API. Follow [custom auth configs](/docs/custom-auth-configs) to learn how to connect users. This is recommended for most use cases.-* Let the agent authenticate users on demand. Passing `include_composio_helper_actions=true` in the URL will include Composio's helper actions and the agent will guide the user through auth on demand.-+* Let the agent authenticate users on demand. Passing `include_composio_helper_actions=true` in the URL will include Composio's helper actions, and the agent will guide the user through authentication on demand.diff --git a/fern/pages/src/mcp/introduction.mdx b/fern/pages/src/mcp/introduction.mdxindex 69aa89f50..8e82a58f0 100644--- a/fern/pages/src/mcp/introduction.mdx+++ b/fern/pages/src/mcp/introduction.mdx@@ -255,7 +255,7 @@ const updatedServer = await composio.mcp.update(allowedTools: ["GMAIL_FETCH_EMAILS", "GMAIL_SEND_EMAIL"]}],- { useComposioManagedAuth: true }+ { isChatAuth: true });```diff --git a/ts/docs/api/mcp.md b/ts/docs/api/mcp.mdindex d3173596b..d481c08e3 100644--- a/ts/docs/api/mcp.md+++ b/ts/docs/api/mcp.md@@ -29,7 +29,7 @@ const server = await composio.mcp.create(allowedTools: ["GMAIL_FETCH_EMAILS", "GMAIL_SEND_EMAIL"]}],- { useComposioManagedAuth: true }+ { isChatAuth: true });// Create an MCP server with multiple toolkits@@ -63,7 +63,7 @@ const urls = await server.getServer({- `authConfigId`: The auth configuration ID to use- `allowedTools`: Array of specific tool IDs to expose- `authOptions` (MCPAuthOptions): Optional authentication options- - `useComposioManagedAuth`: Whether to use Composio-managed authentication+ - `isChatAuth`: Whether to use Composio-managed authentication**Returns:** Promise<McpServerCreateResponse> - Created server details with convenience `getServer` method@@ -91,7 +91,7 @@ const userUrls = await composio.mcp.getServer("server-uuid", {const customAuthUrls = await composio.mcp.getServer("server-uuid",{ userId: "user_123" },- { useComposioManagedAuth: false }+ { isChatAuth: false });```@@ -173,7 +173,7 @@ const updatedServer = await composio.mcp.update(allowedTools: ["GMAIL_FETCH_EMAILS", "GMAIL_SEND_EMAIL", "GMAIL_CREATE_DRAFT"]}],- { useComposioManagedAuth: true }+ { isChatAtuh: true });```@@ -286,7 +286,7 @@ interface MCPToolkitConfig {```typescriptinterface MCPAuthOptions {- useComposioManagedAuth?: boolean; // Use Composio-managed authentication+ isChatAuth?: boolean; // Use Composio-managed authentication}```@@ -364,7 +364,7 @@ const mcpServer = await composio.mcp.create(allowedTools: ["GMAIL_FETCH_EMAILS", "GMAIL_SEND_EMAIL"]}],- { useComposioManagedAuth: true }+ { isChatAuth: true });// Get server URLs for connected accountsdiff --git a/ts/docs/core-concepts.md b/ts/docs/core-concepts.mdindex b2c3384e0..1277bcc00 100644--- a/ts/docs/core-concepts.md+++ b/ts/docs/core-concepts.md@@ -349,7 +349,7 @@ const mcpServer = await composio.mcp.create(allowedTools: ["GMAIL_FETCH_EMAILS", "GMAIL_SEND_EMAIL"]}],- { useComposioManagedAuth: true }+ { isChatAuth: true });// Get server URLs for AI agent to connectdiff --git a/ts/examples/anthropic/src/mcp.ts b/ts/examples/anthropic/src/mcp.tsindex df4490e00..be64a9f3f 100644--- a/ts/examples/anthropic/src/mcp.ts+++ b/ts/examples/anthropic/src/mcp.ts@@ -41,7 +41,7 @@ async function main() {]}],- { useComposioManagedAuth: true }+ { isChatAuth: true });console.log(`✅ MCP server created: ${mcpConfig.id}`);diff --git a/ts/examples/mastra/src/mcp.ts b/ts/examples/mastra/src/mcp.tsindex 41e51b69a..7ddb92de3 100644--- a/ts/examples/mastra/src/mcp.ts+++ b/ts/examples/mastra/src/mcp.ts@@ -39,7 +39,7 @@ const mcpConfig = await composio.mcp.create(]}],- { useComposioManagedAuth: true }+ { isChatAuth: true });console.log(`✅ MCP server created: ${mcpConfig.id}`);diff --git a/ts/packages/core/src/models/MCP.ts b/ts/packages/core/src/models/MCP.tsindex 3472ae05d..69cb714bf 100644--- a/ts/packages/core/src/models/MCP.ts+++ b/ts/packages/core/src/models/MCP.ts@@ -1,8 +1,6 @@/*** @fileoverview MCP class for Composio SDK, used to manage MCP servers.*- * @author Apoorv Taneja <[email protected]>- * @date 2025-06-12* @module MCP*/import ComposioClient from '@composio/client';@@ -13,7 +11,6 @@ import {MCPGetServerParams,MCPToolkitConfigsArraySchema,MCPAuthOptionsSchema,- MCPGetServerParamsSchema,ComposioCustomCreateResponseSchema,ComposioMcpListResponseSchema,McpRetrieveResponseSchema,@@ -35,10 +32,7 @@ import {McpUserConnectionStatus,ConnectionStatus,} from '../types/mcp.types';-import {- CustomCreateResponse as CustomCreateResponseRaw,- GenerateURLParams as GenerateURLParamsRaw,-} from '@composio/client/resources/mcp';+import { CustomCreateResponse as CustomCreateResponseRaw } from '@composio/client/resources/mcp';import { ValidationError } from '../errors/ValidationErrors';import { BaseComposioProvider } from '../provider/BaseProvider';import {@@ -107,15 +101,13 @@ export class MCP<T = McpServerGetResponse> {** @example* ```typescript- * const server = await composio.mcp.create({- * serverConfig: [+ * const server = await composio.mcp.create("personal-mcp-server", [* {* authConfigId: "ac_xyz",* allowedTools: ["GMAIL_FETCH_EMAILS", "SLACK_SEND_MESSAGE"]* }* ],- * options: {- * name: "personal-mcp-server",+ * {* isChatAuth: true* }* });@@ -126,20 +118,16 @@ export class MCP<T = McpServerGetResponse> {* });* ```*/- async create({- name,- serverConfig,- options,- }: {- name: string;+ async create(+ name: string,serverConfig: Array<{authConfigId: string;allowedTools: string[];- }>;+ }>,options: {isChatAuth?: boolean;- };- }): Promise<McpServerCreateResponse<T>> {+ }+ ): Promise<McpServerCreateResponse<T>> {// Validate inputs using Zod schemasif (!serverConfig || serverConfig.length === 0) {throw new ValidationError('At least one auth config is required', {});@@ -236,10 +224,7 @@ export class MCP<T = McpServerGetResponse> {* @example* ```typescript* // Check if user can access an MCP server with Gmail and Slack toolkits- * const connectionStatus = await composio.mcp.getUserConnectionStatus({- * id: 'mcp-server-uuid',- * userId: 'user123'- * });+ * const connectionStatus = await composio.mcp.getUserConnectionStatus('user123', 'mcp-server-uuid');** if (connectionStatus.connected) {* console.log('User can access all required toolkits');@@ -277,18 +262,15 @@ export class MCP<T = McpServerGetResponse> {* }* ```*/- async getUserConnectionStatus({- id,- userId,- }: {- id: string;- userId: string;- }): Promise<McpUserConnectionStatus> {- const serverDetails = await this.get(id);+ async getUserConnectionStatus(+ userId: string,+ serverId: string+ ): Promise<McpUserConnectionStatus> {+ const serverDetails = await this.get(serverId);if (!serverDetails.toolkits || serverDetails.toolkits.length === 0) {throw new ValidationError('MCP server has no toolkits configured', {- meta: { serverId: id },+ meta: { serverId: serverId },});}@@ -342,14 +324,14 @@ export class MCP<T = McpServerGetResponse> {}}- async getConnectionParams({- id,- toolkit,- }: {- id: string;- toolkit: string;- }): Promise<ToolkitAuthFieldsResponse> {- const mcpServerDetails = await this.get(id);+ /**+ * Get the connection parameters for a toolkit+ * @param {string} serverId - The UUID of the MCP server+ * @param {string} toolkit - The toolkit to get connection parameters for+ * @returns {Promise<ToolkitAuthFieldsResponse>} Connection parameters for the toolkit+ */+ async getConnectionParams(serverId: string, toolkit: string): Promise<ToolkitAuthFieldsResponse> {+ const mcpServerDetails = await this.get(serverId);const authConfigs = mcpServerDetails.authConfigIds? await Promise.all(mcpServerDetails.authConfigIds.map(id => this.client.authConfigs.retrieve(id))@@ -359,7 +341,7 @@ export class MCP<T = McpServerGetResponse> {const authConfig = authConfigs.find(config => config.toolkit.slug === toolkit);if (!authConfig) {throw new ValidationError('Auth config not found', {- meta: { serverId: id, toolkit },+ meta: { serverId: serverId, toolkit },});}@@ -370,63 +352,50 @@ export class MCP<T = McpServerGetResponse> {return connectionParams;}- async authorize({- id,- userId,- toolkit,- }: {- id: string;- userId: string;- toolkit: string;- }): Promise<ConnectionRequest> {- const mcpServerDetails = await this.get(id);+ /**+ * Authorize a user for a toolkit+ * @param {string} serverId - The UUID of the MCP server+ * @param {string} userId - The ID of the user to authorize+ * @param {string} toolkit - The toolkit to authorize+ * @returns {Promise<ConnectionRequest>} Connection request for the toolkit+ */+ async authorize(userId: string, serverId: string, toolkit: string): Promise<ConnectionRequest> {+ const mcpServerDetails = await this.get(serverId);const authConfigId = mcpServerDetails.authConfigIds?.[0];return this.toolkits.authorize(userId, toolkit, authConfigId);}/*** Get server URLs for an existing MCP server- * @param {Object} params - Parameters for getting server URLs- * @param {string} params.id - Server UUID- * @param {string} params.userId - User ID to get server URLs for- * @param {Object} [params.options] - Additional options for server configuration- * @param {string[]} [params.options.limitTools] - Subset of tools to limit (from MCP config)- * @param {boolean} [params.options.isChatAuth] - Whether to use chat-based authentication+ * @param {string} serverId - Server UUID+ * @param {string} userId - User ID to get server URLs for+ * @param {Object} [options] - Additional options for server configuration+ * @param {string[]} [options.limitTools] - Subset of tools to limit (from MCP config)+ * @param {boolean} [options.isChatAuth] - Whether to use chat-based authentication* @returns {Promise<T>} Transformed server URLs in provider-specific format** @example* ```typescript* // Get URLs for an existing server with basic user ID- * const urls = await composio.mcp.getServer({- * id: "mcp_xyz",- * userId: "[email protected]"- * });+ * const urls = await composio.mcp.getServer("mcp_xyz", "[email protected]");** // Get URLs with additional options- * const urls = await composio.mcp.getServer({- * id: "mcp_xyz",- * userId: "[email protected]",- * options: {- * limitTools: ["GMAIL_FETCH_EMAILS", "SLACK_SEND_MESSAGE"],- * isChatAuth: true- * }+ * const urls = await composio.mcp.getServer("mcp_xyz", "[email protected]", {+ * limitTools: ["GMAIL_FETCH_EMAILS", "SLACK_SEND_MESSAGE"],+ * isChatAuth: true* });* ```*/- async getServer({- id,- userId,- options,- }: {- id: string;- userId: string;+ async getServer(+ serverId: string,+ userId: string,options?: {limitTools?: string[];isChatAuth?: boolean;- };- }): Promise<T> {+ }+ ): Promise<T> {// Get server details first- const serverDetails = await this.get(id);+ const serverDetails = await this.get(serverId);// Validate userId is providedif (!userId) {@@ -550,7 +519,7 @@ export class MCP<T = McpServerGetResponse> {/*** Get details of a specific MCP server- * @param {string} id - Server UUID+ * @param {string} serverId - Server UUID* @returns {Promise<McpRetrieveResponse>} Server details** @example@@ -558,11 +527,11 @@ export class MCP<T = McpServerGetResponse> {* const serverDetails = await composio.mcp.get('server-uuid');* ```*/- async get(id: string): Promise<McpRetrieveResponse> {+ async get(serverId: string): Promise<McpRetrieveResponse> {// Retrieve MCP server with error handlinglet retrieveResponse;try {- retrieveResponse = await this.client.mcp.retrieve(id);+ retrieveResponse = await this.client.mcp.retrieve(serverId);} catch (error) {throw new ValidationError('Failed to retrieve MCP server', {cause: error,@@ -583,7 +552,7 @@ export class MCP<T = McpServerGetResponse> {/*** Delete an MCP server- * @param {string} id - Server UUID+ * @param {string} serverId - Server UUID* @returns {Promise<McpDeleteResponse>} Deletion response** @example@@ -591,11 +560,11 @@ export class MCP<T = McpServerGetResponse> {* const result = await composio.mcp.delete('server-uuid');* ```*/- async delete(id: string): Promise<McpDeleteResponse> {+ async delete(serverId: string): Promise<McpDeleteResponse> {// Delete MCP server with error handlinglet deleteResponse;try {- deleteResponse = await this.client.mcp.delete(id);+ deleteResponse = await this.client.mcp.delete(serverId);} catch (error) {throw new ValidationError('Failed to delete MCP server', {cause: error,@@ -635,13 +604,13 @@ export class MCP<T = McpServerGetResponse> {* },* ],* {- * useComposioManagedAuth: true,+ * isChatAuth: true,* }* );* ```*/async update(- id: string,+ serverId: string,name: string,toolkitConfigs: MCPToolkitConfig[],authOptions?: MCPAuthOptions@@ -654,11 +623,11 @@ export class MCP<T = McpServerGetResponse> {// Update MCP server with error handlinglet updateResponse;try {- updateResponse = await this.client.mcp.update(id, {+ updateResponse = await this.client.mcp.update(serverId, {name,toolkits: toolkits,allowed_tools: toolkitConfigs.flatMap(config => config.allowedTools),- managed_auth_via_composio: authOptions?.useComposioManagedAuth || false,+ managed_auth_via_composio: authOptions?.isChatAuth || false,});} catch (error) {throw new ValidationError('Failed to update MCP server', {@@ -680,20 +649,20 @@ export class MCP<T = McpServerGetResponse> {/*** Generate URL for an MCP server+ * @param {string} serverId - Server UUID* @param {GenerateURLParams} params - Parameters for URL generation* @returns {Promise<GenerateURLResponse>} Generated URL response** @example* ```typescript- * const urlResponse = await composio.mcp.generateUrl({+ * const urlResponse = await composio.mcp.generateUrl('server-uuid', {* userIds: ['user123'],* connectedAccountIds: ['account456'],- * mcpServerId: 'server-uuid',- * composioManagedAuth: true+ * isChatAuth: true* });* ```*/- async generateUrl(params: GenerateURLParams): Promise<GenerateURLResponse> {+ async generateUrl(serverId: string, params: GenerateURLParams): Promise<GenerateURLResponse> {// Validate parameters using Zod schema (snake_case)const paramsResult = GenerateURLParamsSchema.safeParse(params);if (paramsResult.error) {@@ -706,7 +675,7 @@ export class MCP<T = McpServerGetResponse> {let urlResponse;try {urlResponse = await this.client.mcp.generate.url({- mcp_server_id: params.mcpServerId,+ mcp_server_id: serverId,user_ids: params.userIds,connected_account_ids: params.connectedAccountIds,managed_auth_by_composio: params.composioManagedAuth,@@ -806,8 +775,8 @@ export class MCP<T = McpServerGetResponse> {* const serverDetails = await composio.mcp.getByName('my-gmail-server');* ```*/- async getByName(name: string): Promise<McpRetrieveResponse> {- if (!name) {+ async getByName(serverName: string): Promise<McpRetrieveResponse> {+ if (!serverName) {throw new ValidationError('Server name is required', {});}@@ -815,7 +784,7 @@ export class MCP<T = McpServerGetResponse> {let listResponse;try {listResponse = await this.client.mcp.list({- name: name,+ name: serverName,limit: 10,});} catch (error) {@@ -835,8 +804,8 @@ export class MCP<T = McpServerGetResponse> {const servers = listResponse.items || [];if (servers.length === 0) {- throw new ValidationError(`MCP server with name '${name}' not found`, {- meta: { serverName: name },+ throw new ValidationError(`MCP server with name '${serverName}' not found`, {+ meta: { serverName: serverName },});}diff --git a/ts/packages/core/src/types/mcp.types.ts b/ts/packages/core/src/types/mcp.types.tsindex d64fbb573..d11aeb1eb 100644--- a/ts/packages/core/src/types/mcp.types.ts+++ b/ts/packages/core/src/types/mcp.types.ts@@ -28,7 +28,7 @@ export const MCPToolkitConfigsArraySchema = z}, 'Duplicate toolkits are not allowed. Each toolkit must be unique.');export const MCPAuthOptionsSchema = z.object({- useComposioManagedAuth: z.boolean().optional(),+ isChatAuth: z.boolean().optional(),});export type MCPAuthOptions = z.infer<typeof MCPAuthOptionsSchema>;@@ -59,13 +59,13 @@ export type MCPInstanceParams = {serverId: string;userIds?: string[];connectedAccountIds?: string[];- useComposioManagedAuth?: boolean;+ isChatAuth?: boolean;};export const MCPGenerateURLParamsSchema = z.object({userIds: z.array(z.string()).optional(),connectedAccountIds: z.array(z.string()).optional(),- useComposioManagedAuth: z.boolean().optional(),+ isChatAuth: z.boolean().optional(),});export type MCPGenerateURLParams = z.infer<typeof MCPGenerateURLParamsSchema>;diff --git a/ts/packages/core/test/models/mcp.test.ts b/ts/packages/core/test/models/mcp.test.tsindex 9b6b763ec..bd291fba8 100644--- a/ts/packages/core/test/models/mcp.test.ts+++ b/ts/packages/core/test/models/mcp.test.ts@@ -527,7 +527,7 @@ describe('MCP', () => {mockClient.mcp.update.mockResolvedValue(mockUpdateResponse);const result = await mcp.update('mcp_123', 'updated-server', updatedConfigs, {- useComposioManagedAuth: true,+ isChatAuth: true,});expect(mockClient.mcp.update).toHaveBeenCalledWith('mcp_123', {