langchain-mcp-tools 0.1.9__py3-none-any.whl → 0.1.11__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 +40 -8
- {langchain_mcp_tools-0.1.9.dist-info → langchain_mcp_tools-0.1.11.dist-info}/METADATA +16 -13
- langchain_mcp_tools-0.1.11.dist-info/RECORD +8 -0
- {langchain_mcp_tools-0.1.9.dist-info → langchain_mcp_tools-0.1.11.dist-info}/WHEEL +1 -1
- langchain_mcp_tools-0.1.9.dist-info/RECORD +0 -8
- {langchain_mcp_tools-0.1.9.dist-info → langchain_mcp_tools-0.1.11.dist-info/licenses}/LICENSE +0 -0
- {langchain_mcp_tools-0.1.9.dist-info → langchain_mcp_tools-0.1.11.dist-info}/top_level.txt +0 -0
@@ -24,8 +24,8 @@ from typing import (
|
|
24
24
|
try:
|
25
25
|
from jsonschema_pydantic import jsonschema_to_pydantic # type: ignore
|
26
26
|
from langchain_core.tools import BaseTool, ToolException
|
27
|
-
from mcp import ClientSession
|
28
|
-
from mcp.client.stdio import stdio_client
|
27
|
+
from mcp import ClientSession
|
28
|
+
from mcp.client.stdio import stdio_client, StdioServerParameters
|
29
29
|
import mcp.types as mcp_types
|
30
30
|
from pydantic import BaseModel
|
31
31
|
# from pydantic_core import to_json
|
@@ -90,12 +90,23 @@ async def spawn_mcp_server_and_get_transport(
|
|
90
90
|
server_params = StdioServerParameters(
|
91
91
|
command=server_config['command'],
|
92
92
|
args=server_config.get('args', []),
|
93
|
-
env=env
|
93
|
+
env=env,
|
94
|
+
cwd=server_config.get('cwd', None)
|
94
95
|
)
|
95
96
|
|
96
97
|
# Initialize stdio client and register it with exit stack for cleanup
|
98
|
+
# NOTE: Why the key name `stderr` for `server_config` was chosen:
|
99
|
+
# Unlike the TypeScript SDK's `StdioServerParameters`, the Python SDK's
|
100
|
+
# `StdioServerParameters` doesn't include `stderr`.
|
101
|
+
# Instead, it calls `stdio_client()` with a separate argument
|
102
|
+
# `errlog`. I once thought of using `errlog` for the key for the
|
103
|
+
# Pyhton version, but decided to follow the TypeScript version since
|
104
|
+
# its public API already exposes the key name and I choose consistency.
|
97
105
|
stdio_transport = await exit_stack.enter_async_context(
|
98
|
-
stdio_client(
|
106
|
+
stdio_client(
|
107
|
+
server_params,
|
108
|
+
errlog=server_config.get('stderr', None)
|
109
|
+
)
|
99
110
|
)
|
100
111
|
except Exception as e:
|
101
112
|
logger.error(f'Error spawning MCP server: {str(e)}')
|
@@ -247,13 +258,22 @@ async def get_mcp_server_tools(
|
|
247
258
|
return langchain_tools
|
248
259
|
|
249
260
|
|
261
|
+
# A very simple pre-configured logger for fallback
|
262
|
+
def init_logger() -> logging.Logger:
|
263
|
+
logging.basicConfig(
|
264
|
+
level=logging.INFO, # logging.DEBUG,
|
265
|
+
format='\x1b[90m[%(levelname)s]\x1b[0m %(message)s'
|
266
|
+
)
|
267
|
+
return logging.getLogger()
|
268
|
+
|
269
|
+
|
250
270
|
# Type hint for cleanup function
|
251
271
|
McpServerCleanupFn = Callable[[], Awaitable[None]]
|
252
272
|
|
253
273
|
|
254
274
|
async def convert_mcp_to_langchain_tools(
|
255
275
|
server_configs: Dict[str, Dict[str, Any]],
|
256
|
-
logger: logging.Logger =
|
276
|
+
logger: Optional[logging.Logger] = None
|
257
277
|
) -> Tuple[List[BaseTool], McpServerCleanupFn]:
|
258
278
|
"""Initialize multiple MCP servers and convert their tools to
|
259
279
|
LangChain format.
|
@@ -267,7 +287,8 @@ async def convert_mcp_to_langchain_tools(
|
|
267
287
|
configurations, where each configuration contains command, args,
|
268
288
|
and env settings
|
269
289
|
logger: Logger instance to use for logging events and errors.
|
270
|
-
|
290
|
+
If None, uses module logger with fallback to a pre-configured
|
291
|
+
logger when no root handlers exist.
|
271
292
|
|
272
293
|
Returns:
|
273
294
|
A tuple containing:
|
@@ -277,14 +298,25 @@ async def convert_mcp_to_langchain_tools(
|
|
277
298
|
|
278
299
|
Example:
|
279
300
|
server_configs = {
|
280
|
-
|
281
|
-
|
301
|
+
'fetch': {
|
302
|
+
'command': 'uvx', 'args': ['mcp-server-fetch']
|
303
|
+
},
|
304
|
+
'weather': {
|
305
|
+
'command': 'npx', 'args': ['-y','@h1deya/mcp-server-weather']
|
306
|
+
}
|
282
307
|
}
|
283
308
|
tools, cleanup = await convert_mcp_to_langchain_tools(server_configs)
|
284
309
|
# Use tools...
|
285
310
|
await cleanup()
|
286
311
|
"""
|
287
312
|
|
313
|
+
if logger is None:
|
314
|
+
logger = logging.getLogger(__name__)
|
315
|
+
# Check if the root logger has handlers configured
|
316
|
+
if not logging.root.handlers and not logger.handlers:
|
317
|
+
# No logging configured, use a simple pre-configured logger
|
318
|
+
logger = init_logger()
|
319
|
+
|
288
320
|
# Initialize AsyncExitStack for managing multiple server lifecycles
|
289
321
|
stdio_transports: List[StdioTransport] = []
|
290
322
|
async_exit_stack = AsyncExitStack()
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: langchain-mcp-tools
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.11
|
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
|
@@ -10,9 +10,8 @@ Description-Content-Type: text/markdown
|
|
10
10
|
License-File: LICENSE
|
11
11
|
Requires-Dist: jsonschema-pydantic>=0.6
|
12
12
|
Requires-Dist: langchain>=0.3.14
|
13
|
-
Requires-Dist: mcp>=1.
|
13
|
+
Requires-Dist: mcp>=1.6.0
|
14
14
|
Requires-Dist: pyjson5>=1.6.8
|
15
|
-
Requires-Dist: python-dotenv>=1.0.1
|
16
15
|
Provides-Extra: dev
|
17
16
|
Requires-Dist: dotenv>=0.9.9; extra == "dev"
|
18
17
|
Requires-Dist: langchain-anthropic>=0.3.1; extra == "dev"
|
@@ -21,6 +20,7 @@ Requires-Dist: langchain-openai>=0.3.0; extra == "dev"
|
|
21
20
|
Requires-Dist: langgraph>=0.2.62; extra == "dev"
|
22
21
|
Requires-Dist: pytest>=8.3.4; extra == "dev"
|
23
22
|
Requires-Dist: pytest-asyncio>=0.25.2; extra == "dev"
|
23
|
+
Dynamic: license-file
|
24
24
|
|
25
25
|
# MCP To LangChain Tools Conversion Utility [](https://github.com/hideya/langchain-mcp-tools-py/blob/main/LICENSE) [](https://pypi.org/project/langchain-mcp-tools/)
|
26
26
|
|
@@ -35,21 +35,20 @@ dramatically expands LLM’s scope
|
|
35
35
|
by enabling external tool and resource integration, including
|
36
36
|
Google Drive, Slack, Notion, Spotify, Docker, PostgreSQL, and more…
|
37
37
|
|
38
|
-
Over
|
38
|
+
Over 2000 functional components available as MCP servers:
|
39
39
|
|
40
|
-
- [
|
40
|
+
- [MCP Server Listing on the Official Site](https://github.com/modelcontextprotocol/servers?tab=readme-ov-file#model-context-protocol-servers)
|
41
|
+
- [MCP.so - Find Awesome MCP Servers and Clients](https://mcp.so/)
|
41
42
|
- [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)
|
44
43
|
|
45
|
-
The goal of this utility is to make these
|
44
|
+
The goal of this utility is to make these 2000+ MCP servers readily accessible from LangChain.
|
46
45
|
|
47
46
|
It contains a utility function `convert_mcp_to_langchain_tools()`.
|
48
47
|
This async function handles parallel initialization of specified multiple MCP servers
|
49
48
|
and converts their available tools into a list of LangChain-compatible tools.
|
50
49
|
|
51
50
|
For detailed information on how to use this library, please refer to the following document:
|
52
|
-
- ["Supercharging LangChain: Integrating
|
51
|
+
- ["Supercharging LangChain: Integrating 2000+ MCP with ReAct"](https://medium.com/@h1deya/supercharging-langchain-integrating-450-mcp-with-react-d4e467cbf41a)
|
53
52
|
|
54
53
|
A typescript equivalent of this utility is available
|
55
54
|
[here](https://www.npmjs.com/package/@h1deya/langchain-mcp-tools)
|
@@ -73,7 +72,7 @@ but only the contents of the `mcpServers` property,
|
|
73
72
|
and is expressed as a `dict`, e.g.:
|
74
73
|
|
75
74
|
```python
|
76
|
-
|
75
|
+
mcp_servers = {
|
77
76
|
'filesystem': {
|
78
77
|
'command': 'npx',
|
79
78
|
'args': ['-y', '@modelcontextprotocol/server-filesystem', '.']
|
@@ -85,7 +84,7 @@ mcp_configs = {
|
|
85
84
|
}
|
86
85
|
|
87
86
|
tools, cleanup = await convert_mcp_to_langchain_tools(
|
88
|
-
|
87
|
+
mcp_servers
|
89
88
|
)
|
90
89
|
```
|
91
90
|
|
@@ -120,12 +119,16 @@ For hands-on experimentation with MCP server integration,
|
|
120
119
|
try [this LangChain application built with the utility](https://github.com/hideya/mcp-client-langchain-py)
|
121
120
|
|
122
121
|
For detailed information on how to use this library, please refer to the following document:
|
123
|
-
["Supercharging LangChain: Integrating
|
122
|
+
["Supercharging LangChain: Integrating 2000+ MCP with ReAct"](https://medium.com/@h1deya/supercharging-langchain-integrating-450-mcp-with-react-d4e467cbf41a)
|
124
123
|
|
125
124
|
## Limitations
|
126
125
|
|
127
126
|
Currently, only text results of tool calls are supported.
|
128
127
|
|
128
|
+
Remote MCP server access is not supported.
|
129
|
+
|
130
|
+
Optiional MCP client Features, Roots and Sampling, are not supported.
|
131
|
+
|
129
132
|
## Change Log
|
130
133
|
|
131
134
|
Can be found [here](https://github.com/hideya/langchain-mcp-tools-py/blob/main/CHANGELOG.md)
|
@@ -0,0 +1,8 @@
|
|
1
|
+
langchain_mcp_tools/__init__.py,sha256=Xtv2VphhrWB_KlxTIofHZqtCIGtNEl0MxugnrNXTERA,94
|
2
|
+
langchain_mcp_tools/langchain_mcp_tools.py,sha256=O6TxRRuS-uTOY08-WVKK86Dxx7-dCeFZZRLpBYaPIng,13577
|
3
|
+
langchain_mcp_tools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
+
langchain_mcp_tools-0.1.11.dist-info/licenses/LICENSE,sha256=CRC91e8v116gCpnp7h49oIa6_zjhxqnHFTREeoZFJwA,1072
|
5
|
+
langchain_mcp_tools-0.1.11.dist-info/METADATA,sha256=lW4Mm8snEac1hYSuS0szfHmJZFBs79GAEo0bwyEW_sw,5212
|
6
|
+
langchain_mcp_tools-0.1.11.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
7
|
+
langchain_mcp_tools-0.1.11.dist-info/top_level.txt,sha256=aR_9V2A1Yt-Bca60KmndmGLUWb2wiM5IOG-Gkaf1dxY,20
|
8
|
+
langchain_mcp_tools-0.1.11.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=0uKhEeaMLPTHvsLVMrs18MuVz1SxSQZmTE0y8NYbs5o,12221
|
3
|
-
langchain_mcp_tools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
-
langchain_mcp_tools-0.1.9.dist-info/LICENSE,sha256=CRC91e8v116gCpnp7h49oIa6_zjhxqnHFTREeoZFJwA,1072
|
5
|
-
langchain_mcp_tools-0.1.9.dist-info/METADATA,sha256=7-GqU1Lt_iTfkY0Jn-OmKhcBTMseNx_DlRwTlZNmhbY,5150
|
6
|
-
langchain_mcp_tools-0.1.9.dist-info/WHEEL,sha256=beeZ86-EfXScwlR_HKu4SllMC9wUEj_8Z_4FJ3egI2w,91
|
7
|
-
langchain_mcp_tools-0.1.9.dist-info/top_level.txt,sha256=aR_9V2A1Yt-Bca60KmndmGLUWb2wiM5IOG-Gkaf1dxY,20
|
8
|
-
langchain_mcp_tools-0.1.9.dist-info/RECORD,,
|
{langchain_mcp_tools-0.1.9.dist-info → langchain_mcp_tools-0.1.11.dist-info/licenses}/LICENSE
RENAMED
File without changes
|
File without changes
|