How MCP Integration Works in Composio: A Complete Technical Guide

MCP integration in Composio provides AI models with dedicated, short-lived servers that expose only the tools a specific user is authorized to call, managed through the core MCP class and adapted to each LLM provider's format.

The Model Context Protocol (MCP) is a first-class feature of the Composio SDK that enables secure, isolated tool execution for AI agents. According to the Composio source code, MCP integration creates temporary server instances that enforce fine-grained access controls while adapting to OpenAI, Anthropic, Google, and other providers' function-calling formats.

Core MCP Architecture

The MCP Class Lifecycle Management

The MCP integration is orchestrated by the core MCP class located in ts/packages/core/src/models/MCP.ts. This class is instantiated through the experimental namespace of the main Composio client (new Composio().experimental.mcp) and manages the complete lifecycle of MCP server configurations.

The class implements six primary operations:

  • create(name, config) – Validates the payload and forwards the request to the Composio API via client.mcp.custom.create, returning a helper generate(userId) function for immediate use.
  • list(opts) – Retrieves paginated lists of existing MCP servers, transforming snake_case API responses to camelCase via the transform utility.
  • get(id) – Fetches a single server's full definition.
  • update(id, cfg) – Patches an existing server configuration.
  • delete(id) – Permanently removes a server.
  • generate(userId, mcpConfigId, opts?) – Calls the API to create a temporary URL (client.mcp.generate.url) that models use to invoke the server. The returned MCPServerInstance object contains the URL, allowed tools, and auth configuration IDs.

Response Transformation Layer

All server-side response transformations are handled by dedicated transformers in ts/packages/core/src/utils/transformers/mcp.ts. These utilities map raw snake_case fields (e.g., allowed_tools) to camelCase TypeScript properties (allowedTools), ensuring type consistency throughout the SDK.

Type definitions for MCP operations reside in ts/packages/core/src/types/mcp.experimental.types.ts, while the MCPServerInstanceSchema in ts/packages/core/src/types/toolRouter.types.ts defines the shape of generated server instances returned to callers.

Provider-Specific MCP Adapters

Each LLM provider that supports function calling implements a wrapMcpServerResponse method to adapt Composio's MCP URLs into their native tool formats.

OpenAI Integration

The OpenAI provider adapter in ts/packages/providers/openai/src/OpenAIResponsesProvider.ts transforms MCP responses into OpenAI-compatible tool definitions:

// Transform MCP URL response into OpenAI-specific format
// Source: OpenAIResponsesProvider.wrapMcpServerResponse
// https://github.com/ComposioHQ/composio/blob/next/ts/packages/providers/openai/src/OpenAIResponsesProvider.ts#L76-L91
override wrapMcpServerResponse(data: McpUrlResponse): OpenAiMcpTool[] {
  return data.map(item => ({
    type: 'mcp',
    server_label: item.name,
    server_url: item.url,
    require_approval: 'never',
  }));
}

Anthropic and Claude Agent SDK Support

Similar implementations exist for other providers:

Each adapter maintains the same core pattern: receive the McpUrlResponse ({ name, url }[]), then convert to provider-specific fields such as type, server_label, server_url, and require_approval.

Runtime Flow and Security Model

The MCP integration follows a strict runtime flow that enforces security and isolation:

  1. Configuration Phase – Developers create an MCP config specifying toolkits (e.g., GitHub, Slack) and allowed tools (e.g., GITHUB_CREATE_ISSUE, SLACK_SEND_MESSAGE) via composio.experimental.mcp.create().

  2. URL Generation – At request time, the SDK calls composio.experimental.mcp.generate(userId, configId) to obtain a single-use, temporary URL from the Composio API (client.mcp.generate.url).

  3. Provider Adaptation – The chosen provider's wrapMcpServerResponse converts the MCP URL into a tool definition that the LLM can select from its available functions.

  4. Execution – When the LLM selects the MCP tool, it sends a request to the generated URL. The Composio server authenticates the user via the embedded userId token and forwards tool calls to underlying connected accounts, strictly respecting the allowed-tool whitelist defined in the MCP configuration.

Key Architectural Benefits

  • User Isolation – Each user receives a dedicated server instance, preventing cross-user tool leakage or unauthorized access to other users' connected accounts.
  • Fine-Grained Access Control – Developers configure toolkits and per-tool access at the MCP level, ensuring models can only invoke explicitly permitted operations.
  • Provider Agnosticism – Only the wrapMcpServerResponse adapter differs per provider, keeping core MCP logic consistent across OpenAI, Anthropic, Google, and others.
  • Stateless Security – Generated URLs encode the user and server ID, enabling short-lived, stateless access that expires automatically without server-side session management.

