I’m currently working with MCP servers in my agent setup.
When creating the agent session, I pass all MCP servers like this:
# Create agent session with all components
self.session = AgentSession(
turn_detection=turn_detection,
stt=self.stt_service.stt_service,
vad=silero.VAD.load(),
llm=self.llm_service.llm_service,
tts=self.tts_service.tts_service,
max_tool_steps=2,
user_away_timeout=config.agent.max_silence_duration,
mcp_servers=active_mcp_servers
)
Now, I want to assign only the tools that are required for a specific agent, instead of passing all tools from all MCP servers.
For initialization, I’m doing this:
async def initialize_mcp_servers_for_multi_agent(
self, agent_name: str, mcp_servers: List[mcp.MCPServerHTTP]
) -> None:
for i, server in enumerate(mcp_servers):
logger.debug(f"Initializing MCP server {i} ({server})...")
if not server.initialized:
try:
await server.initialize()
except Exception as e:
logger.critical(f"[MCP initialize_mcp_servers_for_multi_agent]: {e}")
return
This works fine if we want all mcp tools but if want only required tools to pass llm then
The problem is: once the agent session has started, I can’t update the MCP tools (e.g., add/remove tools dynamically).
-
Is there any way to pass new tools after the agent session has already started?
-
Or alternatively, what’s the best approach to handle await server.initialize()
I noticed that if an MCP server is not running, await server.initialize() hangs and never exits.
I’m currently working with MCP servers in my agent setup.
When creating the agent session, I pass all MCP servers like this:
Now, I want to assign only the tools that are required for a specific agent, instead of passing all tools from all MCP servers.
For initialization, I’m doing this:
This works fine if we want all mcp tools but if want only required tools to pass llm then
The problem is: once the agent session has started, I can’t update the MCP tools (e.g., add/remove tools dynamically).
Is there any way to pass new tools after the agent session has already started?
Or alternatively, what’s the best approach to handle
await server.initialize()I noticed that if an MCP server is not running,
await server.initialize()hangs and never exits.