@juspay/neurolink 1.10.0 → 1.11.1

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 (144) hide show
  1. package/CHANGELOG.md +43 -33
  2. package/README.md +16 -0
  3. package/dist/agent/direct-tools.d.ts +9 -9
  4. package/dist/cli/commands/agent-generate.d.ts +1 -2
  5. package/dist/cli/commands/agent-generate.js +5 -8
  6. package/dist/cli/commands/config.d.ts +2 -2
  7. package/dist/cli/commands/config.js +1 -1
  8. package/dist/cli/commands/mcp.js +91 -100
  9. package/dist/cli/commands/ollama.d.ts +2 -7
  10. package/dist/cli/commands/ollama.js +5 -8
  11. package/dist/cli/index.js +185 -276
  12. package/dist/core/factory.js +9 -10
  13. package/dist/index.d.ts +23 -0
  14. package/dist/index.js +35 -0
  15. package/dist/lib/agent/direct-tools.d.ts +9 -9
  16. package/dist/lib/core/factory.js +9 -10
  17. package/dist/lib/index.d.ts +23 -0
  18. package/dist/lib/index.js +35 -0
  19. package/dist/lib/mcp/adapters/plugin-bridge.d.ts +39 -0
  20. package/dist/lib/mcp/adapters/plugin-bridge.js +82 -0
  21. package/dist/lib/mcp/auto-discovery.d.ts +38 -96
  22. package/dist/lib/mcp/auto-discovery.js +100 -744
  23. package/dist/lib/mcp/client.js +4 -4
  24. package/dist/lib/mcp/context-manager.js +72 -1
  25. package/dist/lib/mcp/contracts/mcp-contract.d.ts +162 -0
  26. package/dist/lib/mcp/contracts/mcp-contract.js +58 -0
  27. package/dist/lib/mcp/core/plugin-manager.d.ts +45 -0
  28. package/dist/lib/mcp/core/plugin-manager.js +110 -0
  29. package/dist/lib/mcp/demo/plugin-demo.d.ts +20 -0
  30. package/dist/lib/mcp/demo/plugin-demo.js +116 -0
  31. package/dist/lib/mcp/ecosystem.d.ts +75 -0
  32. package/dist/lib/mcp/ecosystem.js +161 -0
  33. package/dist/lib/mcp/external-client.d.ts +88 -0
  34. package/dist/lib/mcp/external-client.js +323 -0
  35. package/dist/lib/mcp/external-manager.d.ts +112 -0
  36. package/dist/lib/mcp/external-manager.js +302 -0
  37. package/dist/lib/mcp/factory.d.ts +4 -4
  38. package/dist/lib/mcp/function-calling.js +59 -34
  39. package/dist/lib/mcp/index.d.ts +39 -184
  40. package/dist/lib/mcp/index.js +72 -150
  41. package/dist/lib/mcp/initialize.js +5 -5
  42. package/dist/lib/mcp/logging.d.ts +27 -60
  43. package/dist/lib/mcp/logging.js +77 -165
  44. package/dist/lib/mcp/neurolink-mcp-client.js +31 -3
  45. package/dist/lib/mcp/orchestrator.d.ts +1 -1
  46. package/dist/lib/mcp/orchestrator.js +13 -12
  47. package/dist/lib/mcp/plugin-manager.d.ts +98 -0
  48. package/dist/lib/mcp/plugin-manager.js +294 -0
  49. package/dist/lib/mcp/plugins/core/filesystem-mcp.d.ts +35 -0
  50. package/dist/lib/mcp/plugins/core/filesystem-mcp.js +139 -0
  51. package/dist/lib/mcp/plugins/filesystem-mcp.d.ts +36 -0
  52. package/dist/lib/mcp/plugins/filesystem-mcp.js +54 -0
  53. package/dist/lib/mcp/registry.d.ts +27 -176
  54. package/dist/lib/mcp/registry.js +31 -372
  55. package/dist/lib/mcp/security-manager.d.ts +85 -0
  56. package/dist/lib/mcp/security-manager.js +344 -0
  57. package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
  58. package/dist/lib/mcp/tool-integration.d.ts +4 -14
  59. package/dist/lib/mcp/tool-integration.js +43 -21
  60. package/dist/lib/mcp/tool-registry.d.ts +66 -0
  61. package/dist/lib/mcp/tool-registry.js +160 -0
  62. package/dist/lib/mcp/unified-mcp.d.ts +123 -0
  63. package/dist/lib/mcp/unified-mcp.js +246 -0
  64. package/dist/lib/mcp/unified-registry.d.ts +42 -229
  65. package/dist/lib/mcp/unified-registry.js +96 -1346
  66. package/dist/lib/neurolink.d.ts +3 -4
  67. package/dist/lib/neurolink.js +17 -18
  68. package/dist/lib/providers/agent-enhanced-provider.js +2 -2
  69. package/dist/lib/providers/amazonBedrock.js +2 -2
  70. package/dist/lib/providers/anthropic.js +3 -3
  71. package/dist/lib/providers/azureOpenAI.js +3 -3
  72. package/dist/lib/providers/function-calling-provider.js +34 -25
  73. package/dist/lib/providers/googleAIStudio.js +9 -3
  74. package/dist/lib/providers/googleVertexAI.js +2 -2
  75. package/dist/lib/providers/huggingFace.js +2 -2
  76. package/dist/lib/providers/mcp-provider.js +33 -5
  77. package/dist/lib/providers/mistralAI.js +2 -2
  78. package/dist/lib/providers/ollama.js +2 -2
  79. package/dist/lib/providers/openAI.js +2 -2
  80. package/dist/lib/utils/providerUtils-fixed.js +9 -9
  81. package/dist/mcp/adapters/plugin-bridge.d.ts +39 -0
  82. package/dist/mcp/adapters/plugin-bridge.js +82 -0
  83. package/dist/mcp/auto-discovery.d.ts +38 -96
  84. package/dist/mcp/auto-discovery.js +100 -745
  85. package/dist/mcp/client.js +4 -4
  86. package/dist/mcp/context-manager.js +72 -1
  87. package/dist/mcp/contracts/mcp-contract.d.ts +162 -0
  88. package/dist/mcp/contracts/mcp-contract.js +58 -0
  89. package/dist/mcp/core/plugin-manager.d.ts +45 -0
  90. package/dist/mcp/core/plugin-manager.js +110 -0
  91. package/dist/mcp/demo/plugin-demo.d.ts +20 -0
  92. package/dist/mcp/demo/plugin-demo.js +116 -0
  93. package/dist/mcp/ecosystem.d.ts +75 -0
  94. package/dist/mcp/ecosystem.js +162 -0
  95. package/dist/mcp/external-client.d.ts +88 -0
  96. package/dist/mcp/external-client.js +323 -0
  97. package/dist/mcp/external-manager.d.ts +112 -0
  98. package/dist/mcp/external-manager.js +302 -0
  99. package/dist/mcp/factory.d.ts +4 -4
  100. package/dist/mcp/function-calling.js +59 -34
  101. package/dist/mcp/index.d.ts +39 -184
  102. package/dist/mcp/index.js +72 -150
  103. package/dist/mcp/initialize.js +5 -5
  104. package/dist/mcp/logging.d.ts +27 -60
  105. package/dist/mcp/logging.js +77 -165
  106. package/dist/mcp/neurolink-mcp-client.js +31 -3
  107. package/dist/mcp/orchestrator.d.ts +1 -1
  108. package/dist/mcp/orchestrator.js +13 -12
  109. package/dist/mcp/plugin-manager.d.ts +98 -0
  110. package/dist/mcp/plugin-manager.js +295 -0
  111. package/dist/mcp/plugins/core/filesystem-mcp.d.ts +35 -0
  112. package/dist/mcp/plugins/core/filesystem-mcp.js +139 -0
  113. package/dist/mcp/plugins/core/neurolink-mcp.json +17 -0
  114. package/dist/mcp/plugins/filesystem-mcp.d.ts +36 -0
  115. package/dist/mcp/plugins/filesystem-mcp.js +54 -0
  116. package/dist/mcp/registry.d.ts +27 -176
  117. package/dist/mcp/registry.js +31 -372
  118. package/dist/mcp/security-manager.d.ts +85 -0
  119. package/dist/mcp/security-manager.js +344 -0
  120. package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
  121. package/dist/mcp/tool-integration.d.ts +4 -14
  122. package/dist/mcp/tool-integration.js +43 -21
  123. package/dist/mcp/tool-registry.d.ts +66 -0
  124. package/dist/mcp/tool-registry.js +160 -0
  125. package/dist/mcp/unified-mcp.d.ts +123 -0
  126. package/dist/mcp/unified-mcp.js +246 -0
  127. package/dist/mcp/unified-registry.d.ts +42 -229
  128. package/dist/mcp/unified-registry.js +96 -1345
  129. package/dist/neurolink.d.ts +3 -4
  130. package/dist/neurolink.js +17 -18
  131. package/dist/providers/agent-enhanced-provider.js +2 -2
  132. package/dist/providers/amazonBedrock.js +2 -2
  133. package/dist/providers/anthropic.js +3 -3
  134. package/dist/providers/azureOpenAI.js +3 -3
  135. package/dist/providers/function-calling-provider.js +34 -25
  136. package/dist/providers/googleAIStudio.js +9 -3
  137. package/dist/providers/googleVertexAI.js +2 -2
  138. package/dist/providers/huggingFace.js +2 -2
  139. package/dist/providers/mcp-provider.js +33 -5
  140. package/dist/providers/mistralAI.js +2 -2
  141. package/dist/providers/ollama.js +2 -2
  142. package/dist/providers/openAI.js +2 -2
  143. package/dist/utils/providerUtils-fixed.js +9 -9
  144. package/package.json +1 -1
