LangChainMCPAgent management tools first, then exposes the active MCP server’s tools after the model selects a server. Use it when loading every tool from every configured server would create an oversized or confusing tool list.
Enable Server Manager
Server Manager requires explicit mode with anMCPClient. It cannot run with connectors alone.
filesystem, and uses its tools. The agent rebuilds its LangChain executor when the active tool set changes.
Understand the management tools
Only one server is active at a time. The five management tools remain available alongside the active server’s cached tools.
add_mcp_server_from_config loads tools only.
connect_to_mcp_server loads tools, resources, and prompts when it first
caches a configured server.Release a server without closing its session
Despite its tool name,disconnect_from_mcp_server does not close the underlying MCP session. It sets the active server to null; the session and cached tools remain available for later selection.
Use await agent.close() to finish the agent lifecycle. LangChainMCPAgent shuts down observability, clears its executor and tools, and closes the MCPClient sessions.
Customize the manager
ImportServerManager and LangChainAdapter from the LangChain subpath. Use serverManagerFactory when you need to prefetch tools or provide a custom manager instance.
prefetchServerTools() caches tools, resources, and prompts for configured servers. It can create sessions and leaves those sessions open until client cleanup.