langchain-mcp-tools 0.2.4__py3-none-any.whl → 0.2.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/__init__.py +1 -0
- langchain_mcp_tools/langchain_mcp_tools.py +726 -92
- langchain_mcp_tools-0.2.5.dist-info/METADATA +383 -0
- langchain_mcp_tools-0.2.5.dist-info/RECORD +8 -0
- {langchain_mcp_tools-0.2.4.dist-info → langchain_mcp_tools-0.2.5.dist-info}/WHEEL +1 -1
- langchain_mcp_tools-0.2.4.dist-info/METADATA +0 -232
- langchain_mcp_tools-0.2.4.dist-info/RECORD +0 -8
- {langchain_mcp_tools-0.2.4.dist-info → langchain_mcp_tools-0.2.5.dist-info}/licenses/LICENSE +0 -0
- {langchain_mcp_tools-0.2.4.dist-info → langchain_mcp_tools-0.2.5.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,383 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: langchain-mcp-tools
|
3
|
+
Version: 0.2.5
|
4
|
+
Summary: Model Context Protocol (MCP) To LangChain Tools Conversion Utility
|
5
|
+
Project-URL: Bug Tracker, https://github.com/hideya/langchain-mcp-tools-py/issues
|
6
|
+
Project-URL: Source Code, https://github.com/hideya/langchain-mcp-tools-py
|
7
|
+
Keywords: modelcontextprotocol,mcp,mcp-client,langchain,langchain-python,tool-call,tool-calling,python
|
8
|
+
Requires-Python: >=3.11
|
9
|
+
Description-Content-Type: text/markdown
|
10
|
+
License-File: LICENSE
|
11
|
+
Requires-Dist: jsonschema-pydantic>=0.6
|
12
|
+
Requires-Dist: langchain>=0.3.14
|
13
|
+
Requires-Dist: mcp>=1.6.0
|
14
|
+
Provides-Extra: dev
|
15
|
+
Requires-Dist: dotenv>=0.9.9; extra == "dev"
|
16
|
+
Requires-Dist: fastapi>=0.115.12; extra == "dev"
|
17
|
+
Requires-Dist: fastmcp>=2.9.2; extra == "dev"
|
18
|
+
Requires-Dist: pyjwt>=2.10.1; extra == "dev"
|
19
|
+
Requires-Dist: langchain-anthropic>=0.3.1; extra == "dev"
|
20
|
+
Requires-Dist: langchain-google-genai>=2.1.5; extra == "dev"
|
21
|
+
Requires-Dist: langchain-groq>=0.2.3; extra == "dev"
|
22
|
+
Requires-Dist: langchain-openai>=0.3.0; extra == "dev"
|
23
|
+
Requires-Dist: langgraph>=0.2.62; extra == "dev"
|
24
|
+
Requires-Dist: pytest>=8.3.4; extra == "dev"
|
25
|
+
Requires-Dist: pytest-asyncio>=0.25.2; extra == "dev"
|
26
|
+
Requires-Dist: websockets>=15.0.1; extra == "dev"
|
27
|
+
Dynamic: license-file
|
28
|
+
|
29
|
+
# MCP To LangChain Tools Conversion Utility [](https://github.com/hideya/langchain-mcp-tools-py/blob/main/LICENSE) [](https://pypi.org/project/langchain-mcp-tools/)
|
30
|
+
|
31
|
+
A simple, lightweight library intended to simplify the use of
|
32
|
+
[Model Context Protocol (MCP)](https://modelcontextprotocol.io/)
|
33
|
+
server tools with LangChain.
|
34
|
+
|
35
|
+
Its simplicity and extra features for stdio MCP servers can make it useful as a basis for your own customizations.
|
36
|
+
However, it only supports text results of tool calls and does not support MCP features other than tools.
|
37
|
+
|
38
|
+
LangChain's **official LangChain.js MCP Adapters** library,
|
39
|
+
which supports comprehensive integration with LangChain, has been released at:
|
40
|
+
- pypi: https://pypi.org/project/langchain-mcp-adapters/
|
41
|
+
- github: https://github.com/langchain-ai/langchain-mcp-adapters
|
42
|
+
|
43
|
+
You may want to consider using the above if you don't have specific needs for this library.
|
44
|
+
|
45
|
+
## Introduction
|
46
|
+
|
47
|
+
This package is intended to simplify the use of
|
48
|
+
[Model Context Protocol (MCP)](https://modelcontextprotocol.io/)
|
49
|
+
server tools with LangChain / Python.
|
50
|
+
|
51
|
+
[Model Context Protocol (MCP)](https://modelcontextprotocol.io/) is the de facto industry standard
|
52
|
+
that dramatically expands the scope of LLMs by enabling the integration of external tools and resources,
|
53
|
+
including DBs, GitHub, Google Drive, Docker, Slack, Notion, Spotify, and more.
|
54
|
+
|
55
|
+
There are quite a few useful MCP servers already available:
|
56
|
+
|
57
|
+
- [MCP Server Listing on the Official Site](https://github.com/modelcontextprotocol/servers?tab=readme-ov-file#model-context-protocol-servers)
|
58
|
+
- [MCP.so - Find Awesome MCP Servers and Clients](https://mcp.so/)
|
59
|
+
- [Smithery: MCP Server Registry](https://smithery.ai/)
|
60
|
+
|
61
|
+
This utility's goal is to make these massive numbers of MCP servers easily accessible from LangChain.
|
62
|
+
|
63
|
+
It contains a utility function `convert_mcp_to_langchain_tools()`.
|
64
|
+
This async function handles parallel initialization of specified multiple MCP servers
|
65
|
+
and converts their available tools into a list of LangChain-compatible tools.
|
66
|
+
|
67
|
+
For detailed information on how to use this library, please refer to the following document:
|
68
|
+
- ["Supercharging LangChain: Integrating 2000+ MCP with ReAct"](https://medium.com/@h1deya/supercharging-langchain-integrating-450-mcp-with-react-d4e467cbf41a)
|
69
|
+
|
70
|
+
A typescript equivalent of this utility is available
|
71
|
+
[here](https://www.npmjs.com/package/@h1deya/langchain-mcp-tools)
|
72
|
+
|
73
|
+
## Prerequisites
|
74
|
+
|
75
|
+
- Python 3.11+
|
76
|
+
|
77
|
+
## Installation
|
78
|
+
|
79
|
+
```bash
|
80
|
+
pip install langchain-mcp-tools
|
81
|
+
```
|
82
|
+
|
83
|
+
## API docs
|
84
|
+
|
85
|
+
Can be found [here](https://hideya.github.io/langchain-mcp-tools-py/)
|
86
|
+
|
87
|
+
|
88
|
+
## Quick Start
|
89
|
+
|
90
|
+
A minimal but complete working usage example can be found
|
91
|
+
[in this example in the langchain-mcp-tools-py-usage repo](https://github.com/hideya/langchain-mcp-tools-py-usage/blob/main/src/example.py)
|
92
|
+
|
93
|
+
`convert_mcp_to_langchain_tools()` utility function accepts MCP server configurations
|
94
|
+
that follow the same structure as
|
95
|
+
[Claude for Desktop](https://modelcontextprotocol.io/quickstart/user),
|
96
|
+
but only the contents of the `mcpServers` property,
|
97
|
+
and is expressed as a `dict`, e.g.:
|
98
|
+
|
99
|
+
```python
|
100
|
+
mcp_servers = {
|
101
|
+
"filesystem": {
|
102
|
+
"command": "npx",
|
103
|
+
"args": ["-y", "@modelcontextprotocol/server-filesystem", "."]
|
104
|
+
},
|
105
|
+
"fetch": {
|
106
|
+
"command": "uvx",
|
107
|
+
"args": ["mcp-server-fetch"]
|
108
|
+
},
|
109
|
+
"github": {
|
110
|
+
"type": "http",
|
111
|
+
"url": "https://api.githubcopilot.com/mcp/",
|
112
|
+
"headers": {
|
113
|
+
"Authorization": f"Bearer {os.environ.get('GITHUB_PERSONAL_ACCESS_TOKEN', '')}"
|
114
|
+
}
|
115
|
+
},
|
116
|
+
}
|
117
|
+
|
118
|
+
tools, cleanup = await convert_mcp_to_langchain_tools(
|
119
|
+
mcp_servers
|
120
|
+
)
|
121
|
+
```
|
122
|
+
|
123
|
+
This utility function initializes all specified MCP servers in parallel,
|
124
|
+
and returns LangChain Tools
|
125
|
+
([`tools: list[BaseTool]`](https://python.langchain.com/api_reference/core/tools/langchain_core.tools.base.BaseTool.html#langchain_core.tools.base.BaseTool))
|
126
|
+
by gathering available MCP tools from the servers,
|
127
|
+
and by wrapping them into LangChain tools.
|
128
|
+
It also returns an async callback function (`cleanup: McpServerCleanupFn`)
|
129
|
+
to be invoked to close all MCP server sessions when finished.
|
130
|
+
|
131
|
+
The returned tools can be used with LangChain, e.g.:
|
132
|
+
|
133
|
+
```python
|
134
|
+
# from langchain.chat_models import init_chat_model
|
135
|
+
llm = init_chat_model("anthropic:claude-sonnet-4-0")
|
136
|
+
|
137
|
+
# from langgraph.prebuilt import create_react_agent
|
138
|
+
agent = create_react_agent(
|
139
|
+
llm,
|
140
|
+
tools
|
141
|
+
)
|
142
|
+
```
|
143
|
+
|
144
|
+
For hands-on experimentation with MCP server integration,
|
145
|
+
try [this LangChain application built with the utility](https://github.com/hideya/mcp-client-langchain-py)
|
146
|
+
|
147
|
+
For detailed information on how to use this library, please refer to the following document:
|
148
|
+
["Supercharging LangChain: Integrating 2000+ MCP with ReAct"](https://medium.com/@h1deya/supercharging-langchain-integrating-450-mcp-with-react-d4e467cbf41a)
|
149
|
+
|
150
|
+
## Building from Source
|
151
|
+
|
152
|
+
See [README_DEV.md](https://github.com/hideya/langchain-mcp-tools-py/blob/main/README_DEV.md) for details.
|
153
|
+
|
154
|
+
## MCP Protocol Support
|
155
|
+
|
156
|
+
This library supports **MCP Protocol version 2025-03-26** and maintains backwards compatibility with version 2024-11-05.
|
157
|
+
It follows the [official MCP specification](https://modelcontextprotocol.io/specification/2025-03-26/) for transport selection and backwards compatibility.
|
158
|
+
|
159
|
+
## Features
|
160
|
+
|
161
|
+
### stderr Redirection for Local MCP Server
|
162
|
+
|
163
|
+
A new key `"errlog"` has been introduced to specify a file-like object
|
164
|
+
to which local (stdio) MCP server's stderr is redirected.
|
165
|
+
|
166
|
+
```python
|
167
|
+
log_path = f"mcp-server-{server_name}.log"
|
168
|
+
log_file = open(log_path, "w")
|
169
|
+
mcp_servers[server_name]["errlog"] = log_file
|
170
|
+
```
|
171
|
+
|
172
|
+
A usage example can be found [here](https://github.com/hideya/langchain-mcp-tools-py-usage/blob/3bd35d9fb49f4b631fe3d0cc8491d43cbf69693b/src/example.py#L88-L108).
|
173
|
+
The key name `errlog` is derived from
|
174
|
+
[`stdio_client()`'s argument `errlog`](https://github.com/modelcontextprotocol/python-sdk/blob/babb477dffa33f46cdc886bc885eb1d521151430/src/mcp/client/stdio/__init__.py#L96).
|
175
|
+
|
176
|
+
### Working Directory Configuration for Local MCP Servers
|
177
|
+
|
178
|
+
The working directory that is used when spawning a local (stdio) MCP server
|
179
|
+
can be specified with the `"cwd"` key as follows:
|
180
|
+
|
181
|
+
```python
|
182
|
+
"local-server-name": {
|
183
|
+
"command": "...",
|
184
|
+
"args": [...],
|
185
|
+
"cwd": "/working/directory" # the working dir to be use by the server
|
186
|
+
},
|
187
|
+
```
|
188
|
+
|
189
|
+
The key name `cwd` is derived from
|
190
|
+
Python SDK's [`StdioServerParameters`](https://github.com/modelcontextprotocol/python-sdk/blob/babb477dffa33f46cdc886bc885eb1d521151430/src/mcp/client/stdio/__init__.py#L76-L77).
|
191
|
+
|
192
|
+
**Note:** The library automatically adds the `PATH` environment variable to stdio servers if not explicitly provided to ensure servers can find required executables.
|
193
|
+
|
194
|
+
### Transport Selection Priority
|
195
|
+
|
196
|
+
The library selects transports using the following priority order:
|
197
|
+
|
198
|
+
1. **Explicit transport/type field** (must match URL protocol if URL provided)
|
199
|
+
2. **URL protocol auto-detection** (http/https → StreamableHTTP → SSE, ws/wss → WebSocket)
|
200
|
+
3. **Command presence** → Stdio transport
|
201
|
+
4. **Error** if none of the above match
|
202
|
+
|
203
|
+
This ensures predictable behavior while allowing flexibility for different deployment scenarios.
|
204
|
+
|
205
|
+
### Remote MCP Server Support
|
206
|
+
|
207
|
+
`mcp_servers` configuration for Streamable HTTP, SSE (Server-Sent Events) and Websocket servers are as follows:
|
208
|
+
|
209
|
+
```py
|
210
|
+
# Auto-detection: tries Streamable HTTP first, falls back to SSE on 4xx errors
|
211
|
+
"auto-detect-server": {
|
212
|
+
"url": f"http://{server_host}:{server_port}/..."
|
213
|
+
},
|
214
|
+
|
215
|
+
# Explicit Streamable HTTP
|
216
|
+
"streamable-http-server": {
|
217
|
+
"url": f"http://{server_host}:{server_port}/...",
|
218
|
+
"transport": "streamable_http"
|
219
|
+
# "type": "http" # VSCode-style config also works instead of the above
|
220
|
+
},
|
221
|
+
|
222
|
+
# Explicit SSE
|
223
|
+
"sse-server-name": {
|
224
|
+
"url": f"http://{sse_server_host}:{sse_server_port}/...",
|
225
|
+
"transport": "sse" # or `"type": "sse"`
|
226
|
+
},
|
227
|
+
|
228
|
+
# WebSocket
|
229
|
+
"ws-server-name": {
|
230
|
+
"url": f"ws://${ws_server_host}:${ws_server_port}/..."
|
231
|
+
# optionally `"transport": "ws"` or `"type": "ws"`
|
232
|
+
},
|
233
|
+
```
|
234
|
+
|
235
|
+
The `"headers"` key can be used to pass HTTP headers to Streamable HTTP and SSE connection.
|
236
|
+
|
237
|
+
```py
|
238
|
+
"github": {
|
239
|
+
"type": "http",
|
240
|
+
"url": "https://api.githubcopilot.com/mcp/",
|
241
|
+
"headers": {
|
242
|
+
"Authorization": f"Bearer {os.environ.get('GITHUB_PERSONAL_ACCESS_TOKEN', '')}"
|
243
|
+
}
|
244
|
+
},
|
245
|
+
```
|
246
|
+
|
247
|
+
NOTE: When accessing the GitHub MCP server, [GitHub PAT (Personal Access Token)](https://github.com/settings/personal-access-tokens)
|
248
|
+
alone is not enough; your GitHub account must have an active Copilot subscription or be assigned a Copilot license through your organization.
|
249
|
+
|
250
|
+
**Auto-detection behavior (default):**
|
251
|
+
- For HTTP/HTTPS URLs without explicit `transport`, the library follows [MCP specification recommendations](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#backwards-compatibility)
|
252
|
+
- First attempts Streamable HTTP transport
|
253
|
+
- If Streamable HTTP fails with a 4xx error, automatically falls back to SSE transport
|
254
|
+
- Non-4xx errors (network issues, etc.) are re-thrown without fallback
|
255
|
+
|
256
|
+
**Explicit transport selection:**
|
257
|
+
- Set `"transport": "streamable_http"` (or VSCode-style config `"type": "http"`) to force Streamable HTTP (no fallback)
|
258
|
+
- Set `"transport": "sse"` to force SSE transport
|
259
|
+
- WebSocket URLs (`ws://` or `wss://`) always use WebSocket transport
|
260
|
+
|
261
|
+
Streamable HTTP is the modern MCP transport that replaces the older HTTP+SSE transport. According to the [official MCP documentation](https://modelcontextprotocol.io/docs/concepts/transports): "SSE as a standalone transport is deprecated as of protocol version 2025-03-26. It has been replaced by Streamable HTTP, which incorporates SSE as an optional streaming mechanism."
|
262
|
+
|
263
|
+
### Authentication Support for Streamable HTTP Connections
|
264
|
+
|
265
|
+
The library supports OAuth 2.1 authentication for Streamable HTTP connections:
|
266
|
+
|
267
|
+
```py
|
268
|
+
from mcp.client.auth import OAuthClientProvider
|
269
|
+
...
|
270
|
+
|
271
|
+
# Create OAuth authentication provider
|
272
|
+
oauth_auth = OAuthClientProvider(
|
273
|
+
server_url="https://...",
|
274
|
+
client_metadata=...,
|
275
|
+
storage=...,
|
276
|
+
redirect_handler=...,
|
277
|
+
callback_handler=...,
|
278
|
+
)
|
279
|
+
|
280
|
+
# Test configuration with OAuth auth
|
281
|
+
mcp_servers = {
|
282
|
+
"secure-streamable-server": {
|
283
|
+
"url": "https://.../mcp/",
|
284
|
+
"auth": oauth_auth,
|
285
|
+
"timeout": 30.0
|
286
|
+
},
|
287
|
+
}
|
288
|
+
```
|
289
|
+
|
290
|
+
Test implementations are provided:
|
291
|
+
|
292
|
+
- **Streamable HTTP Authentication Tests**:
|
293
|
+
- MCP client uses this library: [streamable_http_oauth_test_client.py](https://github.com/hideya/langchain-mcp-tools-py/tree/main/testfiles/streamable_http_oauth_test_client.py)
|
294
|
+
- Test MCP Server: [streamable_http_oauth_test_server.py](https://github.com/hideya/langchain-mcp-tools-py/tree/main/testfiles/streamable_http_oauth_test_server.py)
|
295
|
+
|
296
|
+
### Authentication Support for SSE Connections (Legacy)
|
297
|
+
|
298
|
+
The library also supports authentication for SSE connections to MCP servers.
|
299
|
+
Note that SSE transport is deprecated; Streamable HTTP is the recommended approach.
|
300
|
+
|
301
|
+
## Limitations
|
302
|
+
|
303
|
+
- **Tool Return Types**: Currently, only text results of tool calls are supported.
|
304
|
+
The library uses LangChain's `response_format: 'content'` (the default), which only supports text strings.
|
305
|
+
While MCP tools can return multiple content types (text, images, etc.), this library currently filters and uses only text content.
|
306
|
+
- **MCP Features**: Only MCP [Tools](https://modelcontextprotocol.io/docs/concepts/tools) are supported. Other MCP features like Resources, Prompts, and Sampling are not implemented.
|
307
|
+
|
308
|
+
## Change Log
|
309
|
+
|
310
|
+
Can be found [here](https://github.com/hideya/langchain-mcp-tools-py/blob/main/CHANGELOG.md)
|
311
|
+
|
312
|
+
## Appendix
|
313
|
+
|
314
|
+
### Troubleshooting Authentication Issues
|
315
|
+
|
316
|
+
When authentication errors occur, they often generate massive logs that make it difficult to identify that authentication is the root cause.
|
317
|
+
|
318
|
+
To address this problem, this library performs authentication pre-validation for HTTP/HTTPS MCP servers before attempting the actual MCP connection.
|
319
|
+
This ensures that clear error messages like `Authentication failed (401 Unauthorized)` or `Authentication failed (403 Forbidden)` appear at the end of the logs, rather than being buried in the middle of extensive error output.
|
320
|
+
|
321
|
+
**Important:** This pre-validation is specific to this library and not part of the official MCP specification.
|
322
|
+
In rare cases, it may interfere with certain MCP server behaviors.
|
323
|
+
|
324
|
+
#### When and How to Disable Pre-validation
|
325
|
+
Set `"__pre_validate_authentication": False` in your server config if:
|
326
|
+
- Using OAuth flows that require complex authentication handshakes
|
327
|
+
- The MCP server doesn't accept simple HTTP POST requests for validation
|
328
|
+
- You're experiencing false negatives in the auth validation
|
329
|
+
|
330
|
+
**Example:**
|
331
|
+
```python
|
332
|
+
"oauth-server": {
|
333
|
+
"url": "https://api.example.com/mcp/",
|
334
|
+
"auth": oauth_provider, # Complex OAuth provider
|
335
|
+
"__pre_validate_authentication": False # Skip the pre-validation
|
336
|
+
}
|
337
|
+
```
|
338
|
+
|
339
|
+
#### Debugging Authentication
|
340
|
+
1. **Check your tokens/credentials** - Most auth failures are due to expired or incorrect tokens
|
341
|
+
2. **Verify token permissions** - Some MCP servers require specific scopes (e.g., GitHub Copilot license)
|
342
|
+
3. **Test with curl** - Try a simple HTTP request to verify your auth setup:
|
343
|
+
```bash
|
344
|
+
curl -H "Authorization: Bearer your-token" https://api.example.com/mcp/
|
345
|
+
```
|
346
|
+
|
347
|
+
### Transport Selection Issues
|
348
|
+
|
349
|
+
The library automatically selects the appropriate transport based on your configuration:
|
350
|
+
|
351
|
+
1. **Explicit transport field** takes priority
|
352
|
+
2. **URL protocol detection** (http/https → Streamable HTTP → SSE fallback, ws/wss → WebSocket)
|
353
|
+
3. **Command presence** → stdio transport
|
354
|
+
|
355
|
+
#### Common Issues
|
356
|
+
- **Both url and command specified**: Choose one approach per server
|
357
|
+
- **Transport/URL mismatch**: e.g., `"transport": "websocket"` with `"url": "https://..."`
|
358
|
+
- **Missing required fields**: Must have either `url` or `command`
|
359
|
+
|
360
|
+
#### Auto-detection vs Explicit
|
361
|
+
For HTTP servers, the library tries Streamable HTTP first, then falls back to SSE on 4xx errors (per MCP specification). Use explicit `"transport"` if you want to skip auto-detection.
|
362
|
+
|
363
|
+
### Debug Mode
|
364
|
+
|
365
|
+
For detailed debugging, enable debug logging:
|
366
|
+
|
367
|
+
```python
|
368
|
+
import logging
|
369
|
+
logging.getLogger("langchain_mcp_tools").setLevel(logging.DEBUG)
|
370
|
+
|
371
|
+
# Also useful for transport debugging:
|
372
|
+
logging.getLogger("mcp").setLevel(logging.DEBUG)
|
373
|
+
```
|
374
|
+
|
375
|
+
This will show:
|
376
|
+
- Transport selection decisions
|
377
|
+
- Authentication validation attempts
|
378
|
+
- Tool discovery and conversion steps
|
379
|
+
- Connection establishment details
|
380
|
+
|
381
|
+
### For Developers
|
382
|
+
|
383
|
+
For deeper technical details about implementation challenges and solutions, see [TECHNICAL.md](TECHNICAL.md).
|
@@ -0,0 +1,8 @@
|
|
1
|
+
langchain_mcp_tools/__init__.py,sha256=vAPa7NK9mcKyzLFwiwF7nzvevHil4Tylc3EhE2CFEn4,223
|
2
|
+
langchain_mcp_tools/langchain_mcp_tools.py,sha256=jgwLcmuBD00yvf-p_N7YapKO8Jvu7-UWTCsIB91ttS0,47665
|
3
|
+
langchain_mcp_tools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
+
langchain_mcp_tools-0.2.5.dist-info/licenses/LICENSE,sha256=CRC91e8v116gCpnp7h49oIa6_zjhxqnHFTREeoZFJwA,1072
|
5
|
+
langchain_mcp_tools-0.2.5.dist-info/METADATA,sha256=W9Hs56GOwtt1JK77p24fbhIWLe5jrx4HmkGxfp9gMCU,16078
|
6
|
+
langchain_mcp_tools-0.2.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
7
|
+
langchain_mcp_tools-0.2.5.dist-info/top_level.txt,sha256=aR_9V2A1Yt-Bca60KmndmGLUWb2wiM5IOG-Gkaf1dxY,20
|
8
|
+
langchain_mcp_tools-0.2.5.dist-info/RECORD,,
|
@@ -1,232 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: langchain-mcp-tools
|
3
|
-
Version: 0.2.4
|
4
|
-
Summary: Model Context Protocol (MCP) To LangChain Tools Conversion Utility
|
5
|
-
Project-URL: Bug Tracker, https://github.com/hideya/langchain-mcp-tools-py/issues
|
6
|
-
Project-URL: Source Code, https://github.com/hideya/langchain-mcp-tools-py
|
7
|
-
Keywords: modelcontextprotocol,mcp,mcp-client,langchain,langchain-python,tool-call,tool-calling,python
|
8
|
-
Requires-Python: >=3.11
|
9
|
-
Description-Content-Type: text/markdown
|
10
|
-
License-File: LICENSE
|
11
|
-
Requires-Dist: jsonschema-pydantic>=0.6
|
12
|
-
Requires-Dist: langchain>=0.3.14
|
13
|
-
Requires-Dist: mcp>=1.6.0
|
14
|
-
Provides-Extra: dev
|
15
|
-
Requires-Dist: dotenv>=0.9.9; extra == "dev"
|
16
|
-
Requires-Dist: fastapi>=0.115.12; extra == "dev"
|
17
|
-
Requires-Dist: pyjwt>=2.10.1; extra == "dev"
|
18
|
-
Requires-Dist: langchain-anthropic>=0.3.1; extra == "dev"
|
19
|
-
Requires-Dist: langchain-groq>=0.2.3; extra == "dev"
|
20
|
-
Requires-Dist: langchain-openai>=0.3.0; extra == "dev"
|
21
|
-
Requires-Dist: langgraph>=0.2.62; extra == "dev"
|
22
|
-
Requires-Dist: pytest>=8.3.4; extra == "dev"
|
23
|
-
Requires-Dist: pytest-asyncio>=0.25.2; extra == "dev"
|
24
|
-
Requires-Dist: websockets>=15.0.1; extra == "dev"
|
25
|
-
Dynamic: license-file
|
26
|
-
|
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
|
-
|
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
|
-
|
39
|
-
This package is intended to simplify the use of
|
40
|
-
[Model Context Protocol (MCP)](https://modelcontextprotocol.io/)
|
41
|
-
server tools with LangChain / Python.
|
42
|
-
|
43
|
-
[Model Context Protocol (MCP)](https://modelcontextprotocol.io/),
|
44
|
-
an open standard
|
45
|
-
[announced by Anthropic](https://www.anthropic.com/news/model-context-protocol),
|
46
|
-
dramatically expands LLM’s scope
|
47
|
-
by enabling external tool and resource integration, including
|
48
|
-
GitHub, Google Drive, Slack, Notion, Spotify, Docker, PostgreSQL, and more…
|
49
|
-
|
50
|
-
MCP is likely to become the de facto industry standard as
|
51
|
-
[OpenAI has announced its adoption](https://techcrunch.com/2025/03/26/openai-adopts-rival-anthropics-standard-for-connecting-ai-models-to-data).
|
52
|
-
|
53
|
-
Over 2000 functional components available as MCP servers:
|
54
|
-
|
55
|
-
- [MCP Server Listing on the Official Site](https://github.com/modelcontextprotocol/servers?tab=readme-ov-file#model-context-protocol-servers)
|
56
|
-
- [MCP.so - Find Awesome MCP Servers and Clients](https://mcp.so/)
|
57
|
-
- [Smithery: MCP Server Registry](https://smithery.ai/)
|
58
|
-
|
59
|
-
The goal of this utility is to make these 2000+ MCP servers readily accessible from LangChain.
|
60
|
-
|
61
|
-
It contains a utility function `convert_mcp_to_langchain_tools()`.
|
62
|
-
This async function handles parallel initialization of specified multiple MCP servers
|
63
|
-
and converts their available tools into a list of LangChain-compatible tools.
|
64
|
-
|
65
|
-
For detailed information on how to use this library, please refer to the following document:
|
66
|
-
- ["Supercharging LangChain: Integrating 2000+ MCP with ReAct"](https://medium.com/@h1deya/supercharging-langchain-integrating-450-mcp-with-react-d4e467cbf41a)
|
67
|
-
|
68
|
-
A typescript equivalent of this utility is available
|
69
|
-
[here](https://www.npmjs.com/package/@h1deya/langchain-mcp-tools)
|
70
|
-
|
71
|
-
## Prerequisites
|
72
|
-
|
73
|
-
- Python 3.11+
|
74
|
-
|
75
|
-
## Installation
|
76
|
-
|
77
|
-
```bash
|
78
|
-
pip install langchain-mcp-tools
|
79
|
-
```
|
80
|
-
|
81
|
-
## API docs
|
82
|
-
|
83
|
-
Can be found [here](https://hideya.github.io/langchain-mcp-tools-py/)
|
84
|
-
|
85
|
-
|
86
|
-
## Quick Start
|
87
|
-
|
88
|
-
A minimal but complete working usage example can be found
|
89
|
-
[in this example in the langchain-mcp-tools-py-usage repo](https://github.com/hideya/langchain-mcp-tools-py-usage/blob/main/src/example.py)
|
90
|
-
|
91
|
-
`convert_mcp_to_langchain_tools()` utility function accepts MCP server configurations
|
92
|
-
that follow the same structure as
|
93
|
-
[Claude for Desktop](https://modelcontextprotocol.io/quickstart/user),
|
94
|
-
but only the contents of the `mcpServers` property,
|
95
|
-
and is expressed as a `dict`, e.g.:
|
96
|
-
|
97
|
-
```python
|
98
|
-
mcp_servers = {
|
99
|
-
"filesystem": {
|
100
|
-
"command": "npx",
|
101
|
-
"args": ["-y", "@modelcontextprotocol/server-filesystem", "."]
|
102
|
-
},
|
103
|
-
"fetch": {
|
104
|
-
"command": "uvx",
|
105
|
-
"args": ["mcp-server-fetch"]
|
106
|
-
}
|
107
|
-
}
|
108
|
-
|
109
|
-
tools, cleanup = await convert_mcp_to_langchain_tools(
|
110
|
-
mcp_servers
|
111
|
-
)
|
112
|
-
```
|
113
|
-
|
114
|
-
This utility function initializes all specified MCP servers in parallel,
|
115
|
-
and returns LangChain Tools
|
116
|
-
([`tools: list[BaseTool]`](https://python.langchain.com/api_reference/core/tools/langchain_core.tools.base.BaseTool.html#langchain_core.tools.base.BaseTool))
|
117
|
-
by gathering available MCP tools from the servers,
|
118
|
-
and by wrapping them into LangChain tools.
|
119
|
-
It also returns an async callback function (`cleanup: McpServerCleanupFn`)
|
120
|
-
to be invoked to close all MCP server sessions when finished.
|
121
|
-
|
122
|
-
The returned tools can be used with LangChain, e.g.:
|
123
|
-
|
124
|
-
```python
|
125
|
-
# from langchain.chat_models import init_chat_model
|
126
|
-
llm = init_chat_model(
|
127
|
-
model="claude-3-7-sonnet-latest",
|
128
|
-
model_provider="anthropic"
|
129
|
-
)
|
130
|
-
|
131
|
-
# from langgraph.prebuilt import create_react_agent
|
132
|
-
agent = create_react_agent(
|
133
|
-
llm,
|
134
|
-
tools
|
135
|
-
)
|
136
|
-
```
|
137
|
-
|
138
|
-
For hands-on experimentation with MCP server integration,
|
139
|
-
try [this LangChain application built with the utility](https://github.com/hideya/mcp-client-langchain-py)
|
140
|
-
|
141
|
-
For detailed information on how to use this library, please refer to the following document:
|
142
|
-
["Supercharging LangChain: Integrating 2000+ MCP with ReAct"](https://medium.com/@h1deya/supercharging-langchain-integrating-450-mcp-with-react-d4e467cbf41a)
|
143
|
-
|
144
|
-
## Experimental Features
|
145
|
-
|
146
|
-
### Remote MCP Server Support
|
147
|
-
|
148
|
-
`mcp_servers` configuration for SSE and Websocket servers are as follows:
|
149
|
-
|
150
|
-
```python
|
151
|
-
"sse-server-name": {
|
152
|
-
"url": f"http://{sse_server_host}:{sse_server_port}/..."
|
153
|
-
},
|
154
|
-
|
155
|
-
"ws-server-name": {
|
156
|
-
"url": f"ws://{ws_server_host}:{ws_server_port}/..."
|
157
|
-
},
|
158
|
-
```
|
159
|
-
|
160
|
-
Note that the key `"url"` may be changed in the future to match
|
161
|
-
the MCP server configurations used by Claude for Desktop once
|
162
|
-
it introduces remote server support.
|
163
|
-
|
164
|
-
A usage example can be found [here](https://github.com/hideya/langchain-mcp-tools-py-usage/blob/3bd35d9fb49f4b631fe3d0cc8491d43cbf69693b/src/example.py#L43-L54)
|
165
|
-
|
166
|
-
### Authentication Support for SSE Connections
|
167
|
-
|
168
|
-
A new key `"headers"` has been introduced to pass HTTP headers to the SSE (Server-Sent Events) connection.
|
169
|
-
It takes `dict[str, str]` and is primarily intended to support SSE MCP servers
|
170
|
-
that require authentication via bearer tokens or other custom headers.
|
171
|
-
|
172
|
-
```python
|
173
|
-
"sse-server-name": {
|
174
|
-
"url": f"http://{sse_server_host}:{sse_server_port}/..."
|
175
|
-
"headers": {"Authorization": f"Bearer {bearer_token}"}
|
176
|
-
},
|
177
|
-
```
|
178
|
-
|
179
|
-
The key name `header` is derived from the Python SDK
|
180
|
-
[`sse_client()`](https://github.com/modelcontextprotocol/python-sdk/blob/babb477dffa33f46cdc886bc885eb1d521151430/src/mcp/client/sse.py#L24) argument name.
|
181
|
-
|
182
|
-
A simple example showing how to implement MCP SSE server and client with authentication can be found
|
183
|
-
in [sse-auth-test-client.py](https://github.com/hideya/langchain-mcp-tools-py-usage/tree/main/src/sse-auth-test-client.py)
|
184
|
-
and in [sse-auth-test-server.py](https://github.com/hideya/langchain-mcp-tools-py-usage/tree/main/src/sse-auth-test-server.py)
|
185
|
-
of [this usage examples repo](https://github.com/hideya/langchain-mcp-tools-py-usage).
|
186
|
-
|
187
|
-
### Working Directory Configuration for Local MCP Servers
|
188
|
-
|
189
|
-
The working directory that is used when spawning a local (stdio) MCP server
|
190
|
-
can be specified with the `"cwd"` key as follows:
|
191
|
-
|
192
|
-
```python
|
193
|
-
"local-server-name": {
|
194
|
-
"command": "...",
|
195
|
-
"args": [...],
|
196
|
-
"cwd": "/working/directory" # the working dir to be use by the server
|
197
|
-
},
|
198
|
-
```
|
199
|
-
|
200
|
-
The key name `cwd` is derived from
|
201
|
-
Python SDK's [`StdioServerParameters`](https://github.com/modelcontextprotocol/python-sdk/blob/babb477dffa33f46cdc886bc885eb1d521151430/src/mcp/client/stdio/__init__.py#L76-L77).
|
202
|
-
|
203
|
-
### stderr Redirection for Local MCP Server
|
204
|
-
|
205
|
-
A new key `"errlog"` has been introduced to specify a file-like object
|
206
|
-
to which local (stdio) MCP server's stderr is redirected.
|
207
|
-
|
208
|
-
```python
|
209
|
-
log_path = f"mcp-server-{server_name}.log"
|
210
|
-
log_file = open(log_path, "w")
|
211
|
-
mcp_servers[server_name]["errlog"] = log_file
|
212
|
-
```
|
213
|
-
|
214
|
-
A usage example can be found [here](https://github.com/hideya/langchain-mcp-tools-py-usage/blob/3bd35d9fb49f4b631fe3d0cc8491d43cbf69693b/src/example.py#L88-L108)
|
215
|
-
|
216
|
-
**NOTE: Why the key name `errlog` was chosen:**
|
217
|
-
Unlike TypeScript SDK's `StdioServerParameters`, the Python
|
218
|
-
SDK's `StdioServerParameters` doesn't include `stderr: int`.
|
219
|
-
Instead, it calls [`stdio_client()` with a separate argument
|
220
|
-
`errlog: TextIO`](https://github.com/modelcontextprotocol/python-sdk/blob/babb477dffa33f46cdc886bc885eb1d521151430/src/mcp/client/stdio/__init__.py#L96).
|
221
|
-
I once included `stderr: int` for
|
222
|
-
compatibility with the TypeScript version, but decided to
|
223
|
-
follow the Python SDK more closely.
|
224
|
-
|
225
|
-
## Limitations
|
226
|
-
|
227
|
-
- Currently, only text results of tool calls are supported.
|
228
|
-
- MCP features other than [Tools](https://modelcontextprotocol.io/docs/concepts/tools) are not supported.
|
229
|
-
|
230
|
-
## Change Log
|
231
|
-
|
232
|
-
Can be found [here](https://github.com/hideya/langchain-mcp-tools-py/blob/main/CHANGELOG.md)
|
@@ -1,8 +0,0 @@
|
|
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,,
|
{langchain_mcp_tools-0.2.4.dist-info → langchain_mcp_tools-0.2.5.dist-info}/licenses/LICENSE
RENAMED
File without changes
|
File without changes
|