@h1deya/langchain-mcp-tools 0.3.2 → 0.3.4
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 +48 -41
- package/dist/langchain-mcp-tools.d.ts +1 -1
- package/dist/langchain-mcp-tools.js +2 -2
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# MCP to LangChain Tools Conversion Utility / TypeScript [](https://github.com/hideya/langchain-mcp-tools-ts/blob/main/LICENSE) [](https://www.npmjs.com/package/@h1deya/langchain-mcp-tools) [](https://dependents.info/hideya/langchain-mcp-tools-ts)
|
|
1
|
+
# MCP to LangChain Tools Conversion Utility / TypeScript [](https://github.com/hideya/langchain-mcp-tools-ts/blob/main/LICENSE) [](https://www.npmjs.com/package/@h1deya/langchain-mcp-tools) [](https://dependents.info/hideya/langchain-mcp-tools-ts)
|
|
2
2
|
|
|
3
|
-
A simple, lightweight library
|
|
3
|
+
A simple, lightweight library to use
|
|
4
4
|
[Model Context Protocol (MCP)](https://modelcontextprotocol.io/)
|
|
5
5
|
server tools from LangChain.
|
|
6
6
|
|
|
@@ -16,30 +16,6 @@ However, it only supports text results of tool calls and does not support MCP fe
|
|
|
16
16
|
which supports comprehensive integration with LangChain, has been released.
|
|
17
17
|
You may want to consider using it if you don't have specific needs for this library.
|
|
18
18
|
|
|
19
|
-
## Introduction
|
|
20
|
-
|
|
21
|
-
This package is intended to simplify the use of
|
|
22
|
-
[Model Context Protocol (MCP)](https://modelcontextprotocol.io/)
|
|
23
|
-
server tools with LangChain / TypeScript.
|
|
24
|
-
|
|
25
|
-
[Model Context Protocol (MCP)](https://modelcontextprotocol.io/) is the de facto industry standard
|
|
26
|
-
that dramatically expands the scope of LLMs by enabling the integration of external tools and resources,
|
|
27
|
-
including DBs, Cloud Storages, GitHub, Docker, Slack, and more.
|
|
28
|
-
There are quite a few useful MCP servers already available.
|
|
29
|
-
See [MCP Server Listing on the Official Site](https://github.com/modelcontextprotocol/servers?tab=readme-ov-file#model-context-protocol-servers).
|
|
30
|
-
|
|
31
|
-
This utility's goal is to make these numerous MCP servers easily accessible from LangChain.
|
|
32
|
-
It contains a utility function `convertMcpToLangchainTools()`.
|
|
33
|
-
This async function handles parallel initialization of specified multiple MCP servers
|
|
34
|
-
and converts their available tools into an array of LangChain-compatible tools.
|
|
35
|
-
It also performs LLM provider-specific schema transformations
|
|
36
|
-
to prevent [schema compatibility issues](https://github.com/hideya/langchain-mcp-tools-ts/blob/main/README.md#llm-provider-schema-compatibility)
|
|
37
|
-
|
|
38
|
-
For detailed information on how to use this library, please refer to the following document:
|
|
39
|
-
["Supercharging LangChain: Integrating 2000+ MCP with ReAct"](https://medium.com/@h1deya/supercharging-langchain-integrating-450-mcp-with-react-d4e467cbf41a).
|
|
40
|
-
A Python equivalent of this utility is available
|
|
41
|
-
[here](https://pypi.org/project/langchain-mcp-tools)
|
|
42
|
-
|
|
43
19
|
## Prerequisites
|
|
44
20
|
|
|
45
21
|
- Node.js 18+
|
|
@@ -50,15 +26,8 @@ A Python equivalent of this utility is available
|
|
|
50
26
|
npm i @h1deya/langchain-mcp-tools
|
|
51
27
|
```
|
|
52
28
|
|
|
53
|
-
## API docs
|
|
54
|
-
|
|
55
|
-
Can be found [here](https://hideya.github.io/langchain-mcp-tools-ts/modules.html)
|
|
56
|
-
|
|
57
29
|
## Quick Start
|
|
58
30
|
|
|
59
|
-
A minimal but complete working usage example can be found
|
|
60
|
-
[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)
|
|
61
|
-
|
|
62
31
|
`convertMcpToLangchainTools()` utility function accepts MCP server configurations
|
|
63
32
|
that follow the same structure as
|
|
64
33
|
[Claude for Desktop](https://modelcontextprotocol.io/quickstart/user),
|
|
@@ -127,9 +96,30 @@ A minimal but complete working usage example can be found
|
|
|
127
96
|
For hands-on experimentation with MCP server integration,
|
|
128
97
|
try [this MCP Client CLI tool built with this library](https://www.npmjs.com/package/@h1deya/mcp-client-cli)
|
|
129
98
|
|
|
130
|
-
|
|
99
|
+
A Python equivalent of this utility is available
|
|
100
|
+
[here](https://pypi.org/project/langchain-mcp-tools)
|
|
131
101
|
|
|
132
|
-
|
|
102
|
+
## Introduction
|
|
103
|
+
|
|
104
|
+
This package is intended to simplify the use of
|
|
105
|
+
[Model Context Protocol (MCP)](https://modelcontextprotocol.io/)
|
|
106
|
+
server tools with LangChain / TypeScript.
|
|
107
|
+
|
|
108
|
+
[Model Context Protocol (MCP)](https://modelcontextprotocol.io/) is the de facto industry standard
|
|
109
|
+
that dramatically expands the scope of LLMs by enabling the integration of external tools and resources,
|
|
110
|
+
including DBs, Cloud Storages, GitHub, Docker, Slack, and more.
|
|
111
|
+
There are quite a few useful MCP servers already available.
|
|
112
|
+
See [MCP Server Listing on the Official Site](https://github.com/modelcontextprotocol/servers?tab=readme-ov-file#model-context-protocol-servers).
|
|
113
|
+
|
|
114
|
+
This utility's goal is to make these numerous MCP servers easily accessible from LangChain.
|
|
115
|
+
It contains a utility function `convertMcpToLangchainTools()`.
|
|
116
|
+
This async function handles parallel initialization of specified multiple MCP servers
|
|
117
|
+
and converts their available tools into an array of LangChain-compatible tools.
|
|
118
|
+
It also performs LLM provider-specific schema transformations
|
|
119
|
+
to prevent [schema compatibility issues](https://github.com/hideya/langchain-mcp-tools-ts/blob/main/README.md#llm-provider-schema-compatibility)
|
|
120
|
+
|
|
121
|
+
For detailed information on how to use this library, please refer to the following document:
|
|
122
|
+
["Supercharging LangChain: Integrating 2000+ MCP with ReAct"](https://medium.com/@h1deya/supercharging-langchain-integrating-450-mcp-with-react-d4e467cbf41a).
|
|
133
123
|
|
|
134
124
|
## MCP Protocol Support
|
|
135
125
|
|
|
@@ -143,12 +133,19 @@ The library uses LangChain's `response_format: 'content'` (the default), which o
|
|
|
143
133
|
While MCP tools can return multiple content types (text, images, etc.), this library currently filters and uses only text content.
|
|
144
134
|
- **MCP Features**: Only MCP [Tools](https://modelcontextprotocol.io/docs/concepts/tools) are supported. Other MCP features like Resources, Prompts, and Sampling are not implemented.
|
|
145
135
|
|
|
146
|
-
### Notes
|
|
136
|
+
### Notes
|
|
147
137
|
|
|
148
138
|
- **LLM Compatibility and Schema Transformations**: The library can perform schema transformations for LLM compatibility.
|
|
149
139
|
[See below](https://github.com/hideya/langchain-mcp-tools-ts/blob/main/README.md#llm-provider-schema-compatibility) for details.
|
|
150
140
|
- **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.
|
|
151
141
|
|
|
142
|
+
## API docs
|
|
143
|
+
|
|
144
|
+
Can be found [here](https://hideya.github.io/langchain-mcp-tools-ts/modules.html)
|
|
145
|
+
|
|
146
|
+
## Building from Source
|
|
147
|
+
|
|
148
|
+
See [README_DEV.md](https://github.com/hideya/langchain-mcp-tools-ts/blob/main/README_DEV.md) for details.
|
|
152
149
|
|
|
153
150
|
## Features
|
|
154
151
|
|
|
@@ -312,15 +309,25 @@ Can be found [here](https://github.com/hideya/langchain-mcp-tools-ts/blob/main/C
|
|
|
312
309
|
3. **Test explicit transports**: Try forcing specific transport types to isolate auto-detection issues
|
|
313
310
|
4. **Verify server independently**: Refer to [Debugging Section in MCP documentation](https://modelcontextprotocol.io/docs/tools/debugging)
|
|
314
311
|
|
|
312
|
+
### Debugging Authentication
|
|
313
|
+
|
|
314
|
+
1. **Check your tokens/credentials** - Most auth failures are due to expired or incorrect tokens
|
|
315
|
+
2. **Verify token permissions** - Some MCP servers require specific scopes (e.g., GitHub Copilot license)
|
|
316
|
+
3. **Test with curl** - Try a simple HTTP request to verify your auth setup:
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
curl -H "Authorization: Bearer your-token" https://api.example.com/mcp/
|
|
320
|
+
```
|
|
321
|
+
|
|
315
322
|
### LLM Provider Schema Compatibility
|
|
316
323
|
|
|
317
324
|
Different LLM providers have incompatible JSON Schema requirements for function calling:
|
|
318
325
|
|
|
319
326
|
- **OpenAI requires**: Optional fields must be nullable (`.optional()` + `.nullable()`)
|
|
320
327
|
for function calling (based on Structured Outputs API requirements,
|
|
321
|
-
strict enforcement coming in future SDK versions)
|
|
328
|
+
strict enforcement coming in future SDK versions)
|
|
322
329
|
- **Google Gemini API**: Rejects nullable fields and `$defs` references, requires strict OpenAPI 3.0 subset compliance
|
|
323
|
-
- **Anthropic Claude**: Very relaxed schema requirements with no documented restrictions
|
|
330
|
+
- **Anthropic Claude** and **xAI Grok**: Very relaxed schema requirements with no documented restrictions
|
|
324
331
|
|
|
325
332
|
**Note**: Google Vertex AI provides OpenAI-compatible endpoints that support nullable fields.
|
|
326
333
|
|
|
@@ -367,8 +374,8 @@ const { tools, cleanup } = await convertMcpToLangchainTools(
|
|
|
367
374
|
| Provider | Transformations Applied |
|
|
368
375
|
|----------|------------------------|
|
|
369
376
|
| `openai` | Makes optional fields nullable, handles union types |
|
|
370
|
-
| `google_gemini` | Filters invalid required fields, fixes anyOf variants, removes unsupported features |
|
|
371
|
-
| `anthropic` | Accepts schemas as-is, but handles them efficiently |
|
|
377
|
+
| `google_gemini` or `google_genai` | Filters invalid required fields, fixes anyOf variants, removes unsupported features |
|
|
378
|
+
| `anthropic` and `xai` | Accepts schemas as-is, but handles them efficiently |
|
|
372
379
|
|
|
373
380
|
For other providers, try without specifying the option:
|
|
374
381
|
|
|
@@ -434,5 +441,5 @@ Available log levels: `"fatal" | "error" | "warn" | "info" | "debug" | "trace"`
|
|
|
434
441
|
|
|
435
442
|
### For Developers
|
|
436
443
|
|
|
437
|
-
See [README_DEV.md](https://github.com/hideya/langchain-mcp-tools-ts/blob/main/
|
|
444
|
+
See [README_DEV.md](https://github.com/hideya/langchain-mcp-tools-ts/blob/main/README_DEV.md)
|
|
438
445
|
for more information about development and testing.
|
|
@@ -109,7 +109,7 @@ export interface LogOptions {
|
|
|
109
109
|
*
|
|
110
110
|
* @public
|
|
111
111
|
*/
|
|
112
|
-
export type LlmProvider = "openai" | "google_gemini" | "google_genai" | "anthropic" | "none";
|
|
112
|
+
export type LlmProvider = "openai" | "google_gemini" | "google_genai" | "anthropic" | "xai" | "none";
|
|
113
113
|
/**
|
|
114
114
|
* Configuration options for converting MCP servers to LangChain tools.
|
|
115
115
|
* Extends LogOptions to include provider-specific schema transformations and custom logging.
|
|
@@ -63,8 +63,8 @@ function processSchemaForLlmProvider(schema, llmProvider, serverName, toolName,
|
|
|
63
63
|
}
|
|
64
64
|
processedSchema = result.schema;
|
|
65
65
|
}
|
|
66
|
-
else if (llmProvider === "anthropic") {
|
|
67
|
-
// Anthropic Claude
|
|
66
|
+
else if (llmProvider === "anthropic" || llmProvider === "xai") {
|
|
67
|
+
// Anthropic Claude and xAI Grok have very relaxed schema requirements with no documented restrictions
|
|
68
68
|
// No schema modifications needed
|
|
69
69
|
// Claude is tested to work fine with passing the JSON schema directly
|
|
70
70
|
}
|
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.4",
|
|
4
4
|
"description": "MCP To LangChain Tools Conversion Utility",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -78,6 +78,7 @@
|
|
|
78
78
|
"@langchain/google-genai": "^0.2.12",
|
|
79
79
|
"@langchain/langgraph": "^0.2.36",
|
|
80
80
|
"@langchain/openai": "^0.3.16",
|
|
81
|
+
"@langchain/xai": "^0.1.0",
|
|
81
82
|
"@types/node": "^22.10.5",
|
|
82
83
|
"@types/ws": "^8.18.1",
|
|
83
84
|
"@typescript-eslint/eslint-plugin": "^8.19.0",
|