MCP Servers for developers

Guide to create and manage MCP servers

Composio MCP lets you build custom MCP servers that your users can connect to and use to perform actions. You can manage these servers via our Dashboard, or use the SDK/API for greater control and flexibility.

The MCP SDK has been updated to use positional parameters instead of object parameters for better performance and simpler usage. All examples below reflect the latest API structure.

Creating MCP Servers and Onboarding End Users

1

Configure Authentication

  • Create and Configure Toolkit permissions:

    • Select the specific scopes and permissions your integration requires for each connected application. This ensures your MCP server has the right level of access.
    • Check this guide on what auth config is and how to configue it - Auth Config setup guide
  • Customize the authentication experience (Optional):

    • Create a seamless, branded experience by providing your own OAuth credentials and customizing the consent screens.
    • Learn more here - Custom auth configs
2

Create and configure an MCP server

1import { Composio } from '@composio/core';
2
3const composio = new Composio({
4 apiKey: process.env.COMPOSIO_API_KEY,
5});
6
7// Create an MCP server with the new API structure
8const mcpConfig = await composio.mcp.create(
9 "Gmail MCP Server",
10 [
11 {
12 authConfigId: "ac_auth_12", // Your auth config ID
13 allowedTools: [
14 "GMAIL_FETCH_EMAILS",
15 "GMAIL_CREATE_EMAIL_DRAFT",
16 "GMAIL_SEND_EMAIL"
17 ]
18 }
19 ],
20 {
21 isChatAuth: true // Enable chat-based authentication
22 }
23);
24
25console.log(`✅ MCP server created: ${mcpConfig.id}`);
26console.log(`🔧 Available toolkits: ${mcpConfig.toolkits.join(", ")}`);
3

Generate server URLs for users

Using the SDK:

1// Get server URLs for a specific user
2const serverUrls = await composio.mcp.getServer(
3 mcpConfig.id,
4 "user123@example.com"
5);
6
7console.log("Server URLs:", serverUrls);

Using the server ID (from create response):

1// Get server URLs using the created server ID
2const serverUrls = await composio.mcp.getServer(
3 mcpConfig.id,
4 "user123@example.com"
5);
4

Client applications connect to the server

The generated server URLs can be used directly by MCP clients. The URLs automatically handle user authentication and tool access based on your server configuration.

Example server URL structure:

https://mcp.composio.dev/composio/server/<UUID>/mcp?user_id=user123@example.com

Optional query parameters:

Query paramPurpose
user_idBind the session to a user identifier from your app
connected_account_idPin the session to a specific Composio connected account
include_composio_helper_actions=trueInclude helper tools for agent-guided authentication

Managing MCP Servers

Check User Connection Status

Before using an MCP server, you can check if a user has the necessary connected accounts:

1// Check if a user has connected accounts for all required toolkits
2const connectionStatus = await composio.mcp.getUserConnectionStatus(
3 "user123@example.com",
4 mcpConfig.id
5);
6
7console.log("Overall connection status:", connectionStatus.connected);
8console.log("Individual toolkit status:", connectionStatus.connectedToolkits);
9
10// Handle missing connections
11if (!connectionStatus.connected) {
12 Object.entries(connectionStatus.connectedToolkits).forEach(([toolkit, status]) => {
13 if (!status.connected) {
14 console.log(`❌ ${toolkit} not connected`);
15 // Guide user through authentication
16 }
17 });
18}

Find Servers by Name

1// Retrieve a server by its name
2const serverDetails = await composio.mcp.getByName("Gmail MCP Server");
3console.log("Server details:", serverDetails);

List All Servers

1// List servers with filtering options
2const servers = await composio.mcp.list({
3 page: 1,
4 limit: 10,
5 toolkits: ["gmail", "slack"], // Filter by toolkits
6 name: "production" // Filter by name
7});
8
9console.log("Found servers:", servers.items);

Update Server Configuration

1// Update an existing server (uses traditional API signature)
2const updatedServer = await composio.mcp.update(
3 "server-uuid",
4 "Updated Gmail Server",
5 [
6 {
7 toolkit: "gmail",
8 authConfigId: "ac_new_auth_config",
9 allowedTools: ["GMAIL_FETCH_EMAILS", "GMAIL_SEND_EMAIL"]
10 }
11 ],
12 { isChatAuth: true }
13);

Authentication Configuration

Authenticate users upfront via the Composio SDK/API before they use the MCP server:

1// Check what authentication is needed
2const authParams = await composio.mcp.getConnectionParams(
3 mcpConfig.id,
4 "gmail"
5);
6
7// Initiate authentication for a user
8const authRequest = await composio.mcp.authorize(
9 "user123@example.com",
10 mcpConfig.id,
11 "gmail"
12);
13
14if (authRequest.redirectUrl) {
15 console.log("Please complete authentication:", authRequest.redirectUrl);
16}

Option 2: Agent-guided Authentication

Let the agent authenticate users on-demand by including helper actions:

1const serverUrls = await composio.mcp.getServer(
2 mcpConfig.id,
3 "user123@example.com"
4);
5
6// The server URLs will include helper actions that guide users through authentication

Pre-authentication is recommended for production applications as it provides better user experience and more predictable behavior.

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 server ID - Store the server ID from the create response for generating URLs.

SSE support is deprecated. If you’re using /sse endpoints or transport=sse query parameters, migrate to the standard /mcp endpoints.

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 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 authentication on demand.