@h1deya/langchain-mcp-tools 0.1.16 → 0.1.18
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 +2 -2
- package/dist/langchain-mcp-tools.d.ts +14 -2
- package/dist/langchain-mcp-tools.js +7 -3
- package/dist/logger.d.ts +6 -7
- package/dist/logger.js +6 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,9 +13,9 @@ Google Drive, Slack, Notion, Spotify, Docker, PostgreSQL, and more…
|
|
|
13
13
|
|
|
14
14
|
Over 1500 functional components available as MCP servers:
|
|
15
15
|
|
|
16
|
-
- [
|
|
16
|
+
- [MCP.so - Find Awesome MCP Servers and Clients](https://mcp.so/)
|
|
17
17
|
- [Smithery: MCP Server Registry](https://smithery.ai/)
|
|
18
|
-
- [
|
|
18
|
+
- [pulse - Browse and discover MCP use cases, servers, clients, and news](https://www.pulsemcp.com/)
|
|
19
19
|
- [MCP Get Started/Example Servers](https://modelcontextprotocol.io/examples)
|
|
20
20
|
|
|
21
21
|
The goal of this utility is to make these 1500+ MCP servers readily accessible from LangChain.
|
|
@@ -3,10 +3,17 @@ interface McpServerConfig {
|
|
|
3
3
|
command: string;
|
|
4
4
|
args: readonly string[];
|
|
5
5
|
env?: Readonly<Record<string, string>>;
|
|
6
|
+
errlog?: number;
|
|
6
7
|
}
|
|
7
8
|
export interface McpServersConfig {
|
|
8
9
|
[key: string]: McpServerConfig;
|
|
9
10
|
}
|
|
11
|
+
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;
|
|
16
|
+
}
|
|
10
17
|
interface LogOptions {
|
|
11
18
|
logLevel?: 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
|
|
12
19
|
}
|
|
@@ -18,7 +25,10 @@ export interface McpServerCleanupFn {
|
|
|
18
25
|
* This function concurrently sets up all specified servers and aggregates their tools.
|
|
19
26
|
*
|
|
20
27
|
* @param configs - A mapping of server names to their respective configurations
|
|
21
|
-
* @param options - Optional
|
|
28
|
+
* @param options - Optional configuration settings
|
|
29
|
+
* @param options.logLevel - Log verbosity level ('fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace')
|
|
30
|
+
* @param options.logger - Custom logger implementation that follows the McpToolsLogger interface.
|
|
31
|
+
* If provided, overrides the default Logger instance.
|
|
22
32
|
*
|
|
23
33
|
* @returns A promise that resolves to:
|
|
24
34
|
* - tools: Array of StructuredTool instances ready for use with LangChain
|
|
@@ -32,7 +42,9 @@ export interface McpServerCleanupFn {
|
|
|
32
42
|
* fetch: { command: 'uvx', args: ['mcp-server-fetch'] }
|
|
33
43
|
* });
|
|
34
44
|
*/
|
|
35
|
-
export declare function convertMcpToLangchainTools(configs: McpServersConfig, options?: LogOptions
|
|
45
|
+
export declare function convertMcpToLangchainTools(configs: McpServersConfig, options?: LogOptions & {
|
|
46
|
+
logger?: McpToolsLogger;
|
|
47
|
+
}): Promise<{
|
|
36
48
|
tools: StructuredTool[];
|
|
37
49
|
cleanup: McpServerCleanupFn;
|
|
38
50
|
}>;
|
|
@@ -20,7 +20,10 @@ class McpInitializationError extends Error {
|
|
|
20
20
|
* This function concurrently sets up all specified servers and aggregates their tools.
|
|
21
21
|
*
|
|
22
22
|
* @param configs - A mapping of server names to their respective configurations
|
|
23
|
-
* @param options - Optional
|
|
23
|
+
* @param options - Optional configuration settings
|
|
24
|
+
* @param options.logLevel - Log verbosity level ('fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace')
|
|
25
|
+
* @param options.logger - Custom logger implementation that follows the McpToolsLogger interface.
|
|
26
|
+
* If provided, overrides the default Logger instance.
|
|
24
27
|
*
|
|
25
28
|
* @returns A promise that resolves to:
|
|
26
29
|
* - tools: Array of StructuredTool instances ready for use with LangChain
|
|
@@ -37,7 +40,7 @@ class McpInitializationError extends Error {
|
|
|
37
40
|
export async function convertMcpToLangchainTools(configs, options) {
|
|
38
41
|
const allTools = [];
|
|
39
42
|
const cleanupCallbacks = [];
|
|
40
|
-
const logger = new Logger({ level: options?.logLevel || 'info' });
|
|
43
|
+
const logger = options?.logger || new Logger({ level: options?.logLevel || 'info' });
|
|
41
44
|
const serverInitPromises = Object.entries(configs).map(async ([name, config]) => {
|
|
42
45
|
const result = await convertSingleMcpToLangchainTools(name, config, logger);
|
|
43
46
|
return { name, result };
|
|
@@ -78,7 +81,7 @@ export async function convertMcpToLangchainTools(configs, options) {
|
|
|
78
81
|
*
|
|
79
82
|
* @param serverName - Unique identifier for the server instance
|
|
80
83
|
* @param config - Server configuration including command, arguments, and environment variables
|
|
81
|
-
* @param logger -
|
|
84
|
+
* @param logger - McpToolsLogger instance for recording operation details
|
|
82
85
|
*
|
|
83
86
|
* @returns A promise that resolves to:
|
|
84
87
|
* - tools: Array of StructuredTool instances from this server
|
|
@@ -105,6 +108,7 @@ async function convertSingleMcpToLangchainTools(serverName, config, logger) {
|
|
|
105
108
|
command: config.command,
|
|
106
109
|
args: config.args,
|
|
107
110
|
env: env,
|
|
111
|
+
stderr: config.errlog
|
|
108
112
|
});
|
|
109
113
|
client = new Client({
|
|
110
114
|
name: "mcp-client",
|
package/dist/logger.d.ts
CHANGED
|
@@ -16,12 +16,11 @@ declare class Logger {
|
|
|
16
16
|
private parseLogLevel;
|
|
17
17
|
private log;
|
|
18
18
|
private formatValue;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
fatal: (...args: unknown[]) => void;
|
|
19
|
+
trace(...args: unknown[]): void;
|
|
20
|
+
debug(...args: unknown[]): void;
|
|
21
|
+
info(...args: unknown[]): void;
|
|
22
|
+
warn(...args: unknown[]): void;
|
|
23
|
+
error(...args: unknown[]): void;
|
|
24
|
+
fatal(...args: unknown[]): void;
|
|
26
25
|
}
|
|
27
26
|
export { Logger, LogLevel, LogLevelString };
|
package/dist/logger.js
CHANGED
|
@@ -49,14 +49,11 @@ class Logger {
|
|
|
49
49
|
return 'undefined';
|
|
50
50
|
return typeof value === 'object' ? JSON.stringify(value, null, 2) : String(value);
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
warn = this.createLogMethod(LogLevel.WARN);
|
|
59
|
-
error = this.createLogMethod(LogLevel.ERROR);
|
|
60
|
-
fatal = this.createLogMethod(LogLevel.FATAL);
|
|
52
|
+
trace(...args) { this.log(LogLevel.TRACE, ...args); }
|
|
53
|
+
debug(...args) { this.log(LogLevel.DEBUG, ...args); }
|
|
54
|
+
info(...args) { this.log(LogLevel.INFO, ...args); }
|
|
55
|
+
warn(...args) { this.log(LogLevel.WARN, ...args); }
|
|
56
|
+
error(...args) { this.log(LogLevel.ERROR, ...args); }
|
|
57
|
+
fatal(...args) { this.log(LogLevel.FATAL, ...args); }
|
|
61
58
|
}
|
|
62
59
|
export { Logger, LogLevel };
|