brief-book-57365
11/21/2025, 8:49 AMtall-airline-16756
11/21/2025, 8:50 AMtall-airline-16756
11/21/2025, 8:50 AMtools when creating it.
2. Update at runtime — call agent.update_tools() to remove or add tools dynamically after the MCP server has been connected.
If you’d like, tell me whether you prefer to filter at startup or dynamically, and share the agent SDK/language you’re using so I can provide a short code example.
Sources: Tool definition and use | LiveKit docsbrief-book-57365
11/21/2025, 8:51 AMtall-airline-16756
11/21/2025, 8:52 AMagent.update_tools() at runtime). Below is a concise example that fits your existing setup.
1) Helper to fetch and convert MCP tools:
import httpx
from livekit.protocol.agent import FunctionCall # convert to agent tool type
async def list_tools_from_mcp_server(capabilities_url: str):
async with httpx.AsyncClient() as client:
r = await client.get(capabilities_url)
r.raise_for_status()
capabilities = r.json()
tools = []
for t in capabilities.get("tools", []):
# Build a FunctionCall (or your agent's tool type) from MCP tool metadata
tools.append(
FunctionCall(
name=t["name"],
description=t.get("description", ""),
parameters=t.get("parameters", {}), # adapt if needed
)
)
return tools
2) Create filtered AgentSession (filter by name here):
from livekit.agents import AgentSession, mcp
from livekit.plugins import openai, silero, deepgram
# import your MultilingualModel class
async def create_agent_with_filtered_mcp():
# fetch all MCP tools
all_tools = await list_tools_from_mcp_server("http://localhost:8000/capabilities")
# choose which tools to allow (allowlist example)
allowed = {"get_weather", "search_knowledge_base"}
filtered_tools = [t for t in all_tools if t.name in allowed]
session = AgentSession(
vad=silero.VAD.load(),
stt=deepgram.STT(model="nova-3", language="multi"),
llm=openai.LLM(model="gpt-4o-mini"),
tts=openai.TTS(voice="ash"),
turn_detection=MultilingualModel(),
mcp_servers=[
mcp.MCPServerHTTP(url="http://localhost:8000/sse"),
],
tools=filtered_tools, # enforce only these tools are available
)
return session
3) Alternative: update tools at runtime
# after you have a running agent instance
await agent.update_tools(filtered_tools)
Notes:
• Use GET /capabilities (or your MCP server's equivalent) to list tools.
• Filtering can be done by name, description, parameters, or any other metadata.
• Passing tools= to AgentSession enforces only those tools are available; agent.update_tools() lets you change tools dynamically.
Would you like a version that filters by capability type or parameter schema instead of tool name?
Sources: Tool definition and use | LiveKit docs