@h1deya/langchain-mcp-tools 0.3.8 → 0.3.9
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.
- package/README.md +39 -36
- package/package.json +17 -12
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ However, it only supports text results of tool calls and does not support MCP fe
|
|
|
14
14
|
|
|
15
15
|
[LangChain's **official LangChain.js MCP Adapters** library](https://www.npmjs.com/package/@langchain/mcp-adapters),
|
|
16
16
|
which supports comprehensive integration with LangChain, has been released.
|
|
17
|
-
You
|
|
17
|
+
You might want to consider using it if the extra features that this library supports are not necessary.
|
|
18
18
|
|
|
19
19
|
## Prerequisites
|
|
20
20
|
|
|
@@ -44,6 +44,11 @@ const mcpServers: McpServersConfig = {
|
|
|
44
44
|
command: "uvx",
|
|
45
45
|
args: ["mcp-server-fetch"]
|
|
46
46
|
},
|
|
47
|
+
"brave-search": {
|
|
48
|
+
command: "npx",
|
|
49
|
+
args: [ "-y", "@modelcontextprotocol/server-brave-search"],
|
|
50
|
+
env: { "BRAVE_API_KEY": `${process.env.BRAVE_API_KEY}` }
|
|
51
|
+
},
|
|
47
52
|
github: {
|
|
48
53
|
type: "http",
|
|
49
54
|
url: "https://api.githubcopilot.com/mcp/",
|
|
@@ -86,16 +91,35 @@ to be invoked to close all MCP server sessions when finished.
|
|
|
86
91
|
The returned tools can be used with LangChain, e.g.:
|
|
87
92
|
|
|
88
93
|
```ts
|
|
89
|
-
// import {
|
|
90
|
-
const
|
|
94
|
+
// import { createAgent } from "langchain";
|
|
95
|
+
const model = new ChatGoogleGenerativeAI({ model: "gemini-2.5-flash" });
|
|
91
96
|
|
|
92
97
|
// import { createReactAgent } from "@langchain/langgraph/prebuilt";
|
|
93
|
-
const agent =
|
|
94
|
-
|
|
98
|
+
const agent = createAgent({
|
|
99
|
+
model,
|
|
95
100
|
tools
|
|
96
101
|
});
|
|
97
102
|
```
|
|
98
103
|
|
|
104
|
+
The returned `cleanup` function properly handles resource cleanup:
|
|
105
|
+
|
|
106
|
+
- Closes all MCP server connections concurrently and logs any cleanup failures
|
|
107
|
+
- Continues cleanup of remaining servers even if some fail
|
|
108
|
+
- Should always be called when done using the tools
|
|
109
|
+
|
|
110
|
+
It is typically invoked in a finally block:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
const { tools, cleanup } = await convertMcpToLangchainTools(mcpServers);
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
// Use tools with your LLM
|
|
117
|
+
} finally {
|
|
118
|
+
// Always cleanup, even if errors occur
|
|
119
|
+
await cleanup();
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
99
123
|
A minimal but complete working usage example can be found
|
|
100
124
|
[in this example in the langchain-mcp-tools-ts-usage repo](https://github.com/hideya/langchain-mcp-tools-ts-usage/blob/main/src/index.ts)
|
|
101
125
|
|
|
@@ -145,14 +169,6 @@ While MCP tools can return multiple content types (text, images, etc.), this lib
|
|
|
145
169
|
[See below](https://github.com/hideya/langchain-mcp-tools-ts/blob/main/README.md#llm-provider-schema-compatibility) for details.
|
|
146
170
|
- **Passing PATH Env Variable**: The library automatically adds the `PATH` environment variable to stdio server configrations if not explicitly provided to ensure servers can find required executables.
|
|
147
171
|
|
|
148
|
-
## API docs
|
|
149
|
-
|
|
150
|
-
Can be found [here](https://hideya.github.io/langchain-mcp-tools-ts/modules.html)
|
|
151
|
-
|
|
152
|
-
## Building from Source
|
|
153
|
-
|
|
154
|
-
See [README_DEV.md](https://github.com/hideya/langchain-mcp-tools-ts/blob/main/README_DEV.md) for details.
|
|
155
|
-
|
|
156
172
|
## Features
|
|
157
173
|
|
|
158
174
|
### `stderr` Redirection for Local MCP Server
|
|
@@ -260,10 +276,10 @@ Streamable HTTP is the modern MCP transport that replaces the older HTTP+SSE tra
|
|
|
260
276
|
|
|
261
277
|
### Accessing Remote MCP Servers with OAuth Quickly
|
|
262
278
|
|
|
263
|
-
If you need to use MCP servers that require OAuth
|
|
279
|
+
If you need to use MCP servers that require OAuth, consider using **"[mcp-remote](https://www.npmjs.com/package/mcp-remote)"**.
|
|
264
280
|
|
|
265
281
|
```ts
|
|
266
|
-
|
|
282
|
+
notion: {
|
|
267
283
|
command: "npx",
|
|
268
284
|
args: ["-y", "mcp-remote", "https://mcp.notion.com/mcp"],
|
|
269
285
|
},
|
|
@@ -313,10 +329,18 @@ Test implementations are provided:
|
|
|
313
329
|
- MCP client uses this library: [streamable-http-auth-test-client.ts](https://github.com/hideya/langchain-mcp-tools-ts/tree/main/testfiles/streamable-http-auth-test-client.ts)
|
|
314
330
|
- Test MCP Server: [streamable-http-auth-test-server.ts](https://github.com/hideya/langchain-mcp-tools-ts/tree/main/testfiles/streamable-http-auth-test-server.ts)
|
|
315
331
|
|
|
332
|
+
## API docs
|
|
333
|
+
|
|
334
|
+
Can be found [here](https://hideya.github.io/langchain-mcp-tools-ts/modules.html)
|
|
335
|
+
|
|
316
336
|
## Change Log
|
|
317
337
|
|
|
318
338
|
Can be found [here](https://github.com/hideya/langchain-mcp-tools-ts/blob/main/CHANGELOG.md)
|
|
319
339
|
|
|
340
|
+
## Building from Source
|
|
341
|
+
|
|
342
|
+
See [README_DEV.md](https://github.com/hideya/langchain-mcp-tools-ts/blob/main/README_DEV.md) for details.
|
|
343
|
+
|
|
320
344
|
## Appendix
|
|
321
345
|
|
|
322
346
|
### Troubleshooting
|
|
@@ -408,27 +432,6 @@ const { tools, cleanup } = await convertMcpToLangchainTools(
|
|
|
408
432
|
- [Gemini API Schema Requirements](https://ai.google.dev/api/caching#Schema)
|
|
409
433
|
- [Anthropic Tool Use](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview)
|
|
410
434
|
|
|
411
|
-
|
|
412
|
-
### Resource Management
|
|
413
|
-
|
|
414
|
-
The returned `cleanup` function properly handles resource cleanup:
|
|
415
|
-
|
|
416
|
-
- Closes all MCP server connections concurrently
|
|
417
|
-
- Logs any cleanup failures
|
|
418
|
-
- Continues cleanup of remaining servers even if some fail
|
|
419
|
-
- Should always be called when done using the tools
|
|
420
|
-
|
|
421
|
-
```ts
|
|
422
|
-
const { tools, cleanup } = await convertMcpToLangchainTools(mcpServers);
|
|
423
|
-
|
|
424
|
-
try {
|
|
425
|
-
// Use tools with your LLM
|
|
426
|
-
} finally {
|
|
427
|
-
// Always cleanup, even if errors occur
|
|
428
|
-
await cleanup();
|
|
429
|
-
}
|
|
430
|
-
```
|
|
431
|
-
|
|
432
435
|
### Debugging and Logging
|
|
433
436
|
|
|
434
437
|
The library provides configurable logging to help debug connection and tool execution issues:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h1deya/langchain-mcp-tools",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.9",
|
|
4
4
|
"description": "MCP To LangChain Tools Conversion Utility",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -51,6 +51,8 @@
|
|
|
51
51
|
"test:coverage": "vitest run --coverage",
|
|
52
52
|
"_comment_examples": "# Basic usage examples",
|
|
53
53
|
"example:simple": "tsx testfiles/simple-usage.ts",
|
|
54
|
+
"_comment_sse_ws": "# SSE and WS transport tests",
|
|
55
|
+
"test:sse-and-ws": "tsx testfiles/sse-and-ws-test.ts",
|
|
54
56
|
"_comment_streamable": "# Streamable HTTP transport tests",
|
|
55
57
|
"test:streamable:auth:server": "tsx testfiles/streamable-http-auth-test-server.ts",
|
|
56
58
|
"test:streamable:auth:client": "tsx testfiles/streamable-http-auth-test-client.ts",
|
|
@@ -68,33 +70,36 @@
|
|
|
68
70
|
},
|
|
69
71
|
"dependencies": {
|
|
70
72
|
"@h1deya/json-schema-to-zod": "^0.1.1",
|
|
71
|
-
"@langchain/core": "
|
|
72
|
-
"@modelcontextprotocol/sdk": "
|
|
73
|
+
"@langchain/core": ">=0.3.62",
|
|
74
|
+
"@modelcontextprotocol/sdk": ">=1.15.0",
|
|
73
75
|
"zod": "^3.25.74"
|
|
74
76
|
},
|
|
75
77
|
"devDependencies": {
|
|
76
78
|
"@eslint/js": "^9.17.0",
|
|
77
|
-
"@langchain/anthropic": "^
|
|
78
|
-
"@langchain/cerebras": "^
|
|
79
|
-
"@langchain/google-genai": "^
|
|
80
|
-
"@langchain/groq": "^
|
|
81
|
-
"@langchain/
|
|
82
|
-
"@langchain/
|
|
83
|
-
"@
|
|
79
|
+
"@langchain/anthropic": "^1.3.17",
|
|
80
|
+
"@langchain/cerebras": "^1.0.1",
|
|
81
|
+
"@langchain/google-genai": "^2.1.18",
|
|
82
|
+
"@langchain/groq": "^1.1.0",
|
|
83
|
+
"@langchain/openai": "^1.2.7",
|
|
84
|
+
"@langchain/xai": "^1.3.3",
|
|
85
|
+
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
86
|
+
"@types/cors": "^2.8.19",
|
|
87
|
+
"@types/express": "^5.0.6",
|
|
84
88
|
"@types/node": "^22.10.5",
|
|
85
89
|
"@types/ws": "^8.18.1",
|
|
86
90
|
"@typescript-eslint/eslint-plugin": "^8.19.0",
|
|
87
91
|
"@typescript-eslint/parser": "^8.19.0",
|
|
88
|
-
"@vitest/coverage-v8": "^3.
|
|
92
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
89
93
|
"cors": "^2.8.5",
|
|
90
94
|
"dotenv": "^16.4.7",
|
|
91
95
|
"eslint": "^9.17.0",
|
|
92
96
|
"express": "^4.19.2",
|
|
97
|
+
"langchain": "^1.2.23",
|
|
93
98
|
"tsx": "^4.19.3",
|
|
94
99
|
"typedoc": "^0.28.3",
|
|
95
100
|
"typescript": "^5.7.2",
|
|
96
101
|
"typescript-eslint": "^8.19.0",
|
|
97
|
-
"vitest": "^3.
|
|
102
|
+
"vitest": "^3.2.4",
|
|
98
103
|
"ws": "^8.18.1"
|
|
99
104
|
}
|
|
100
105
|
}
|