Skip to content
  • Auto
  • Light
  • Dark
DiscordForumGitHubSign up
Tools
Model Context Protocol
View as Markdown
Copy Markdown

Open in Claude
Open in ChatGPT

Connecting Letta to Remote MCP Servers

Remote MCP servers work with both Letta Cloud and self-hosted deployments. Streamable HTTP is recommended for new integrations; SSE is deprecated but supported for legacy compatibility.

Streamable HTTP is the recommended transport with support for MCP servers that use Bearer authorization, API keys, or OAuth 2.1. Letta also supports passing in custom headers for additional configuration.

ADE: Tool Manager → Add MCP Server → Streamable HTTP

When Letta makes tool calls to an MCP server, it includes the following in the HTTP request header:

  • x-agent-id: The ID of the agent making the tool call

If you’re implementing your own MCP server, this can be used to make requests against your Letta Agent via our API/SDK.

Letta recognizes templated variables in the custom header and auth token fields to allow for agent-scoped parameters defined in your tool variables:

  • For example, {{ AGENT_API_KEY }} will use the AGENT_API_KEY tool variable if available.
  • To provide a default value, {{ AGENT_API_KEY | api_key }} will fallback to api_key if AGENT_API_KEY is not set.
  • This is supported in the ADE as well when configuring API key/access tokens and custom headers.
import { LettaClient, Letta } from "@letta-ai/letta-client";
const client = new LettaClient({ token: "LETTA_API_KEY" });
// Connect a Streamable HTTP server with Bearer token auth
const streamableConfig: Letta.StreamableHttpServerConfig = {
serverName: "my-server",
type: Letta.McpServerType.StreamableHttp,
serverUrl: "https://mcp-server.example.com/mcp",
authHeader: "Authorization",
authToken: "Bearer your-token", // Include "Bearer " prefix
customHeaders: {
"X-API-Version": "v1", // Additional custom headers
},
};
await client.tools.addMcpServer(streamableConfig);
// Example with templated variables for agent-scoped authentication
const agentScopedConfig: Letta.StreamableHttpServerConfig = {
serverName: "user-specific-server",
type: Letta.McpServerType.StreamableHttp,
serverUrl: "https://api.example.com/mcp",
authHeader: "Authorization",
authToken: "Bearer {{AGENT_API_KEY | api_key}}", // Agent-specific API key
customHeaders: {
"X-User-ID": "{{AGENT_API_KEY | user_id}}", // Agent-specific user ID
"X-API-Version": "v2",
},
};
await client.tools.addMcpServer(agentScopedConfig);

For legacy MCP servers that only support SSE.

ADE: Tool Manager → Add MCP Server → SSE

When Letta makes tool calls to an MCP server, it includes the following in the HTTP request header:

  • x-agent-id: The ID of the agent making the tool call

If you’re implementing your own MCP server, this can be used to make requests against your Letta Agent via our API/SDK.

Letta recognizes templated variables in the custom header and auth token fields to allow for agent-scoped parameters defined in your tool variables:

  • For example, {{ AGENT_API_KEY }} will use the AGENT_API_KEY tool variable if available.
  • To provide a default value, {{ AGENT_API_KEY | api_key }} will fallback to api_key if AGENT_API_KEY is not set.
  • This is supported in the ADE as well when configuring API key/access tokens and custom headers.
import { LettaClient, Letta } from '@letta-ai/letta-client';
const client = new LettaClient({ token: "LETTA_API_KEY" });
// Connect a SSE server (legacy)
const sseConfig: Letta.SseServerConfig = {
serverName: "legacy-server",
type: Letta.McpServerType.Sse,
serverUrl: "https://legacy-mcp.example.com/sse",
authHeader: "Authorization",
authToken: "Bearer optional-token" // Include "Bearer " prefix
customHeaders: {
"X-User-ID": "{{AGENT_API_KEY | user_id}}", // Agent-specific user ID
"X-API-Version": "v2"
}
};
await client.tools.addMcpServer(sseConfig);

ADE: Agent → Tools → Select MCP tools

import { LettaClient } from "@letta-ai/letta-client";
const client = new LettaClient({ token: "LETTA_API_KEY" });
// List tools from an MCP server
const tools = await client.tools.listMcpToolsByServer("weather-server");
// Add a specific tool from the MCP server
const tool = await client.tools.addMcpTool("weather-server", "get_weather");
// Create agent with MCP tool
const agentState = await client.agents.create({
model: "openai/gpt-4o-mini",
embedding: "openai/text-embedding-3-small",
toolIds: [tool.id],
});
// Use the agent with MCP tools
const response = await client.agents.messages.create(agentState.id, {
messages: [
{
role: "user",
content: "Use the weather tool to check the forecast",
},
],
});