@h1deya/langchain-mcp-tools 0.1.11 → 0.1.12
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 +20 -19
- package/dist/langchain-mcp-tools.js +13 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,35 +5,32 @@ 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
|
-
|
|
9
|
-
[Anthropic](https://www.anthropic.com/news/model-context-protocol),
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
an open source technology
|
|
9
|
+
[announced by Anthropic](https://www.anthropic.com/news/model-context-protocol),
|
|
10
|
+
dramatically expands LLM’s scope
|
|
11
|
+
by enabling external tool and resource integration, including
|
|
12
|
+
Google Drive, Slack, Notion, Spotify, Docker, PostgreSQL, and more…
|
|
13
|
+
|
|
14
|
+
Over 450 functional components available as MCP servers:
|
|
14
15
|
|
|
15
16
|
- [Glama’s list of Open-Source MCP servers](https://glama.ai/mcp/servers)
|
|
16
17
|
- [Smithery: MCP Server Registry](https://smithery.ai/)
|
|
17
18
|
- [awesome-mcp-servers](https://github.com/hideya/awesome-mcp-servers#Server-Implementations)
|
|
18
19
|
- [MCP Get Started/Example Servers](https://modelcontextprotocol.io/examples)
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
which typically runs in a separate process and communicates
|
|
22
|
-
via `stdio` using the open standard protocol.
|
|
23
|
-
This clean decoupling makes it easy to adopt and reuse any of
|
|
24
|
-
the significant collections of MCP servers listed above.
|
|
25
|
-
|
|
26
|
-
To make it easy for LangChain users to take advantage of such a vast resource base,
|
|
27
|
-
this package offers quick and seamless access from LangChain to MCP servers.
|
|
21
|
+
The goal of this utility is to make these 450+ MCP servers readily accessible from LangChain.
|
|
28
22
|
|
|
29
23
|
It contains a utility function `convertMcpToLangchainTools()`.
|
|
30
24
|
This async function handles parallel initialization of specified multiple MCP servers
|
|
31
25
|
and converts their available tools into an array of LangChain-compatible tools.
|
|
32
26
|
|
|
27
|
+
For detailed information on how to use this library, please refer to the following document:
|
|
28
|
+
- ["Supercharging LangChain: Integrating 450+ MCP with ReAct"](https://medium.com/@h1deya/supercharging-langchain-integrating-450-mcp-with-react-d4e467cbf41a)
|
|
29
|
+
|
|
33
30
|
A python equivalent of this utility is available
|
|
34
31
|
[here](https://pypi.org/project/langchain-mcp-tools)
|
|
35
32
|
|
|
36
|
-
##
|
|
33
|
+
## Prerequisites
|
|
37
34
|
|
|
38
35
|
- Node.js 16+
|
|
39
36
|
|
|
@@ -78,7 +75,7 @@ The returned tools can be used with LangChain, e.g.:
|
|
|
78
75
|
|
|
79
76
|
```ts
|
|
80
77
|
// import { ChatAnthropic } from '@langchain/anthropic';
|
|
81
|
-
const llm = new ChatAnthropic({ model: 'claude-3-5-
|
|
78
|
+
const llm = new ChatAnthropic({ model: 'claude-3-5-sonnet-latest' });
|
|
82
79
|
|
|
83
80
|
// import { createReactAgent } from '@langchain/langgraph/prebuilt';
|
|
84
81
|
const agent = createReactAgent({
|
|
@@ -86,11 +83,15 @@ const agent = createReactAgent({
|
|
|
86
83
|
tools
|
|
87
84
|
});
|
|
88
85
|
```
|
|
89
|
-
|
|
86
|
+
|
|
87
|
+
Find complete, minimal working usage examples
|
|
90
88
|
[here](https://github.com/hideya/langchain-mcp-tools-ts-usage/blob/main/src/index.ts)
|
|
91
89
|
|
|
92
|
-
|
|
93
|
-
[
|
|
90
|
+
For hands-on experimentation with MCP server integration,
|
|
91
|
+
try [this LangChain application built with the utility](https://github.com/hideya/mcp-client-langchain-ts)
|
|
92
|
+
|
|
93
|
+
For detailed information on how to use this library, please refer to the following document:
|
|
94
|
+
["Supercharging LangChain: Integrating 450+ MCP with ReAct"](https://medium.com/@h1deya/supercharging-langchain-integrating-450-mcp-with-react-d4e467cbf41a)
|
|
94
95
|
|
|
95
96
|
## Limitations
|
|
96
97
|
|
|
@@ -131,16 +131,19 @@ async function convertSingleMcpToLangchainTools(serverName, config, logger) {
|
|
|
131
131
|
arguments: input,
|
|
132
132
|
},
|
|
133
133
|
}, CallToolResultSchema);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
//
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
134
|
+
// Handles null/undefined cases gracefully
|
|
135
|
+
if (!result?.content) {
|
|
136
|
+
logger.info(`MCP tool "${serverName}"/"${tool.name}" received null/undefined result`);
|
|
137
|
+
return '';
|
|
138
|
+
}
|
|
139
|
+
// For multiple content pieces or mixed types
|
|
140
|
+
const textContent = result.content
|
|
141
|
+
.filter(content => content.type === 'text')
|
|
142
|
+
.map(content => content.text)
|
|
143
|
+
.join('\n\n');
|
|
144
|
+
logger.info(`MCP tool "${serverName}"/"${tool.name}" received result (length: ${textContent.length})`);
|
|
145
|
+
// If no text content, return a clear message describing the situation
|
|
146
|
+
return textContent || 'No text content available in response';
|
|
144
147
|
},
|
|
145
148
|
})));
|
|
146
149
|
logger.info(`MCP server "${serverName}": ${tools.length} tool(s) available:`);
|