@h1deya/langchain-mcp-tools 0.1.1 → 0.1.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 CHANGED
@@ -1,11 +1,11 @@
1
- # MCP Server To LangChain Tools Conversion Utility [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/hideya/langchain-mcp-tools-ts/blob/main/LICENSE) [![npm version](https://img.shields.io/npm/v/@h1deya/langchain-mcp-tools.svg)](https://www.npmjs.com/package/@h1deya/langchain-mcp-tools)
1
+ # MCP To LangChain Tools Conversion Utility [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/hideya/langchain-mcp-tools-ts/blob/main/LICENSE) [![npm version](https://img.shields.io/npm/v/@h1deya/langchain-mcp-tools.svg)](https://www.npmjs.com/package/@h1deya/langchain-mcp-tools)
2
2
 
3
3
  This package is intended to simplify the use of MCP server tools within LangChain.
4
4
 
5
- It contains a utility function `convertMCPServersToLangChainTools()`
5
+ It contains a utility function `convertMcpToLangchainTools()`
6
6
  that initializes specified MCP servers,
7
7
  and returns [LangChain Tools](https://js.langchain.com/docs/how_to/tool_calling/)
8
- that wrap all the available MCP server tools.
8
+ that wrap all the tools found in given MCP servers.
9
9
 
10
10
  ## Installation
11
11
 
@@ -15,14 +15,14 @@ npm i @h1deya/langchain-mcp-tools
15
15
 
16
16
  ## Quick Start
17
17
 
18
- `convertMCPServersToLangChainTools()` utility function accepts MCP server configuration
19
- in pretty much the same format as a JS Object interpretation of the JSON format used by
20
- [Claude for Desktop](https://modelcontextprotocol.io/quickstart/user)
21
- (it just needs the contents of the `mcpServers` property).
22
- e.g.:
18
+ `convertMcpToLangchainTools()` utility function accepts MCP server configuration
19
+ that follows the same structure as
20
+ [Claude for Desktop](https://modelcontextprotocol.io/quickstart/user),
21
+ but only the contents of the `mcpServers` property,
22
+ and is expressed as a JS Object, e.g.:
23
23
 
24
24
  ```ts
25
- const mcpServers: MCPServersConfig = {
25
+ const mcpServers: McpServersConfig = {
26
26
  filesystem: {
27
27
  command: 'npx',
28
28
  args: [
@@ -39,10 +39,10 @@ const mcpServers: MCPServersConfig = {
39
39
  }
40
40
  };
41
41
 
42
- const { tools, cleanup } = await convertMCPServersToLangChainTools(mcpServers);
42
+ const { tools, cleanup } = await convertMcpToLangchainTools(mcpServers);
43
43
  ```
44
44
 
45
- The utility function initializes all the MCP server connections concurrently,
45
+ The utility function initializes all specified MCP servers in parallel,
46
46
  and returns LangChain Tools (`tools: DynamicStructuredTool[]`)
47
47
  by gathering all the available MCP server tools,
48
48
  and by wrapping them into [LangChain Tools](https://js.langchain.com/docs/how_to/tool_calling/).
@@ -52,6 +52,7 @@ which is used to close all the connections to the MCP servers when finished.
52
52
  The returned tools can be used with LangChain, e.g.:
53
53
 
54
54
  ```ts
55
+ // import { ChatAnthropic } from '@langchain/anthropic';
55
56
  const llm = new ChatAnthropic({ model: 'claude-3-5-haiku-latest' });
56
57
 
57
58
  // import { createReactAgent } from '@langchain/langgraph/prebuilt';
@@ -1,20 +1,20 @@
1
1
  import { DynamicStructuredTool } from '@langchain/core/tools';
2
- interface MCPServerConfig {
2
+ interface McpServerConfig {
3
3
  command: string;
4
4
  args: readonly string[];
5
5
  env?: Readonly<Record<string, string>>;
6
6
  }
7
- export interface MCPServersConfig {
8
- [key: string]: MCPServerConfig;
7
+ export interface McpServersConfig {
8
+ [key: string]: McpServerConfig;
9
9
  }
10
10
  interface LogOptions {
11
11
  logLevel?: 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
12
12
  }
13
- export interface MCPServerCleanupFunction {
13
+ export interface McpServerCleanupFunction {
14
14
  (): Promise<void>;
15
15
  }
16
- export declare function convertMCPServersToLangChainTools(configs: MCPServersConfig, options?: LogOptions): Promise<{
16
+ export declare function convertMcpToLangchainTools(configs: McpServersConfig, options?: LogOptions): Promise<{
17
17
  tools: DynamicStructuredTool[];
18
- cleanup: MCPServerCleanupFunction;
18
+ cleanup: McpServerCleanupFunction;
19
19
  }>;
20
20
  export {};
@@ -16,12 +16,12 @@ class MCPInitializationError extends Error {
16
16
  }
17
17
  }
18
18
  // Primary function to convert multiple MCP servers to LangChain tools
19
- export async function convertMCPServersToLangChainTools(configs, options) {
19
+ export async function convertMcpToLangchainTools(configs, options) {
20
20
  const allTools = [];
21
21
  const cleanupCallbacks = [];
22
22
  const logger = new Logger({ level: options?.logLevel || 'info' });
23
23
  const serverInitPromises = Object.entries(configs).map(async ([name, config]) => {
24
- const result = await convertMCPServerToLangChainTools(name, config, logger);
24
+ const result = await convertSingleMcpToLangchainTools(name, config, logger);
25
25
  return { name, result };
26
26
  });
27
27
  // Track server names alongside their promises
@@ -54,7 +54,7 @@ export async function convertMCPServersToLangChainTools(configs, options) {
54
54
  return { tools: allTools, cleanup };
55
55
  }
56
56
  // Convert a single MCP server into LangChain tools
57
- async function convertMCPServerToLangChainTools(serverName, config, logger) {
57
+ async function convertSingleMcpToLangchainTools(serverName, config, logger) {
58
58
  let transport = null;
59
59
  let client = null;
60
60
  logger.info(`MCP server "${serverName}": initializing with: ${JSON.stringify(config)}`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@h1deya/langchain-mcp-tools",
3
- "version": "0.1.1",
4
- "description": "A utility that wraps MCP servers into LangChain tools",
3
+ "version": "0.1.3",
4
+ "description": "MCP To LangChain Tools Conversion Utility",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "modelcontextprotocol",