langchain-mcp-tools 0.0.16__py3-none-any.whl → 0.1.0__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 +7 -7
- {langchain_mcp_tools-0.0.16.dist-info → langchain_mcp_tools-0.1.0.dist-info}/METADATA +41 -41
- langchain_mcp_tools-0.1.0.dist-info/RECORD +8 -0
- langchain_mcp_tools-0.0.16.dist-info/RECORD +0 -8
- {langchain_mcp_tools-0.0.16.dist-info → langchain_mcp_tools-0.1.0.dist-info}/LICENSE +0 -0
- {langchain_mcp_tools-0.0.16.dist-info → langchain_mcp_tools-0.1.0.dist-info}/WHEEL +0 -0
- {langchain_mcp_tools-0.0.16.dist-info → langchain_mcp_tools-0.1.0.dist-info}/top_level.txt +0 -0
@@ -36,7 +36,7 @@ This code implements a specific pattern for managing async resources that
|
|
36
36
|
require context managers while enabling parallel initialization.
|
37
37
|
The key aspects are:
|
38
38
|
|
39
|
-
1.
|
39
|
+
1. Challenge:
|
40
40
|
|
41
41
|
A key requirement for parallel initialization is that each server must be
|
42
42
|
initialized in its own dedicated task - there's no way around this as far as
|
@@ -46,14 +46,13 @@ The key aspects are:
|
|
46
46
|
- Resources management for `stdio_client` and `ClientSession` seems
|
47
47
|
to require relying exclusively on `asynccontextmanager` for cleanup,
|
48
48
|
with no manual cleanup options
|
49
|
-
(based on
|
49
|
+
(based on the mcp python-sdk impl as of Jan 14, 2025)
|
50
50
|
- Initializing multiple MCP servers in parallel requires a dedicated
|
51
51
|
`asyncio.Task` per server
|
52
|
-
-
|
53
|
-
|
54
|
-
- Need to ensure proper cleanup later in the same task that created them
|
52
|
+
- Server cleanup can be initiated later by a task other than the one that
|
53
|
+
initialized the resources
|
55
54
|
|
56
|
-
2. Solution
|
55
|
+
2. Solution:
|
57
56
|
|
58
57
|
The key insight is to keep the initialization tasks alive throughout the
|
59
58
|
session lifetime, rather than letting them complete after initialization.
|
@@ -75,7 +74,8 @@ The key aspects are:
|
|
75
74
|
|
76
75
|
3. Task Lifecycle:
|
77
76
|
|
78
|
-
The following illustrates how
|
77
|
+
The following task lifecyle diagram illustrates how the above strategy
|
78
|
+
was impelemented:
|
79
79
|
```
|
80
80
|
[Task starts]
|
81
81
|
↓
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: langchain-mcp-tools
|
3
|
-
Version: 0.0
|
3
|
+
Version: 0.1.0
|
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
|
@@ -8,7 +8,6 @@ Requires-Python: >=3.11
|
|
8
8
|
Description-Content-Type: text/markdown
|
9
9
|
License-File: LICENSE
|
10
10
|
Requires-Dist: jsonschema-pydantic>=0.6
|
11
|
-
Requires-Dist: langchain-core>=0.3.29
|
12
11
|
Requires-Dist: langchain>=0.3.14
|
13
12
|
Requires-Dist: langchain-anthropic>=0.3.1
|
14
13
|
Requires-Dist: langchain-groq>=0.2.3
|
@@ -19,7 +18,8 @@ Requires-Dist: pyjson5>=1.6.8
|
|
19
18
|
Requires-Dist: pympler>=1.1
|
20
19
|
Requires-Dist: python-dotenv>=1.0.1
|
21
20
|
Provides-Extra: dev
|
22
|
-
Requires-Dist:
|
21
|
+
Requires-Dist: pytest>=8.3.4; extra == "dev"
|
22
|
+
Requires-Dist: pytest-asyncio>=0.25.2; extra == "dev"
|
23
23
|
|
24
24
|
# MCP To LangChain Tools Conversion Utility [](https://github.com/hideya/langchain-mcp-tools-py/blob/main/LICENSE) [](https://pypi.org/project/langchain-mcp-tools/)
|
25
25
|
|
@@ -29,8 +29,7 @@ server tools with LangChain / Python.
|
|
29
29
|
|
30
30
|
It contains a utility function `convert_mcp_to_langchain_tools()`.
|
31
31
|
This function handles parallel initialization of specified multiple MCP servers
|
32
|
-
and converts their available tools into a list of
|
33
|
-
[LangChain-compatible tools](https://js.langchain.com/docs/how_to/tool_calling/).
|
32
|
+
and converts their available tools into a list of LangChain-compatible tools.
|
34
33
|
|
35
34
|
A typescript equivalent of this utility library is available
|
36
35
|
[here](https://www.npmjs.com/package/@h1deya/langchain-mcp-tools)
|
@@ -54,43 +53,44 @@ but only the contents of the `mcpServers` property,
|
|
54
53
|
and is expressed as a `dict`, e.g.:
|
55
54
|
|
56
55
|
```python
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
}
|
56
|
+
mcp_configs = {
|
57
|
+
'filesystem': {
|
58
|
+
'command': 'npx',
|
59
|
+
'args': ['-y', '@modelcontextprotocol/server-filesystem', '.']
|
60
|
+
},
|
61
|
+
'fetch': {
|
62
|
+
'command': 'uvx',
|
63
|
+
'args': ['mcp-server-fetch']
|
66
64
|
}
|
65
|
+
}
|
67
66
|
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
tools, cleanup = await convert_mcp_to_langchain_tools(
|
68
|
+
mcp_configs
|
69
|
+
)
|
71
70
|
```
|
72
71
|
|
73
|
-
|
74
|
-
and returns LangChain Tools
|
75
|
-
|
76
|
-
|
77
|
-
|
72
|
+
This utility function initializes all specified MCP servers in parallel,
|
73
|
+
and returns LangChain Tools
|
74
|
+
([`tools: List[BaseTool]`](https://python.langchain.com/api_reference/core/tools/langchain_core.tools.base.BaseTool.html#langchain_core.tools.base.BaseTool))
|
75
|
+
by gathering available MCP tools from the servers,
|
76
|
+
and by wrapping them into LangChain tools.
|
77
|
+
It also returns an async callback function (`cleanup: McpServerCleanupFn`)
|
78
78
|
to be invoked to close all MCP server sessions when finished.
|
79
79
|
|
80
80
|
The returned tools can be used with LangChain, e.g.:
|
81
81
|
|
82
82
|
```python
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
83
|
+
# from langchain.chat_models import init_chat_model
|
84
|
+
llm = init_chat_model(
|
85
|
+
model='claude-3-5-haiku-latest',
|
86
|
+
model_provider='anthropic'
|
87
|
+
)
|
88
|
+
|
89
|
+
# from langgraph.prebuilt import create_react_agent
|
90
|
+
agent = create_react_agent(
|
91
|
+
llm,
|
92
|
+
tools
|
93
|
+
)
|
94
94
|
```
|
95
95
|
A simple and experimentable usage example can be found
|
96
96
|
[here](https://github.com/hideya/langchain-mcp-tools-py-usage/blob/main/src/example.py)
|
@@ -112,11 +112,11 @@ I'm new to Python, so it is very possible that my ignorance is playing
|
|
112
112
|
a big role here...
|
113
113
|
I'll summarize the difficulties I faced below.
|
114
114
|
The source code is available
|
115
|
-
[here](https://github.com/hideya/langchain-mcp-tools-py/blob/main/langchain_mcp_tools/langchain_mcp_tools.py).
|
115
|
+
[here](https://github.com/hideya/langchain-mcp-tools-py/blob/main/src/langchain_mcp_tools/langchain_mcp_tools.py).
|
116
116
|
Any comments pointing out something I am missing would be greatly appreciated!
|
117
117
|
[(comment here)](https://github.com/hideya/langchain-mcp-tools-ts/issues)
|
118
118
|
|
119
|
-
1.
|
119
|
+
1. Challenge:
|
120
120
|
|
121
121
|
A key requirement for parallel initialization is that each server must be
|
122
122
|
initialized in its own dedicated task - there's no way around this as far as
|
@@ -129,11 +129,10 @@ Any comments pointing out something I am missing would be greatly appreciated!
|
|
129
129
|
(based on [the mcp python-sdk impl as of Jan 14, 2025](https://github.com/modelcontextprotocol/python-sdk/tree/99727a9/src/mcp/client))
|
130
130
|
- Initializing multiple MCP servers in parallel requires a dedicated
|
131
131
|
`asyncio.Task` per server
|
132
|
-
-
|
133
|
-
|
134
|
-
- Need to ensure proper cleanup later in the same task that created them
|
132
|
+
- Server cleanup can be initiated later by a task other than the one
|
133
|
+
that initialized the resources
|
135
134
|
|
136
|
-
2. Solution
|
135
|
+
2. Solution:
|
137
136
|
|
138
137
|
The key insight is to keep the initialization tasks alive throughout the
|
139
138
|
session lifetime, rather than letting them complete after initialization.
|
@@ -155,7 +154,8 @@ Any comments pointing out something I am missing would be greatly appreciated!
|
|
155
154
|
|
156
155
|
3. Task Lifecycle:
|
157
156
|
|
158
|
-
The following illustrates how
|
157
|
+
The following task lifecyle diagram illustrates how the above strategy
|
158
|
+
was impelemented:
|
159
159
|
```
|
160
160
|
[Task starts]
|
161
161
|
↓
|
@@ -176,5 +176,5 @@ It usually means I'm doing something very worng...
|
|
176
176
|
I think it is a natural assumption that MCP SDK is designed with consideration
|
177
177
|
for parallel server initialization.
|
178
178
|
I'm not sure what I'm missing...
|
179
|
-
(FYI, with the TypeScript MCP SDK, parallel initialization was
|
179
|
+
(FYI, with the TypeScript MCP SDK, parallel initialization was
|
180
180
|
[pretty straightforward](https://github.com/hideya/langchain-mcp-tools-ts/blob/main/src/langchain-mcp-tools.ts))
|
@@ -0,0 +1,8 @@
|
|
1
|
+
langchain_mcp_tools/__init__.py,sha256=Xtv2VphhrWB_KlxTIofHZqtCIGtNEl0MxugnrNXTERA,94
|
2
|
+
langchain_mcp_tools/langchain_mcp_tools.py,sha256=PxkOAwQ8WUd12N-hZNfy2u5hawvhlEQhs0CsyPTWch0,10374
|
3
|
+
langchain_mcp_tools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
+
langchain_mcp_tools-0.1.0.dist-info/LICENSE,sha256=CRC91e8v116gCpnp7h49oIa6_zjhxqnHFTREeoZFJwA,1072
|
5
|
+
langchain_mcp_tools-0.1.0.dist-info/METADATA,sha256=FuNglrw844NXdrNWNgkK7WNIUIIdW7a1sdJKRSmdT4o,6794
|
6
|
+
langchain_mcp_tools-0.1.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
7
|
+
langchain_mcp_tools-0.1.0.dist-info/top_level.txt,sha256=aR_9V2A1Yt-Bca60KmndmGLUWb2wiM5IOG-Gkaf1dxY,20
|
8
|
+
langchain_mcp_tools-0.1.0.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=EJgm28o2M3mBsFkeDtpw6hooSE1oWwjFJYhRfirxCgE,10511
|
3
|
-
langchain_mcp_tools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
-
langchain_mcp_tools-0.0.16.dist-info/LICENSE,sha256=CRC91e8v116gCpnp7h49oIa6_zjhxqnHFTREeoZFJwA,1072
|
5
|
-
langchain_mcp_tools-0.0.16.dist-info/METADATA,sha256=S7Ii62KuH2HTe1eg3eqSqfpUWWagTKz0diIn3Wdc-Ns,6876
|
6
|
-
langchain_mcp_tools-0.0.16.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
7
|
-
langchain_mcp_tools-0.0.16.dist-info/top_level.txt,sha256=aR_9V2A1Yt-Bca60KmndmGLUWb2wiM5IOG-Gkaf1dxY,20
|
8
|
-
langchain_mcp_tools-0.0.16.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|