MCP Integration

Connect to MCP servers and use their tools in your app

Provider-Level Config

The simplest way to add MCP servers — configure them directly on CopilotProvider:

import { CopilotProvider } from '@yourgpt/copilot-sdk/react';
import { CopilotChat } from '@yourgpt/copilot-sdk/ui';

function App() {
  return (
    <CopilotProvider
      runtimeUrl="/api/chat"
      mcpServers={[
        {
          name: "mcp360",
          transport: "http",
          url: "https://connect.mcp360.ai/v1/mcp360/mcp?token=YOUR_TOKEN",
        },
        {
          name: "github",
          transport: "http",
          url: "https://mcp.github.com",
          headers: { Authorization: `Bearer ${githubToken}` },
        },
      ]}
    >
      <CopilotChat />
    </CopilotProvider>
  );
}

All servers connect automatically and tools are registered with the AI.

MCPServerConfig Options

OptionTypeDefaultDescription
namestringRequiredUnique identifier for this server
transport"http" | "sse"RequiredTransport type
urlstringRequiredServer URL
headersRecord<string, string>{}Custom HTTP headers
timeoutnumber30000Request timeout in ms
prefixToolNamesbooleantruePrefix tools with server name

useMCPTools Hook

For more control, use the hook directly inside CopilotProvider:

function Chat() {
  const { isConnected, isLoading, toolDefinitions } = useMCPTools({
    name: "mcp360",
    transport: "http",
    url: "https://connect.mcp360.ai/v1/mcp360/mcp?token=YOUR_TOKEN",
  });

  return <CopilotChat />;
}

Hook Return Values

PropertyTypeDescription
isConnectedbooleanWhether connected to the server
isLoadingbooleanWhether connection is in progress
toolDefinitionsToolDefinition[]Available tools
stateMCPClientStateFull connection state including errors
connect() => PromiseManually connect
disconnect() => PromiseDisconnect
callTool(name, args) => PromiseCall a tool directly

Transport Types

useMCPTools({ name: "server", transport: "http", url: "https://mcp.example.com" });

Best for most remote MCP servers.

useMCPTools({ name: "realtime", transport: "sse", url: "https://mcp.example.com/events" });

Best for real-time streaming connections.


Multiple Servers

Call the hook multiple times — all tools register with the same CopilotProvider:

function Chat() {
  useMCPTools({ name: "github", transport: "http", url: "https://mcp.github.com", headers: { Authorization: `Bearer ${githubToken}` } });
  useMCPTools({ name: "slack", transport: "http", url: "https://mcp.slack.com", headers: { Authorization: `Bearer ${slackToken}` } });

  return <CopilotChat />;
}

With prefixToolNames: true (default), tools are namespaced to avoid conflicts: github_create_issue, slack_send_message.


MCP-UI

MCP-UI extends MCP to allow tools to return interactive HTML components — product cards, forms, charts — rendered inline in chat.

function Chat() {
  useMCPTools({ name: "shop", transport: "http", url: "/api/mcp" });

  const { handleIntent } = useMCPUIIntents({
    onIntent: (action, data) => {
      if (action === "add_to_cart") addToCart(data.productId, data.quantity);
    },
    onPrompt: (text) => setChatInput(text),
    onNotify: (message, level) => toast[level || "info"](message),
  });

  return <CopilotChat onUIIntent={handleIntent} />;
}

Intent Types

TypeHandlerDescription
intentonIntentSemantic action for your app
promptonPromptAdd text to chat input
notifyonNotifyShow notification
linkonLinkOpen a URL
toolonToolCallCall another MCP tool

Error Handling

const { state } = useMCPTools({
  name: "server",
  transport: "http",
  url: "https://mcp.example.com",
  onError: (error) => console.error(`MCP Error: ${error.message}`),
});

// state.connectionState: "disconnected" | "connecting" | "connected" | "error"

MCP360 Gateway

Access 100+ tools through a single connection with MCP360:

useMCPTools({
  name: "mcp360",
  transport: "http",
  url: "https://connect.mcp360.ai/v1/mcp360/mcp?token=YOUR_TOKEN",
});

MCP360 includes web search, scraping, SEO tools, e-commerce data, and more. Explore all tools →

On this page