Connecting Letta to Remote MCP Servers

Using Streamable HTTP and SSE transports

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

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

Agent Id Header

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.

Agent Scoped Variables

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.
1from letta_client import Letta
2from letta_client.types import StreamableHTTPServerConfig, MCPServerType
3
4client = Letta(token="LETTA_API_KEY")
5
6# Connect a Streamable HTTP server with Bearer token auth
7streamable_config = StreamableHTTPServerConfig(
8 server_name="my-server",
9 type=MCPServerType.STREAMABLE_HTTP,
10 server_url="https://mcp-server.example.com/mcp",
11 auth_header="Authorization",
12 auth_token="Bearer your-token", # Include "Bearer " prefix
13 custom_headers={"X-API-Version": "v1"} # Additional custom headers
14)
15
16client.tools.add_mcp_server(request=streamable_config)
17
18# Example with templated variables for agent-scoped authentication
19agent_scoped_config = StreamableHTTPServerConfig(
20 server_name="user-specific-server",
21 type=MCPServerType.STREAMABLE_HTTP,
22 server_url="https://api.example.com/mcp",
23 auth_header="Authorization",
24 auth_token="Bearer {{AGENT_API_KEY | api_key}}", # Agent-specific API key
25 custom_headers={
26 "X-User-ID": "{{AGENT_API_KEY | user_id}}", # Agent-specific user ID
27 "X-API-Version": "v2"
28 }
29)
30
31client.tools.add_mcp_server(request=agent_scoped_config)

SSE (Deprecated)

SSE is deprecated. Use Streamable HTTP for new integrations if available.

For legacy MCP servers that only support SSE.

ADE: Tool Manager → Add MCP Server → SSE

Agent Id Header

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.

Agent Scoped Variables

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.
1from letta_client import Letta
2from letta_client.types import SseServerConfig, MCPServerType
3
4client = Letta(token="LETTA_API_KEY")
5
6# Connect a SSE server (legacy)
7sse_config = SseServerConfig(
8 server_name="legacy-server",
9 type=MCPServerType.SSE,
10 server_url="https://legacy-mcp.example.com/sse",
11 auth_header="Authorization",
12 auth_token="Bearer optional-token" # Include "Bearer " prefix
13 custom_headers={
14 "X-User-ID": "{{AGENT_API_KEY | user_id}}", # Agent-specific user ID
15 "X-API-Version": "v2"
16 }
17)
18
19client.tools.add_mcp_server(request=sse_config)

Using MCP Tools

ADE: Agent → Tools → Select MCP tools

1from letta_client import Letta
2
3client = Letta(token="LETTA_API_KEY")
4
5# List tools from an MCP server
6tools = client.tools.list_mcp_tools_by_server(mcp_server_name="weather-server")
7
8# Add a specific tool from the MCP server
9tool = client.tools.add_mcp_tool(
10 mcp_server_name="weather-server",
11 mcp_tool_name="get_weather"
12)
13
14# Create agent with MCP tool attached
15agent_state = client.agents.create(
16 model="openai/gpt-4o-mini",
17 embedding="openai/text-embedding-3-small",
18 tool_ids=[tool.id]
19)
20
21# Or attach tools to an existing agent
22client.agents.tool.attach(
23 agent_id=agent_state.id
24 tool_id=tool.id
25)
26
27# Use the agent with MCP tools
28response = client.agents.messages.create(
29 agent_id=agent_state.id,
30 messages=[
31 {
32 "role": "user",
33 "content": "Use the weather tool to check the forecast"
34 }
35 ]
36)