@juspay/neurolink 1.10.0 → 1.11.0

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 +36 -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 +3 -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 +3 -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
@@ -1,196 +1,47 @@
1
1
  /**
2
- * NeuroLink MCP Tool Registry System
3
- * Central registry for managing MCP servers and tools with execution capabilities
4
- * Supports tool discovery, registration, and orchestrated execution
2
+ * MCP Registry - Plugin Registration and Management
5
3
  */
6
- import type { NeuroLinkMCPServer, NeuroLinkMCPTool, NeuroLinkExecutionContext, ToolResult } from "./factory.js";
7
- import { ContextManager } from "./context-manager.js";
4
+ import type { DiscoveredMCP } from "./contracts/mcp-contract.js";
8
5
  /**
9
- * Tool registration information
6
+ * Simple MCP registry for plugin management
10
7
  */
11
- export interface ToolRegistration {
12
- tool: NeuroLinkMCPTool;
13
- serverId: string;
14
- serverTitle: string;
15
- serverCategory?: string;
16
- qualifiedName: string;
17
- simpleName: string;
18
- registeredAt: number;
19
- }
20
- /**
21
- * Tool execution options
22
- */
23
- export interface ToolExecutionOptions {
24
- validateInput?: boolean;
25
- validatePermissions?: boolean;
26
- trackMetrics?: boolean;
27
- timeoutMs?: number;
28
- }
29
- /**
30
- * Tool search criteria
31
- */
32
- export interface ToolSearchCriteria {
33
- name?: string;
34
- category?: string;
35
- serverId?: string;
36
- serverCategory?: string;
37
- permissions?: string[];
38
- implemented?: boolean;
39
- }
40
- /**
41
- * Registry statistics
42
- */
43
- export interface RegistryStats {
44
- totalServers: number;
45
- totalTools: number;
46
- toolsByCategory: Record<string, number>;
47
- serversByCategory: Record<string, number>;
48
- executionCount: number;
49
- averageExecutionTime: number;
50
- errorRate: number;
51
- }
52
- /**
53
- * Central MCP Tool Registry
54
- * Manages all MCP servers and their tools with advanced execution capabilities
55
- */
56
- export declare class MCPToolRegistry {
57
- private servers;
58
- private tools;
59
- private contextManager;
60
- private executionCount;
61
- private totalExecutionTime;
62
- private errorCount;
63
- constructor(contextManager?: ContextManager);
64
- /**
65
- * Register an MCP server and all its tools
66
- *
67
- * @param server MCP server to register
68
- * @throws Error if server ID already exists
69
- */
70
- registerServer(server: NeuroLinkMCPServer): Promise<void>;
8
+ export declare class MCPRegistry {
9
+ private plugins;
71
10
  /**
72
- * Register a single tool from a server
73
- *
74
- * @param server Source server
75
- * @param toolName Tool name
76
- * @param tool Tool implementation
11
+ * Register a plugin
77
12
  */
78
- private registerToolFromServer;
13
+ register(plugin: DiscoveredMCP): void;
79
14
  /**
80
- * Execute a tool with comprehensive error handling and context tracking
81
- *
82
- * @param toolName Tool name (simple or qualified)
83
- * @param params Tool parameters
84
- * @param context Execution context
85
- * @param options Execution options
86
- * @returns Tool execution result
15
+ * Unregister a plugin
87
16
  */
88
- executeTool(toolName: string, params: any, context: NeuroLinkExecutionContext, options?: ToolExecutionOptions): Promise<ToolResult>;
17
+ unregister(name: string): boolean;
89
18
  /**
90
- * List all available tools with optional filtering
91
- *
92
- * @param criteria Search criteria for filtering tools
93
- * @returns Array of tool information
19
+ * Get a plugin
94
20
  */
95
- listTools(criteria?: ToolSearchCriteria): {
96
- name: string;
97
- qualifiedName: string;
98
- description: string;
99
- server: string;
100
- serverTitle: string;
101
- category?: string;
102
- serverCategory?: string;
103
- permissions?: string[];
104
- isImplemented?: boolean;
105
- }[];
21
+ get(name: string): DiscoveredMCP | undefined;
106
22
  /**
107
- * Get detailed information about a specific tool
108
- *
109
- * @param toolName Tool name (simple or qualified)
110
- * @returns Detailed tool information or undefined if not found
23
+ * List all plugins
111
24
  */
112
- getToolInfo(toolName: string): {
113
- tool: NeuroLinkMCPTool;
114
- server: NeuroLinkMCPServer;
115
- registration: ToolRegistration;
116
- } | undefined;
25
+ list(): DiscoveredMCP[];
117
26
  /**
118
- * Get registry statistics
119
- *
120
- * @returns Comprehensive registry statistics
27
+ * Check if plugin exists
121
28
  */
122
- getStats(): RegistryStats;
29
+ has(name: string): boolean;
123
30
  /**
124
- * Unregister a server and all its tools
125
- *
126
- * @param serverId Server ID to unregister
127
- * @returns Whether server was found and removed
128
- */
129
- unregisterServer(serverId: string): boolean;
130
- /**
131
- * Clear all servers and tools
31
+ * Clear all plugins
132
32
  */
133
33
  clear(): void;
134
- /**
135
- * Create timeout promise wrapper
136
- *
137
- * @param promise Promise to wrap
138
- * @param timeoutMs Timeout in milliseconds
139
- * @param timeoutMessage Error message for timeout
140
- * @returns Promise that rejects on timeout
141
- */
142
- private createTimeoutPromise;
143
- /**
144
- * Update execution metrics
145
- *
146
- * @param executionTime Execution time in milliseconds
147
- * @param success Whether execution was successful
148
- */
149
- private updateExecutionMetrics;
150
34
  }
151
35
  /**
152
- * Get the default singleton instance of the MCPToolRegistry.
153
- * This function ensures that the registry is only instantiated once.
154
- * Using a function getter helps prevent circular dependency issues during module initialization.
155
- *
156
- * @returns The singleton MCPToolRegistry instance.
157
- */
158
- export declare function getDefaultToolRegistry(): MCPToolRegistry;
159
- /**
160
- * @deprecated The direct export `defaultToolRegistry` is deprecated and will be removed.
161
- * Please use `getDefaultToolRegistry()` instead to avoid circular dependency issues.
162
- */
163
- export declare const defaultToolRegistry: MCPToolRegistry;
164
- /**
165
- * Utility function to register server with default registry
166
- *
167
- * @param server MCP server to register
168
- */
169
- export declare function registerServer(server: NeuroLinkMCPServer): Promise<void>;
170
- /**
171
- * Utility function to execute tool with default registry
172
- *
173
- * @param toolName Tool name to execute
174
- * @param params Tool parameters
175
- * @param context Execution context
176
- * @param options Execution options
177
- * @returns Tool execution result
178
- */
179
- export declare function executeTool(toolName: string, params: any, context: NeuroLinkExecutionContext, options?: ToolExecutionOptions): Promise<ToolResult>;
180
- /**
181
- * Utility function to list tools with default registry
182
- *
183
- * @param criteria Search criteria
184
- * @returns Array of tool information
36
+ * Default registry instance
185
37
  */
186
- export declare function listTools(criteria?: ToolSearchCriteria): {
187
- name: string;
188
- qualifiedName: string;
189
- description: string;
190
- server: string;
191
- serverTitle: string;
192
- category?: string;
193
- serverCategory?: string;
194
- permissions?: string[];
195
- isImplemented?: boolean;
196
- }[];
38
+ export declare const mcpRegistry: MCPRegistry;
39
+ export type MCPToolRegistry = MCPRegistry;
40
+ export declare const defaultToolRegistry: MCPRegistry;
41
+ export { mcpRegistry as defaultMCPRegistry };
42
+ export interface ToolExecutionOptions {
43
+ preferredSource?: string;
44
+ fallbackEnabled?: boolean;
45
+ validateBeforeExecution?: boolean;
46
+ timeoutMs?: number;
47
+ }
@@ -1,400 +1,59 @@
1
1
  /**
2
- * NeuroLink MCP Tool Registry System
3
- * Central registry for managing MCP servers and tools with execution capabilities
4
- * Supports tool discovery, registration, and orchestrated execution
2
+ * MCP Registry - Plugin Registration and Management
5
3
  */
6
- import { ContextManager, ContextValidator } from "./context-manager.js";
7
- import { registryLogger, mcpLogger } from "./logging.js";
4
+ import { registryLogger } from "./logging.js";
8
5
  /**
9
- * Central MCP Tool Registry
10
- * Manages all MCP servers and their tools with advanced execution capabilities
6
+ * Simple MCP registry for plugin management
11
7
  */
12
- export class MCPToolRegistry {
13
- servers = new Map();
14
- tools = new Map();
15
- contextManager;
16
- // Execution tracking
17
- executionCount = 0;
18
- totalExecutionTime = 0;
19
- errorCount = 0;
20
- constructor(contextManager) {
21
- this.contextManager = contextManager || new ContextManager();
22
- }
23
- /**
24
- * Register an MCP server and all its tools
25
- *
26
- * @param server MCP server to register
27
- * @throws Error if server ID already exists
28
- */
29
- async registerServer(server) {
30
- // Check for duplicate server ID - if already registered, skip silently
31
- if (this.servers.has(server.id)) {
32
- mcpLogger.debug(`Server with ID '${server.id}' is already registered, skipping registration`);
33
- return;
34
- }
35
- // Register the server
36
- this.servers.set(server.id, server);
37
- // Register all tools from the server
38
- for (const [toolName, tool] of Object.entries(server.tools)) {
39
- await this.registerToolFromServer(server, toolName, tool);
40
- }
41
- registryLogger.debug(`Registered server '${server.id}' with ${Object.keys(server.tools).length} tools`);
42
- }
43
- /**
44
- * Register a single tool from a server
45
- *
46
- * @param server Source server
47
- * @param toolName Tool name
48
- * @param tool Tool implementation
49
- */
50
- async registerToolFromServer(server, toolName, tool) {
51
- const qualifiedName = `${server.id}.${toolName}`;
52
- const simpleName = toolName;
53
- const registration = {
54
- tool,
55
- serverId: server.id,
56
- serverTitle: server.title,
57
- serverCategory: server.category,
58
- qualifiedName,
59
- simpleName,
60
- registeredAt: Date.now(),
61
- };
62
- // Register with both qualified and simple names
63
- this.tools.set(qualifiedName, registration);
64
- // Only register simple name if it doesn't conflict
65
- if (!this.tools.has(simpleName)) {
66
- this.tools.set(simpleName, registration);
67
- }
68
- else {
69
- registryLogger.warn(`Tool name conflict: '${simpleName}' already exists, use qualified name '${qualifiedName}'`);
70
- }
71
- }
8
+ export class MCPRegistry {
9
+ plugins = new Map();
72
10
  /**
73
- * Execute a tool with comprehensive error handling and context tracking
74
- *
75
- * @param toolName Tool name (simple or qualified)
76
- * @param params Tool parameters
77
- * @param context Execution context
78
- * @param options Execution options
79
- * @returns Tool execution result
11
+ * Register a plugin
80
12
  */
81
- async executeTool(toolName, params, context, options = {}) {
82
- const startTime = Date.now();
83
- const { validateInput = true, validatePermissions = true, trackMetrics = true, timeoutMs = 30000, } = options;
84
- try {
85
- // Find the tool
86
- const registration = this.tools.get(toolName);
87
- if (!registration) {
88
- throw new Error(`Tool not found: ${toolName}`);
89
- }
90
- const { tool, serverId, serverTitle } = registration;
91
- // Validate context
92
- if (validatePermissions) {
93
- const contextValidation = ContextValidator.validateContext(context);
94
- if (!contextValidation.isValid) {
95
- throw new Error(`Context validation failed: ${contextValidation.errors.join(", ")}`);
96
- }
97
- // Check tool permissions
98
- if (tool.permissions &&
99
- !ContextValidator.hasPermissions(context, tool.permissions)) {
100
- throw new Error(`Insufficient permissions for tool '${toolName}'. Required: ${tool.permissions.join(", ")}`);
101
- }
102
- }
103
- // Validate input parameters if schema provided
104
- if (validateInput && tool.inputSchema) {
105
- try {
106
- tool.inputSchema.parse(params);
107
- }
108
- catch (error) {
109
- const errorMessage = error instanceof Error ? error.message : String(error);
110
- throw new Error(`Input validation failed for tool '${toolName}': ${errorMessage}`);
111
- }
112
- }
113
- // Add tool to execution chain
114
- this.contextManager.addToToolChain(context, toolName);
115
- // Execute tool with timeout
116
- const executeWithTimeout = this.createTimeoutPromise(tool.execute(params, context), timeoutMs, `Tool '${toolName}' execution timeout`);
117
- const result = await executeWithTimeout;
118
- // Add execution metadata
119
- const executionTime = Date.now() - startTime;
120
- const enhancedResult = {
121
- ...result,
122
- metadata: {
123
- ...result.metadata,
124
- toolName,
125
- serverId,
126
- serverTitle,
127
- sessionId: context.sessionId,
128
- timestamp: Date.now(),
129
- executionTime,
130
- },
131
- };
132
- // Track metrics
133
- if (trackMetrics) {
134
- this.updateExecutionMetrics(executionTime, result.success);
135
- }
136
- // Validate output if schema provided
137
- if (tool.outputSchema && result.success) {
138
- try {
139
- tool.outputSchema.parse(result.data);
140
- }
141
- catch (error) {
142
- const errorMessage = error instanceof Error ? error.message : String(error);
143
- registryLogger.warn(`Output validation warning for tool '${toolName}': ${errorMessage}`);
144
- }
145
- }
146
- registryLogger.debug(`Executed tool '${toolName}' in ${executionTime}ms - ${result.success ? "SUCCESS" : "FAILED"}`);
147
- return enhancedResult;
148
- }
149
- catch (error) {
150
- const executionTime = Date.now() - startTime;
151
- // Track error metrics
152
- if (trackMetrics) {
153
- this.updateExecutionMetrics(executionTime, false);
154
- }
155
- const errorMessage = error instanceof Error ? error.message : String(error);
156
- const errorResult = {
157
- success: false,
158
- error: errorMessage,
159
- metadata: {
160
- toolName,
161
- sessionId: context.sessionId,
162
- timestamp: Date.now(),
163
- executionTime,
164
- },
165
- };
166
- registryLogger.error(`Tool execution failed '${toolName}': ${errorMessage}`);
167
- return errorResult;
168
- }
13
+ register(plugin) {
14
+ this.plugins.set(plugin.metadata.name, plugin);
15
+ registryLogger.info(`Registered plugin: ${plugin.metadata.name}`);
169
16
  }
170
17
  /**
171
- * List all available tools with optional filtering
172
- *
173
- * @param criteria Search criteria for filtering tools
174
- * @returns Array of tool information
18
+ * Unregister a plugin
175
19
  */
176
- listTools(criteria = {}) {
177
- const tools = [];
178
- // Get unique tools (prefer qualified names over simple names)
179
- const uniqueTools = new Map();
180
- for (const [name, registration] of this.tools) {
181
- if (name.includes(".")) {
182
- // Qualified name
183
- uniqueTools.set(registration.qualifiedName, registration);
184
- }
185
- else if (!uniqueTools.has(registration.qualifiedName)) {
186
- uniqueTools.set(registration.qualifiedName, registration);
187
- }
188
- }
189
- for (const registration of uniqueTools.values()) {
190
- const { tool, serverId, serverTitle, serverCategory, qualifiedName, simpleName, } = registration;
191
- // Apply filters
192
- if (criteria.name &&
193
- !simpleName.toLowerCase().includes(criteria.name.toLowerCase())) {
194
- continue;
195
- }
196
- if (criteria.category && tool.category !== criteria.category) {
197
- continue;
198
- }
199
- if (criteria.serverId && serverId !== criteria.serverId) {
200
- continue;
201
- }
202
- if (criteria.serverCategory &&
203
- serverCategory !== criteria.serverCategory) {
204
- continue;
205
- }
206
- if (criteria.implemented !== undefined &&
207
- tool.isImplemented !== criteria.implemented) {
208
- continue;
209
- }
210
- if (criteria.permissions && criteria.permissions.length > 0) {
211
- const toolPermissions = tool.permissions || [];
212
- const hasAllPermissions = criteria.permissions.every((p) => toolPermissions.includes(p));
213
- if (!hasAllPermissions) {
214
- continue;
215
- }
216
- }
217
- tools.push({
218
- name: simpleName,
219
- qualifiedName,
220
- description: tool.description,
221
- server: serverId,
222
- serverTitle,
223
- category: tool.category,
224
- serverCategory,
225
- permissions: tool.permissions,
226
- isImplemented: tool.isImplemented,
227
- });
20
+ unregister(name) {
21
+ const removed = this.plugins.delete(name);
22
+ if (removed) {
23
+ registryLogger.info(`Unregistered plugin: ${name}`);
228
24
  }
229
- return tools.sort((a, b) => a.qualifiedName.localeCompare(b.qualifiedName));
25
+ return removed;
230
26
  }
231
27
  /**
232
- * Get detailed information about a specific tool
233
- *
234
- * @param toolName Tool name (simple or qualified)
235
- * @returns Detailed tool information or undefined if not found
28
+ * Get a plugin
236
29
  */
237
- getToolInfo(toolName) {
238
- const registration = this.tools.get(toolName);
239
- if (!registration) {
240
- return undefined;
241
- }
242
- const server = this.servers.get(registration.serverId);
243
- if (!server) {
244
- return undefined;
245
- }
246
- return {
247
- tool: registration.tool,
248
- server,
249
- registration,
250
- };
30
+ get(name) {
31
+ return this.plugins.get(name);
251
32
  }
252
33
  /**
253
- * Get registry statistics
254
- *
255
- * @returns Comprehensive registry statistics
34
+ * List all plugins
256
35
  */
257
- getStats() {
258
- const toolsByCategory = {};
259
- const serversByCategory = {};
260
- // Count tools by category
261
- for (const registration of this.tools.values()) {
262
- const category = registration.tool.category || "uncategorized";
263
- toolsByCategory[category] = (toolsByCategory[category] || 0) + 1;
264
- }
265
- // Count servers by category
266
- for (const server of this.servers.values()) {
267
- const category = server.category || "uncategorized";
268
- serversByCategory[category] = (serversByCategory[category] || 0) + 1;
269
- }
270
- return {
271
- totalServers: this.servers.size,
272
- totalTools: new Set(Array.from(this.tools.values()).map((r) => r.qualifiedName)).size,
273
- toolsByCategory,
274
- serversByCategory,
275
- executionCount: this.executionCount,
276
- averageExecutionTime: this.executionCount > 0
277
- ? this.totalExecutionTime / this.executionCount
278
- : 0,
279
- errorRate: this.executionCount > 0 ? this.errorCount / this.executionCount : 0,
280
- };
36
+ list() {
37
+ return Array.from(this.plugins.values());
281
38
  }
282
39
  /**
283
- * Unregister a server and all its tools
284
- *
285
- * @param serverId Server ID to unregister
286
- * @returns Whether server was found and removed
40
+ * Check if plugin exists
287
41
  */
288
- unregisterServer(serverId) {
289
- const server = this.servers.get(serverId);
290
- if (!server) {
291
- return false;
292
- }
293
- // Remove all tools from this server
294
- const toolsToRemove = [];
295
- for (const [name, registration] of this.tools) {
296
- if (registration.serverId === serverId) {
297
- toolsToRemove.push(name);
298
- }
299
- }
300
- for (const toolName of toolsToRemove) {
301
- this.tools.delete(toolName);
302
- }
303
- // Remove the server
304
- this.servers.delete(serverId);
305
- registryLogger.debug(`Unregistered server '${serverId}' and ${toolsToRemove.length} tools`);
306
- return true;
42
+ has(name) {
43
+ return this.plugins.has(name);
307
44
  }
308
45
  /**
309
- * Clear all servers and tools
46
+ * Clear all plugins
310
47
  */
311
48
  clear() {
312
- this.servers.clear();
313
- this.tools.clear();
314
- this.executionCount = 0;
315
- this.totalExecutionTime = 0;
316
- this.errorCount = 0;
317
- registryLogger.debug("Cleared all servers and tools");
318
- }
319
- /**
320
- * Create timeout promise wrapper
321
- *
322
- * @param promise Promise to wrap
323
- * @param timeoutMs Timeout in milliseconds
324
- * @param timeoutMessage Error message for timeout
325
- * @returns Promise that rejects on timeout
326
- */
327
- createTimeoutPromise(promise, timeoutMs, timeoutMessage) {
328
- return Promise.race([
329
- promise,
330
- new Promise((_, reject) => {
331
- setTimeout(() => reject(new Error(timeoutMessage)), timeoutMs);
332
- }),
333
- ]);
334
- }
335
- /**
336
- * Update execution metrics
337
- *
338
- * @param executionTime Execution time in milliseconds
339
- * @param success Whether execution was successful
340
- */
341
- updateExecutionMetrics(executionTime, success) {
342
- this.executionCount++;
343
- this.totalExecutionTime += executionTime;
344
- if (!success) {
345
- this.errorCount++;
346
- }
49
+ this.plugins.clear();
50
+ registryLogger.info("Registry cleared");
347
51
  }
348
52
  }
349
53
  /**
350
54
  * Default registry instance
351
- * Can be used across the application for consistent tool management
352
55
  */
353
- let defaultRegistryInstance = null;
354
- /**
355
- * Get the default singleton instance of the MCPToolRegistry.
356
- * This function ensures that the registry is only instantiated once.
357
- * Using a function getter helps prevent circular dependency issues during module initialization.
358
- *
359
- * @returns The singleton MCPToolRegistry instance.
360
- */
361
- export function getDefaultToolRegistry() {
362
- if (!defaultRegistryInstance) {
363
- defaultRegistryInstance = new MCPToolRegistry();
364
- }
365
- return defaultRegistryInstance;
366
- }
367
- /**
368
- * @deprecated The direct export `defaultToolRegistry` is deprecated and will be removed.
369
- * Please use `getDefaultToolRegistry()` instead to avoid circular dependency issues.
370
- */
371
- export const defaultToolRegistry = getDefaultToolRegistry();
372
- /**
373
- * Utility function to register server with default registry
374
- *
375
- * @param server MCP server to register
376
- */
377
- export async function registerServer(server) {
378
- return getDefaultToolRegistry().registerServer(server);
379
- }
380
- /**
381
- * Utility function to execute tool with default registry
382
- *
383
- * @param toolName Tool name to execute
384
- * @param params Tool parameters
385
- * @param context Execution context
386
- * @param options Execution options
387
- * @returns Tool execution result
388
- */
389
- export async function executeTool(toolName, params, context, options) {
390
- return getDefaultToolRegistry().executeTool(toolName, params, context, options);
391
- }
392
- /**
393
- * Utility function to list tools with default registry
394
- *
395
- * @param criteria Search criteria
396
- * @returns Array of tool information
397
- */
398
- export function listTools(criteria) {
399
- return getDefaultToolRegistry().listTools(criteria);
400
- }
56
+ export const mcpRegistry = new MCPRegistry();
57
+ export const defaultToolRegistry = mcpRegistry;
58
+ // Additional exports for compatibility
59
+ export { mcpRegistry as defaultMCPRegistry };