@h1deya/langchain-mcp-tools 0.3.1 → 0.3.3
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 +51 -42
- 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,8 +1,10 @@
|
|
|
1
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
|
-
server tools
|
|
5
|
+
server tools from LangChain.
|
|
6
|
+
|
|
7
|
+
<img style="width:450px;" alt="langchain-mcp-tools-diagram" src="https://raw.githubusercontent.com/hideya/langchain-mcp-tools-py/refs/heads/main/docs/images/langchain-mcp-tools-diagram.png" />
|
|
6
8
|
|
|
7
9
|
Its simplicity and extra features, such as
|
|
8
10
|
[tools schema adjustments for LLM compatibility](https://github.com/hideya/langchain-mcp-tools-ts/blob/main/README.md#llm-provider-schema-compatibility)
|
|
@@ -14,30 +16,6 @@ However, it only supports text results of tool calls and does not support MCP fe
|
|
|
14
16
|
which supports comprehensive integration with LangChain, has been released.
|
|
15
17
|
You may want to consider using it if you don't have specific needs for this library.
|
|
16
18
|
|
|
17
|
-
## Introduction
|
|
18
|
-
|
|
19
|
-
This package is intended to simplify the use of
|
|
20
|
-
[Model Context Protocol (MCP)](https://modelcontextprotocol.io/)
|
|
21
|
-
server tools with LangChain / TypeScript.
|
|
22
|
-
|
|
23
|
-
[Model Context Protocol (MCP)](https://modelcontextprotocol.io/) is the de facto industry standard
|
|
24
|
-
that dramatically expands the scope of LLMs by enabling the integration of external tools and resources,
|
|
25
|
-
including DBs, Cloud Storages, GitHub, Docker, Slack, and more.
|
|
26
|
-
There are [quite a few useful MCP servers already available.
|
|
27
|
-
See [MCP Server Listing on the Official Site](https://github.com/modelcontextprotocol/servers?tab=readme-ov-file#model-context-protocol-servers).
|
|
28
|
-
|
|
29
|
-
This utility's goal is to make these numerous MCP servers easily accessible from LangChain.
|
|
30
|
-
It contains a utility function `convertMcpToLangchainTools()`.
|
|
31
|
-
This async function handles parallel initialization of specified multiple MCP servers
|
|
32
|
-
and converts their available tools into an array of LangChain-compatible tools.
|
|
33
|
-
It also performs LLM provider-specific schema transformations
|
|
34
|
-
to prevent [schema compatibility issues](https://github.com/hideya/langchain-mcp-tools-ts/blob/main/README.md#llm-provider-schema-compatibility)
|
|
35
|
-
|
|
36
|
-
For detailed information on how to use this library, please refer to the following document:
|
|
37
|
-
["Supercharging LangChain: Integrating 2000+ MCP with ReAct"](https://medium.com/@h1deya/supercharging-langchain-integrating-450-mcp-with-react-d4e467cbf41a).
|
|
38
|
-
A Python equivalent of this utility is available
|
|
39
|
-
[here](https://pypi.org/project/langchain-mcp-tools)
|
|
40
|
-
|
|
41
19
|
## Prerequisites
|
|
42
20
|
|
|
43
21
|
- Node.js 18+
|
|
@@ -48,15 +26,8 @@ A Python equivalent of this utility is available
|
|
|
48
26
|
npm i @h1deya/langchain-mcp-tools
|
|
49
27
|
```
|
|
50
28
|
|
|
51
|
-
## API docs
|
|
52
|
-
|
|
53
|
-
Can be found [here](https://hideya.github.io/langchain-mcp-tools-ts/modules.html)
|
|
54
|
-
|
|
55
29
|
## Quick Start
|
|
56
30
|
|
|
57
|
-
A minimal but complete working usage example can be found
|
|
58
|
-
[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)
|
|
59
|
-
|
|
60
31
|
`convertMcpToLangchainTools()` utility function accepts MCP server configurations
|
|
61
32
|
that follow the same structure as
|
|
62
33
|
[Claude for Desktop](https://modelcontextprotocol.io/quickstart/user),
|
|
@@ -125,9 +96,30 @@ A minimal but complete working usage example can be found
|
|
|
125
96
|
For hands-on experimentation with MCP server integration,
|
|
126
97
|
try [this MCP Client CLI tool built with this library](https://www.npmjs.com/package/@h1deya/mcp-client-cli)
|
|
127
98
|
|
|
128
|
-
|
|
99
|
+
A Python equivalent of this utility is available
|
|
100
|
+
[here](https://pypi.org/project/langchain-mcp-tools)
|
|
129
101
|
|
|
130
|
-
|
|
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).
|
|
131
123
|
|
|
132
124
|
## MCP Protocol Support
|
|
133
125
|
|
|
@@ -141,12 +133,19 @@ The library uses LangChain's `response_format: 'content'` (the default), which o
|
|
|
141
133
|
While MCP tools can return multiple content types (text, images, etc.), this library currently filters and uses only text content.
|
|
142
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.
|
|
143
135
|
|
|
144
|
-
### Notes
|
|
136
|
+
### Notes
|
|
145
137
|
|
|
146
138
|
- **LLM Compatibility and Schema Transformations**: The library can perform schema transformations for LLM compatibility.
|
|
147
139
|
[See below](https://github.com/hideya/langchain-mcp-tools-ts/blob/main/README.md#llm-provider-schema-compatibility) for details.
|
|
148
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.
|
|
149
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.
|
|
150
149
|
|
|
151
150
|
## Features
|
|
152
151
|
|
|
@@ -308,7 +307,17 @@ Can be found [here](https://github.com/hideya/langchain-mcp-tools-ts/blob/main/C
|
|
|
308
307
|
1. **Enable debug logging**: Set `logLevel: "debug"` to see detailed connection and execution logs
|
|
309
308
|
2. **Check server stderr**: For stdio MCP servers, use `stderr` redirection to capture server error output
|
|
310
309
|
3. **Test explicit transports**: Try forcing specific transport types to isolate auto-detection issues
|
|
311
|
-
4. **Verify server independently**:
|
|
310
|
+
4. **Verify server independently**: Refer to [Debugging Section in MCP documentation](https://modelcontextprotocol.io/docs/tools/debugging)
|
|
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
|
+
```
|
|
312
321
|
|
|
313
322
|
### LLM Provider Schema Compatibility
|
|
314
323
|
|
|
@@ -316,9 +325,9 @@ Different LLM providers have incompatible JSON Schema requirements for function
|
|
|
316
325
|
|
|
317
326
|
- **OpenAI requires**: Optional fields must be nullable (`.optional()` + `.nullable()`)
|
|
318
327
|
for function calling (based on Structured Outputs API requirements,
|
|
319
|
-
strict enforcement coming in future SDK versions)
|
|
328
|
+
strict enforcement coming in future SDK versions)
|
|
320
329
|
- **Google Gemini API**: Rejects nullable fields and `$defs` references, requires strict OpenAPI 3.0 subset compliance
|
|
321
|
-
- **Anthropic Claude**: Very relaxed schema requirements with no documented restrictions
|
|
330
|
+
- **Anthropic Claude** and **xAI Grok**: Very relaxed schema requirements with no documented restrictions
|
|
322
331
|
|
|
323
332
|
**Note**: Google Vertex AI provides OpenAI-compatible endpoints that support nullable fields.
|
|
324
333
|
|
|
@@ -365,8 +374,8 @@ const { tools, cleanup } = await convertMcpToLangchainTools(
|
|
|
365
374
|
| Provider | Transformations Applied |
|
|
366
375
|
|----------|------------------------|
|
|
367
376
|
| `openai` | Makes optional fields nullable, handles union types |
|
|
368
|
-
| `google_gemini` | Filters invalid required fields, fixes anyOf variants, removes unsupported features |
|
|
369
|
-
| `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 |
|
|
370
379
|
|
|
371
380
|
For other providers, try without specifying the option:
|
|
372
381
|
|
|
@@ -432,5 +441,5 @@ Available log levels: `"fatal" | "error" | "warn" | "info" | "debug" | "trace"`
|
|
|
432
441
|
|
|
433
442
|
### For Developers
|
|
434
443
|
|
|
435
|
-
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)
|
|
436
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.3",
|
|
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",
|