How should I provide an agent to a LangGraph server?

hi @wigging

MultiServerMCPClient dropped context manager support in 0.1.0
The async with MultiServerMCPClient({...}) as mcp: syntax was removed. You now have two correct approaches:

Option A - client.get_tools() (simplest):

client = MultiServerMCPClient(connections=MCP_CONNECTIONS)
tools = await client.get_tools()

Option B - client.session() + load_mcp_tools() (explicit per-server control, what deepagents CLI uses internally in mcp_tools.py):

from contextlib import AsyncExitStack
from langchain_mcp_adapters.tools import load_mcp_tools

client = MultiServerMCPClient(connections=MCP_CONNECTIONS)
async with AsyncExitStack() as stack:
    session = await stack.enter_async_context(client.session("your-server"))
    tools = await load_mcp_tools(session, server_name="your-server")

Updated ServerRuntime pattern (post-0.1.0)

@contextlib.asynccontextmanager
async def get_agent(runtime: ServerRuntime):
    if runtime.execution_runtime:
        client = MultiServerMCPClient(connections=MCP_CONNECTIONS)
        async with AsyncExitStack() as stack:
            all_tools = []
            for server_name in MCP_CONNECTIONS:
                session = await stack.enter_async_context(client.session(server_name))
                tools = await load_mcp_tools(session, server_name=server_name)
                all_tools.extend(tools)
            yield create_agent(llm, tools=all_tools)
            # AsyncExitStack cleans up all sessions on exit
    else:
        yield _base_agent

Or the minimal single-server form using get_tools():

@contextlib.asynccontextmanager
async def get_agent(runtime: ServerRuntime):
    if runtime.execution_runtime:
        tools = await MultiServerMCPClient(connections=MCP_CONNECTIONS).get_tools()
        yield create_agent(llm, tools=tools)
    else:
        yield _base_agent

Alternative (load once at startup): If the MCP server is stable, compile the graph at module level using asyncio.run() - that’s exactly what the deepagents CLI does in server_graph.py. Trade-off: if the MCP session drops, you must restart the LangGraph server process to reconnect.