langchain-mcp-tools 0.1.4__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 +42 -10
- {langchain_mcp_tools-0.1.4.dist-info → langchain_mcp_tools-0.1.5.dist-info}/METADATA +20 -20
- langchain_mcp_tools-0.1.5.dist-info/RECORD +8 -0
- langchain_mcp_tools-0.1.4.dist-info/RECORD +0 -8
- {langchain_mcp_tools-0.1.4.dist-info → langchain_mcp_tools-0.1.5.dist-info}/LICENSE +0 -0
- {langchain_mcp_tools-0.1.4.dist-info → langchain_mcp_tools-0.1.5.dist-info}/WHEEL +0 -0
- {langchain_mcp_tools-0.1.4.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,
|
@@ -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:
|
@@ -164,15 +167,44 @@ async def get_mcp_server_tools(
|
|
164
167
|
"""
|
165
168
|
logger.info(f'MCP tool "{server_name}"/"{tool.name}"'
|
166
169
|
f' received input: {kwargs}')
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
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,35 +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
|
-
|
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…
|
37
|
+
|
38
|
+
Over 450 functional components available as MCP servers:
|
38
39
|
|
39
40
|
- [Glama’s list of Open-Source MCP servers](https://glama.ai/mcp/servers)
|
40
41
|
- [Smithery: MCP Server Registry](https://smithery.ai/)
|
41
42
|
- [awesome-mcp-servers](https://github.com/hideya/awesome-mcp-servers#Server-Implementations)
|
42
43
|
- [MCP Get Started/Example Servers](https://modelcontextprotocol.io/examples)
|
43
44
|
|
44
|
-
|
45
|
-
which typically runs in a separate process and communicates
|
46
|
-
via `stdio` using the open standard protocol.
|
47
|
-
This clean decoupling makes it easy to adopt and reuse any of
|
48
|
-
the significant collections of MCP servers listed above.
|
49
|
-
|
50
|
-
To make it easy for LangChain users to take advantage of such a vast resource base,
|
51
|
-
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.
|
52
46
|
|
53
47
|
It contains a utility function `convert_mcp_to_langchain_tools()`.
|
54
48
|
This async function handles parallel initialization of specified multiple MCP servers
|
55
49
|
and converts their available tools into a list of LangChain-compatible tools.
|
56
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
|
+
|
57
54
|
A typescript equivalent of this utility is available
|
58
55
|
[here](https://www.npmjs.com/package/@h1deya/langchain-mcp-tools)
|
59
56
|
|
60
|
-
##
|
57
|
+
## Prerequisites
|
61
58
|
|
62
59
|
- Python 3.11+
|
63
60
|
|
@@ -105,7 +102,7 @@ The returned tools can be used with LangChain, e.g.:
|
|
105
102
|
```python
|
106
103
|
# from langchain.chat_models import init_chat_model
|
107
104
|
llm = init_chat_model(
|
108
|
-
model='claude-3-5-
|
105
|
+
model='claude-3-5-sonnet-latest',
|
109
106
|
model_provider='anthropic'
|
110
107
|
)
|
111
108
|
|
@@ -115,12 +112,15 @@ agent = create_react_agent(
|
|
115
112
|
tools
|
116
113
|
)
|
117
114
|
```
|
118
|
-
|
115
|
+
|
116
|
+
Find complete, minimal working usage examples
|
119
117
|
[here](https://github.com/hideya/langchain-mcp-tools-py-usage/blob/main/src/example.py)
|
120
118
|
|
121
|
-
|
122
|
-
[
|
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)
|
123
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)
|
124
124
|
|
125
125
|
## Limitations
|
126
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=-kzxOhYUaieWngSSYk0kUZw6SeBNmxjnXm6Ed2rStz8,9627
|
3
|
-
langchain_mcp_tools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
-
langchain_mcp_tools-0.1.4.dist-info/LICENSE,sha256=CRC91e8v116gCpnp7h49oIa6_zjhxqnHFTREeoZFJwA,1072
|
5
|
-
langchain_mcp_tools-0.1.4.dist-info/METADATA,sha256=-JPzwr4567fPMFq9caElQjQ2BorchdeXyf_TDje-bwo,4794
|
6
|
-
langchain_mcp_tools-0.1.4.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
7
|
-
langchain_mcp_tools-0.1.4.dist-info/top_level.txt,sha256=aR_9V2A1Yt-Bca60KmndmGLUWb2wiM5IOG-Gkaf1dxY,20
|
8
|
-
langchain_mcp_tools-0.1.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|