-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Open
Labels
Description
Please read this first
- Have you read the docs?Agents SDK docs
- Have you searched for related issues? Others may have had similar requests
Describe the feature
Currently the UX around initializing multiple MCP Servers is a little cumbersome for the users. The CUJ mentioned in the docs would be as follows:
async with (
MCPServerStreamableHttp(...) as mcp_server_a,
MCPServerStreamableHttp(...) as mcp_server_b,
MCPServerStreamableHttp(...) as mcp_server_c,
):
agent = Agent(
...,
mcp_servers=[
mcp_server_a,
mcp_server_b,
mcp_server_c,
],
)
result = await Runner.run(agent, ...)
Some drawbacks of this can include:
- Verbose setup of multiple McpServers with async compared to Tools which can just be passed in as a list
- Handling the async lifecycle of each McpServer individually causes a tight coupling between MCP Server initialization, agent initialization and agent invocation
- Initializing Agent and running of the agent in the async clause can be cumbersome for Multi Agent usecases where agents can be defined in multiple different files
Some potential solutions for this can include:
- Introducing a McpManger
This manager can take in multiple mcp servers and manage a group connection of all MCP Servers, simplifying the code and also decoupling mcp server initialization, agent initialization and the invocation of the agent.
- Example CUJ from a previous ticket: How to properly invoke non-hosted MCP server in multi-agent workflow? #1881 (comment)
- Similar CUJ supported in langchain: https://github.com/langchain-ai/langchain-mcp-adapters?tab=readme-ov-file#client-1
- Completely manage the lifecycle for the session connections
To make the experience even simpler, the library can be updated to manage the async connections internally which can auto connect to the mcp session on startup and clean up the connections on exit or with an explicitclosemethod.
agent = Agent(
mcp_servers=[
MCPServerStreamableHttp(...),
MCPServerStreamableHttp(...),
]
)
result = await agent.run(...)
Would it be possible to introduce any of these?