langchain-mcp-tools 0.1.3__py3-none-any.whl → 0.1.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- langchain_mcp_tools/langchain_mcp_tools.py +45 -13
- {langchain_mcp_tools-0.1.3.dist-info → langchain_mcp_tools-0.1.5.dist-info}/METADATA +23 -20
- langchain_mcp_tools-0.1.5.dist-info/RECORD +8 -0
- langchain_mcp_tools-0.1.3.dist-info/RECORD +0 -8
- {langchain_mcp_tools-0.1.3.dist-info → langchain_mcp_tools-0.1.5.dist-info}/LICENSE +0 -0
- {langchain_mcp_tools-0.1.3.dist-info → langchain_mcp_tools-0.1.5.dist-info}/WHEEL +0 -0
- {langchain_mcp_tools-0.1.3.dist-info → langchain_mcp_tools-0.1.5.dist-info}/top_level.txt +0 -0
@@ -14,6 +14,7 @@ from typing import (
|
|
14
14
|
Dict,
|
15
15
|
List,
|
16
16
|
NoReturn,
|
17
|
+
Optional,
|
17
18
|
Tuple,
|
18
19
|
Type,
|
19
20
|
TypeAlias,
|
@@ -64,8 +65,8 @@ async def spawn_mcp_server_and_get_transport(
|
|
64
65
|
Exception: If server spawning fails
|
65
66
|
"""
|
66
67
|
try:
|
67
|
-
logger.info(f'MCP server "{server_name}":
|
68
|
-
server_config)
|
68
|
+
logger.info(f'MCP server "{server_name}": '
|
69
|
+
f'initializing with: {server_config}')
|
69
70
|
|
70
71
|
# NOTE: `uv` and `npx` seem to require PATH to be set.
|
71
72
|
# To avoid confusion, it was decided to automatically append it
|
@@ -143,6 +144,7 @@ async def get_mcp_server_tools(
|
|
143
144
|
# Wrap MCP tools into LangChain tools
|
144
145
|
langchain_tools: List[BaseTool] = []
|
145
146
|
for tool in tools_response.tools:
|
147
|
+
|
146
148
|
# Define adapter class to convert MCP tool to LangChain format
|
147
149
|
class McpToLangChainAdapter(BaseTool):
|
148
150
|
name: str = tool.name or 'NO NAME'
|
@@ -151,10 +153,11 @@ async def get_mcp_server_tools(
|
|
151
153
|
args_schema: Type[BaseModel] = jsonschema_to_pydantic(
|
152
154
|
tool.inputSchema
|
153
155
|
)
|
156
|
+
session: Optional[ClientSession] = None
|
154
157
|
|
155
158
|
def _run(self, **kwargs: Any) -> NoReturn:
|
156
159
|
raise NotImplementedError(
|
157
|
-
'
|
160
|
+
'MCP tools only support async operations'
|
158
161
|
)
|
159
162
|
|
160
163
|
async def _arun(self, **kwargs: Any) -> Any:
|
@@ -163,16 +166,45 @@ async def get_mcp_server_tools(
|
|
163
166
|
Logs input/output and handles errors.
|
164
167
|
"""
|
165
168
|
logger.info(f'MCP tool "{server_name}"/"{tool.name}"'
|
166
|
-
f' received input:
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
169
|
+
f' received input: {kwargs}')
|
170
|
+
|
171
|
+
try:
|
172
|
+
result = await session.call_tool(self.name, kwargs)
|
173
|
+
|
174
|
+
if hasattr(result, 'isError') and result.isError:
|
175
|
+
raise ToolException(
|
176
|
+
f'Tool execution failed: {result.content}'
|
177
|
+
)
|
178
|
+
|
179
|
+
if not hasattr(result, 'content'):
|
180
|
+
return str(result)
|
181
|
+
|
182
|
+
# The return type of `BaseTool`'s `arun` is `str`.
|
183
|
+
try:
|
184
|
+
result_content_text = '\n\n'.join(
|
185
|
+
item.text
|
186
|
+
for item in result.content
|
187
|
+
if isinstance(item, mcp_types.TextContent)
|
188
|
+
)
|
189
|
+
result_content_text = result_content_text or ''
|
190
|
+
|
191
|
+
except KeyError as e:
|
192
|
+
result_content_text = (
|
193
|
+
f'Error in parsing result.content: {str(e)}; '
|
194
|
+
f'contents: {repr(result.content)}'
|
195
|
+
)
|
196
|
+
|
197
|
+
# Log result size for monitoring
|
198
|
+
size = asizeof.asizeof(result_content_text)
|
199
|
+
logger.info(f'MCP tool "{server_name}"/"{tool.name}" '
|
200
|
+
f'received result (size: {size})')
|
201
|
+
|
202
|
+
return result_content_text
|
203
|
+
|
204
|
+
except Exception as e:
|
205
|
+
if self.handle_tool_error:
|
206
|
+
return f'Error executing MCP tool: {str(e)}'
|
207
|
+
raise
|
176
208
|
|
177
209
|
langchain_tools.append(McpToLangChainAdapter())
|
178
210
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: langchain-mcp-tools
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.5
|
4
4
|
Summary: Model Context Protocol (MCP) To LangChain Tools Conversion Utility
|
5
5
|
Project-URL: Bug Tracker, https://github.com/hideya/langchain-mcp-tools-py/issues
|
6
6
|
Project-URL: Source Code, https://github.com/hideya/langchain-mcp-tools-py
|
@@ -29,32 +29,32 @@ This package is intended to simplify the use of
|
|
29
29
|
server tools with LangChain / Python.
|
30
30
|
|
31
31
|
[Model Context Protocol (MCP)](https://modelcontextprotocol.io/),
|
32
|
-
|
33
|
-
[Anthropic](https://www.anthropic.com/news/model-context-protocol),
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
with over 400 MCP servers already developed and shared:
|
32
|
+
an open source technology
|
33
|
+
[announced by Anthropic](https://www.anthropic.com/news/model-context-protocol),
|
34
|
+
dramatically expands LLM’s scope
|
35
|
+
by enabling external tool and resource integration, including
|
36
|
+
Google Drive, Slack, Notion, Spotify, Docker, PostgreSQL, and more…
|
38
37
|
|
39
|
-
|
40
|
-
- [Glama’s list of Open-Source MCP servers](https://glama.ai/mcp/servers)
|
38
|
+
Over 450 functional components available as MCP servers:
|
41
39
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
- [Glama’s list of Open-Source MCP servers](https://glama.ai/mcp/servers)
|
41
|
+
- [Smithery: MCP Server Registry](https://smithery.ai/)
|
42
|
+
- [awesome-mcp-servers](https://github.com/hideya/awesome-mcp-servers#Server-Implementations)
|
43
|
+
- [MCP Get Started/Example Servers](https://modelcontextprotocol.io/examples)
|
46
44
|
|
47
|
-
|
48
|
-
this package offers quick and seamless access from LangChain to MCP servers.
|
45
|
+
The goal of this utility is to make these 450+ MCP servers readily accessible from LangChain.
|
49
46
|
|
50
47
|
It contains a utility function `convert_mcp_to_langchain_tools()`.
|
51
48
|
This async function handles parallel initialization of specified multiple MCP servers
|
52
49
|
and converts their available tools into a list of LangChain-compatible tools.
|
53
50
|
|
51
|
+
For detailed information on how to use this library, please refer to the following document:
|
52
|
+
- ["Supercharging LangChain: Integrating 450+ MCP with ReAct"](https://medium.com/@h1deya/supercharging-langchain-integrating-450-mcp-with-react-d4e467cbf41a)
|
53
|
+
|
54
54
|
A typescript equivalent of this utility is available
|
55
55
|
[here](https://www.npmjs.com/package/@h1deya/langchain-mcp-tools)
|
56
56
|
|
57
|
-
##
|
57
|
+
## Prerequisites
|
58
58
|
|
59
59
|
- Python 3.11+
|
60
60
|
|
@@ -102,7 +102,7 @@ The returned tools can be used with LangChain, e.g.:
|
|
102
102
|
```python
|
103
103
|
# from langchain.chat_models import init_chat_model
|
104
104
|
llm = init_chat_model(
|
105
|
-
model='claude-3-5-
|
105
|
+
model='claude-3-5-sonnet-latest',
|
106
106
|
model_provider='anthropic'
|
107
107
|
)
|
108
108
|
|
@@ -112,12 +112,15 @@ agent = create_react_agent(
|
|
112
112
|
tools
|
113
113
|
)
|
114
114
|
```
|
115
|
-
|
115
|
+
|
116
|
+
Find complete, minimal working usage examples
|
116
117
|
[here](https://github.com/hideya/langchain-mcp-tools-py-usage/blob/main/src/example.py)
|
117
118
|
|
118
|
-
|
119
|
-
[
|
119
|
+
For hands-on experimentation with MCP server integration,
|
120
|
+
try [this LangChain application built with the utility](https://github.com/hideya/mcp-client-langchain-py)
|
120
121
|
|
122
|
+
For detailed information on how to use this library, please refer to the following document:
|
123
|
+
["Supercharging LangChain: Integrating 450+ MCP with ReAct"](https://medium.com/@h1deya/supercharging-langchain-integrating-450-mcp-with-react-d4e467cbf41a)
|
121
124
|
|
122
125
|
## Limitations
|
123
126
|
|
@@ -0,0 +1,8 @@
|
|
1
|
+
langchain_mcp_tools/__init__.py,sha256=Xtv2VphhrWB_KlxTIofHZqtCIGtNEl0MxugnrNXTERA,94
|
2
|
+
langchain_mcp_tools/langchain_mcp_tools.py,sha256=UNvQSkj2MPV4aF1HFVLjE5AncXqw6eRLwqMuIQgefoc,10926
|
3
|
+
langchain_mcp_tools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
+
langchain_mcp_tools-0.1.5.dist-info/LICENSE,sha256=CRC91e8v116gCpnp7h49oIa6_zjhxqnHFTREeoZFJwA,1072
|
5
|
+
langchain_mcp_tools-0.1.5.dist-info/METADATA,sha256=mlv50j7vIG3dtlmwP7qX2giU4G_T-PA5RYBWUitF-80,4954
|
6
|
+
langchain_mcp_tools-0.1.5.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
7
|
+
langchain_mcp_tools-0.1.5.dist-info/top_level.txt,sha256=aR_9V2A1Yt-Bca60KmndmGLUWb2wiM5IOG-Gkaf1dxY,20
|
8
|
+
langchain_mcp_tools-0.1.5.dist-info/RECORD,,
|
@@ -1,8 +0,0 @@
|
|
1
|
-
langchain_mcp_tools/__init__.py,sha256=Xtv2VphhrWB_KlxTIofHZqtCIGtNEl0MxugnrNXTERA,94
|
2
|
-
langchain_mcp_tools/langchain_mcp_tools.py,sha256=hdlCAAwy7xVHzBNq-t5K91uqfieqeMXJcdr3ZoUcDGo,9621
|
3
|
-
langchain_mcp_tools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
-
langchain_mcp_tools-0.1.3.dist-info/LICENSE,sha256=CRC91e8v116gCpnp7h49oIa6_zjhxqnHFTREeoZFJwA,1072
|
5
|
-
langchain_mcp_tools-0.1.3.dist-info/METADATA,sha256=ZQCV-DU31mUuM6tjj5ygkrRav_wpUnr1I7pzzx29P8s,4547
|
6
|
-
langchain_mcp_tools-0.1.3.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
7
|
-
langchain_mcp_tools-0.1.3.dist-info/top_level.txt,sha256=aR_9V2A1Yt-Bca60KmndmGLUWb2wiM5IOG-Gkaf1dxY,20
|
8
|
-
langchain_mcp_tools-0.1.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|