MCP Integration
Connect to external tool servers using the Model Context Protocol
The chat UI supports Model Context Protocol (MCP) for connecting to external tool servers. MCP enables LLMs to access tools, resources, and prompts from any compatible server, extending capabilities beyond built-in frontend tools.
Overview
MCP integration runs entirely in the browser, connecting to external MCP servers via HTTP. When you connect to an MCP server, its tools become available to models during chat sessions.
Key capabilities:
- Connect to multiple MCP servers simultaneously
- Automatic tool discovery from connected servers
- Per-server and per-tool enable/disable controls
- Persistent server configuration across sessions
- Real-time connection status monitoring
Transport
The implementation uses the Streamable HTTP transport (MCP specification 2025-03-26), which provides:
| Feature | Description |
|---|---|
| Single endpoint | All communication through one HTTP URL |
| Session management | Mcp-Session-Id header for stateful connections |
| Bidirectional | POST requests + Server-Sent Events (SSE) for notifications |
| Resumable | Event IDs enable reconnection without data loss |
| Browser-compatible | Works in web environments (unlike stdio transport) |
Stdio transport is not supported as it requires process-level access unavailable in browsers. Use MCP servers that expose an HTTP endpoint.
Adding a Server
Via the UI
- Click the Tools button in the chat input toolbar
- Click Configure next to MCP Servers (or the plug icon)
- Click Add Server
- Fill in the server details:
| Field | Required | Description |
|---|---|---|
| Name | Yes | Display name (e.g., "GitHub Tools") |
| URL | Yes | HTTP endpoint (e.g., https://mcp.example.com/api) |
| Headers | No | JSON object for authentication headers |
Authentication Headers
For servers requiring authentication, add headers as a JSON object:
{
"Authorization": "Bearer your-api-key",
"X-Custom-Header": "value"
}Common authentication patterns:
| Provider | Header Format |
|---|---|
| API Key | {"Authorization": "Bearer sk-..."} |
| Basic Auth | {"Authorization": "Basic base64-encoded"} |
| Custom | {"X-API-Key": "your-key"} |
Connecting to Servers
After adding a server, click Connect to establish a session. The connection process:
1. Initialize handshake (protocol version, capabilities)
2. Server returns session ID and available capabilities
3. Client sends initialized notification
4. SSE stream opened for server notifications
5. Tool discovery via tools/list
6. Status changes to "connected"Connection Status
| Status | Indicator | Description |
|---|---|---|
| Disconnected | Gray | Not connected |
| Connecting | Blue (animated) | Handshake in progress |
| Connected | Green | Ready to use |
| Error | Red | Connection failed (hover for details) |
Servers auto-reconnect if the SSE stream drops. Manual reconnection is available via the Connect button.
Tool Discovery
Once connected, the client automatically discovers available tools:
// Example discovered tools from a GitHub MCP server
[
{
name: "search_repos",
description: "Search GitHub repositories",
inputSchema: {
type: "object",
properties: {
query: { type: "string", description: "Search query" },
sort: { type: "string", enum: ["stars", "forks", "updated"] }
},
required: ["query"]
}
},
{
name: "create_issue",
description: "Create a GitHub issue",
inputSchema: { ... }
}
]Managing Tools
Each tool can be individually enabled or disabled:
- Expand a connected server in the MCP configuration modal
- Toggle individual tools on/off
- Disabled tools are not sent to the model
Tool preferences persist across sessions in localStorage.
Using MCP Tools in Chat
Enabling MCP
- Click Tools in the chat input toolbar
- Enable MCP Servers
- Ensure at least one server is connected with enabled tools
Tool Registration
When MCP is enabled, tools from connected servers are automatically added to the model's available functions. Tools use namespaced names to prevent conflicts:
Format: mcp_{serverId}_{toolName}
Examples:
- mcp_github-server_search_repos
- mcp_github-server_create_issue
- mcp_slack-server_send_messageThe model sees tools with descriptions prefixed by the server name:
[MCP: GitHub Tools] Search GitHub repositoriesExecution Flow
1. User sends message with MCP enabled
2. Model decides to call an MCP tool
3. Frontend parses tool name to extract server ID and tool name
4. Request sent to MCP server via tools/call
5. Server executes tool and returns result
6. Result formatted and sent back to model
7. Model continues with tool resultTool Results
MCP tools can return multiple content types:
| Type | Handling |
|---|---|
| Text | Displayed as-is |
| Image | Shown as [Image: mime/type] |
| Resource | Text content extracted, blobs noted |
Example tool result:
{
"content": [
{
"type": "text",
"text": "Found 50 repositories:\n1. facebook/react (220k stars)..."
}
],
"isError": false
}Configuration
Server Configuration
Server configurations are persisted to localStorage:
interface MCPServerConfig {
id: string; // Auto-generated unique ID
name: string; // Display name
url: string; // HTTP endpoint
enabled: boolean; // Whether server is active
headers?: {
// Optional auth headers
[key: string]: string;
};
toolsEnabled: {
// Per-tool enable state
[toolName: string]: boolean;
};
}Client Settings
| Setting | Default | Description |
|---|---|---|
| Timeout | 30 seconds | Request timeout for tool calls |
| Protocol version | 2024-11-05 | MCP protocol version |
Persisted vs Ephemeral State
| Persisted (localStorage) | Ephemeral (session only) |
|---|---|
| Server configurations | Connection status |
| Tool enable/disable preferences | Discovered tools list |
| Authentication headers | Server capabilities |
| Error messages |
Refreshing the page disconnects all servers. Enabled servers automatically reconnect when you return to the chat.
Protocol Support
Client Capabilities
The client advertises these capabilities to servers:
{
"tools": { "progress": false },
"resources": { "subscribe": false }
}Supported Methods
| Category | Method | Description |
|---|---|---|
| Tools | tools/list | List available tools (paginated) |
| Tools | tools/call | Execute a tool |
| Resources | resources/list | List available resources |
| Resources | resources/read | Read resource content |
| Prompts | prompts/list | List available prompts |
| Prompts | prompts/get | Get prompt with arguments |
| Utility | ping | Check server connectivity |
Notification Types
The client handles these server notifications via SSE:
| Notification | Action |
|---|---|
notifications/tools/list_changed | Re-fetch tool list |
notifications/resources/list_changed | Re-fetch resource list |
notifications/prompts/list_changed | Re-fetch prompt list |
Error Handling
Connection Errors
| Error | Cause | Resolution |
|---|---|---|
| Connection refused | Server not running | Start the MCP server |
| 401 Unauthorized | Invalid credentials | Check authentication headers |
| Network error | Firewall/proxy blocking | Verify network access to server URL |
| Timeout | Server unresponsive | Increase timeout or check server health |
Connection errors are displayed in the UI with the error message visible on hover.
Tool Execution Errors
When a tool fails, the error is returned to the model:
{
"success": false,
"error": "Repository not found",
"output": "{\"error\": \"Repository not found\", \"serverId\": \"github\", \"toolName\": \"get_repo\"}"
}The model can then handle the error appropriately (retry, ask for clarification, etc.).
Example Workflow
1. Set Up a GitHub MCP Server
Name: GitHub Tools
URL: https://your-mcp-server.com/github
Headers: {"Authorization": "Bearer ghp_xxxx"}2. Connect and Discover Tools
After connecting, you see:
search_repos- Search GitHub repositoriesget_repo- Get repository detailscreate_issue- Create an issuelist_issues- List repository issues
3. Use in Chat
User: Find popular React component libraries on GitHub
Model: I'll search GitHub for React component libraries.
Calls mcp_github-tools_search_repos with:
{
"query": "react components library stars:>1000",
"sort": "stars"
}Tool Result:
Found 25 repositories:
1. chakra-ui/chakra-ui (35k stars) - Simple, modular component library
2. shadcn/ui (45k stars) - Beautifully designed components
3. ant-design/ant-design (88k stars) - Enterprise UI design language
...Model: Here are the most popular React component libraries on GitHub...
Comparison with Frontend Tools
| Feature | Frontend Tools | MCP Tools |
|---|---|---|
| Execution | Browser (WASM) | External server |
| Latency | Very low | Network dependent |
| Capabilities | Fixed (Python, JS, SQL, etc.) | Unlimited (server-defined) |
| Setup | None | Server configuration |
| Offline | Yes | No |
| Security | Sandboxed | Server-controlled |
Use frontend tools for general computation and data analysis. Use MCP for external integrations, file system access, database queries, and custom enterprise tools.
Security Considerations
Server Trust
MCP servers can execute arbitrary actions. Only connect to trusted servers:
- Verify the server URL is legitimate
- Use HTTPS for all connections
- Review available tools before enabling
Credential Storage
Authentication headers are stored in localStorage:
- Accessible to JavaScript on the same origin
- Consider using short-lived tokens where possible
- Clear server configurations when using shared computers
Network Security
- All requests use the configured URL directly
- No server-side proxy (requests go from browser to MCP server)
- CORS must be configured on the MCP server to allow browser requests
MCP servers have full access to execute their defined tools. Only connect to servers you trust and review available tools before use.
Troubleshooting
Server won't connect
- Check URL: Ensure the endpoint is correct and accessible
- Check CORS: Server must allow requests from your origin
- Check auth: Verify authentication headers are correct
- Check network: Try accessing the URL directly in browser
Tools not appearing
- Check connection: Ensure status shows "Connected"
- Check capabilities: Server must advertise tool support
- Check tool list: Server's
tools/listmust return tools
Tool execution fails
- Check arguments: Ensure model is providing valid inputs
- Check server logs: Review MCP server for error details
- Check timeout: Long-running tools may need longer timeouts
SSE notifications not working
- Check browser console: Look for EventSource errors
- Check server support: Server must support GET requests for SSE
- Notifications are optional: Core functionality works without them