11"""Client for connecting to multiple MCP servers and loading LangChain tools/resources.
22
3- This module provides the MultiServerMCPClient class for managing connections to multiple
3+ This module provides the ` MultiServerMCPClient` class for managing connections to multiple
44MCP servers and loading tools, prompts, and resources from them.
55"""
66
@@ -55,49 +55,49 @@ def __init__(
5555 callbacks : Callbacks | None = None ,
5656 tool_interceptors : list [ToolCallInterceptor ] | None = None ,
5757 ) -> None :
58- """Initialize a MultiServerMCPClient with MCP servers connections.
58+ """Initialize a ` MultiServerMCPClient` with MCP servers connections.
5959
6060 Args:
61- connections: A dictionary mapping server names to connection configurations.
62- If None, no initial connections are established.
61+ connections: A `dict` mapping server names to connection configurations. If
62+ ` None` , no initial connections are established.
6363 callbacks: Optional callbacks for handling notifications and events.
6464 tool_interceptors: Optional list of tool call interceptors for modifying
6565 requests and responses.
6666
67- Example: basic usage (starting a new session on each tool call)
68-
69- ```python
70- from langchain_mcp_adapters.client import MultiServerMCPClient
71-
72- client = MultiServerMCPClient(
73- {
74- "math": {
75- "command": "python",
76- # Make sure to update to the full absolute path to your
77- # math_server.py file
78- "args": ["/path/to/math_server.py"],
79- "transport": "stdio",
80- },
81- "weather": {
82- # Make sure you start your weather server on port 8000
83- "url": "http://localhost:8000/mcp",
84- "transport": "streamable_http",
67+ !!! example "Basic usage (starting a new session on each tool call)"
68+
69+ ```python
70+ from langchain_mcp_adapters.client import MultiServerMCPClient
71+
72+ client = MultiServerMCPClient(
73+ {
74+ "math": {
75+ "command": "python",
76+ # Make sure to update to the full absolute path to your
77+ # math_server.py file
78+ "args": ["/path/to/math_server.py"],
79+ "transport": "stdio",
80+ },
81+ "weather": {
82+ # Make sure you start your weather server on port 8000
83+ "url": "http://localhost:8000/mcp",
84+ "transport": "streamable_http",
85+ }
8586 }
86- }
87- )
88- all_tools = await client.get_tools()
89- ```
87+ )
88+ all_tools = await client.get_tools()
89+ ```
9090
91- Example: explicitly starting a session
91+ !!! example "Explicitly starting a session"
9292
93- ```python
94- from langchain_mcp_adapters.client import MultiServerMCPClient
95- from langchain_mcp_adapters.tools import load_mcp_tools
93+ ```python
94+ from langchain_mcp_adapters.client import MultiServerMCPClient
95+ from langchain_mcp_adapters.tools import load_mcp_tools
9696
97- client = MultiServerMCPClient({...})
98- async with client.session("math") as session:
99- tools = await load_mcp_tools(session)
100- ```
97+ client = MultiServerMCPClient({...})
98+ async with client.session("math") as session:
99+ tools = await load_mcp_tools(session)
100+ ```
101101 """
102102 self .connections : dict [str , Connection ] = (
103103 connections if connections is not None else {}
@@ -122,7 +122,7 @@ async def session(
122122 ValueError: If the server name is not found in the connections
123123
124124 Yields:
125- An initialized ClientSession
125+ An initialized ` ClientSession`
126126
127127 """
128128 if server_name not in self .connections :
@@ -148,12 +148,14 @@ async def get_tools(self, *, server_name: str | None = None) -> list[BaseTool]:
148148
149149 Args:
150150 server_name: Optional name of the server to get tools from.
151- If None, all tools from all servers will be returned (default).
151+ If `None`, all tools from all servers will be returned.
152+
153+ !!! note
152154
153- NOTE: a new session will be created for each tool call
155+ A new session will be created for each tool call
154156
155157 Returns:
156- A list of LangChain tools
158+ A list of LangChain [ tools](https://docs.langchain.com/oss/python/langchain/tools)
157159
158160 """
159161 if server_name is not None :
@@ -214,7 +216,7 @@ async def get_resources(
214216 all resources will be loaded.
215217
216218 Returns:
217- A list of LangChain Blobs
219+ A list of LangChain [Blob][langchain_core.documents.base.Blob] objects.
218220
219221 """
220222 async with self .session (server_name ) as session :
0 commit comments