@h1deya/langchain-mcp-tools 0.2.0 → 0.2.2
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 +68 -13
- package/dist/langchain-mcp-tools.d.ts +6 -0
- package/dist/langchain-mcp-tools.js +16 -1
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -5,11 +5,14 @@ This package is intended to simplify the use of
|
|
|
5
5
|
server tools with LangChain / TypeScript.
|
|
6
6
|
|
|
7
7
|
[Model Context Protocol (MCP)](https://modelcontextprotocol.io/),
|
|
8
|
-
an open
|
|
8
|
+
an open standard
|
|
9
9
|
[announced by Anthropic](https://www.anthropic.com/news/model-context-protocol),
|
|
10
|
-
dramatically expands LLM
|
|
10
|
+
dramatically expands LLM's scope
|
|
11
11
|
by enabling external tool and resource integration, including
|
|
12
|
-
Google Drive, Slack, Notion, Spotify, Docker, PostgreSQL, and more…
|
|
12
|
+
GitHub, Google Drive, Slack, Notion, Spotify, Docker, PostgreSQL, and more…
|
|
13
|
+
|
|
14
|
+
MCP is likely to become the de facto industry standard as
|
|
15
|
+
[OpenAI has announced its adoption](https://techcrunch.com/2025/03/26/openai-adopts-rival-anthropics-standard-for-connecting-ai-models-to-data).
|
|
13
16
|
|
|
14
17
|
Over 2000 functional components available as MCP servers:
|
|
15
18
|
|
|
@@ -24,7 +27,7 @@ This async function handles parallel initialization of specified multiple MCP se
|
|
|
24
27
|
and converts their available tools into an array of LangChain-compatible tools.
|
|
25
28
|
|
|
26
29
|
For detailed information on how to use this library, please refer to the following document:
|
|
27
|
-
- ["Supercharging LangChain: Integrating 2000+ MCP with
|
|
30
|
+
- ["Supercharging LangChain: Integrating 2000+ MCP with ReAct"](https://medium.com/@h1deya/supercharging-langchain-integrating-450-mcp-with-react-d4e467cbf41a)
|
|
28
31
|
|
|
29
32
|
A python equivalent of this utility is available
|
|
30
33
|
[here](https://pypi.org/project/langchain-mcp-tools)
|
|
@@ -41,6 +44,9 @@ npm i @h1deya/langchain-mcp-tools
|
|
|
41
44
|
|
|
42
45
|
## Quick Start
|
|
43
46
|
|
|
47
|
+
A minimal but complete working usage example can be found
|
|
48
|
+
[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)
|
|
49
|
+
|
|
44
50
|
`convertMcpToLangchainTools()` utility function accepts MCP server configurations
|
|
45
51
|
that follow the same structure as
|
|
46
52
|
[Claude for Desktop](https://modelcontextprotocol.io/quickstart/user),
|
|
@@ -83,14 +89,11 @@ const agent = createReactAgent({
|
|
|
83
89
|
});
|
|
84
90
|
```
|
|
85
91
|
|
|
86
|
-
Find complete, minimal working usage examples
|
|
87
|
-
[here](https://github.com/hideya/langchain-mcp-tools-ts-usage/blob/main/src/index.ts)
|
|
88
|
-
|
|
89
92
|
For hands-on experimentation with MCP server integration,
|
|
90
93
|
try [this LangChain application built with the utility](https://github.com/hideya/mcp-client-langchain-ts)
|
|
91
94
|
|
|
92
95
|
For detailed information on how to use this library, please refer to the following document:
|
|
93
|
-
["Supercharging LangChain: Integrating 2000+ MCP with
|
|
96
|
+
["Supercharging LangChain: Integrating 2000+ MCP with ReAct"](https://medium.com/@h1deya/supercharging-langchain-integrating-450-mcp-with-react-d4e467cbf41a)
|
|
94
97
|
|
|
95
98
|
## Experimental Features
|
|
96
99
|
|
|
@@ -112,9 +115,57 @@ Note that the key `"url"` may be changed in the future to match
|
|
|
112
115
|
the MCP server configurations used by Claude for Desktop once
|
|
113
116
|
it introduces remote server support.
|
|
114
117
|
|
|
118
|
+
A usage example can be found [here](
|
|
119
|
+
https://github.com/hideya/langchain-mcp-tools-ts-usage/blob/694b877ed5336bfcd5274d95d3f6d14bed0937a6/src/index.ts#L26-L38)
|
|
120
|
+
|
|
121
|
+
### Authentication Support for SSE Connections
|
|
122
|
+
|
|
123
|
+
The library now supports authentication for SSE connections to MCP servers.
|
|
124
|
+
This is particularly useful for accessing authenticated MCP servers that require OAuth.
|
|
125
|
+
|
|
126
|
+
To enable authentication, provide SSE options in your server configuration:
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js';
|
|
130
|
+
|
|
131
|
+
// Implement your own OAuth client provider
|
|
132
|
+
class MyOAuthProvider implements OAuthClientProvider {
|
|
133
|
+
// Implementation details...
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const mcpServers = {
|
|
137
|
+
"secure-server": {
|
|
138
|
+
url: "https://secure-mcp-server.example.com",
|
|
139
|
+
sseOptions: {
|
|
140
|
+
// Provide an OAuth client provider
|
|
141
|
+
authProvider: new MyOAuthProvider(),
|
|
142
|
+
|
|
143
|
+
// Optionally customize the initial SSE request
|
|
144
|
+
eventSourceInit: {
|
|
145
|
+
// Custom options
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
// Optionally customize recurring POST requests
|
|
149
|
+
requestInit: {
|
|
150
|
+
headers: {
|
|
151
|
+
'X-Custom-Header': 'custom-value'
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
A simple but complete example showing how to implement an OAuth client provider can be found
|
|
160
|
+
in the [sse-auth-test-client.ts](https://github.com/hideya/langchain-mcp-tools-ts/tree/main/testfiles/sse-auth-test-client.ts) file.
|
|
161
|
+
Note that this is test code for this library and does not use the npm.js library.
|
|
162
|
+
|
|
163
|
+
FYI, a sample MCP server with OAuth authentication support is also provided
|
|
164
|
+
in [sse-auth-test-server.ts](https://github.com/hideya/langchain-mcp-tools-ts/tree/main/testfiles/sse-auth-test-server.ts).
|
|
165
|
+
|
|
115
166
|
### Working Directory Configuration for Local MCP Servers
|
|
116
167
|
|
|
117
|
-
The working directory that is used when spawning a local MCP server
|
|
168
|
+
The working directory that is used when spawning a local (stdio) MCP server
|
|
118
169
|
can be specified with the `"cwd"` key as follows:
|
|
119
170
|
|
|
120
171
|
```ts
|
|
@@ -125,10 +176,13 @@ can be specified with the `"cwd"` key as follows:
|
|
|
125
176
|
},
|
|
126
177
|
```
|
|
127
178
|
|
|
128
|
-
|
|
179
|
+
The key name `cwd` is derived from TypeScript SDK's `StdioServerParameters`.
|
|
180
|
+
|
|
181
|
+
### Configuration for Local MCP Server `stderr` Redirection
|
|
129
182
|
|
|
130
183
|
A new key `"stderr"` has been introduced to specify a file descriptor
|
|
131
|
-
to which MCP server's stderr is redirected.
|
|
184
|
+
to which local (stdio) MCP server's stderr is redirected.
|
|
185
|
+
The key name `stderr` is derived from TypeScript SDK's `StdioServerParameters`.
|
|
132
186
|
|
|
133
187
|
```ts
|
|
134
188
|
const logPath = `mcp-server-${serverName}.log`;
|
|
@@ -136,12 +190,13 @@ to which MCP server's stderr is redirected.
|
|
|
136
190
|
mcpServers[serverName].stderr = logFd;
|
|
137
191
|
```
|
|
138
192
|
|
|
139
|
-
|
|
193
|
+
A usage example can be found [here](
|
|
194
|
+
https://github.com/hideya/langchain-mcp-tools-ts-usage/blob/694b877ed5336bfcd5274d95d3f6d14bed0937a6/src/index.ts#L72-L83)
|
|
140
195
|
|
|
141
196
|
## Limitations
|
|
142
197
|
|
|
143
198
|
- Currently, only text results of tool calls are supported.
|
|
144
|
-
-
|
|
199
|
+
- MCP features other than [Tools](https://modelcontextprotocol.io/docs/concepts/tools) are not supported.
|
|
145
200
|
|
|
146
201
|
## Change Log
|
|
147
202
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IOType } from "node:child_process";
|
|
2
2
|
import { Stream } from "node:stream";
|
|
3
3
|
import { StructuredTool } from "@langchain/core/tools";
|
|
4
|
+
import { OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
4
5
|
interface CommandBasedConfig {
|
|
5
6
|
url?: never;
|
|
6
7
|
command: string;
|
|
@@ -16,6 +17,11 @@ interface UrlBasedConfig {
|
|
|
16
17
|
env?: never;
|
|
17
18
|
stderr?: never;
|
|
18
19
|
cwd?: never;
|
|
20
|
+
sseOptions?: {
|
|
21
|
+
authProvider?: OAuthClientProvider;
|
|
22
|
+
eventSourceInit?: EventSourceInit;
|
|
23
|
+
requestInit?: RequestInit;
|
|
24
|
+
};
|
|
19
25
|
}
|
|
20
26
|
type McpServerConfig = CommandBasedConfig | UrlBasedConfig;
|
|
21
27
|
export interface McpServersConfig {
|
|
@@ -107,7 +107,22 @@ async function convertSingleMcpToLangchainTools(serverName, config, logger) {
|
|
|
107
107
|
// Ignore
|
|
108
108
|
}
|
|
109
109
|
if (url?.protocol === "http:" || url?.protocol === "https:") {
|
|
110
|
-
|
|
110
|
+
// Extract SSE options from config if available
|
|
111
|
+
const urlConfig = config;
|
|
112
|
+
const sseOptions = {};
|
|
113
|
+
if (urlConfig.sseOptions) {
|
|
114
|
+
if (urlConfig.sseOptions.authProvider) {
|
|
115
|
+
sseOptions.authProvider = urlConfig.sseOptions.authProvider;
|
|
116
|
+
logger.info(`MCP server "${serverName}": configuring SSE with authentication provider`);
|
|
117
|
+
}
|
|
118
|
+
if (urlConfig.sseOptions.eventSourceInit) {
|
|
119
|
+
sseOptions.eventSourceInit = urlConfig.sseOptions.eventSourceInit;
|
|
120
|
+
}
|
|
121
|
+
if (urlConfig.sseOptions.requestInit) {
|
|
122
|
+
sseOptions.requestInit = urlConfig.sseOptions.requestInit;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
transport = new SSEClientTransport(url, Object.keys(sseOptions).length > 0 ? sseOptions : undefined);
|
|
111
126
|
}
|
|
112
127
|
else if (url?.protocol === "ws:" || url?.protocol === "wss:") {
|
|
113
128
|
transport = new WebSocketClientTransport(url);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h1deya/langchain-mcp-tools",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "MCP To LangChain Tools Conversion Utility",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -34,6 +34,9 @@
|
|
|
34
34
|
"prepare": "npm run build",
|
|
35
35
|
"watch": "tsc --watch",
|
|
36
36
|
"simple-usage": "tsx testfiles/simple-usage.ts",
|
|
37
|
+
"direct-test": "tsx -- testfiles/direct-test.ts",
|
|
38
|
+
"sse-auth-test-client": "tsx testfiles/sse-auth-test-client.ts",
|
|
39
|
+
"sse-auth-test-server": "tsx testfiles/sse-auth-test-server.ts",
|
|
37
40
|
"lint": "eslint src",
|
|
38
41
|
"test": "vitest run",
|
|
39
42
|
"test:watch": "vitest",
|
|
@@ -46,7 +49,6 @@
|
|
|
46
49
|
"@langchain/core": "^0.3.27",
|
|
47
50
|
"@modelcontextprotocol/sdk": "^1.8.0",
|
|
48
51
|
"@n8n/json-schema-to-zod": "^1.1.0",
|
|
49
|
-
"ws": "^8.18.1",
|
|
50
52
|
"zod": "^3.24.1"
|
|
51
53
|
},
|
|
52
54
|
"devDependencies": {
|
|
@@ -58,11 +60,15 @@
|
|
|
58
60
|
"@typescript-eslint/eslint-plugin": "^8.19.0",
|
|
59
61
|
"@typescript-eslint/parser": "^8.19.0",
|
|
60
62
|
"@vitest/coverage-v8": "^3.0.9",
|
|
63
|
+
"cors": "^2.8.5",
|
|
61
64
|
"dotenv": "^16.4.7",
|
|
62
65
|
"eslint": "^9.17.0",
|
|
66
|
+
"express": "^4.19.2",
|
|
63
67
|
"tsx": "^4.19.3",
|
|
64
68
|
"typescript": "^5.7.2",
|
|
65
69
|
"typescript-eslint": "^8.19.0",
|
|
66
|
-
"
|
|
70
|
+
"uuid": "^9.0.1",
|
|
71
|
+
"vitest": "^3.0.9",
|
|
72
|
+
"ws": "^8.18.1"
|
|
67
73
|
}
|
|
68
74
|
}
|