Client for connecting to multiple MCP servers and loading LC tools/resources.
This module provides the MultiServerMCPClient class for managing connections
to multiple MCP servers and loading tools, prompts, resources, and server info
from them.
Load MCP prompt and convert to LangChain messages.
Load MCP resources and convert them to LangChain Blob objects.
Load server info from the MCP initialize handshake.
Returns the full InitializeResult from the MCP protocol, which includes
server instructions, capabilities, implementation details, and protocol
version.
Unlike load_mcp_tools,
load_mcp_prompt and
load_mcp_resources,
which expect an already-initialized session, this function performs the
initialize() handshake itself and therefore requires a session that has
not been initialized yet. MultiServerMCPClient.session() initializes
by default, so pass auto_initialize=False when obtaining a session for
this function. Passing an already-initialized session raises ValueError
rather than re-running the handshake.
There is no way to recover an InitializeResult from a session that is
already initialized: the MCP SDK caches only capabilities and discards
instructions, serverInfo and protocolVersion.
Create a new session to an MCP server.
Load all available MCP tools and convert them to LangChain tools.
LangChain MCP client callback context.
Callbacks for the LangChain MCP client.
Protocol for tool call interceptors using handler callback pattern.
Interceptors wrap tool execution to enable request/response modification, retry logic, caching, rate limiting, and other cross-cutting concerns. Multiple interceptors compose in "onion" pattern (first is outermost).
The handler can be called multiple times (retry), skipped (caching/short-circuit), or wrapped with error handling. Each handler call is independent.
Similar to LangChain's middleware pattern but adapted for MCP remote tools.
Protocol for creating httpx.AsyncClient instances for MCP connections.
Configuration for Server-Sent Events (SSE) transport connections to MCP.
Configuration for stdio transport connections to MCP servers.
Connection configuration for Streamable HTTP transport.
Configuration for WebSocket transport connections to MCP servers.
Client for connecting to multiple MCP servers.
Loads LangChain-compatible tools, prompts and resources from MCP servers, and retrieves server info from them.