@@ -0,0 +1,160 @@
1
+ /**
2
+ * MCP Tool Registry - Extended Registry with Tool Management
3
+ */
4
+ import { MCPRegistry } from "./registry.js";
5
+ import { registryLogger } from "./logging.js";
6
+ export class MCPToolRegistry extends MCPRegistry {
7
+ tools = new Map();
8
+ toolExecutionStats = new Map();
9
+ /**
10
+ * Register a server with its tools
11
+ */
12
+ async registerServer(serverId, serverInfo) {
13
+ registryLogger.info(`Registering server: ${serverId}`);
14
+ // Extract tools from server info if available
15
+ if (serverInfo.tools) {
16
+ for (const [toolName, toolDef] of Object.entries(serverInfo.tools)) {
17
+ const toolId = `${serverId}.${toolName}`;
18
+ this.tools.set(toolId, {
19
+ id: toolId,
20
+ name: toolName,
21
+ description: toolDef.description,
22
+ inputSchema: toolDef.inputSchema,
23
+ outputSchema: toolDef.outputSchema,
24
+ serverId,
25
+ server: serverId, // Backward compatibility alias
26
+ source: "manual",
27
+ isImplemented: true,
28
+ });
29
+ }
30
+ }
31
+ }
32
+ /**
33
+ * Unregister a server and its tools
34
+ */
35
+ async unregisterServer(serverId) {
36
+ registryLogger.info(`Unregistering server: ${serverId}`);
37
+ // Remove all tools for this server
38
+ for (const [toolId, toolInfo] of this.tools) {
39
+ if (toolInfo.serverId === serverId) {
40
+ this.tools.delete(toolId);
41
+ this.toolExecutionStats.delete(toolId);
42
+ }
43
+ }
44
+ }
45
+ /**
46
+ * Execute a tool
47
+ */
48
+ async executeTool(toolName, args, context) {
49
+ const startTime = Date.now();
50
+ try {
51
+ const toolInfo = this.getToolInfo(toolName);
52
+ if (!toolInfo) {
53
+ throw new Error(`Tool not found: ${toolName}`);
54
+ }
55
+ registryLogger.info(`Executing tool: ${toolName}`);
56
+ // Get the plugin that provides this tool
57
+ const plugin = this.get(toolInfo.serverId);
58
+ if (!plugin) {
59
+ throw new Error(`Plugin not found for tool: ${toolName}`);
60
+ }
61
+ // Execute through the plugin (stub implementation)
62
+ const result = {
63
+ success: true,
64
+ data: `Tool ${toolInfo.name} executed with args: ${JSON.stringify(args)}`,
65
+ };
66
+ const executionTime = Date.now() - startTime;
67
+ this.updateStats(toolName, executionTime);
68
+ return {
69
+ success: true,
70
+ data: result,
71
+ metadata: {
72
+ toolName,
73
+ executionTime,
74
+ timestamp: Date.now(),
75
+ },
76
+ };
77
+ }
78
+ catch (error) {
79
+ registryLogger.error(`Tool execution failed: ${toolName}`, error);
80
+ return {
81
+ success: false,
82
+ error: error instanceof Error ? error : new Error(String(error)),
83
+ metadata: {
84
+ toolName,
85
+ executionTime: Date.now() - startTime,
86
+ timestamp: Date.now(),
87
+ },
88
+ };
89
+ }
90
+ }
91
+ /**
92
+ * List all available tools
93
+ */
94
+ async listTools() {
95
+ return Array.from(this.tools.values());
96
+ }
97
+ /**
98
+ * Get tool information
99
+ */
100
+ getToolInfo(toolName) {
101
+ return this.tools.get(toolName);
102
+ }
103
+ /**
104
+ * Update execution statistics
105
+ */
106
+ updateStats(toolName, executionTime) {
107
+ const stats = this.toolExecutionStats.get(toolName) || {
108
+ count: 0,
109
+ totalTime: 0,
110
+ };
111
+ stats.count++;
112
+ stats.totalTime += executionTime;
113
+ this.toolExecutionStats.set(toolName, stats);
114
+ }
115
+ /**
116
+ * Get tool execution statistics
117
+ */
118
+ getToolStats(toolName) {
119
+ if (toolName) {
120
+ const stats = this.toolExecutionStats.get(toolName);
121
+ return stats
122
+ ? {
123
+ ...stats,
124
+ averageTime: stats.totalTime / stats.count,
125
+ }
126
+ : null;
127
+ }
128
+ // Return all stats
129
+ const allStats = {};
130
+ for (const [tool, stats] of this.toolExecutionStats) {
131
+ allStats[tool] = {
132
+ ...stats,
133
+ averageTime: stats.totalTime / stats.count,
134
+ };
135
+ }
136
+ return allStats;
137
+ }
138
+ /**
139
+ * Get tool execution statistics
140
+ */
141
+ async getStats() {
142
+ const tools = await this.listTools();
143
+ return {
144
+ totalTools: tools.length,
145
+ totalExecutions: Array.from(this.toolExecutionStats.values()).reduce((acc, stats) => acc + stats.count, 0),
146
+ };
147
+ }
148
+ /**
149
+ * Clear all tools and stats
150
+ */
151
+ clear() {
152
+ super.clear();
153
+ this.tools.clear();
154
+ this.toolExecutionStats.clear();
155
+ }
156
+ }
157
+ // Export singleton instance
158
+ export const toolRegistry = new MCPToolRegistry();
159
+ // Additional exports for backward compatibility
160
+ export const defaultToolRegistry = toolRegistry;
@@ -0,0 +1,123 @@
1
+ /**
2
+ * NeuroLink Unified MCP System
3
+ * Combines internal MCP servers with external MCP server integration
4
+ * Single initialization point for the complete MCP ecosystem
5
+ */
6
+ import { MCPToolRegistry } from "./tool-registry.js";
7
+ import { ExternalMCPManager } from "./external-manager.js";
8
+ import type { NeuroLinkExecutionContext, ToolResult } from "./factory.js";
9
+ /**
10
+ * Unified MCP System Options
11
+ */
12
+ export interface UnifiedMCPOptions {
13
+ configPath?: string;
14
+ enableExternalServers?: boolean;
15
+ enableInternalServers?: boolean;
16
+ autoInitialize?: boolean;
17
+ registry?: MCPToolRegistry;
18
+ }
19
+ /**
20
+ * Unified MCP System Status
21
+ */
22
+ export interface UnifiedMCPStatus {
23
+ isInitialized: boolean;
24
+ internalServers: {
25
+ count: number;
26
+ tools: number;
27
+ };
28
+ externalServers: {
29
+ configured: number;
30
+ connected: number;
31
+ tools: number;
32
+ };
33
+ totalTools: number;
34
+ registryStats: any;
35
+ }
36
+ /**
37
+ * Unified MCP System
38
+ * Central hub for managing both internal and external MCP servers
39
+ */
40
+ export declare class UnifiedMCPSystem {
41
+ private registry;
42
+ private externalManager;
43
+ private internalServers;
44
+ private isInitialized;
45
+ private options;
46
+ constructor(options?: UnifiedMCPOptions);
47
+ /**
48
+ * Initialize the unified MCP system
49
+ */
50
+ initialize(): Promise<void>;
51
+ /**
52
+ * Initialize internal MCP servers
53
+ */
54
+ private initializeInternalServers;
55
+ /**
56
+ * Initialize external MCP servers
57
+ */
58
+ private initializeExternalServers;
59
+ /**
60
+ * Execute a tool from any registered server
61
+ */
62
+ executeTool(toolName: string, params: any, context: NeuroLinkExecutionContext): Promise<ToolResult>;
63
+ /**
64
+ * List all available tools
65
+ */
66
+ listTools(criteria?: any): Promise<import("./tool-registry.js").ToolInfo[]>;
67
+ /**
68
+ * Get tool information
69
+ */
70
+ getToolInfo(toolName: string): import("./tool-registry.js").ToolInfo | undefined;
71
+ /**
72
+ * Get registry instance
73
+ */
74
+ getRegistry(): MCPToolRegistry;
75
+ /**
76
+ * Get external manager instance
77
+ */
78
+ getExternalManager(): ExternalMCPManager;
79
+ /**
80
+ * Get comprehensive status
81
+ */
82
+ getStatus(): Promise<UnifiedMCPStatus>;
83
+ /**
84
+ * Refresh external connections
85
+ */
86
+ refreshExternalServers(): Promise<void>;
87
+ /**
88
+ * Shutdown the unified MCP system
89
+ */
90
+ shutdown(): Promise<void>;
91
+ /**
92
+ * Check if system is initialized
93
+ */
94
+ isSystemInitialized(): boolean;
95
+ }
96
+ /**
97
+ * Default unified MCP system instance
98
+ */
99
+ export declare const defaultUnifiedMCP: UnifiedMCPSystem;
100
+ /**
101
+ * Initialize the default unified MCP system
102
+ */
103
+ export declare function initializeMCP(options?: UnifiedMCPOptions): Promise<UnifiedMCPSystem>;
104
+ /**
105
+ * Get the default unified MCP system
106
+ */
107
+ export declare function getMCPSystem(): UnifiedMCPSystem;
108
+ /**
109
+ * Execute a tool using the default system
110
+ */
111
+ export declare function executeMCPTool(toolName: string, params: any, context: NeuroLinkExecutionContext): Promise<ToolResult>;
112
+ /**
113
+ * List all available MCP tools
114
+ */
115
+ export declare function listMCPTools(criteria?: any): Promise<import("./tool-registry.js").ToolInfo[]>;
116
+ /**
117
+ * Get MCP tool information
118
+ */
119
+ export declare function getMCPToolInfo(toolName: string): import("./tool-registry.js").ToolInfo | undefined;
120
+ /**
121
+ * Get unified MCP system status
122
+ */
123
+ export declare function getMCPStatus(): Promise<UnifiedMCPStatus>;
@@ -0,0 +1,246 @@
1
+ /**
2
+ * NeuroLink Unified MCP System
3
+ * Combines internal MCP servers with external MCP server integration
4
+ * Single initialization point for the complete MCP ecosystem
5
+ */
6
+ import { MCPToolRegistry } from "./tool-registry.js";
7
+ import { ExternalMCPManager } from "./external-manager.js";
8
+ import { aiCoreServer } from "./servers/ai-providers/ai-core-server.js";
9
+ import { mcpLogger as logger } from "./logging.js";
10
+ /**
11
+ * Unified MCP System
12
+ * Central hub for managing both internal and external MCP servers
13
+ */
14
+ export class UnifiedMCPSystem {
15
+ registry;
16
+ externalManager;
17
+ internalServers = [];
18
+ isInitialized = false;
19
+ options;
20
+ constructor(options = {}) {
21
+ this.options = {
22
+ configPath: ".mcp-config.json",
23
+ enableExternalServers: true,
24
+ enableInternalServers: true,
25
+ autoInitialize: false,
26
+ registry: new MCPToolRegistry(),
27
+ ...options,
28
+ };
29
+ this.registry = this.options.registry;
30
+ this.externalManager = new ExternalMCPManager(this.options.configPath, this.registry);
31
+ }
32
+ /**
33
+ * Initialize the unified MCP system
34
+ */
35
+ async initialize() {
36
+ if (this.isInitialized) {
37
+ logger.debug("[Unified MCP] Already initialized");
38
+ return;
39
+ }
40
+ try {
41
+ logger.info("[Unified MCP] Initializing unified MCP system...");
42
+ const startTime = Date.now();
43
+ // Initialize internal servers first
44
+ if (this.options.enableInternalServers) {
45
+ await this.initializeInternalServers();
46
+ }
47
+ // Initialize external servers
48
+ if (this.options.enableExternalServers) {
49
+ await this.initializeExternalServers();
50
+ }
51
+ this.isInitialized = true;
52
+ const initTime = Date.now() - startTime;
53
+ const status = this.getStatus();
54
+ const currentStatus = await this.getStatus();
55
+ logger.info(`[Unified MCP] Initialization complete in ${initTime}ms`, {
56
+ totalTools: currentStatus.totalTools,
57
+ internalServers: currentStatus.internalServers.count,
58
+ externalServers: currentStatus.externalServers.connected,
59
+ });
60
+ }
61
+ catch (error) {
62
+ logger.error("[Unified MCP] Initialization failed:", error);
63
+ throw error;
64
+ }
65
+ }
66
+ /**
67
+ * Initialize internal MCP servers
68
+ */
69
+ async initializeInternalServers() {
70
+ try {
71
+ logger.info("[Unified MCP] Initializing internal servers...");
72
+ // Register AI Core Server (with 10 tools)
73
+ await this.registry.registerServer("ai-core", aiCoreServer);
74
+ this.internalServers.push(aiCoreServer);
75
+ // TODO: Add other internal servers here as they are created
76
+ // await this.registry.registerServer(utilityServer);
77
+ // this.internalServers.push(utilityServer);
78
+ const totalInternalTools = this.internalServers.reduce((sum, server) => sum + Object.keys(server.tools).length, 0);
79
+ logger.info(`[Unified MCP] Registered ${this.internalServers.length} internal servers with ${totalInternalTools} tools`);
80
+ }
81
+ catch (error) {
82
+ logger.error("[Unified MCP] Failed to initialize internal servers:", error);
83
+ throw error;
84
+ }
85
+ }
86
+ /**
87
+ * Initialize external MCP servers
88
+ */
89
+ async initializeExternalServers() {
90
+ try {
91
+ logger.info("[Unified MCP] Initializing external servers...");
92
+ await this.externalManager.initialize();
93
+ const connectedServers = this.externalManager.getConnectedServers();
94
+ const totalExternalTools = connectedServers.reduce((sum, server) => sum + server.toolCount, 0);
95
+ logger.info(`[Unified MCP] Connected to ${connectedServers.length} external servers with ${totalExternalTools} tools`);
96
+ }
97
+ catch (error) {
98
+ logger.warn("[Unified MCP] External server initialization failed (continuing without external servers):", error);
99
+ // Don't throw here - external servers are optional
100
+ }
101
+ }
102
+ /**
103
+ * Execute a tool from any registered server
104
+ */
105
+ async executeTool(toolName, params, context) {
106
+ if (!this.isInitialized) {
107
+ throw new Error("Unified MCP system not initialized. Call initialize() first.");
108
+ }
109
+ return this.registry.executeTool(toolName, params, context);
110
+ }
111
+ /**
112
+ * List all available tools
113
+ */
114
+ listTools(criteria) {
115
+ return this.registry.listTools();
116
+ }
117
+ /**
118
+ * Get tool information
119
+ */
120
+ getToolInfo(toolName) {
121
+ return this.registry.getToolInfo(toolName);
122
+ }
123
+ /**
124
+ * Get registry instance
125
+ */
126
+ getRegistry() {
127
+ return this.registry;
128
+ }
129
+ /**
130
+ * Get external manager instance
131
+ */
132
+ getExternalManager() {
133
+ return this.externalManager;
134
+ }
135
+ /**
136
+ * Get comprehensive status
137
+ */
138
+ async getStatus() {
139
+ const registryStats = await this.registry.getStats();
140
+ const externalStatus = this.externalManager.getStatus();
141
+ const internalToolCount = this.internalServers.reduce((sum, server) => sum + Object.keys(server.tools).length, 0);
142
+ return {
143
+ isInitialized: this.isInitialized,
144
+ internalServers: {
145
+ count: this.internalServers.length,
146
+ tools: internalToolCount,
147
+ },
148
+ externalServers: {
149
+ configured: externalStatus.totalServers,
150
+ connected: externalStatus.connected,
151
+ tools: externalStatus.totalTools,
152
+ },
153
+ totalTools: registryStats.totalTools,
154
+ registryStats,
155
+ };
156
+ }
157
+ /**
158
+ * Refresh external connections
159
+ */
160
+ async refreshExternalServers() {
161
+ if (!this.options.enableExternalServers) {
162
+ return;
163
+ }
164
+ logger.info("[Unified MCP] Refreshing external servers...");
165
+ await this.externalManager.refresh();
166
+ }
167
+ /**
168
+ * Shutdown the unified MCP system
169
+ */
170
+ async shutdown() {
171
+ if (!this.isInitialized) {
172
+ return;
173
+ }
174
+ logger.info("[Unified MCP] Shutting down unified MCP system...");
175
+ try {
176
+ // Disconnect external servers
177
+ await this.externalManager.disconnectAll();
178
+ // Clear registry
179
+ this.registry.clear();
180
+ // Clear internal servers
181
+ this.internalServers = [];
182
+ this.isInitialized = false;
183
+ logger.info("[Unified MCP] Shutdown complete");
184
+ }
185
+ catch (error) {
186
+ logger.error("[Unified MCP] Shutdown failed:", error);
187
+ throw error;
188
+ }
189
+ }
190
+ /**
191
+ * Check if system is initialized
192
+ */
193
+ isSystemInitialized() {
194
+ return this.isInitialized;
195
+ }
196
+ }
197
+ /**
198
+ * Default unified MCP system instance
199
+ */
200
+ export const defaultUnifiedMCP = new UnifiedMCPSystem({
201
+ autoInitialize: false,
202
+ });
203
+ /**
204
+ * Initialize the default unified MCP system
205
+ */
206
+ export async function initializeMCP(options) {
207
+ if (options) {
208
+ const customSystem = new UnifiedMCPSystem(options);
209
+ await customSystem.initialize();
210
+ return customSystem;
211
+ }
212
+ if (!defaultUnifiedMCP.isSystemInitialized()) {
213
+ await defaultUnifiedMCP.initialize();
214
+ }
215
+ return defaultUnifiedMCP;
216
+ }
217
+ /**
218
+ * Get the default unified MCP system
219
+ */
220
+ export function getMCPSystem() {
221
+ return defaultUnifiedMCP;
222
+ }
223
+ /**
224
+ * Execute a tool using the default system
225
+ */
226
+ export async function executeMCPTool(toolName, params, context) {
227
+ return defaultUnifiedMCP.executeTool(toolName, params, context);
228
+ }
229
+ /**
230
+ * List all available MCP tools
231
+ */
232
+ export function listMCPTools(criteria) {
233
+ return defaultUnifiedMCP.listTools(criteria);
234
+ }
235
+ /**
236
+ * Get MCP tool information
237
+ */
238
+ export function getMCPToolInfo(toolName) {
239
+ return defaultUnifiedMCP.getToolInfo(toolName);
240
+ }
241
+ /**
242
+ * Get unified MCP system status
243
+ */
244
+ export async function getMCPStatus() {
245
+ return await defaultUnifiedMCP.getStatus();
246
+ }