Implementation Examples

Creating an MCP Configuration and Generating a User-Specific URL

import { Composio } from '@composio/code';

const composio = new Composio({ apiKey: process.env.COMPOSIO_API_KEY });

// 1️⃣ Create the MCP config (run once)
const config = await composio.experimental.mcp.create('my-mcp-server', {
  toolkits: ['github', 'slack'],
  allowedTools: ['GITHUB_CREATE_ISSUE', 'SLACK_SEND_MESSAGE'],
  manuallyManageConnections: false,
});

// 2️⃣ Generate a server URL for a specific user
const instance = await composio.experimental.mcp.generate(
  'user-123',               // your internal user identifier
  config.id,                // MCP config ID returned above
  { isChatAuth: true }      // optional: use chat-based auth flow
);

console.log('MCP URL for the LLM:', instance.url);
// → https://mcp.composio.io/<generated-token>

Source: MCP.create and MCP.generate implementations – create, generate.

Adapting MCP for OpenAI Function Calling

import { OpenAIResponsesProvider } from '@composio/providers/openai';
import { Composio } from '@composio/code';

const composio = new Composio({ apiKey: process.env.COMPOSIO_API_KEY });
const provider = new OpenAIResponsesProvider();

// Assume an MCP instance was generated as above
const mcpInstance = await composio.experimental.mcp.generate('user-123', 'mcp_cfg_abc');

// Convert the URL response to OpenAI tool format
const mcpTools = provider.wrapMcpServerResponse([
  { name: mcpInstance.MCPUrl, url: mcpInstance.url }
]);

console.log('OpenAI-compatible MCP tool definition:', mcpTools);

Source: OpenAIResponsesProvider.wrapMcpServerResponselink.

Handling LLM-Initiated MCP Tool Calls

// Inside an OpenAI chat flow
const response = await openai.responses.create({
  model: 'gpt-4o-mini',
  input: 'Fetch my GitHub issues',
  tools: await composio.tools.get(composioTools), // includes MCP tool
});

const toolOutputs = await provider.handleResponse('user-123', response);
await openai.responses.create({
  model: 'gpt-4o-mini',
  input: toolOutputs,
  // …continue the conversation
});

Source: OpenAIResponsesProvider.handleResponselink.

Summary

  • MCP integration in Composio provides isolated, temporary servers that expose only permitted tools to specific users, managed through the core MCP class in ts/packages/core/src/models/MCP.ts.
  • The MCP lifecycle includes creating configurations, generating single-use URLs via generate(), and transforming responses through ts/packages/core/src/utils/transformers/mcp.ts.
  • Provider adapters in ts/packages/providers/openai/src/OpenAIResponsesProvider.ts and similar files convert MCP URLs into LLM-specific tool formats using wrapMcpServerResponse.
  • Security architecture ensures user isolation through dedicated server instances, fine-grained access control via allowed-tool whitelists, and stateless, short-lived URLs that encode authentication tokens.

Frequently Asked Questions

What is the Model Context Protocol (MCP) in Composio?

The Model Context Protocol (MCP) is a first-class feature of the Composio SDK that creates dedicated, short-lived servers exposing only the tools a specific user is authorized to use. According to the Composio source code, MCP integration ensures that AI models receive isolated access to external APIs through temporary URLs that enforce fine-grained permissions and automatic user authentication.

How do I generate an MCP server URL for a specific user?

To generate an MCP server URL, first create an MCP configuration using composio.experimental.mcp.create() with your desired toolkits and allowed tools, then call composio.experimental.mcp.generate(userId, configId). This method, implemented in ts/packages/core/src/models/MCP.ts, returns an MCPServerInstance containing a temporary URL that encodes the user identity and permitted tool scope.

Which LLM providers support Composio's MCP integration?

Composio's MCP integration supports all major function-calling providers including OpenAI, Anthropic, Google, and the Claude Agent SDK. Each provider implements a wrapMcpServerResponse method—found in files like ts/packages/providers/openai/src/OpenAIResponsesProvider.ts and ts/packages/providers/anthropic/src/index.ts—that transforms Composio's MCP URL responses into the provider-specific tool format required by their respective APIs.

How does Composio ensure security with MCP servers?

Composio ensures MCP security through user isolation, fine-grained access control, and stateless URL architecture. Each generate() call creates a dedicated server instance in ts/packages/core/src/models/MCP.ts that prevents cross-user tool leakage, while the configuration's allowedTools whitelist restricts available operations. The generated URLs are short-lived, encode user authentication tokens directly, and require no server-side session management, minimizing the attack surface for unauthorized access.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →