Skip to content

Simplify multi-MCP server initialization #2058

@aravind-segu

Description

@aravind-segu

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:

  1. 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.
  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 explicit close method.
agent = Agent(
    mcp_servers=[
        MCPServerStreamableHttp(...),
        MCPServerStreamableHttp(...),
    ]
)
result = await agent.run(...)

Would it be possible to introduce any of these?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions