DeepAgents
Connect a DeepAgents agent to Leadovaro using langchain-mcp-adapters, which bridges DeepAgents' tool interface with Leadovaro's Streamable HTTP MCP transport.
Prerequisites
- Python 3.11+
- A Leadovaro account at app.leadovaro.com with a configured toolkit
- A Leadovaro token (generate from Install → MCP URL)
- An API key for your chosen LLM provider (e.g., Anthropic, OpenAI)
Installation
Using uv (recommended):
uv add deepagents langchain-mcp-adapters langchain-anthropic fastapi uvicorn python-dotenv
Or with pip:
pip install deepagents langchain-mcp-adapters langchain-anthropic fastapi uvicorn python-dotenv
Environment Variables
# Leadovaro token generated from app.leadovaro.com → Install → MCP URL
LEADOVARO_TOKEN=your-leadovaro-token
# API key for your chosen LLM provider
ANTHROPIC_API_KEY=your-anthropic-key # or OPENAI_API_KEY, etc.
How to generate a Leadovaro token and configure toolkit URL parameters
Connecting to Leadovaro
Use MultiServerMCPClient to connect to the Leadovaro MCP Hub during app startup, then pass the discovered tools to create_deep_agent:
import os
from contextlib import asynccontextmanager
from fastapi import FastAPI
from deepagents import create_deep_agent
from langchain_mcp_adapters.client import MultiServerMCPClient
mcp_client = None
agent = None
@asynccontextmanager
async def lifespan(app: FastAPI):
global mcp_client, agent
mcp_client = MultiServerMCPClient({
"leadovaro-nexus": {
"transport": "streamable_http",
"url": "/_sites/app.leadovaro.com/hub/mcp",
"headers": {"Authorization": f"Bearer {os.environ['LEADOVARO_TOKEN']}"},
}
})
tools = await mcp_client.get_tools()
agent = create_deep_agent(
model="anthropic:claude-sonnet-4-6", # or "openai:gpt-4o", etc.
tools=tools,
system_prompt="You are a helpful assistant with access to calendar and email tools.",
)
yield
await mcp_client.__aexit__(None, None, None)
app = FastAPI(lifespan=lifespan)
Running the Agent
from fastapi import FastAPI
from pydantic import BaseModel
class ChatRequest(BaseModel):
message: str
thread_id: str = "default"
@app.post("/chat")
async def chat(request: ChatRequest):
result = await agent.ainvoke(
{"messages": [{"role": "user", "content": request.message}]},
config={"configurable": {"thread_id": request.thread_id}},
)
return {"response": result["messages"][-1].content}
Start the server:
uv run uvicorn main:app --reload
Production Configuration
Lock to a Toolkit
For production agents, scope to a specific toolkit by adding profile to the MCP URL:
mcp_client = MultiServerMCPClient({
"leadovaro-nexus": {
"transport": "streamable_http",
"url": f"/_sites/app.leadovaro.com/hub/mcp?profile={os.environ['LEADOVARO_PROFILE_ID']}",
"headers": {"Authorization": f"Bearer {os.environ['LEADOVARO_TOKEN']}"},
}
})
When a profile is specified, the session is locked by default — the agent cannot switch toolkits or modify its own guardrails. This prevents prompt injection attacks from escaping the defined tool scope.
Environment Variable Reference
| Variable | Description |
|---|---|
LEADOVARO_TOKEN | Leadovaro token from app.leadovaro.com → Install → MCP URL |
ANTHROPIC_API_KEY | API key for your LLM provider (e.g., Anthropic, OpenAI) |
Reference Implementation
Complete implementation with FastAPI server, streaming chat UI, and production patterns