Skip to content

Commit 8b02c53

Browse files
authored
fix: refs styling (#354)
1 parent e83c0c7 commit 8b02c53

File tree

4 files changed

+66
-60
lines changed

4 files changed

+66
-60
lines changed

langchain_mcp_adapters/client.py

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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
44
MCP 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:

langchain_mcp_adapters/prompts.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Prompts adapter for converting MCP prompts to LangChain messages.
1+
"""Prompts adapter for converting MCP prompts to LangChain [messages](https://docs.langchain.com/oss/python/langchain/messages).
22
33
This module provides functionality to convert MCP prompt messages into LangChain
44
message objects, handling both user and assistant message types.
@@ -41,15 +41,16 @@ async def load_mcp_prompt(
4141
*,
4242
arguments: dict[str, Any] | None = None,
4343
) -> list[HumanMessage | AIMessage]:
44-
"""Load MCP prompt and convert to LangChain messages.
44+
"""Load MCP prompt and convert to LangChain [messages](https://docs.langchain.com/oss/python/langchain/messages).
4545
4646
Args:
4747
session: The MCP client session.
4848
name: Name of the prompt to load.
4949
arguments: Optional arguments to pass to the prompt.
5050
5151
Returns:
52-
A list of LangChain messages converted from the MCP prompt.
52+
A list of LangChain [messages](https://docs.langchain.com/oss/python/langchain/messages)
53+
converted from the MCP prompt.
5354
"""
5455
response = await session.get_prompt(name, arguments)
5556
return [

langchain_mcp_adapters/resources.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
"""Resources adapter for converting MCP resources to LangChain Blobs.
1+
"""Resources adapter for converting MCP resources to LangChain [Blob objects][langchain_core.documents.base.Blob].
22
33
This module provides functionality to convert MCP resources into LangChain Blob
44
objects, handling both text and binary resource content types.
5-
"""
5+
""" # noqa: E501
66

77
import base64
88

@@ -38,15 +38,15 @@ def convert_mcp_resource_to_langchain_blob(
3838

3939

4040
async def get_mcp_resource(session: ClientSession, uri: str) -> list[Blob]:
41-
"""Fetch a single MCP resource and convert it to LangChain Blobs.
41+
"""Fetch a single MCP resource and convert it to LangChain [Blob objects][langchain_core.documents.base.Blob].
4242
4343
Args:
4444
session: MCP client session.
4545
uri: URI of the resource to fetch.
4646
4747
Returns:
48-
A list of LangChain Blobs.
49-
"""
48+
A list of LangChain [Blob][langchain_core.documents.base.Blob] objects.
49+
""" # noqa: E501
5050
contents_result = await session.read_resource(uri)
5151
if not contents_result.contents or len(contents_result.contents) == 0:
5252
return []
@@ -62,21 +62,24 @@ async def load_mcp_resources(
6262
*,
6363
uris: str | list[str] | None = None,
6464
) -> list[Blob]:
65-
"""Load MCP resources and convert them to LangChain Blobs.
65+
"""Load MCP resources and convert them to LangChain [Blob objects][langchain_core.documents.base.Blob].
6666
6767
Args:
6868
session: MCP client session.
69-
uris: List of URIs to load. If None, all resources will be loaded.
70-
Note: Dynamic resources will NOT be loaded when None is specified,
71-
as they require parameters and are ignored by the MCP SDK's
72-
session.list_resources() method.
69+
uris: List of URIs to load. If `None`, all resources will be loaded.
70+
71+
!!! note
72+
73+
Dynamic resources will NOT be loaded when `None` is specified,
74+
as they require parameters and are ignored by the MCP SDK's
75+
`session.list_resources()` method.
7376
7477
Returns:
75-
A list of LangChain Blobs.
78+
A list of LangChain [Blob][langchain_core.documents.base.Blob] objects.
7679
7780
Raises:
7881
RuntimeError: If an error occurs while fetching a resource.
79-
"""
82+
""" # noqa: E501
8083
blobs = []
8184

8285
if uris is None:

langchain_mcp_adapters/tools.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,18 +314,18 @@ async def load_mcp_tools(
314314
tool_interceptors: list[ToolCallInterceptor] | None = None,
315315
server_name: str | None = None,
316316
) -> list[BaseTool]:
317-
"""Load all available MCP tools and convert them to LangChain tools.
317+
"""Load all available MCP tools and convert them to LangChain [tools](https://docs.langchain.com/oss/python/langchain/tools).
318318
319319
Args:
320-
session: The MCP client session. If None, connection must be provided.
321-
connection: Connection config to create a new session if session is None.
322-
callbacks: Optional callbacks for handling notifications and events.
320+
session: The MCP client session. If `None`, connection must be provided.
321+
connection: Connection config to create a new session if session is `None`.
322+
callbacks: Optional `Callbacks` for handling notifications and events.
323323
tool_interceptors: Optional list of interceptors for tool call processing.
324324
server_name: Name of the server these tools belong to.
325325
326326
Returns:
327-
List of LangChain tools. Tool annotations are returned as part
328-
of the tool metadata object.
327+
List of LangChain [tools](https://docs.langchain.com/oss/python/langchain/tools).
328+
Tool annotations are returned as part of the tool metadata object.
329329
330330
Raises:
331331
ValueError: If neither session nor connection is provided.

0 commit comments

Comments
 (0)