@h1deya/langchain-mcp-tools 0.1.18 → 0.1.20

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
@@ -11,21 +11,20 @@ dramatically expands LLM’s scope
11
11
  by enabling external tool and resource integration, including
12
12
  Google Drive, Slack, Notion, Spotify, Docker, PostgreSQL, and more…
13
13
 
14
- Over 1500 functional components available as MCP servers:
14
+ Over 2000 functional components available as MCP servers:
15
15
 
16
+ - [MCP Server Listing on the Official Site](https://github.com/modelcontextprotocol/servers?tab=readme-ov-file#model-context-protocol-servers)
16
17
  - [MCP.so - Find Awesome MCP Servers and Clients](https://mcp.so/)
17
18
  - [Smithery: MCP Server Registry](https://smithery.ai/)
18
- - [pulse - Browse and discover MCP use cases, servers, clients, and news](https://www.pulsemcp.com/)
19
- - [MCP Get Started/Example Servers](https://modelcontextprotocol.io/examples)
20
19
 
21
- The goal of this utility is to make these 1500+ MCP servers readily accessible from LangChain.
20
+ The goal of this utility is to make these 2000+ MCP servers readily accessible from LangChain.
22
21
 
23
22
  It contains a utility function `convertMcpToLangchainTools()`.
24
23
  This async function handles parallel initialization of specified multiple MCP servers
25
24
  and converts their available tools into an array of LangChain-compatible tools.
26
25
 
27
26
  For detailed information on how to use this library, please refer to the following document:
28
- - ["Supercharging LangChain: Integrating 1500+ MCP with ReAct"](https://medium.com/@h1deya/supercharging-langchain-integrating-1500-mcp-with-react-d4e467cbf41a)
27
+ - ["Supercharging LangChain: Integrating 2000+ MCP with ReAct"](https://medium.com/@h1deya/supercharging-langchain-integrating-450-mcp-with-react-d4e467cbf41a)
29
28
 
30
29
  A python equivalent of this utility is available
31
30
  [here](https://pypi.org/project/langchain-mcp-tools)
@@ -75,7 +74,7 @@ The returned tools can be used with LangChain, e.g.:
75
74
 
76
75
  ```ts
77
76
  // import { ChatAnthropic } from '@langchain/anthropic';
78
- const llm = new ChatAnthropic({ model: 'claude-3-5-sonnet-latest' });
77
+ const llm = new ChatAnthropic({ model: 'claude-3-7-sonnet-latest' });
79
78
 
80
79
  // import { createReactAgent } from '@langchain/langgraph/prebuilt';
81
80
  const agent = createReactAgent({
@@ -91,12 +90,16 @@ For hands-on experimentation with MCP server integration,
91
90
  try [this LangChain application built with the utility](https://github.com/hideya/mcp-client-langchain-ts)
92
91
 
93
92
  For detailed information on how to use this library, please refer to the following document:
94
- ["Supercharging LangChain: Integrating 1500+ MCP with ReAct"](https://medium.com/@h1deya/supercharging-langchain-integrating-1500-mcp-with-react-d4e467cbf41a)
93
+ ["Supercharging LangChain: Integrating 2000+ MCP with ReAct"](https://medium.com/@h1deya/supercharging-langchain-integrating-450-mcp-with-react-d4e467cbf41a)
95
94
 
96
95
  ## Limitations
97
96
 
98
97
  Currently, only text results of tool calls are supported.
99
98
 
99
+ Remote MCP server is not supported.
100
+
101
+ Fatures other than [Tools](https://modelcontextprotocol.io/docs/concepts/tools) are not supported.
102
+
100
103
  ## Change Log
101
104
 
102
105
  Can be found [here](https://github.com/hideya/langchain-mcp-tools-ts/blob/main/CHANGELOG.md)
@@ -1,18 +1,13 @@
1
1
  import { StructuredTool } from '@langchain/core/tools';
2
- interface McpServerConfig {
3
- command: string;
4
- args: readonly string[];
5
- env?: Readonly<Record<string, string>>;
6
- errlog?: number;
7
- }
2
+ import { StdioServerParameters } from "@modelcontextprotocol/sdk/client/stdio.js";
8
3
  export interface McpServersConfig {
9
- [key: string]: McpServerConfig;
4
+ [key: string]: StdioServerParameters;
10
5
  }
11
6
  export interface McpToolsLogger {
12
- debug(message: string, ...args: any[]): void;
13
- info(message: string, ...args: any[]): void;
14
- warn(message: string, ...args: any[]): void;
15
- error(message: string, ...args: any[]): void;
7
+ debug(...args: unknown[]): void;
8
+ info(...args: unknown[]): void;
9
+ warn(...args: unknown[]): void;
10
+ error(...args: unknown[]): void;
16
11
  }
17
12
  interface LogOptions {
18
13
  logLevel?: 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
@@ -1,7 +1,9 @@
1
+ import { DynamicStructuredTool } from '@langchain/core/tools';
1
2
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
2
- import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
3
+ import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
4
+ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
5
+ import { WebSocketClientTransport } from "@modelcontextprotocol/sdk/client/websocket.js";
3
6
  import { CallToolResultSchema, ListToolsResultSchema } from '@modelcontextprotocol/sdk/types.js';
4
- import { DynamicStructuredTool } from '@langchain/core/tools';
5
7
  import { jsonSchemaToZod } from '@n8n/json-schema-to-zod';
6
8
  import { Logger } from './logger.js';
7
9
  // Custom error type for MCP server initialization failures
@@ -104,12 +106,29 @@ async function convertSingleMcpToLangchainTools(serverName, config, logger) {
104
106
  env.PATH = process.env.PATH || '';
105
107
  }
106
108
  try {
107
- transport = new StdioClientTransport({
108
- command: config.command,
109
- args: config.args,
110
- env: env,
111
- stderr: config.errlog
112
- });
109
+ const url_or_command = config.command;
110
+ let url = undefined;
111
+ try {
112
+ url = new URL(url_or_command);
113
+ }
114
+ catch {
115
+ // Ignore
116
+ }
117
+ if (url?.protocol === "http:" || url?.protocol === "https:") {
118
+ transport = new SSEClientTransport(new URL(url_or_command));
119
+ }
120
+ else if (url?.protocol === "ws:" || url?.protocol === "wss:") {
121
+ transport = new WebSocketClientTransport(new URL(url_or_command));
122
+ }
123
+ else {
124
+ transport = new StdioClientTransport({
125
+ command: url_or_command,
126
+ args: config.args,
127
+ env,
128
+ stderr: config.stderr,
129
+ cwd: config.cwd
130
+ });
131
+ }
113
132
  client = new Client({
114
133
  name: "mcp-client",
115
134
  version: "0.0.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h1deya/langchain-mcp-tools",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "description": "MCP To LangChain Tools Conversion Utility",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -33,7 +33,7 @@
33
33
  "build": "tsc",
34
34
  "prepare": "npm run build",
35
35
  "watch": "tsc --watch",
36
- "example": "tsx examples/example.ts",
36
+ "simple-usage": "tsx testfiles/simple-usage.ts",
37
37
  "lint": "eslint src",
38
38
  "test": "vitest run",
39
39
  "test:watch": "vitest",
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@langchain/core": "^0.3.27",
47
- "@modelcontextprotocol/sdk": "^1.1.0",
47
+ "@modelcontextprotocol/sdk": "^1.8.0",
48
48
  "@n8n/json-schema-to-zod": "^1.1.0",
49
49
  "zod": "^3.24.1"
50
50
  },