mcp-use 0.0.4 → 0.0.8

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.
Files changed (59) hide show
  1. package/README.md +34 -5
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +2 -0
  5. package/dist/src/adapters/langchain_adapter.d.ts +4 -4
  6. package/dist/src/adapters/langchain_adapter.d.ts.map +1 -1
  7. package/dist/src/adapters/langchain_adapter.js +2 -17
  8. package/dist/src/agents/index.d.ts +0 -1
  9. package/dist/src/agents/index.d.ts.map +1 -1
  10. package/dist/src/agents/index.js +0 -1
  11. package/dist/src/agents/mcp_agent.d.ts +3 -4
  12. package/dist/src/agents/mcp_agent.d.ts.map +1 -1
  13. package/dist/src/agents/mcp_agent.js +3 -3
  14. package/dist/src/agents/prompts/system_prompt_builder.d.ts +3 -3
  15. package/dist/src/agents/prompts/system_prompt_builder.d.ts.map +1 -1
  16. package/dist/src/client.d.ts +1 -1
  17. package/dist/src/client.d.ts.map +1 -1
  18. package/dist/src/client.js +6 -3
  19. package/dist/src/connectors/base.d.ts +466 -0
  20. package/dist/src/connectors/base.d.ts.map +1 -1
  21. package/dist/src/connectors/base.js +14 -0
  22. package/dist/src/logging.d.ts +15 -4
  23. package/dist/src/logging.d.ts.map +1 -1
  24. package/dist/src/logging.js +71 -38
  25. package/dist/src/managers/index.d.ts +3 -0
  26. package/dist/src/managers/index.d.ts.map +1 -0
  27. package/dist/src/managers/index.js +2 -0
  28. package/dist/src/managers/server_manager.d.ts +15 -0
  29. package/dist/src/managers/server_manager.d.ts.map +1 -0
  30. package/dist/src/managers/server_manager.js +72 -0
  31. package/dist/src/managers/tools/acquire_active_mcp_server.d.ts +13 -0
  32. package/dist/src/managers/tools/acquire_active_mcp_server.d.ts.map +1 -0
  33. package/dist/src/managers/tools/acquire_active_mcp_server.js +17 -0
  34. package/dist/src/managers/tools/base.d.ts +24 -0
  35. package/dist/src/managers/tools/base.d.ts.map +1 -0
  36. package/dist/src/managers/tools/base.js +17 -0
  37. package/dist/src/managers/tools/connect_mcp_server.d.ts +26 -0
  38. package/dist/src/managers/tools/connect_mcp_server.d.ts.map +1 -0
  39. package/dist/src/managers/tools/connect_mcp_server.js +46 -0
  40. package/dist/src/managers/tools/index.d.ts +5 -0
  41. package/dist/src/managers/tools/index.d.ts.map +1 -0
  42. package/dist/src/managers/tools/index.js +4 -0
  43. package/dist/src/managers/tools/list_mcp_servers.d.ts +13 -0
  44. package/dist/src/managers/tools/list_mcp_servers.d.ts.map +1 -0
  45. package/dist/src/managers/tools/list_mcp_servers.js +33 -0
  46. package/dist/src/managers/tools/release_mcp_server_connection.d.ts +13 -0
  47. package/dist/src/managers/tools/release_mcp_server_connection.d.ts.map +1 -0
  48. package/dist/src/managers/tools/release_mcp_server_connection.js +19 -0
  49. package/dist/src/session.d.ts +1 -9
  50. package/dist/src/session.d.ts.map +1 -1
  51. package/dist/src/session.js +1 -30
  52. package/dist/src/task_managers/sse.d.ts.map +1 -1
  53. package/dist/src/task_managers/sse.js +0 -1
  54. package/dist/src/task_managers/stdio.d.ts.map +1 -1
  55. package/dist/src/task_managers/stdio.js +0 -1
  56. package/package.json +37 -22
  57. package/dist/src/agents/server_manager.d.ts +0 -22
  58. package/dist/src/agents/server_manager.d.ts.map +0 -1
  59. package/dist/src/agents/server_manager.js +0 -152
