@juspay/neurolink 3.0.1 → 4.0.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 (192) hide show
  1. package/CHANGELOG.md +57 -6
  2. package/README.md +235 -2
  3. package/dist/agent/direct-tools.d.ts +6 -6
  4. package/dist/chat/client-utils.d.ts +92 -0
  5. package/dist/chat/client-utils.js +298 -0
  6. package/dist/chat/index.d.ts +27 -0
  7. package/dist/chat/index.js +41 -0
  8. package/dist/chat/session-storage.d.ts +77 -0
  9. package/dist/chat/session-storage.js +233 -0
  10. package/dist/chat/session.d.ts +95 -0
  11. package/dist/chat/session.js +257 -0
  12. package/dist/chat/sse-handler.d.ts +49 -0
  13. package/dist/chat/sse-handler.js +266 -0
  14. package/dist/chat/types.d.ts +73 -0
  15. package/dist/chat/types.js +5 -0
  16. package/dist/chat/websocket-chat-handler.d.ts +36 -0
  17. package/dist/chat/websocket-chat-handler.js +262 -0
  18. package/dist/cli/commands/config.js +12 -12
  19. package/dist/cli/commands/mcp.js +3 -4
  20. package/dist/cli/index.d.ts +0 -7
  21. package/dist/cli/index.js +247 -28
  22. package/dist/config/configManager.d.ts +60 -0
  23. package/dist/config/configManager.js +300 -0
  24. package/dist/config/types.d.ts +136 -0
  25. package/dist/config/types.js +43 -0
  26. package/dist/core/analytics.d.ts +23 -0
  27. package/dist/core/analytics.js +131 -0
  28. package/dist/core/constants.d.ts +41 -0
  29. package/dist/core/constants.js +50 -0
  30. package/dist/core/defaults.d.ts +18 -0
  31. package/dist/core/defaults.js +29 -0
  32. package/dist/core/evaluation-config.d.ts +29 -0
  33. package/dist/core/evaluation-config.js +144 -0
  34. package/dist/core/evaluation-providers.d.ts +30 -0
  35. package/dist/core/evaluation-providers.js +187 -0
  36. package/dist/core/evaluation.d.ts +117 -0
  37. package/dist/core/evaluation.js +528 -0
  38. package/dist/core/factory.js +33 -25
  39. package/dist/core/types.d.ts +165 -6
  40. package/dist/core/types.js +3 -4
  41. package/dist/index.d.ts +9 -4
  42. package/dist/index.js +25 -4
  43. package/dist/lib/agent/direct-tools.d.ts +6 -6
  44. package/dist/lib/chat/client-utils.d.ts +92 -0
  45. package/dist/lib/chat/client-utils.js +298 -0
  46. package/dist/lib/chat/index.d.ts +27 -0
  47. package/dist/lib/chat/index.js +41 -0
  48. package/dist/lib/chat/session-storage.d.ts +77 -0
  49. package/dist/lib/chat/session-storage.js +233 -0
  50. package/dist/lib/chat/session.d.ts +95 -0
  51. package/dist/lib/chat/session.js +257 -0
  52. package/dist/lib/chat/sse-handler.d.ts +49 -0
  53. package/dist/lib/chat/sse-handler.js +266 -0
  54. package/dist/lib/chat/types.d.ts +73 -0
  55. package/dist/lib/chat/types.js +5 -0
  56. package/dist/lib/chat/websocket-chat-handler.d.ts +36 -0
  57. package/dist/lib/chat/websocket-chat-handler.js +262 -0
  58. package/dist/lib/config/configManager.d.ts +60 -0
  59. package/dist/lib/config/configManager.js +300 -0
  60. package/dist/lib/config/types.d.ts +136 -0
  61. package/dist/lib/config/types.js +43 -0
  62. package/dist/lib/core/analytics.d.ts +23 -0
  63. package/dist/lib/core/analytics.js +131 -0
  64. package/dist/lib/core/constants.d.ts +41 -0
  65. package/dist/lib/core/constants.js +50 -0
  66. package/dist/lib/core/defaults.d.ts +18 -0
  67. package/dist/lib/core/defaults.js +29 -0
  68. package/dist/lib/core/evaluation-config.d.ts +29 -0
  69. package/dist/lib/core/evaluation-config.js +144 -0
  70. package/dist/lib/core/evaluation-providers.d.ts +30 -0
  71. package/dist/lib/core/evaluation-providers.js +187 -0
  72. package/dist/lib/core/evaluation.d.ts +117 -0
  73. package/dist/lib/core/evaluation.js +528 -0
  74. package/dist/lib/core/factory.js +33 -26
  75. package/dist/lib/core/types.d.ts +165 -6
  76. package/dist/lib/core/types.js +3 -4
  77. package/dist/lib/index.d.ts +9 -4
  78. package/dist/lib/index.js +25 -4
  79. package/dist/lib/mcp/contracts/mcpContract.d.ts +118 -0
  80. package/dist/lib/mcp/contracts/mcpContract.js +5 -0
  81. package/dist/lib/mcp/function-calling.js +11 -3
  82. package/dist/lib/mcp/logging.js +5 -0
  83. package/dist/lib/mcp/neurolink-mcp-client.js +2 -1
  84. package/dist/lib/mcp/orchestrator.js +18 -9
  85. package/dist/lib/mcp/registry.d.ts +49 -16
  86. package/dist/lib/mcp/registry.js +80 -6
  87. package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.js +5 -4
  88. package/dist/lib/mcp/tool-integration.js +1 -1
  89. package/dist/lib/mcp/tool-registry.d.ts +55 -34
  90. package/dist/lib/mcp/tool-registry.js +111 -97
  91. package/dist/lib/mcp/unified-mcp.js +6 -1
  92. package/dist/lib/mcp/unified-registry.d.ts +12 -4
  93. package/dist/lib/mcp/unified-registry.js +17 -4
  94. package/dist/lib/neurolink.d.ts +26 -0
  95. package/dist/lib/neurolink.js +43 -1
  96. package/dist/lib/providers/agent-enhanced-provider.d.ts +11 -2
  97. package/dist/lib/providers/agent-enhanced-provider.js +86 -15
  98. package/dist/lib/providers/amazonBedrock.d.ts +9 -1
  99. package/dist/lib/providers/amazonBedrock.js +26 -2
  100. package/dist/lib/providers/analytics-helper.d.ts +53 -0
  101. package/dist/lib/providers/analytics-helper.js +151 -0
  102. package/dist/lib/providers/anthropic.d.ts +11 -1
  103. package/dist/lib/providers/anthropic.js +29 -4
  104. package/dist/lib/providers/azureOpenAI.d.ts +3 -1
  105. package/dist/lib/providers/azureOpenAI.js +28 -4
  106. package/dist/lib/providers/function-calling-provider.d.ts +9 -1
  107. package/dist/lib/providers/function-calling-provider.js +14 -1
  108. package/dist/lib/providers/googleAIStudio.d.ts +15 -1
  109. package/dist/lib/providers/googleAIStudio.js +32 -2
  110. package/dist/lib/providers/googleVertexAI.d.ts +9 -1
  111. package/dist/lib/providers/googleVertexAI.js +31 -2
  112. package/dist/lib/providers/huggingFace.d.ts +3 -1
  113. package/dist/lib/providers/huggingFace.js +26 -3
  114. package/dist/lib/providers/mcp-provider.d.ts +9 -1
  115. package/dist/lib/providers/mcp-provider.js +12 -0
  116. package/dist/lib/providers/mistralAI.d.ts +3 -1
  117. package/dist/lib/providers/mistralAI.js +25 -2
  118. package/dist/lib/providers/ollama.d.ts +3 -1
  119. package/dist/lib/providers/ollama.js +27 -4
  120. package/dist/lib/providers/openAI.d.ts +15 -1
  121. package/dist/lib/providers/openAI.js +32 -2
  122. package/dist/lib/proxy/proxy-fetch.js +8 -7
  123. package/dist/lib/services/streaming/streaming-manager.d.ts +29 -0
  124. package/dist/lib/services/streaming/streaming-manager.js +244 -0
  125. package/dist/lib/services/types.d.ts +155 -0
  126. package/dist/lib/services/types.js +2 -0
  127. package/dist/lib/services/websocket/websocket-server.d.ts +34 -0
  128. package/dist/lib/services/websocket/websocket-server.js +304 -0
  129. package/dist/lib/telemetry/index.d.ts +15 -0
  130. package/dist/lib/telemetry/index.js +22 -0
  131. package/dist/lib/telemetry/telemetry-service.d.ts +47 -0
  132. package/dist/lib/telemetry/telemetry-service.js +259 -0
  133. package/dist/lib/utils/streaming-utils.d.ts +67 -0
  134. package/dist/lib/utils/streaming-utils.js +201 -0
  135. package/dist/mcp/contracts/mcpContract.d.ts +118 -0
  136. package/dist/mcp/contracts/mcpContract.js +5 -0
  137. package/dist/mcp/function-calling.js +11 -3
  138. package/dist/mcp/logging.js +5 -0
  139. package/dist/mcp/neurolink-mcp-client.js +2 -1
  140. package/dist/mcp/orchestrator.js +18 -9
  141. package/dist/mcp/registry.d.ts +49 -16
  142. package/dist/mcp/registry.js +80 -6
  143. package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
  144. package/dist/mcp/servers/ai-providers/ai-workflow-tools.js +5 -4
  145. package/dist/mcp/tool-integration.js +1 -1
  146. package/dist/mcp/tool-registry.d.ts +55 -34
  147. package/dist/mcp/tool-registry.js +111 -97
  148. package/dist/mcp/unified-mcp.js +6 -1
  149. package/dist/mcp/unified-registry.d.ts +12 -4
  150. package/dist/mcp/unified-registry.js +17 -4
  151. package/dist/neurolink.d.ts +26 -0
  152. package/dist/neurolink.js +43 -1
  153. package/dist/providers/agent-enhanced-provider.d.ts +11 -2
  154. package/dist/providers/agent-enhanced-provider.js +86 -15
  155. package/dist/providers/amazonBedrock.d.ts +9 -1
  156. package/dist/providers/amazonBedrock.js +26 -2
  157. package/dist/providers/analytics-helper.d.ts +53 -0
  158. package/dist/providers/analytics-helper.js +151 -0
  159. package/dist/providers/anthropic.d.ts +11 -1
  160. package/dist/providers/anthropic.js +29 -4
  161. package/dist/providers/azureOpenAI.d.ts +3 -1
  162. package/dist/providers/azureOpenAI.js +29 -4
  163. package/dist/providers/function-calling-provider.d.ts +9 -1
  164. package/dist/providers/function-calling-provider.js +14 -1
  165. package/dist/providers/googleAIStudio.d.ts +15 -1
  166. package/dist/providers/googleAIStudio.js +32 -2
  167. package/dist/providers/googleVertexAI.d.ts +9 -1
  168. package/dist/providers/googleVertexAI.js +31 -2
  169. package/dist/providers/huggingFace.d.ts +3 -1
  170. package/dist/providers/huggingFace.js +26 -3
  171. package/dist/providers/mcp-provider.d.ts +9 -1
  172. package/dist/providers/mcp-provider.js +12 -0
  173. package/dist/providers/mistralAI.d.ts +3 -1
  174. package/dist/providers/mistralAI.js +25 -2
  175. package/dist/providers/ollama.d.ts +3 -1
  176. package/dist/providers/ollama.js +27 -4
  177. package/dist/providers/openAI.d.ts +15 -1
  178. package/dist/providers/openAI.js +33 -2
  179. package/dist/proxy/proxy-fetch.js +8 -7
  180. package/dist/services/streaming/streaming-manager.d.ts +29 -0
  181. package/dist/services/streaming/streaming-manager.js +244 -0
  182. package/dist/services/types.d.ts +155 -0
  183. package/dist/services/types.js +2 -0
  184. package/dist/services/websocket/websocket-server.d.ts +34 -0
  185. package/dist/services/websocket/websocket-server.js +304 -0
  186. package/dist/telemetry/index.d.ts +15 -0
  187. package/dist/telemetry/index.js +22 -0
  188. package/dist/telemetry/telemetry-service.d.ts +47 -0
  189. package/dist/telemetry/telemetry-service.js +261 -0
  190. package/dist/utils/streaming-utils.d.ts +67 -0
  191. package/dist/utils/streaming-utils.js +201 -0
  192. package/package.json +18 -2
