langchain-mcp-tools 0.2.3__py3-none-any.whl → 0.2.4__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/__init__.py +3 -0
- langchain_mcp_tools/langchain_mcp_tools.py +112 -15
- {langchain_mcp_tools-0.2.3.dist-info → langchain_mcp_tools-0.2.4.dist-info}/METADATA +11 -1
- langchain_mcp_tools-0.2.4.dist-info/RECORD +8 -0
- {langchain_mcp_tools-0.2.3.dist-info → langchain_mcp_tools-0.2.4.dist-info}/WHEEL +1 -1
- langchain_mcp_tools-0.2.3.dist-info/RECORD +0 -8
- {langchain_mcp_tools-0.2.3.dist-info → langchain_mcp_tools-0.2.4.dist-info}/licenses/LICENSE +0 -0
- {langchain_mcp_tools-0.2.3.dist-info → langchain_mcp_tools-0.2.4.dist-info}/top_level.txt +0 -0
langchain_mcp_tools/__init__.py
CHANGED
@@ -38,6 +38,31 @@ except ImportError as e:
|
|
38
38
|
|
39
39
|
|
40
40
|
class McpServerCommandBasedConfig(TypedDict):
|
41
|
+
"""Configuration for an MCP server launched via command line.
|
42
|
+
|
43
|
+
This configuration is used for local MCP servers that are started as child
|
44
|
+
processes using the stdio client. It defines the command to run, optional
|
45
|
+
arguments, environment variables, working directory, and error logging
|
46
|
+
options.
|
47
|
+
|
48
|
+
Attributes:
|
49
|
+
command: The executable command to run (e.g., "npx", "uvx", "python").
|
50
|
+
args: Optional list of command-line arguments to pass to the command.
|
51
|
+
env: Optional dictionary of environment variables to set for the
|
52
|
+
process.
|
53
|
+
cwd: Optional working directory where the command will be executed.
|
54
|
+
errlog: Optional file-like object for redirecting the server's stderr
|
55
|
+
output.
|
56
|
+
|
57
|
+
Example:
|
58
|
+
{
|
59
|
+
"command": "npx",
|
60
|
+
"args": ["-y", "@modelcontextprotocol/server-filesystem", "."],
|
61
|
+
"env": {"NODE_ENV": "production"},
|
62
|
+
"cwd": "/path/to/working/directory",
|
63
|
+
"errlog": open("server.log", "w")
|
64
|
+
}
|
65
|
+
"""
|
41
66
|
command: str
|
42
67
|
args: NotRequired[list[str] | None]
|
43
68
|
env: NotRequired[dict[str, str] | None]
|
@@ -46,21 +71,81 @@ class McpServerCommandBasedConfig(TypedDict):
|
|
46
71
|
|
47
72
|
|
48
73
|
class McpServerUrlBasedConfig(TypedDict):
|
74
|
+
"""Configuration for a remote MCP server accessed via URL.
|
75
|
+
|
76
|
+
This configuration is used for remote MCP servers that are accessed via
|
77
|
+
HTTP/HTTPS (Server-Sent Events) or WebSocket connections. It defines the
|
78
|
+
URL to connect to and optional HTTP headers for authentication.
|
79
|
+
|
80
|
+
Attributes:
|
81
|
+
url: The URL of the remote MCP server. For SSE servers,
|
82
|
+
use http:// or https:// prefix. For WebSocket servers,
|
83
|
+
use ws:// or wss:// prefix.
|
84
|
+
headers: Optional dictionary of HTTP headers to include in the request,
|
85
|
+
typically used for authentication (e.g., bearer tokens).
|
86
|
+
|
87
|
+
Example for SSE server:
|
88
|
+
{
|
89
|
+
"url": "https://example.com/mcp/sse",
|
90
|
+
"headers": {"Authorization": "Bearer token123"}
|
91
|
+
}
|
92
|
+
|
93
|
+
Example for WebSocket server:
|
94
|
+
{
|
95
|
+
"url": "wss://example.com/mcp/ws"
|
96
|
+
}
|
97
|
+
"""
|
49
98
|
url: str
|
50
99
|
headers: NotRequired[dict[str, str] | None]
|
51
100
|
|
52
101
|
|
53
|
-
|
54
|
-
|
55
|
-
|
102
|
+
# Type for a single MCP server configuration, which can be either
|
103
|
+
# command-based or URL-based.
|
104
|
+
SingleMcpServerConfig = McpServerCommandBasedConfig | McpServerUrlBasedConfig
|
105
|
+
"""Configuration for a single MCP server, either command-based or URL-based.
|
106
|
+
|
107
|
+
This type represents the configuration for a single MCP server, which can
|
108
|
+
be either:
|
109
|
+
1. A local server launched via command line (McpServerCommandBasedConfig)
|
110
|
+
2. A remote server accessed via URL (McpServerUrlBasedConfig)
|
111
|
+
|
112
|
+
The type is determined by the presence of either the "command" key
|
113
|
+
(for command-based) or the "url" key (for URL-based).
|
114
|
+
"""
|
115
|
+
|
116
|
+
# Configuration dictionary for multiple MCP servers
|
117
|
+
McpServersConfig = dict[str, SingleMcpServerConfig]
|
118
|
+
"""Configuration dictionary for multiple MCP servers.
|
119
|
+
|
120
|
+
A dictionary mapping server names (as strings) to their respective
|
121
|
+
configurations. Each server name acts as a logical identifier used for logging
|
122
|
+
and debugging. The configuration for each server can be either command-based
|
123
|
+
or URL-based.
|
124
|
+
|
125
|
+
Example:
|
126
|
+
{
|
127
|
+
"filesystem": {
|
128
|
+
"command": "npx",
|
129
|
+
"args": ["-y", "@modelcontextprotocol/server-filesystem", "."]
|
130
|
+
},
|
131
|
+
"fetch": {
|
132
|
+
"command": "uvx",
|
133
|
+
"args": ["mcp-server-fetch"]
|
134
|
+
},
|
135
|
+
"remote-server": {
|
136
|
+
"url": "https://example.com/mcp/sse",
|
137
|
+
"headers": {"Authorization": "Bearer token123"}
|
138
|
+
}
|
139
|
+
}
|
140
|
+
"""
|
56
141
|
|
57
142
|
|
58
143
|
def fix_schema(schema: dict) -> dict:
|
59
144
|
"""Converts JSON Schema "type": ["string", "null"] to "anyOf" format.
|
60
|
-
|
145
|
+
|
61
146
|
Args:
|
62
147
|
schema: A JSON schema dictionary
|
63
|
-
|
148
|
+
|
64
149
|
Returns:
|
65
150
|
Modified schema with converted type formats
|
66
151
|
"""
|
@@ -83,7 +168,7 @@ Transport: TypeAlias = tuple[
|
|
83
168
|
|
84
169
|
async def spawn_mcp_server_and_get_transport(
|
85
170
|
server_name: str,
|
86
|
-
server_config:
|
171
|
+
server_config: SingleMcpServerConfig,
|
87
172
|
exit_stack: AsyncExitStack,
|
88
173
|
logger: logging.Logger = logging.getLogger(__name__)
|
89
174
|
) -> Transport:
|
@@ -233,15 +318,15 @@ async def get_mcp_server_tools(
|
|
233
318
|
|
234
319
|
async def _arun(self, **kwargs: Any) -> Any:
|
235
320
|
"""Asynchronously executes the tool with given arguments.
|
236
|
-
|
321
|
+
|
237
322
|
Logs input/output and handles errors.
|
238
|
-
|
323
|
+
|
239
324
|
Args:
|
240
325
|
**kwargs: Arguments to be passed to the MCP tool
|
241
|
-
|
326
|
+
|
242
327
|
Returns:
|
243
328
|
Formatted response from the MCP tool as a string
|
244
|
-
|
329
|
+
|
245
330
|
Raises:
|
246
331
|
ToolException: If the tool execution fails
|
247
332
|
"""
|
@@ -319,7 +404,7 @@ async def get_mcp_server_tools(
|
|
319
404
|
# A very simple pre-configured logger for fallback
|
320
405
|
def init_logger() -> logging.Logger:
|
321
406
|
"""Creates a simple pre-configured logger.
|
322
|
-
|
407
|
+
|
323
408
|
Returns:
|
324
409
|
A configured Logger instance
|
325
410
|
"""
|
@@ -332,10 +417,22 @@ def init_logger() -> logging.Logger:
|
|
332
417
|
|
333
418
|
# Type hint for cleanup function
|
334
419
|
McpServerCleanupFn = Callable[[], Awaitable[None]]
|
420
|
+
"""Type for the async cleanup function returned by
|
421
|
+
convert_mcp_to_langchain_tools.
|
422
|
+
|
423
|
+
This represents an asynchronous function that takes no arguments and returns
|
424
|
+
nothing. It's used to properly shut down all MCP server connections and clean
|
425
|
+
up resources when the tools are no longer needed.
|
426
|
+
|
427
|
+
Example usage:
|
428
|
+
tools, cleanup = await convert_mcp_to_langchain_tools(server_configs)
|
429
|
+
# Use tools...
|
430
|
+
await cleanup() # Clean up resources when done
|
431
|
+
"""
|
335
432
|
|
336
433
|
|
337
434
|
async def convert_mcp_to_langchain_tools(
|
338
|
-
server_configs:
|
435
|
+
server_configs: McpServersConfig,
|
339
436
|
logger: logging.Logger | None = None
|
340
437
|
) -> tuple[list[BaseTool], McpServerCleanupFn]:
|
341
438
|
"""Initialize multiple MCP servers and convert their tools to
|
@@ -369,11 +466,11 @@ async def convert_mcp_to_langchain_tools(
|
|
369
466
|
"command": "npx", "args": ["-y","@h1deya/mcp-server-weather"]
|
370
467
|
}
|
371
468
|
}
|
372
|
-
|
469
|
+
|
373
470
|
tools, cleanup = await convert_mcp_to_langchain_tools(server_configs)
|
374
|
-
|
471
|
+
|
375
472
|
# Use tools...
|
376
|
-
|
473
|
+
|
377
474
|
await cleanup()
|
378
475
|
"""
|
379
476
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: langchain-mcp-tools
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.4
|
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
|
@@ -26,6 +26,16 @@ Dynamic: license-file
|
|
26
26
|
|
27
27
|
# MCP To LangChain Tools Conversion Utility [](https://github.com/hideya/langchain-mcp-tools-py/blob/main/LICENSE) [](https://pypi.org/project/langchain-mcp-tools/)
|
28
28
|
|
29
|
+
## NOTE
|
30
|
+
|
31
|
+
LangChain's official **LangChain MCP Adapters** library has been released at:
|
32
|
+
- pypi: https://pypi.org/project/langchain-mcp-adapters/
|
33
|
+
- github: https://github.com/langchain-ai/langchain-mcp-adapters
|
34
|
+
|
35
|
+
You may want to consider using the above if you don't have specific needs for using this library...
|
36
|
+
|
37
|
+
## Introduction
|
38
|
+
|
29
39
|
This package is intended to simplify the use of
|
30
40
|
[Model Context Protocol (MCP)](https://modelcontextprotocol.io/)
|
31
41
|
server tools with LangChain / Python.
|
@@ -0,0 +1,8 @@
|
|
1
|
+
langchain_mcp_tools/__init__.py,sha256=CYyhniRN10ktRD1z06JyBoeo_m72Q8OIbqHjh-OGoFA,197
|
2
|
+
langchain_mcp_tools/langchain_mcp_tools.py,sha256=LximGy_0QYKuwsKFr5SvUwMZ7475CIJWxLtNDq68b-g,19377
|
3
|
+
langchain_mcp_tools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
+
langchain_mcp_tools-0.2.4.dist-info/licenses/LICENSE,sha256=CRC91e8v116gCpnp7h49oIa6_zjhxqnHFTREeoZFJwA,1072
|
5
|
+
langchain_mcp_tools-0.2.4.dist-info/METADATA,sha256=RJ00zZEh3UCSe6S6B_aaD4YZRiYd3SemWQrPrO9BM8M,9377
|
6
|
+
langchain_mcp_tools-0.2.4.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
|
7
|
+
langchain_mcp_tools-0.2.4.dist-info/top_level.txt,sha256=aR_9V2A1Yt-Bca60KmndmGLUWb2wiM5IOG-Gkaf1dxY,20
|
8
|
+
langchain_mcp_tools-0.2.4.dist-info/RECORD,,
|
@@ -1,8 +0,0 @@
|
|
1
|
-
langchain_mcp_tools/__init__.py,sha256=iatHG2fCpz143wgQUZpyFVilgri4yOh2P0vxr22gguE,114
|
2
|
-
langchain_mcp_tools/langchain_mcp_tools.py,sha256=3XfJUW98usqrWmn1RqbVzVr_Z4piv8PLzAm29YVj6z4,15806
|
3
|
-
langchain_mcp_tools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
-
langchain_mcp_tools-0.2.3.dist-info/licenses/LICENSE,sha256=CRC91e8v116gCpnp7h49oIa6_zjhxqnHFTREeoZFJwA,1072
|
5
|
-
langchain_mcp_tools-0.2.3.dist-info/METADATA,sha256=PPZz0kgmD2JQfUntk4D9R1gcm5DZZ_utV6L0YRo3b-M,9049
|
6
|
-
langchain_mcp_tools-0.2.3.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
|
7
|
-
langchain_mcp_tools-0.2.3.dist-info/top_level.txt,sha256=aR_9V2A1Yt-Bca60KmndmGLUWb2wiM5IOG-Gkaf1dxY,20
|
8
|
-
langchain_mcp_tools-0.2.3.dist-info/RECORD,,
|
{langchain_mcp_tools-0.2.3.dist-info → langchain_mcp_tools-0.2.4.dist-info}/licenses/LICENSE
RENAMED
File without changes
|
File without changes
|