@@ -1,59 +1,92 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { createLogger, format, transports } from 'winston';
4
- const { combine, timestamp, label, printf } = format;
5
- let MCP_USE_DEBUG = 0;
6
- const debugEnv = process.env.DEBUG?.toLowerCase();
7
- if (debugEnv === '2') {
8
- MCP_USE_DEBUG = 2;
9
- }
10
- else if (debugEnv === '1') {
11
- MCP_USE_DEBUG = 1;
4
+ const { combine, timestamp, label, printf, colorize, splat } = format;
5
+ const DEFAULT_LOGGER_NAME = 'mcp-use';
6
+ function resolveLevel(env) {
7
+ switch (env?.trim()) {
8
+ case '2':
9
+ return 'debug';
10
+ case '1':
11
+ return 'info';
12
+ default:
13
+ return 'warn';
14
+ }
12
15
  }
13
- const defaultFormat = printf(({ level, message, label, timestamp }) => `${timestamp} [${label}] ${level.toUpperCase()}: ${message}`);
16
+ const minimalFormatter = printf(({ level, message, label, timestamp }) => {
17
+ return `${timestamp} [${label}] ${level}: ${message}`;
18
+ });
19
+ const detailedFormatter = printf(({ level, message, label, timestamp }) => {
20
+ return `${timestamp} [${label}] ${level.toUpperCase()}: ${message}`;
21
+ });
22
+ const emojiFormatter = printf(({ level, message, label, timestamp }) => {
23
+ return `${timestamp} [${label}] ${level.toUpperCase()}: ${message}`;
24
+ });
14
25
  export class Logger {
15
- static loggers = {};
16
- static getLogger(name = 'mcp_use') {
17
- if (!this.loggers[name]) {
18
- this.loggers[name] = createLogger({
19
- level: 'warn',
20
- format: combine(label({ label: name }), timestamp(), defaultFormat),
26
+ static instances = {};
27
+ static currentFormat = 'minimal';
28
+ static get(name = DEFAULT_LOGGER_NAME) {
29
+ if (!this.instances[name]) {
30
+ this.instances[name] = createLogger({
31
+ level: resolveLevel(process.env.DEBUG),
32
+ format: combine(colorize(), splat(), label({ label: name }), timestamp({ format: 'HH:mm:ss' }), this.getFormatter()),
21
33
  transports: [],
22
34
  });
23
35
  }
24
- return this.loggers[name];
36
+ return this.instances[name];
25
37
  }
26
- static configure(level, toConsole = true, toFile) {
27
- const root = this.getLogger();
28
- if (!level) {
29
- level
30
- = MCP_USE_DEBUG === 2
31
- ? 'debug'
32
- : MCP_USE_DEBUG === 1 ? 'info' : 'warn';
38
+ static getFormatter() {
39
+ switch (this.currentFormat) {
40
+ case 'minimal':
41
+ return minimalFormatter;
42
+ case 'detailed':
43
+ return detailedFormatter;
44
+ case 'emoji':
45
+ return emojiFormatter;
46
+ default:
47
+ return minimalFormatter;
33
48
  }
34
- root.level = level;
49
+ }
50
+ static configure(options = {}) {
51
+ const { level, console = true, file, format = 'minimal' } = options;
52
+ const resolvedLevel = level ?? resolveLevel(process.env.DEBUG);
53
+ this.currentFormat = format;
54
+ const root = this.get();
55
+ root.level = resolvedLevel;
35
56
  root.clear();
36
- if (toConsole) {
57
+ if (console) {
37
58
  root.add(new transports.Console());
38
59
  }
39
- if (toFile) {
40
- const dir = path.dirname(toFile);
41
- if (dir && !fs.existsSync(dir)) {
60
+ if (file) {
61
+ const dir = path.dirname(path.resolve(file));
62
+ if (!fs.existsSync(dir)) {
42
63
  fs.mkdirSync(dir, { recursive: true });
43
64
  }
44
- root.add(new transports.File({ filename: toFile }));
65
+ root.add(new transports.File({ filename: file }));
45
66
  }
67
+ // Update all existing loggers with new format
68
+ Object.values(this.instances).forEach((logger) => {
69
+ logger.level = resolvedLevel;
70
+ logger.format = combine(colorize(), splat(), label({ label: DEFAULT_LOGGER_NAME }), timestamp({ format: 'HH:mm:ss' }), this.getFormatter());
71
+ });
46
72
  }
47
- static setDebug(debugLevel = 2) {
48
- MCP_USE_DEBUG = debugLevel;
49
- process.env.LANGCHAIN_VERBOSE = debugLevel >= 1 ? 'true' : 'false';
50
- const newLevel = debugLevel === 2
51
- ? 'debug'
52
- : debugLevel === 1 ? 'info' : 'warn';
53
- Object.values(this.loggers).forEach((log) => {
54
- log.level = newLevel;
73
+ static setDebug(enabled) {
74
+ let level;
75
+ if (enabled === 2 || enabled === true)
76
+ level = 'debug';
77
+ else if (enabled === 1)
78
+ level = 'info';
79
+ else
80
+ level = 'warn';
81
+ Object.values(this.instances).forEach((logger) => {
82
+ logger.level = level;
55
83
  });
84
+ process.env.DEBUG = enabled ? (enabled === true ? '2' : String(enabled)) : '0';
85
+ }
86
+ static setFormat(format) {
87
+ this.currentFormat = format;
88
+ this.configure({ format });
56
89
  }
57
90
  }
58
91
  Logger.configure();
59
- export const logger = Logger.getLogger();
92
+ export const logger = Logger.get();
@@ -0,0 +1,3 @@
1
+ export * from './server_manager.js';
2
+ export * from './tools/index.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/managers/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './server_manager.js';
2
+ export * from './tools/index.js';
@@ -0,0 +1,15 @@
1
+ import type { StructuredToolInterface } from '@langchain/core/tools';
2
+ import type { LangChainAdapter } from '../adapters/langchain_adapter.js';
3
+ import type { MCPClient } from '../client.js';
4
+ export declare class ServerManager {
5
+ readonly initializedServers: Record<string, boolean>;
6
+ readonly serverTools: Record<string, StructuredToolInterface[]>;
7
+ readonly client: MCPClient;
8
+ readonly adapter: LangChainAdapter;
9
+ activeServer: string | null;
10
+ constructor(client: MCPClient, adapter: LangChainAdapter);
11
+ initialize(): void;
12
+ prefetchServerTools(): Promise<void>;
13
+ get tools(): StructuredToolInterface[];
14
+ }
15
+ //# sourceMappingURL=server_manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server_manager.d.ts","sourceRoot":"","sources":["../../../src/managers/server_manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAA;AACxE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAU7C,qBAAa,aAAa;IACxB,SAAgB,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAK;IAChE,SAAgB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,EAAE,CAAC,CAAK;IAE3E,SAAgB,MAAM,EAAE,SAAS,CAAA;IACjC,SAAgB,OAAO,EAAE,gBAAgB,CAAA;IAClC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAO;gBAE7B,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,gBAAgB;IAKxD,UAAU,IAAI,IAAI;IAOZ,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAoD1C,IAAI,KAAK,IAAI,uBAAuB,EAAE,CAOrC;CACF"}
@@ -0,0 +1,72 @@
1
+ import { isEqual } from 'lodash-es';
2
+ import { logger } from '../logging.js';
3
+ import { AcquireActiveMCPServerTool } from './tools/acquire_active_mcp_server.js';
4
+ import { ConnectMCPServerTool } from './tools/connect_mcp_server.js';
5
+ import { ListMCPServersTool } from './tools/list_mcp_servers.js';
6
+ import { ReleaseMCPServerConnectionTool } from './tools/release_mcp_server_connection.js';
7
+ export class ServerManager {
8
+ initializedServers = {};
9
+ serverTools = {};
10
+ client;
11
+ adapter;
12
+ activeServer = null;
13
+ constructor(client, adapter) {
14
+ this.client = client;
15
+ this.adapter = adapter;
16
+ }
17
+ initialize() {
18
+ const serverNames = this.client.getServerNames?.();
19
+ if (serverNames.length === 0) {
20
+ logger.warning('No MCP servers defined in client configuration');
21
+ }
22
+ }
23
+ async prefetchServerTools() {
24
+ const servers = this.client.getServerNames();
25
+ for (const serverName of servers) {
26
+ try {
27
+ let session = null;
28
+ session = this.client.getSession(serverName);
29
+ logger.debug(`Using existing session for server '${serverName}' to prefetch tools.`);
30
+ if (!session) {
31
+ session = await this.client.createSession(serverName).catch((createSessionError) => {
32
+ logger.warn(`Could not create session for '${serverName}' during prefetch: ${createSessionError}`);
33
+ return null;
34
+ });
35
+ logger.debug(`Temporarily created session for '${serverName}' to prefetch tools.`);
36
+ }
37
+ if (session) {
38
+ const connector = session.connector;
39
+ let tools = [];
40
+ try {
41
+ tools = await this.adapter.createToolsFromConnectors([connector]);
42
+ }
43
+ catch (toolFetchError) {
44
+ logger.error(`Failed to create tools from connector for server '${serverName}': ${toolFetchError}`);
45
+ continue;
46
+ }
47
+ const cachedTools = this.serverTools[serverName];
48
+ const toolsChanged = !cachedTools || !isEqual(cachedTools, tools);
49
+ if (toolsChanged) {
50
+ this.serverTools[serverName] = tools;
51
+ this.initializedServers[serverName] = true;
52
+ logger.debug(`Prefetched ${tools.length} tools for server '${serverName}'.`);
53
+ }
54
+ else {
55
+ logger.debug(`Tools for server '${serverName}' unchanged, using cached version.`);
56
+ }
57
+ }
58
+ }
59
+ catch (outerError) {
60
+ logger.error(`Error prefetching tools for server '${serverName}': ${outerError}`);
61
+ }
62
+ }
63
+ }
64
+ get tools() {
65
+ return [
66
+ new ListMCPServersTool(this),
67
+ new ConnectMCPServerTool(this),
68
+ new AcquireActiveMCPServerTool(this),
69
+ new ReleaseMCPServerConnectionTool(this),
70
+ ];
71
+ }
72
+ }
@@ -0,0 +1,13 @@
1
+ import type { ServerManager } from '../server_manager.js';
2
+ import { z } from 'zod';
3
+ import { MCPServerTool } from './base.js';
4
+ declare const PresentActiveServerSchema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
5
+ export declare class AcquireActiveMCPServerTool extends MCPServerTool<typeof PresentActiveServerSchema> {
6
+ name: string;
7
+ description: string;
8
+ schema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
9
+ constructor(manager: ServerManager);
10
+ _call(): Promise<string>;
11
+ }
12
+ export {};
13
+ //# sourceMappingURL=acquire_active_mcp_server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acquire_active_mcp_server.d.ts","sourceRoot":"","sources":["../../../../src/managers/tools/acquire_active_mcp_server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAEzC,QAAA,MAAM,yBAAyB,gDAAe,CAAA;AAE9C,qBAAa,0BAA2B,SAAQ,aAAa,CAAC,OAAO,yBAAyB,CAAC;IACpF,IAAI,SAA0B;IAC9B,WAAW,SAAiE;IAC5E,MAAM,iDAA4B;gBAE/B,OAAO,EAAE,aAAa;IAI5B,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;CAO/B"}
@@ -0,0 +1,17 @@
1
+ import { z } from 'zod';
2
+ import { MCPServerTool } from './base.js';
3
+ const PresentActiveServerSchema = z.object({});
4
+ export class AcquireActiveMCPServerTool extends MCPServerTool {
5
+ name = 'get_active_mcp_server';
6
+ description = 'Get the currently active MCP (Model Context Protocol) server';
7
+ schema = PresentActiveServerSchema;
8
+ constructor(manager) {
9
+ super(manager);
10
+ }
11
+ async _call() {
12
+ if (!this.manager.activeServer) {
13
+ return `No MCP server is currently active. Use connect_to_mcp_server to connect to a server.`;
14
+ }
15
+ return `Currently active MCP server: ${this.manager.activeServer}`;
16
+ }
17
+ }
@@ -0,0 +1,24 @@
1
+ import type { CallbackManagerForToolRun } from '@langchain/core/callbacks/manager';
2
+ import type { ToolParams, ToolRunnableConfig, ToolSchemaBase } from '@langchain/core/tools';
3
+ import type { JSONSchema } from '@langchain/core/utils/json_schema';
4
+ import type z from 'zod';
5
+ import type { ServerManager } from '../server_manager.js';
6
+ import { StructuredTool } from '@langchain/core/tools';
7
+ export type ToolOutputT = any;
8
+ export type SchemaOutputT<T extends ToolSchemaBase> = T extends z.ZodSchema ? z.output<T> : T extends JSONSchema ? unknown : never;
9
+ export interface MCPServerToolOptions extends ToolParams {
10
+ name?: string;
11
+ description?: string;
12
+ returnDirect?: boolean;
13
+ sandboxId?: string;
14
+ }
15
+ export declare class MCPServerTool<SchemaT extends ToolSchemaBase> extends StructuredTool<SchemaT, SchemaOutputT<SchemaT>> {
16
+ name: string;
17
+ description: string;
18
+ schema: SchemaT;
19
+ private readonly _manager;
20
+ constructor(manager: ServerManager);
21
+ protected _call(_arg: SchemaOutputT<SchemaT>, _runManager?: CallbackManagerForToolRun, _parentConfig?: ToolRunnableConfig): Promise<ToolOutputT>;
22
+ get manager(): ServerManager;
23
+ }
24
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/managers/tools/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAA;AAClF,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC3F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtD,MAAM,MAAM,WAAW,GAAG,GAAG,CAAA;AAC7B,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,cAAc,IAAI,CAAC,SAAS,CAAC,CAAC,SAAS,GACvE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GACX,CAAC,SAAS,UAAU,GAClB,OAAO,GACP,KAAK,CAAA;AAEX,MAAM,WAAW,oBAAqB,SAAQ,UAAU;IACtD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,qBAAa,aAAa,CAAC,OAAO,SAAS,cAAc,CAAE,SAAQ,cAAc,CAAC,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IACvG,IAAI,EAAE,MAAM,CAAoB;IAChC,WAAW,EAAE,MAAM,CAAyC;IAC5D,MAAM,EAAG,OAAO,CAAA;IAEzB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;gBAE5B,OAAO,EAAE,aAAa;cAKlB,KAAK,CACnB,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,EAC5B,WAAW,CAAC,EAAE,yBAAyB,EACvC,aAAa,CAAC,EAAE,kBAAkB,GACjC,OAAO,CAAC,WAAW,CAAC;IAIvB,IAAI,OAAO,IAAI,aAAa,CAE3B;CACF"}
@@ -0,0 +1,17 @@
1
+ import { StructuredTool } from '@langchain/core/tools';
2
+ export class MCPServerTool extends StructuredTool {
3
+ name = 'mcp_server_tool';
4
+ description = 'Base tool for MCP server operations.';
5
+ schema;
6
+ _manager;
7
+ constructor(manager) {
8
+ super();
9
+ this._manager = manager;
10
+ }
11
+ async _call(_arg, _runManager, _parentConfig) {
12
+ throw new Error('Method not implemented.');
13
+ }
14
+ get manager() {
15
+ return this._manager;
16
+ }
17
+ }
@@ -0,0 +1,26 @@
1
+ import type { ServerManager } from '../server_manager.js';
2
+ import type { SchemaOutputT } from './base.js';
3
+ import { z } from 'zod';
4
+ import { MCPServerTool } from './base.js';
5
+ declare const ConnectMCPServerSchema: z.ZodObject<{
6
+ serverName: z.ZodString;
7
+ }, "strip", z.ZodTypeAny, {
8
+ serverName: string;
9
+ }, {
10
+ serverName: string;
11
+ }>;
12
+ export declare class ConnectMCPServerTool extends MCPServerTool<typeof ConnectMCPServerSchema> {
13
+ name: string;
14
+ description: string;
15
+ schema: z.ZodObject<{
16
+ serverName: z.ZodString;
17
+ }, "strip", z.ZodTypeAny, {
18
+ serverName: string;
19
+ }, {
20
+ serverName: string;
21
+ }>;
22
+ constructor(manager: ServerManager);
23
+ _call({ serverName }: SchemaOutputT<typeof ConnectMCPServerSchema>): Promise<string>;
24
+ }
25
+ export {};
26
+ //# sourceMappingURL=connect_mcp_server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect_mcp_server.d.ts","sourceRoot":"","sources":["../../../../src/managers/tools/connect_mcp_server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAEzC,QAAA,MAAM,sBAAsB;;;;;;EAE1B,CAAA;AAEF,qBAAa,oBAAqB,SAAQ,aAAa,CAAC,OAAO,sBAAsB,CAAC;IAC3E,IAAI,SAA0B;IAC9B,WAAW,SAAiJ;IAC5J,MAAM;;;;;;OAAyB;gBAE5B,OAAO,EAAE,aAAa;IAI5B,KAAK,CAAC,EAAE,UAAU,EAAE,EAAE,aAAa,CAAC,OAAO,sBAAsB,CAAC;CAmCzE"}
@@ -0,0 +1,46 @@
1
+ import { z } from 'zod';
2
+ import { logger } from '../../logging.js';
3
+ import { MCPServerTool } from './base.js';
4
+ const ConnectMCPServerSchema = z.object({
5
+ serverName: z.string().describe('The name of the MCP server.'),
6
+ });
7
+ export class ConnectMCPServerTool extends MCPServerTool {
8
+ name = 'connect_to_mcp_server';
9
+ description = 'Connect to a specific MCP (Model Context Protocol) server to use its tools. Use this tool to connect to a specific server and use its tools.';
10
+ schema = ConnectMCPServerSchema;
11
+ constructor(manager) {
12
+ super(manager);
13
+ }
14
+ async _call({ serverName }) {
15
+ const serverNames = this.manager.client.getServerNames();
16
+ if (!serverNames.includes(serverName)) {
17
+ const available = serverNames.length > 0 ? serverNames.join(', ') : 'none';
18
+ return `Server '${serverName}' not found. Available servers: ${available}`;
19
+ }
20
+ if (this.manager.activeServer === serverName) {
21
+ return `Already connected to MCP server '${serverName}'`;
22
+ }
23
+ try {
24
+ let session = this.manager.client.getSession(serverName);
25
+ logger.debug(`Using existing session for server '${serverName}'`);
26
+ if (!session) {
27
+ logger.debug(`Creating new session for server '${serverName}'`);
28
+ session = await this.manager.client.createSession(serverName);
29
+ }
30
+ this.manager.activeServer = serverName;
31
+ if (this.manager.serverTools[serverName]) {
32
+ const connector = session.connector;
33
+ const tools = await this.manager.adapter.createToolsFromConnectors([connector]);
34
+ this.manager.serverTools[serverName] = tools;
35
+ this.manager.initializedServers[serverName] = true;
36
+ }
37
+ const serverTools = this.manager.serverTools[serverName] || [];
38
+ const numTools = serverTools.length;
39
+ return `Connected to MCP server '${serverName}'. ${numTools} tools are now available.`;
40
+ }
41
+ catch (error) {
42
+ logger.error(`Error connecting to server '${serverName}': ${String(error)}`);
43
+ return `Failed to connect to server '${serverName}': ${String(error)}`;
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,5 @@
1
+ export * from './acquire_active_mcp_server.js';
2
+ export * from './connect_mcp_server.js';
3
+ export * from './list_mcp_servers.js';
4
+ export * from './release_mcp_server_connection.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/managers/tools/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAA;AAC9C,cAAc,yBAAyB,CAAA;AACvC,cAAc,uBAAuB,CAAA;AACrC,cAAc,oCAAoC,CAAA"}
@@ -0,0 +1,4 @@
1
+ export * from './acquire_active_mcp_server.js';
2
+ export * from './connect_mcp_server.js';
3
+ export * from './list_mcp_servers.js';
4
+ export * from './release_mcp_server_connection.js';
@@ -0,0 +1,13 @@
1
+ import type { ServerManager } from '../server_manager.js';
2
+ import { z } from 'zod';
3
+ import { MCPServerTool } from './base.js';
4
+ declare const EnumerateServersSchema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
5
+ export declare class ListMCPServersTool extends MCPServerTool<typeof EnumerateServersSchema> {
6
+ name: string;
7
+ description: string;
8
+ schema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
9
+ constructor(manager: ServerManager);
10
+ _call(): Promise<string>;
11
+ }
12
+ export {};
13
+ //# sourceMappingURL=list_mcp_servers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list_mcp_servers.d.ts","sourceRoot":"","sources":["../../../../src/managers/tools/list_mcp_servers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAEzC,QAAA,MAAM,sBAAsB,gDAAe,CAAA;AAE3C,qBAAa,kBAAmB,SAAQ,aAAa,CAAC,OAAO,sBAAsB,CAAC;IACzE,IAAI,SAAqB;IACzB,WAAW,SAAiN;IAC5N,MAAM,iDAAyB;gBAE5B,OAAO,EAAE,aAAa;IAI5B,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;CAwB/B"}
@@ -0,0 +1,33 @@
1
+ import { z } from 'zod';
2
+ import { logger } from '../../logging.js';
3
+ import { MCPServerTool } from './base.js';
4
+ const EnumerateServersSchema = z.object({});
5
+ export class ListMCPServersTool extends MCPServerTool {
6
+ name = 'list_mcp_servers';
7
+ description = `Lists all available MCP (Model Context Protocol) servers that can be connected to, along with the tools available on each server. Use this tool to discover servers and see what functionalities they offer.`;
8
+ schema = EnumerateServersSchema;
9
+ constructor(manager) {
10
+ super(manager);
11
+ }
12
+ async _call() {
13
+ const serverNames = this.manager.client.getServerNames();
14
+ if (serverNames.length === 0) {
15
+ return `No MCP servers are currently defined.`;
16
+ }
17
+ const outputLines = ['Available MCP servers:'];
18
+ for (const serverName of serverNames) {
19
+ const isActiveServer = serverName === this.manager.activeServer;
20
+ const activeFlag = isActiveServer ? ' (ACTIVE)' : '';
21
+ outputLines.push(`- ${serverName}${activeFlag}`);
22
+ try {
23
+ const serverTools = this.manager.serverTools?.[serverName] ?? [];
24
+ const numberOfTools = Array.isArray(serverTools) ? serverTools.length : 0;
25
+ outputLines.push(`${numberOfTools} tools available for this server\n`);
26
+ }
27
+ catch (error) {
28
+ logger.error(`Unexpected error listing tools for server '${serverName}': ${String(error)}`);
29
+ }
30
+ }
31
+ return outputLines.join('\n');
32
+ }
33
+ }
@@ -0,0 +1,13 @@
1
+ import type { ServerManager } from '../server_manager.js';
2
+ import { z } from 'zod';
3
+ import { MCPServerTool } from './base.js';
4
+ declare const ReleaseConnectionSchema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
5
+ export declare class ReleaseMCPServerConnectionTool extends MCPServerTool<typeof ReleaseConnectionSchema> {
6
+ name: string;
7
+ description: string;
8
+ schema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
9
+ constructor(manager: ServerManager);
10
+ _call(): Promise<string>;
11
+ }
12
+ export {};
13
+ //# sourceMappingURL=release_mcp_server_connection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"release_mcp_server_connection.d.ts","sourceRoot":"","sources":["../../../../src/managers/tools/release_mcp_server_connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAEzC,QAAA,MAAM,uBAAuB,gDAAe,CAAA;AAE5C,qBAAa,8BAA+B,SAAQ,aAAa,CAAC,OAAO,uBAAuB,CAAC;IACtF,IAAI,SAA+B;IACnC,WAAW,SAA6E;IACxF,MAAM,iDAA0B;gBAE7B,OAAO,EAAE,aAAa;IAI5B,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;CAQ/B"}
@@ -0,0 +1,19 @@
1
+ import { z } from 'zod';
2
+ import { MCPServerTool } from './base.js';
3
+ const ReleaseConnectionSchema = z.object({});
4
+ export class ReleaseMCPServerConnectionTool extends MCPServerTool {
5
+ name = 'disconnect_from_mcp_server';
6
+ description = 'Disconnect from the currently active MCP (Model Context Protocol) server';
7
+ schema = ReleaseConnectionSchema;
8
+ constructor(manager) {
9
+ super(manager);
10
+ }
11
+ async _call() {
12
+ if (!this.manager.activeServer) {
13
+ return `No MCP server is currently active, so there's nothing to disconnect from.`;
14
+ }
15
+ const serverName = this.manager.activeServer;
16
+ this.manager.activeServer = null;
17
+ return `Successfully disconnected from MCP server '${serverName}'.`;
18
+ }
19
+ }
@@ -2,18 +2,10 @@ import type { BaseConnector } from './connectors/base.js';
2
2
  export declare class MCPSession {
3
3
  readonly connector: BaseConnector;
4
4
  private autoConnect;
5
- private _sessionInfo;
6
- private _tools;
7
5
  constructor(connector: BaseConnector, autoConnect?: boolean);
8
- open(): Promise<this>;
9
- close(): Promise<void>;
10
6
  connect(): Promise<void>;
11
7
  disconnect(): Promise<void>;
12
- initialize(): Promise<Record<string, any>>;
8
+ initialize(): Promise<void>;
13
9
  get isConnected(): boolean;
14
- get sessionInfo(): Record<string, any> | null;
15
- get tools(): Record<string, any>[];
16
- discoverTools(): Promise<Record<string, any>[]>;
17
- callTool(name: string, args: Record<string, any>): Promise<any>;
18
10
  }
19
11
  //# sourceMappingURL=session.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAGzD,qBAAa,UAAU;IACrB,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAA;IACjC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,YAAY,CAAmC;IACvD,OAAO,CAAC,MAAM,CAA4B;gBAE9B,SAAS,EAAE,aAAa,EAAE,WAAW,UAAO;IAKlD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAKrB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAUhD,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED,IAAI,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAE5C;IAED,IAAI,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAEjC;IAEK,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;IAK/C,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;CAOtE"}
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEzD,qBAAa,UAAU;IACrB,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAA;IACjC,OAAO,CAAC,WAAW,CAAS;gBAEhB,SAAS,EAAE,aAAa,EAAE,WAAW,UAAO;IAKlD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAOjC,IAAI,WAAW,IAAI,OAAO,CAEzB;CACF"}
@@ -1,20 +1,10 @@
1
- import { logger } from './logging.js';
2
1
  export class MCPSession {
3
2
  connector;
4
3
  autoConnect;
5
- _sessionInfo = null;
6
- _tools = [];
7
4
  constructor(connector, autoConnect = true) {
8
5
  this.connector = connector;
9
6
  this.autoConnect = autoConnect;
10
7
  }
11
- async open() {
12
- await this.connect();
13
- return this;
14
- }
15
- async close() {
16
- await this.disconnect();
17
- }
18
8
  async connect() {
19
9
  await this.connector.connect();
20
10
  }
@@ -25,28 +15,9 @@ export class MCPSession {
25
15
  if (!this.isConnected && this.autoConnect) {
26
16
  await this.connect();
27
17
  }
28
- this._sessionInfo = await this.connector.initialize() ?? {};
29
- await this.discoverTools();
30
- return this._sessionInfo;
18
+ await this.connector.initialize();
31
19
  }
32
20
  get isConnected() {
33
21
  return this.connector && this.connector.isClientConnected;
34
22
  }
35
- get sessionInfo() {
36
- return this._sessionInfo;
37
- }
38
- get tools() {
39
- return this._tools;
40
- }
41
- async discoverTools() {
42
- this._tools = this.connector.tools;
43
- return this._tools;
44
- }
45
- async callTool(name, args) {
46
- if (!this.isConnected && this.autoConnect) {
47
- await this.connect();
48
- }
49
- logger.debug(`MCPSession calling tool '${name}'`);
50
- return await this.connector.callTool(name, args);
51
- }
52
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../src/task_managers/sse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAA;AACxF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAE5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAE7C,qBAAa,oBAAqB,SAAQ,iBAAiB,CAAC,kBAAkB,CAAC;IAC7E,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAK;IACzB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAA2B;IACjD,OAAO,CAAC,UAAU,CAAkC;IAEpD;;;;;OAKG;gBACS,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,yBAAyB;IAM/D;;OAEG;cACa,mBAAmB,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAQlE;;OAEG;cACa,eAAe,CAAC,WAAW,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;CAahF"}
1
+ {"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../src/task_managers/sse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAA;AACxF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAE5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAE7C,qBAAa,oBAAqB,SAAQ,iBAAiB,CAAC,kBAAkB,CAAC;IAC7E,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAK;IACzB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAA2B;IACjD,OAAO,CAAC,UAAU,CAAkC;IAEpD;;;;;OAKG;gBACS,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,yBAAyB;IAM/D;;OAEG;cACa,mBAAmB,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAOlE;;OAEG;cACa,eAAe,CAAC,WAAW,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;CAahF"}
@@ -21,7 +21,6 @@ export class SseConnectionManager extends ConnectionManager {
21
21
  */
22
22
  async establishConnection() {
23
23
  this._transport = new SSEClientTransport(this.url, this.opts);
24
- // await this._transport.start()
25
24
  logger.debug(`${this.constructor.name} connected successfully`);
26
25
  return this._transport;
27
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../../../src/task_managers/stdio.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2CAA2C,CAAA;AACtF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAEhF,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAE7C,qBAAa,sBAAuB,SAAQ,iBAAiB,CAAC,oBAAoB,CAAC;IACjF,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAuB;IACpD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IACjC,OAAO,CAAC,UAAU,CAAoC;IAEtD;;;;;;OAMG;gBACS,YAAY,EAAE,qBAAqB,EAAE,MAAM,GAAE,QAAyB;IAMlF;;;OAGG;cACa,mBAAmB,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAcpE;;;OAGG;cACa,eAAe,CAAC,WAAW,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;CAalF"}
1
+ {"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../../../src/task_managers/stdio.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2CAA2C,CAAA;AACtF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAEhF,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAE7C,qBAAa,sBAAuB,SAAQ,iBAAiB,CAAC,oBAAoB,CAAC;IACjF,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAuB;IACpD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IACjC,OAAO,CAAC,UAAU,CAAoC;IAEtD;;;;;;OAMG;gBACS,YAAY,EAAE,qBAAqB,EAAE,MAAM,GAAE,QAAyB;IAMlF;;;OAGG;cACa,mBAAmB,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAapE;;;OAGG;cACa,eAAe,CAAC,WAAW,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;CAalF"}
@@ -24,7 +24,6 @@ export class StdioConnectionManager extends ConnectionManager {
24
24
  async establishConnection() {
25
25
  // Instantiate and start the transport
26
26
  this._transport = new StdioClientTransport(this.serverParams);
27
- // await this._transport.start()
28
27
  // If stderr was piped, forward it to `errlog` for visibility
29
28
  if (this._transport.stderr && typeof this._transport.stderr.pipe === 'function') {
30
29
  this._transport.stderr.pipe(this.errlog);