@@ -1,9 +1,10 @@
1
1
  /**
2
- * MCP Registry - Plugin Registration and Management
2
+ * MCP Registry - Industry Standard Interface with camelCase
3
3
  */
4
4
  import { registryLogger } from "./logging.js";
5
5
  /**
6
6
  * Simple MCP registry for plugin management
7
+ * Maintains backward compatibility with existing code
7
8
  */
8
9
  export class MCPRegistry {
9
10
  plugins = new Map();
@@ -49,11 +50,84 @@ export class MCPRegistry {
49
50
  this.plugins.clear();
50
51
  registryLogger.info("Registry cleared");
51
52
  }
53
+ /**
54
+ * Register a server (compatible with new interface)
55
+ */
56
+ async registerServer(serverId, serverConfig, context) {
57
+ const plugin = {
58
+ metadata: {
59
+ name: serverId,
60
+ description: typeof serverConfig === "object" && serverConfig
61
+ ? serverConfig.description || "No description"
62
+ : "No description",
63
+ },
64
+ tools: typeof serverConfig === "object" && serverConfig
65
+ ? serverConfig.tools
66
+ : {},
67
+ configuration: typeof serverConfig === "object" && serverConfig
68
+ ? serverConfig
69
+ : {},
70
+ };
71
+ this.register(plugin);
72
+ }
73
+ /**
74
+ * Execute a tool (mock implementation for tests)
75
+ */
76
+ async executeTool(toolName, args, context) {
77
+ registryLogger.info(`Executing tool: ${toolName}`);
78
+ return { result: `Mock execution of ${toolName}`, args };
79
+ }
80
+ /**
81
+ * List all tools (compatible with new interface)
82
+ */
83
+ async listTools(context) {
84
+ const tools = this.list().map((plugin) => ({
85
+ name: plugin.metadata.name,
86
+ description: plugin.metadata.description || "No description",
87
+ serverId: plugin.metadata.name,
88
+ category: "general",
89
+ }));
90
+ return tools;
91
+ }
92
+ // Legacy methods for backward compatibility
93
+ /**
94
+ * Register a server (legacy sync version)
95
+ */
96
+ registerServerSync(plugin) {
97
+ this.register(plugin);
98
+ }
99
+ /**
100
+ * Execute a tool (legacy sync version)
101
+ */
102
+ executeToolSync(toolName, args) {
103
+ registryLogger.info(`Executing tool (sync): ${toolName}`);
104
+ return { result: `Mock execution of ${toolName}`, args };
105
+ }
106
+ /**
107
+ * List all tools (legacy sync version)
108
+ */
109
+ listToolsSync() {
110
+ const tools = this.list().map((plugin) => ({
111
+ name: plugin.metadata.name,
112
+ description: plugin.metadata.description || "No description",
113
+ }));
114
+ return tools;
115
+ }
52
116
  }
