can i filter tools for an mcp server added to an a...
# ask-ai
b
can i filter tools for an mcp server added to an agent?
t
Thanks for reaching out, Antonio. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Regarding filtering tools for an MCP server added to an agent: yes — you can filter which MCP-provided tools the agent exposes. You control this on the agent side by managing the agent’s tools list when initializing or at runtime. Two common approaches: 1. Filter during initialization — load tools from the MCP server but only pass the selected subset into the agent’s
tools
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 docs
b
can you show me how? I just added the mcp server like so 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"), ], )
t
You can filter MCP-provided tools by fetching the MCP server’s capabilities, selecting the tools you want, and then passing that filtered list into the AgentSession (or calling
agent.update_tools()
at runtime). Below is a concise example that fits your existing setup. 1) Helper to fetch and convert MCP tools:
Copy code
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):
Copy code
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
Copy code
# 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