@h1deya/langchain-mcp-tools 0.1.10 → 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 CHANGED
@@ -5,32 +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
- introduced by
9
- [Anthropic](https://www.anthropic.com/news/model-context-protocol),
10
- extends the capabilities of LLMs by enabling interaction with external tools and resources,
11
- such as web search and database access.
12
- Thanks to its open-source nature, MCP has gained significant traction in the developer community,
13
- with over 400 MCP servers already developed and shared:
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…
14
13
 
15
- - [Smithery: MCP Server Registry](https://smithery.ai/)
16
- - [Glama’s list of Open-Source MCP servers](https://glama.ai/mcp/servers)
14
+ Over 450 functional components available as MCP servers:
17
15
 
18
- In the MCP framework, external features are encapsulated in an MCP server
19
- that runs in a separate process.
20
- This clear decoupling allows for easy adoption and reuse of
21
- any of the significant collections of MCP servers listed above.
16
+ - [Glama’s list of Open-Source MCP servers](https://glama.ai/mcp/servers)
17
+ - [Smithery: MCP Server Registry](https://smithery.ai/)
18
+ - [awesome-mcp-servers](https://github.com/hideya/awesome-mcp-servers#Server-Implementations)
19
+ - [MCP Get Started/Example Servers](https://modelcontextprotocol.io/examples)
22
20
 
23
- To make it easy for LangChain to take advantage of such a vast resource base,
24
- 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.
25
22
 
26
23
  It contains a utility function `convertMcpToLangchainTools()`.
27
24
  This async function handles parallel initialization of specified multiple MCP servers
28
25
  and converts their available tools into an array of LangChain-compatible tools.
29
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
+
30
30
  A python equivalent of this utility is available
31
31
  [here](https://pypi.org/project/langchain-mcp-tools)
32
32
 
33
- ## Requirements
33
+ ## Prerequisites
34
34
 
35
35
  - Node.js 16+
36
36
 
@@ -75,7 +75,7 @@ The returned tools can be used with LangChain, e.g.:
75
75
 
76
76
  ```ts
77
77
  // import { ChatAnthropic } from '@langchain/anthropic';
78
- const llm = new ChatAnthropic({ model: 'claude-3-5-haiku-latest' });
78
+ const llm = new ChatAnthropic({ model: 'claude-3-5-sonnet-latest' });
79
79
 
80
80
  // import { createReactAgent } from '@langchain/langgraph/prebuilt';
81
81
  const agent = createReactAgent({
@@ -83,11 +83,15 @@ const agent = createReactAgent({
83
83
  tools
84
84
  });
85
85
  ```
86
- A simple and experimentable usage example can be found
86
+
87
+ Find complete, minimal working usage examples
87
88
  [here](https://github.com/hideya/langchain-mcp-tools-ts-usage/blob/main/src/index.ts)
88
89
 
89
- A more realistic usage example can be found
90
- [here](https://github.com/hideya/langchain-mcp-client-ts)
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)
91
95
 
92
96
  ## Limitations
93
97
 
@@ -131,16 +131,19 @@ async function convertSingleMcpToLangchainTools(serverName, config, logger) {
131
131
  arguments: input,
132
132
  },
133
133
  }, CallToolResultSchema);
134
- const resultStringfied = JSON.stringify(result?.content);
135
- const roughLength = resultStringfied.length;
136
- logger.info(`MCP tool "${serverName}"/"${tool.name}" received result (length: ${roughLength})`);
137
- logger.debug('result:', result?.content);
138
- return resultStringfied;
139
- // const filteredResult = result?.content
140
- // .filter(content => content.type === 'text')
141
- // .map(content => content.text)
142
- // .join('\n\n');
143
- // return filteredResult;
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:`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h1deya/langchain-mcp-tools",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "MCP To LangChain Tools Conversion Utility",
5
5
  "license": "MIT",
6
6
  "keywords": [