53
117
  /**
54
- * Default registry instance
118
+ * Enhanced MCP Registry implementation with config integration
119
+ * Will be implemented in Phase 3.2
55
120
  */
56
- export const mcpRegistry = new MCPRegistry();
57
- export const defaultToolRegistry = mcpRegistry;
58
- // Additional exports for compatibility
59
- export { mcpRegistry as defaultMCPRegistry };
121
+ export class McpRegistryImpl {
122
+ baseRegistry = new MCPRegistry();
123
+ // Additional implementation will be added in Phase 3.2
124
+ async registerServer(serverId, serverConfig, context) {
125
+ return this.baseRegistry.registerServer(serverId, serverConfig, context);
126
+ }
127
+ async executeTool(toolName, args, context) {
128
+ return this.baseRegistry.executeTool(toolName, args, context);
129
+ }
130
+ async listTools(context) {
131
+ return this.baseRegistry.listTools(context);
132
+ }
133
+ }
@@ -30,13 +30,13 @@ export declare const workflowToolSchemas: {
30
30
  includeAsyncTests: z.ZodDefault<z.ZodBoolean>;
31
31
  }, "strip", z.ZodTypeAny, {
32
32
  codeFunction: string;
33
- testTypes: ("integration" | "unit" | "edge-cases" | "performance" | "security")[];
33
+ testTypes: ("integration" | "unit" | "performance" | "edge-cases" | "security")[];
34
34
  framework: "jest" | "mocha" | "vitest" | "pytest" | "unittest" | "rspec";
35
35
  coverageTarget: number;
36
36
  includeAsyncTests: boolean;
37
37
  }, {
38
38
  codeFunction: string;
39
- testTypes?: ("integration" | "unit" | "edge-cases" | "performance" | "security")[] | undefined;
39
+ testTypes?: ("integration" | "unit" | "performance" | "edge-cases" | "security")[] | undefined;
40
40
  framework?: "jest" | "mocha" | "vitest" | "pytest" | "unittest" | "rspec" | undefined;
41
41
  coverageTarget?: number | undefined;
42
42
  includeAsyncTests?: boolean | undefined;
@@ -5,6 +5,7 @@
5
5
  import { z } from "zod";
6
6
  import { AIProviderFactory } from "../../../core/factory.js";
7
7
  import { getBestProviderSync as getBestProvider } from "../../../utils/providerUtils.js";
8
+ import { DEFAULT_MAX_TOKENS } from "../../../core/constants.js";
8
9
  // Tool-specific schemas with comprehensive validation
9
10
  const generateTestCasesSchema = z.object({
10
11
  codeFunction: z
@@ -145,7 +146,7 @@ Return ONLY a valid JSON object with this exact structure:
145
146
  Generate 3-5 comprehensive test cases covering the requested types.`;
146
147
  const result = await provider.generateText({
147
148
  prompt,
148
- maxTokens: 1200,
149
+ maxTokens: Math.floor(DEFAULT_MAX_TOKENS * 1.2),
149
150
  temperature: 0.3, // Lower temperature for more consistent structured output
150
151
  });
151
152
  if (!result || !result.text) {
@@ -251,7 +252,7 @@ Return ONLY a valid JSON object with this exact structure:
251
252
  Focus on real, actionable improvements based on the specified objectives.`;
252
253
  const result = await provider.generateText({
253
254
  prompt,
254
- maxTokens: 1000,
255
+ maxTokens: DEFAULT_MAX_TOKENS,
255
256
  temperature: 0.2, // Very low temperature for consistent refactoring
256
257
  });
257
258
  if (!result || !result.text) {
@@ -359,7 +360,7 @@ Return ONLY a valid JSON object with this exact structure:
359
360
  Focus on creating accurate, useful documentation that explains the code's purpose, parameters, return values, and usage patterns.`;
360
361
  const result = await provider.generateText({
361
362
  prompt,
362
- maxTokens: 1200,
363
+ maxTokens: Math.floor(DEFAULT_MAX_TOKENS * 1.2),
363
364
  temperature: 0.3, // Moderate temperature for creative but structured documentation
364
365
  });
365
366
  if (!result || !result.text) {
@@ -484,7 +485,7 @@ Return ONLY a valid JSON object with this exact structure:
484
485
  Provide thorough, actionable analysis focused on improving AI output quality.`;
485
486
  const result = await provider.generateText({
486
487
  prompt,
487
- maxTokens: 1000,
488
+ maxTokens: DEFAULT_MAX_TOKENS,
488
489
  temperature: 0.4, // Moderate temperature for analytical thinking
489
490
  });
490
491
  if (!result || !result.text) {
@@ -93,7 +93,7 @@ export class MCPToolIntegration {
93
93
  results.push({
94
94
  name: toolInfo.name,
95
95
  description: toolInfo.description || "No description available",
96
- serverId: toolInfo.server || "unknown",
96
+ serverId: toolInfo.serverId || "unknown",
97
97
  relevance,
98
98
  });
99
99
  }
@@ -1,40 +1,38 @@
1
1
  /**
2
2
  * MCP Tool Registry - Extended Registry with Tool Management
3
+ * Updated to match industry standard camelCase interfaces
3
4
  */
4
- import type { ExecutionContext } from "./contracts/mcp-contract.js";
5
+ import type { ExecutionContext, ToolInfo } from "./contracts/mcpContract.js";
5
6
  import type { ToolResult } from "./factory.js";
6
7
  import { MCPRegistry } from "./registry.js";
7
- export interface ToolInfo {
8
- id: string;
9
- name: string;
10
- description?: string;
11
- inputSchema?: any;
12
- outputSchema?: any;
13
- serverId: string;
14
- source: "manual" | "auto" | "default";
15
- isImplemented?: boolean;
16
- server?: string;
17
- }
18
8
  export type ToolExecutionResult = ToolResult;
9
+ /**
10
+ * Tool execution options
11
+ */
12
+ export interface ToolExecutionOptions {
13
+ timeout?: number;
14
+ retries?: number;
15
+ context?: ExecutionContext;
16
+ preferredSource?: string;
17
+ fallbackEnabled?: boolean;
18
+ validateBeforeExecution?: boolean;
19
+ timeoutMs?: number;
20
+ }
19
21
  export declare class MCPToolRegistry extends MCPRegistry {
20
22
  private tools;
21
23
  private toolExecutionStats;
22
24
  /**
23
- * Register a server with its tools
24
- */
25
- registerServer(serverId: string, serverInfo: any): Promise<void>;
26
- /**
27
- * Unregister a server and its tools
25
+ * Register a server with its tools (updated signature)
28
26
  */
29
- unregisterServer(serverId: string): Promise<void>;
27
+ registerServer(serverId: string, serverConfig?: unknown, context?: ExecutionContext): Promise<void>;
30
28
  /**
31
- * Execute a tool
29
+ * Execute a tool with enhanced context
32
30
  */
33
- executeTool(toolName: string, args: any, context: ExecutionContext): Promise<ToolExecutionResult>;
31
+ executeTool<T = unknown>(toolName: string, args?: unknown, context?: ExecutionContext): Promise<T>;
34
32
  /**
35
- * List all available tools
33
+ * List all available tools (updated signature)
36
34
  */
37
- listTools(): Promise<ToolInfo[]>;
35
+ listTools(context?: ExecutionContext): Promise<ToolInfo[]>;
38
36
  /**
39
37
  * Get tool information
40
38
  */
@@ -44,23 +42,46 @@ export declare class MCPToolRegistry extends MCPRegistry {
44
42
  */
45
43
  private updateStats;
46
44
  /**
47
- * Get tool execution statistics
45
+ * Get execution statistics
48
46
  */
49
- getToolStats(toolName?: string): any;
47
+ getExecutionStats(): Record<string, {
48
+ count: number;
49
+ averageTime: number;
50
+ totalTime: number;
51
+ }>;
50
52
  /**
51
- * Get tool execution statistics
53
+ * Clear execution statistics
52
54
  */
53
- getStats(): Promise<any>;
55
+ clearStats(): void;
54
56
  /**
55
- * Clear all tools and stats
57
+ * Get tools by category
56
58
  */
57
- clear(): void;
59
+ getToolsByCategory(category: string): ToolInfo[];
60
+ /**
61
+ * Check if tool exists
62
+ */
63
+ hasTool(toolName: string): boolean;
64
+ /**
65
+ * Remove a tool
66
+ */
67
+ removeTool(toolName: string): boolean;
68
+ /**
69
+ * Get tool count
70
+ */
71
+ getToolCount(): number;
72
+ /**
73
+ * Get statistics (alias for getExecutionStats)
74
+ */
75
+ getStats(): Record<string, {
76
+ count: number;
77
+ averageTime: number;
78
+ totalTime: number;
79
+ }>;
80
+ /**
81
+ * Unregister a server
82
+ */
83
+ unregisterServer(serverId: string): boolean;
58
84
  }
59
85
  export declare const toolRegistry: MCPToolRegistry;
60
86
  export declare const defaultToolRegistry: MCPToolRegistry;
61
- export interface ToolExecutionOptions {
62
- preferredSource?: string;
63
- fallbackEnabled?: boolean;
64
- validateBeforeExecution?: boolean;
65
- timeoutMs?: number;
66
- }
87
+ export type { ToolInfo } from "./contracts/mcpContract.js";
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * MCP Tool Registry - Extended Registry with Tool Management
3
+ * Updated to match industry standard camelCase interfaces
3
4
  */
4
5
  import { MCPRegistry } from "./registry.js";
5
6
  import { registryLogger } from "./logging.js";
@@ -7,91 +8,74 @@ export class MCPToolRegistry extends MCPRegistry {
7
8
  tools = new Map();
8
9
  toolExecutionStats = new Map();
9
10
  /**
10
- * Register a server with its tools
11
+ * Register a server with its tools (updated signature)
11
12
  */
12
- async registerServer(serverId, serverInfo) {
13
+ async registerServer(serverId, serverConfig, context) {
13
14
  registryLogger.info(`Registering server: ${serverId}`);
15
+ // Convert to DiscoveredMcp format for compatibility
16
+ const plugin = {
17
+ metadata: {
18
+ name: serverId,
19
+ description: typeof serverConfig === "object" && serverConfig
20
+ ? serverConfig.description || "No description"
21
+ : "No description",
22
+ },
23
+ tools: typeof serverConfig === "object" && serverConfig
24
+ ? serverConfig.tools
25
+ : {},
26
+ configuration: typeof serverConfig === "object" && serverConfig
27
+ ? serverConfig
28
+ : {},
29
+ };
30
+ // Call the parent register method
31
+ this.register(plugin);
14
32
  // 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
- }
33
+ const tools = plugin.tools || {};
34
+ for (const [toolName, toolDef] of Object.entries(tools)) {
35
+ const toolId = `${serverId}.${toolName}`;
36
+ this.tools.set(toolId, {
37
+ name: toolName,
38
+ description: toolDef?.description,
39
+ inputSchema: toolDef?.inputSchema,
40
+ outputSchema: toolDef?.outputSchema,
41
+ serverId,
42
+ category: toolDef?.category || "general",
43
+ });
43
44
  }
44
45
  }
45
46
  /**
46
- * Execute a tool
47
+ * Execute a tool with enhanced context
47
48
  */
48
49
  async executeTool(toolName, args, context) {
49
50
  const startTime = Date.now();
50
51
  try {
51
- const toolInfo = this.getToolInfo(toolName);
52
- if (!toolInfo) {
53
- throw new Error(`Tool not found: ${toolName}`);
54
- }
55
52
  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)}`,
53
+ // Create execution context if not provided
54
+ const execContext = {
55
+ sessionId: context?.sessionId || crypto.randomUUID(),
56
+ userId: context?.userId,
57
+ ...context,
65
58
  };
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
- },
59
+ // Mock execution for now
60
+ const result = {
61
+ result: `Mock execution of ${toolName}`,
62
+ args,
63
+ context: execContext,
76
64
  };
65
+ // Update statistics
66
+ const duration = Date.now() - startTime;
67
+ this.updateStats(toolName, duration);
68
+ return result;
77
69
  }
78
70
  catch (error) {
79
71
  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
- };
72
+ throw error;
89
73
  }
90
74
  }
91
75
  /**
92
- * List all available tools
76
+ * List all available tools (updated signature)
93
77
  */
94
- async listTools() {
78
+ async listTools(context) {
95
79
  return Array.from(this.tools.values());
96
80
  }
97
81
  /**
@@ -108,53 +92,83 @@ export class MCPToolRegistry extends MCPRegistry {
108
92
  count: 0,
109
93
  totalTime: 0,
110
94
  };
111
- stats.count++;
95
+ stats.count += 1;
112
96
  stats.totalTime += executionTime;
113
97
  this.toolExecutionStats.set(toolName, stats);
114
98
  }
115
99
  /**
116
- * Get tool execution statistics
100
+ * Get execution statistics
117
101
  */
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,
102
+ getExecutionStats() {
103
+ const result = {};
104
+ for (const [toolName, stats] of this.toolExecutionStats.entries()) {
105
+ result[toolName] = {
106
+ count: stats.count,
107
+ totalTime: stats.totalTime,
133
108
  averageTime: stats.totalTime / stats.count,
134
109
  };
135
110
  }
136
- return allStats;
111
+ return result;
137
112
  }
138
113
  /**
139
- * Get tool execution statistics
114
+ * Clear execution statistics
140
115
  */
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
- };
116
+ clearStats() {
117
+ this.toolExecutionStats.clear();
147
118
  }
148
119
  /**
149
- * Clear all tools and stats
120
+ * Get tools by category
150
121
  */
151
- clear() {
152
- super.clear();
153
- this.tools.clear();
154
- this.toolExecutionStats.clear();
122
+ getToolsByCategory(category) {
123
+ return Array.from(this.tools.values()).filter((tool) => tool.category === category);
124
+ }
125
+ /**
126
+ * Check if tool exists
127
+ */
128
+ hasTool(toolName) {
129
+ return this.tools.has(toolName);
130
+ }
131
+ /**
132
+ * Remove a tool
133
+ */
134
+ removeTool(toolName) {
135
+ const removed = this.tools.delete(toolName);
136
+ if (removed) {
137
+ this.toolExecutionStats.delete(toolName);
138
+ registryLogger.info(`Removed tool: ${toolName}`);
139
+ }
140
+ return removed;
141
+ }
142
+ /**
143
+ * Get tool count
144
+ */
145
+ getToolCount() {
146
+ return this.tools.size;
147
+ }
148
+ /**
149
+ * Get statistics (alias for getExecutionStats)
150
+ */
151
+ getStats() {
152
+ return this.getExecutionStats();
153
+ }
154
+ /**
155
+ * Unregister a server
156
+ */
157
+ unregisterServer(serverId) {
158
+ // Remove all tools for this server
159
+ const removedTools = [];
160
+ for (const [toolId, tool] of this.tools.entries()) {
161
+ if (tool.serverId === serverId) {
162
+ this.tools.delete(toolId);
163
+ removedTools.push(toolId);
164
+ }
165
+ }
166
+ // Remove from parent registry
167
+ const removed = this.unregister(serverId);
168
+ registryLogger.info(`Unregistered server ${serverId}, removed ${removedTools.length} tools`);
169
+ return removed;
155
170
  }
156
171
  }
157
- // Export singleton instance
172
+ // Create default instance
158
173
  export const toolRegistry = new MCPToolRegistry();
159
- // Additional exports for backward compatibility
160
174
  export const defaultToolRegistry = toolRegistry;
@@ -139,6 +139,11 @@ export class UnifiedMCPSystem {
139
139
  const registryStats = await this.registry.getStats();
140
140
  const externalStatus = this.externalManager.getStatus();
141
141
  const internalToolCount = this.internalServers.reduce((sum, server) => sum + Object.keys(server.tools).length, 0);
142
+ // Calculate total tools from registry
143
+ const registryToolCount = this.registry.getToolCount
144
+ ? this.registry.getToolCount()
145
+ : 0;
146
+ const totalTools = internalToolCount + externalStatus.totalTools + registryToolCount;
142
147
  return {
143
148
  isInitialized: this.isInitialized,
144
149
  internalServers: {
@@ -150,7 +155,7 @@ export class UnifiedMCPSystem {
150
155
  connected: externalStatus.connected,
151
156
  tools: externalStatus.totalTools,
152
157
  },
153
- totalTools: registryStats.totalTools,
158
+ totalTools,
154
159
  registryStats,
155
160
  };
156
161
  }
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import type { DiscoveredMCP, ExecutionContext } from "./contracts/mcp-contract.js";
5
5
  import type { DiscoveryOptions } from "./auto-discovery.js";
6
- import { MCPToolRegistry, type ToolInfo, type ToolExecutionResult } from "./tool-registry.js";
6
+ import { MCPToolRegistry, type ToolInfo } from "./tool-registry.js";
7
7
  /**
8
8
  * Unified registry combining multiple sources
9
9
  */
@@ -47,7 +47,7 @@ export declare class UnifiedMCPRegistry extends MCPToolRegistry {
47
47
  /**
48
48
  * Execute a tool through the registry
49
49
  */
50
- executeTool(toolName: string, args: any, context: ExecutionContext): Promise<ToolExecutionResult>;
50
+ executeTool<T = unknown>(toolName: string, args?: unknown, context?: ExecutionContext): Promise<T>;
51
51
  /**
52
52
  * Lazily activate a server by ID
53
53
  */
@@ -57,9 +57,17 @@ export declare class UnifiedMCPRegistry extends MCPToolRegistry {
57
57
  */
58
58
  registerManualServer(id: string, server: any): void;
59
59
  /**
60
- * Get registry statistics
60
+ * Get registry statistics (override parent method)
61
61
  */
62
- getStats(): Promise<{
62
+ getStats(): Record<string, {
63
+ count: number;
64
+ averageTime: number;
65
+ totalTime: number;
66
+ }>;
67
+ /**
68
+ * Get detailed registry statistics
69
+ */
70
+ getDetailedStats(): Promise<{
63
71
  total: number;
64
72
  bySource: Record<string, number>;
65
73
  byType: Record<string, number>;
@@ -79,7 +79,12 @@ export class UnifiedMCPRegistry extends MCPToolRegistry {
79
79
  try {
80
80
  // Get tools from plugin metadata if available
81
81
  const tools = await this.listTools();
82
- allTools.push(...tools);
82
+ allTools.push(...tools.map((tool) => ({
83
+ ...tool,
84
+ id: tool.name,
85
+ serverId: tool.serverId || plugin.metadata.name,
86
+ source: "unified",
87
+ })));
83
88
  }
84
89
  catch (error) {
85
90
  unifiedRegistryLogger.warn(`Failed to get tools from ${plugin.metadata.name}:`, error);
@@ -125,14 +130,22 @@ export class UnifiedMCPRegistry extends MCPToolRegistry {
125
130
  this.availableServers.add(id);
126
131
  }
127
132
  /**
128
- * Get registry statistics
133
+ * Get registry statistics (override parent method)
129
134
  */
130
- async getStats() {
135
+ getStats() {
136
+ // Return execution stats in the expected format
137
+ return super.getStats();
138
+ }
139
+ /**
140
+ * Get detailed registry statistics
141
+ */
142
+ async getDetailedStats() {
131
143
  const plugins = this.list();
132
144
  const bySource = {};
133
145
  const byType = {};
134
146
  for (const plugin of plugins) {
135
- bySource[plugin.source] = (bySource[plugin.source] || 0) + 1;
147
+ const source = plugin.source || "unknown";
148
+ bySource[source] = (bySource[source] || 0) + 1;
136
149
  // Extract type from name or metadata
137
150
  const type = plugin.metadata.name.split("/")[1]?.split("-")[0] || "unknown";
138
151
  byType[type] = (byType[type] || 0) + 1;