@juspay/neurolink 6.1.0 → 6.2.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 (303) hide show
  1. package/CHANGELOG.md +16 -6
  2. package/dist/agent/direct-tools.js +6 -5
  3. package/dist/cli/commands/config.d.ts +13 -13
  4. package/dist/cli/index.js +3 -9
  5. package/dist/config/configManager.js +11 -10
  6. package/dist/core/analytics.d.ts +11 -1
  7. package/dist/core/analytics.js +2 -2
  8. package/dist/core/base-provider.js +4 -18
  9. package/dist/core/dynamic-models.d.ts +8 -8
  10. package/dist/core/factory.js +3 -11
  11. package/dist/index.d.ts +2 -4
  12. package/dist/index.js +2 -11
  13. package/dist/lib/agent/direct-tools.js +6 -5
  14. package/dist/lib/config/configManager.js +11 -10
  15. package/dist/lib/core/analytics.d.ts +11 -1
  16. package/dist/lib/core/analytics.js +2 -2
  17. package/dist/lib/core/base-provider.js +4 -18
  18. package/dist/lib/core/dynamic-models.d.ts +8 -8
  19. package/dist/lib/core/factory.js +3 -11
  20. package/dist/lib/index.d.ts +2 -4
  21. package/dist/lib/index.js +2 -11
  22. package/dist/lib/mcp/factory.d.ts +1 -1
  23. package/dist/lib/mcp/index.d.ts +9 -21
  24. package/dist/lib/mcp/index.js +16 -57
  25. package/dist/lib/mcp/registry.js +1 -1
  26. package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.js +2 -1
  27. package/dist/lib/mcp/tool-registry.js +1 -1
  28. package/dist/lib/neurolink.d.ts +1 -9
  29. package/dist/lib/neurolink.js +22 -71
  30. package/dist/lib/providers/amazon-bedrock.js +5 -16
  31. package/dist/lib/providers/anthropic-baseprovider.js +3 -21
  32. package/dist/lib/providers/anthropic.js +4 -7
  33. package/dist/lib/providers/azure-openai.js +6 -3
  34. package/dist/lib/providers/google-vertex.js +5 -9
  35. package/dist/lib/providers/huggingFace.js +5 -10
  36. package/dist/lib/providers/mistral.js +5 -8
  37. package/dist/lib/providers/openAI.js +4 -7
  38. package/dist/lib/telemetry/index.js +2 -1
  39. package/dist/lib/utils/logger.d.ts +62 -2
  40. package/dist/lib/utils/logger.js +174 -9
  41. package/dist/lib/utils/providerConfig.d.ts +117 -0
  42. package/dist/lib/utils/providerConfig.js +353 -0
  43. package/dist/lib/utils/providerUtils.d.ts +2 -1
  44. package/dist/lib/utils/providerUtils.js +53 -36
  45. package/dist/lib/utils/timeout.d.ts +72 -1
  46. package/dist/lib/utils/timeout.js +203 -2
  47. package/dist/mcp/factory.d.ts +1 -1
  48. package/dist/mcp/index.d.ts +9 -21
  49. package/dist/mcp/index.js +16 -57
  50. package/dist/mcp/registry.js +1 -1
  51. package/dist/mcp/servers/ai-providers/ai-analysis-tools.js +2 -1
  52. package/dist/mcp/tool-registry.js +1 -1
  53. package/dist/neurolink.d.ts +1 -9
  54. package/dist/neurolink.js +22 -71
  55. package/dist/providers/amazon-bedrock.js +5 -16
  56. package/dist/providers/anthropic-baseprovider.js +3 -21
  57. package/dist/providers/anthropic.js +4 -7
  58. package/dist/providers/azure-openai.js +6 -3
  59. package/dist/providers/google-vertex.js +5 -9
  60. package/dist/providers/huggingFace.js +5 -10
  61. package/dist/providers/mistral.js +5 -8
  62. package/dist/providers/openAI.js +4 -7
  63. package/dist/telemetry/index.js +2 -1
  64. package/dist/utils/logger.d.ts +62 -2
  65. package/dist/utils/logger.js +174 -9
  66. package/dist/utils/providerConfig.d.ts +117 -0
  67. package/dist/utils/providerConfig.js +353 -0
  68. package/dist/utils/providerUtils.d.ts +2 -1
  69. package/dist/utils/providerUtils.js +53 -36
  70. package/dist/utils/timeout.d.ts +72 -1
  71. package/dist/utils/timeout.js +203 -2
  72. package/package.json +1 -1
  73. package/dist/chat/client-utils.d.ts +0 -95
  74. package/dist/chat/client-utils.js +0 -315
  75. package/dist/chat/index.d.ts +0 -24
  76. package/dist/chat/index.js +0 -33
  77. package/dist/chat/session-storage.d.ts +0 -77
  78. package/dist/chat/session-storage.js +0 -233
  79. package/dist/chat/session.d.ts +0 -96
  80. package/dist/chat/session.js +0 -257
  81. package/dist/chat/sse-handler.d.ts +0 -49
  82. package/dist/chat/sse-handler.js +0 -259
  83. package/dist/chat/types.d.ts +0 -74
  84. package/dist/chat/types.js +0 -5
  85. package/dist/chat/websocket-chat-handler.d.ts +0 -37
  86. package/dist/chat/websocket-chat-handler.js +0 -262
  87. package/dist/cli/commands/mcp.d.ts +0 -20
  88. package/dist/cli/commands/mcp.js +0 -1272
  89. package/dist/core/defaults.d.ts +0 -19
  90. package/dist/core/defaults.js +0 -29
  91. package/dist/core/evaluation-config.d.ts +0 -29
  92. package/dist/core/evaluation-config.js +0 -144
  93. package/dist/factories/compatibility-factory.d.ts +0 -35
  94. package/dist/factories/compatibility-factory.js +0 -71
  95. package/dist/factories/provider-generate-factory.d.ts +0 -20
  96. package/dist/factories/provider-generate-factory.js +0 -93
  97. package/dist/lib/chat/client-utils.d.ts +0 -95
  98. package/dist/lib/chat/client-utils.js +0 -315
  99. package/dist/lib/chat/index.d.ts +0 -24
  100. package/dist/lib/chat/index.js +0 -33
  101. package/dist/lib/chat/session-storage.d.ts +0 -77
  102. package/dist/lib/chat/session-storage.js +0 -233
  103. package/dist/lib/chat/session.d.ts +0 -96
  104. package/dist/lib/chat/session.js +0 -257
  105. package/dist/lib/chat/sse-handler.d.ts +0 -49
  106. package/dist/lib/chat/sse-handler.js +0 -259
  107. package/dist/lib/chat/types.d.ts +0 -74
  108. package/dist/lib/chat/types.js +0 -5
  109. package/dist/lib/chat/websocket-chat-handler.d.ts +0 -37
  110. package/dist/lib/chat/websocket-chat-handler.js +0 -262
  111. package/dist/lib/core/defaults.d.ts +0 -19
  112. package/dist/lib/core/defaults.js +0 -29
  113. package/dist/lib/core/evaluation-config.d.ts +0 -29
  114. package/dist/lib/core/evaluation-config.js +0 -144
  115. package/dist/lib/factories/compatibility-factory.d.ts +0 -35
  116. package/dist/lib/factories/compatibility-factory.js +0 -71
  117. package/dist/lib/factories/provider-generate-factory.d.ts +0 -20
  118. package/dist/lib/factories/provider-generate-factory.js +0 -93
  119. package/dist/lib/mcp/adapters/plugin-bridge.d.ts +0 -40
  120. package/dist/lib/mcp/adapters/plugin-bridge.js +0 -89
  121. package/dist/lib/mcp/auto-discovery.d.ts +0 -62
  122. package/dist/lib/mcp/auto-discovery.js +0 -149
  123. package/dist/lib/mcp/client.d.ts +0 -68
  124. package/dist/lib/mcp/client.js +0 -248
  125. package/dist/lib/mcp/config.d.ts +0 -31
  126. package/dist/lib/mcp/config.js +0 -99
  127. package/dist/lib/mcp/context-manager.d.ts +0 -171
  128. package/dist/lib/mcp/context-manager.js +0 -362
  129. package/dist/lib/mcp/contracts/mcp-contract.d.ts +0 -169
  130. package/dist/lib/mcp/contracts/mcp-contract.js +0 -58
  131. package/dist/lib/mcp/core/plugin-manager.d.ts +0 -46
  132. package/dist/lib/mcp/core/plugin-manager.js +0 -110
  133. package/dist/lib/mcp/demo/plugin-demo.d.ts +0 -20
  134. package/dist/lib/mcp/demo/plugin-demo.js +0 -118
  135. package/dist/lib/mcp/dynamic-chain-executor.d.ts +0 -225
  136. package/dist/lib/mcp/dynamic-chain-executor.js +0 -489
  137. package/dist/lib/mcp/dynamic-orchestrator.d.ts +0 -115
  138. package/dist/lib/mcp/dynamic-orchestrator.js +0 -351
  139. package/dist/lib/mcp/ecosystem.d.ts +0 -75
  140. package/dist/lib/mcp/ecosystem.js +0 -161
  141. package/dist/lib/mcp/error-manager.d.ts +0 -254
  142. package/dist/lib/mcp/error-manager.js +0 -501
  143. package/dist/lib/mcp/error-recovery.d.ts +0 -159
  144. package/dist/lib/mcp/error-recovery.js +0 -405
  145. package/dist/lib/mcp/external-client.d.ts +0 -88
  146. package/dist/lib/mcp/external-client.js +0 -331
  147. package/dist/lib/mcp/external-manager.d.ts +0 -112
  148. package/dist/lib/mcp/external-manager.js +0 -308
  149. package/dist/lib/mcp/function-calling.d.ts +0 -65
  150. package/dist/lib/mcp/function-calling.js +0 -642
  151. package/dist/lib/mcp/health-monitor.d.ts +0 -257
  152. package/dist/lib/mcp/health-monitor.js +0 -630
  153. package/dist/lib/mcp/initialize-tools.d.ts +0 -29
  154. package/dist/lib/mcp/initialize-tools.js +0 -261
  155. package/dist/lib/mcp/initialize.d.ts +0 -18
  156. package/dist/lib/mcp/initialize.js +0 -62
  157. package/dist/lib/mcp/logging.d.ts +0 -38
  158. package/dist/lib/mcp/logging.js +0 -100
  159. package/dist/lib/mcp/manager.d.ts +0 -68
  160. package/dist/lib/mcp/manager.js +0 -176
  161. package/dist/lib/mcp/neurolink-mcp-client.d.ts +0 -97
  162. package/dist/lib/mcp/neurolink-mcp-client.js +0 -462
  163. package/dist/lib/mcp/orchestrator.d.ts +0 -302
  164. package/dist/lib/mcp/orchestrator.js +0 -703
  165. package/dist/lib/mcp/plugin-manager.d.ts +0 -98
  166. package/dist/lib/mcp/plugin-manager.js +0 -296
  167. package/dist/lib/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
  168. package/dist/lib/mcp/plugins/core/filesystem-mcp.js +0 -142
  169. package/dist/lib/mcp/plugins/filesystem-mcp.d.ts +0 -37
  170. package/dist/lib/mcp/plugins/filesystem-mcp.js +0 -54
  171. package/dist/lib/mcp/security-manager.d.ts +0 -87
  172. package/dist/lib/mcp/security-manager.js +0 -344
  173. package/dist/lib/mcp/semaphore-manager.d.ts +0 -137
  174. package/dist/lib/mcp/semaphore-manager.js +0 -329
  175. package/dist/lib/mcp/session-manager.d.ts +0 -187
  176. package/dist/lib/mcp/session-manager.js +0 -400
  177. package/dist/lib/mcp/session-persistence.d.ts +0 -93
  178. package/dist/lib/mcp/session-persistence.js +0 -301
  179. package/dist/lib/mcp/tool-integration.d.ts +0 -58
  180. package/dist/lib/mcp/tool-integration.js +0 -203
  181. package/dist/lib/mcp/transport-manager.d.ts +0 -154
  182. package/dist/lib/mcp/transport-manager.js +0 -334
  183. package/dist/lib/mcp/unified-mcp.d.ts +0 -133
  184. package/dist/lib/mcp/unified-mcp.js +0 -251
  185. package/dist/lib/mcp/unified-registry.d.ts +0 -165
  186. package/dist/lib/mcp/unified-registry.js +0 -538
  187. package/dist/lib/providers/analytics-helper.d.ts +0 -38
  188. package/dist/lib/providers/analytics-helper.js +0 -216
  189. package/dist/lib/providers/function-calling-provider.d.ts +0 -142
  190. package/dist/lib/providers/function-calling-provider.js +0 -630
  191. package/dist/lib/providers/mcp-provider.d.ts +0 -75
  192. package/dist/lib/providers/mcp-provider.js +0 -283
  193. package/dist/lib/providers/timeout-wrapper.d.ts +0 -40
  194. package/dist/lib/providers/timeout-wrapper.js +0 -100
  195. package/dist/lib/sdk/tool-extension.d.ts +0 -181
  196. package/dist/lib/sdk/tool-extension.js +0 -284
  197. package/dist/lib/services/streaming/streaming-manager.d.ts +0 -29
  198. package/dist/lib/services/streaming/streaming-manager.js +0 -245
  199. package/dist/lib/services/types.d.ts +0 -156
  200. package/dist/lib/services/types.js +0 -2
  201. package/dist/lib/services/websocket/websocket-server.d.ts +0 -34
  202. package/dist/lib/services/websocket/websocket-server.js +0 -305
  203. package/dist/lib/utils/provider-validation.d.ts +0 -36
  204. package/dist/lib/utils/provider-validation.js +0 -625
  205. package/dist/lib/utils/providerUtils-fixed.d.ts +0 -8
  206. package/dist/lib/utils/providerUtils-fixed.js +0 -94
  207. package/dist/lib/utils/streaming-utils.d.ts +0 -79
  208. package/dist/lib/utils/streaming-utils.js +0 -198
  209. package/dist/lib/utils/timeout-manager.d.ts +0 -75
  210. package/dist/lib/utils/timeout-manager.js +0 -244
  211. package/dist/mcp/adapters/plugin-bridge.d.ts +0 -40
  212. package/dist/mcp/adapters/plugin-bridge.js +0 -89
  213. package/dist/mcp/auto-discovery.d.ts +0 -62
  214. package/dist/mcp/auto-discovery.js +0 -149
  215. package/dist/mcp/client.d.ts +0 -68
  216. package/dist/mcp/client.js +0 -248
  217. package/dist/mcp/config.d.ts +0 -31
  218. package/dist/mcp/config.js +0 -99
  219. package/dist/mcp/context-manager.d.ts +0 -171
  220. package/dist/mcp/context-manager.js +0 -362
  221. package/dist/mcp/contracts/mcp-contract.d.ts +0 -169
  222. package/dist/mcp/contracts/mcp-contract.js +0 -58
  223. package/dist/mcp/core/plugin-manager.d.ts +0 -46
  224. package/dist/mcp/core/plugin-manager.js +0 -110
  225. package/dist/mcp/demo/plugin-demo.d.ts +0 -20
  226. package/dist/mcp/demo/plugin-demo.js +0 -118
  227. package/dist/mcp/dynamic-chain-executor.d.ts +0 -225
  228. package/dist/mcp/dynamic-chain-executor.js +0 -489
  229. package/dist/mcp/dynamic-orchestrator.d.ts +0 -115
  230. package/dist/mcp/dynamic-orchestrator.js +0 -351
  231. package/dist/mcp/ecosystem.d.ts +0 -75
  232. package/dist/mcp/ecosystem.js +0 -162
  233. package/dist/mcp/error-manager.d.ts +0 -254
  234. package/dist/mcp/error-manager.js +0 -501
  235. package/dist/mcp/error-recovery.d.ts +0 -159
  236. package/dist/mcp/error-recovery.js +0 -405
  237. package/dist/mcp/external-client.d.ts +0 -88
  238. package/dist/mcp/external-client.js +0 -331
  239. package/dist/mcp/external-manager.d.ts +0 -112
  240. package/dist/mcp/external-manager.js +0 -308
  241. package/dist/mcp/function-calling.d.ts +0 -65
  242. package/dist/mcp/function-calling.js +0 -642
  243. package/dist/mcp/health-monitor.d.ts +0 -257
  244. package/dist/mcp/health-monitor.js +0 -630
  245. package/dist/mcp/initialize-tools.d.ts +0 -29
  246. package/dist/mcp/initialize-tools.js +0 -262
  247. package/dist/mcp/initialize.d.ts +0 -18
  248. package/dist/mcp/initialize.js +0 -62
  249. package/dist/mcp/logging.d.ts +0 -38
  250. package/dist/mcp/logging.js +0 -100
  251. package/dist/mcp/manager.d.ts +0 -68
  252. package/dist/mcp/manager.js +0 -176
  253. package/dist/mcp/neurolink-mcp-client.d.ts +0 -97
  254. package/dist/mcp/neurolink-mcp-client.js +0 -462
  255. package/dist/mcp/orchestrator.d.ts +0 -302
  256. package/dist/mcp/orchestrator.js +0 -703
  257. package/dist/mcp/plugin-manager.d.ts +0 -98
  258. package/dist/mcp/plugin-manager.js +0 -297
  259. package/dist/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
  260. package/dist/mcp/plugins/core/filesystem-mcp.js +0 -142
  261. package/dist/mcp/plugins/core/neurolink-mcp.json +0 -17
  262. package/dist/mcp/plugins/filesystem-mcp.d.ts +0 -37
  263. package/dist/mcp/plugins/filesystem-mcp.js +0 -54
  264. package/dist/mcp/security-manager.d.ts +0 -87
  265. package/dist/mcp/security-manager.js +0 -344
  266. package/dist/mcp/semaphore-manager.d.ts +0 -137
  267. package/dist/mcp/semaphore-manager.js +0 -329
  268. package/dist/mcp/session-manager.d.ts +0 -187
  269. package/dist/mcp/session-manager.js +0 -400
  270. package/dist/mcp/session-persistence.d.ts +0 -93
  271. package/dist/mcp/session-persistence.js +0 -302
  272. package/dist/mcp/tool-integration.d.ts +0 -58
  273. package/dist/mcp/tool-integration.js +0 -203
  274. package/dist/mcp/transport-manager.d.ts +0 -154
  275. package/dist/mcp/transport-manager.js +0 -335
  276. package/dist/mcp/unified-mcp.d.ts +0 -133
  277. package/dist/mcp/unified-mcp.js +0 -251
  278. package/dist/mcp/unified-registry.d.ts +0 -165
  279. package/dist/mcp/unified-registry.js +0 -539
  280. package/dist/providers/analytics-helper.d.ts +0 -38
  281. package/dist/providers/analytics-helper.js +0 -216
  282. package/dist/providers/function-calling-provider.d.ts +0 -142
  283. package/dist/providers/function-calling-provider.js +0 -630
  284. package/dist/providers/mcp-provider.d.ts +0 -75
  285. package/dist/providers/mcp-provider.js +0 -283
  286. package/dist/providers/timeout-wrapper.d.ts +0 -40
  287. package/dist/providers/timeout-wrapper.js +0 -100
  288. package/dist/sdk/tool-extension.d.ts +0 -181
  289. package/dist/sdk/tool-extension.js +0 -284
  290. package/dist/services/streaming/streaming-manager.d.ts +0 -29
  291. package/dist/services/streaming/streaming-manager.js +0 -245
  292. package/dist/services/types.d.ts +0 -156
  293. package/dist/services/types.js +0 -2
  294. package/dist/services/websocket/websocket-server.d.ts +0 -34
  295. package/dist/services/websocket/websocket-server.js +0 -306
  296. package/dist/utils/provider-validation.d.ts +0 -36
  297. package/dist/utils/provider-validation.js +0 -625
  298. package/dist/utils/providerUtils-fixed.d.ts +0 -8
  299. package/dist/utils/providerUtils-fixed.js +0 -94
  300. package/dist/utils/streaming-utils.d.ts +0 -79
  301. package/dist/utils/streaming-utils.js +0 -198
  302. package/dist/utils/timeout-manager.d.ts +0 -75
  303. package/dist/utils/timeout-manager.js +0 -244
@@ -1,98 +0,0 @@
1
- /**
2
- * PluginManager - Central Orchestrator for MCP Lifecycle
3
- * Implements generic factory pattern with manifest-based discovery
4
- * Based on research blueprint for extensible plugin architecture
5
- */
6
- import { MCP } from "./contracts/mcp-contract.js";
7
- import type { MCPMetadata } from "./contracts/mcp-contract.js";
8
- /**
9
- * Plugin Manager Configuration
10
- */
11
- interface PluginManagerConfig {
12
- /** Enable/disable plugin discovery */
13
- enableDiscovery?: boolean;
14
- /** Custom plugin directories */
15
- pluginDirectories?: string[];
16
- /** Security level for plugins */
17
- securityLevel?: "strict" | "moderate" | "permissive";
18
- /** Maximum plugins to load */
19
- maxPlugins?: number;
20
- }
21
- /**
22
- * Central Plugin Manager implementing the research blueprint
23
- */
24
- export declare class PluginManager {
25
- private static instance;
26
- private mcpConstructors;
27
- private mcpInstances;
28
- private discoveredMCPs;
29
- private securityManager;
30
- private initialized;
31
- private config;
32
- private constructor();
33
- /**
34
- * Get the singleton instance
35
- */
36
- static getInstance(config?: PluginManagerConfig): PluginManager;
37
- /**
38
- * Initialize the plugin manager with discovery
39
- */
40
- initialize(): Promise<void>;
41
- /**
42
- * Discover plugins following research blueprint priority:
43
- * 1. Core plugins (bundled)
44
- * 2. Project plugins (./neurolink-mcp/)
45
- * 3. Installed plugins (node_modules)
46
- */
47
- private discoverPlugins;
48
- /**
49
- * Discover core plugins bundled with NeuroLink
50
- */
51
- private discoverCorePlugins;
52
- /**
53
- * Discover project-local plugins
54
- */
55
- private discoverProjectPlugins;
56
- /**
57
- * Discover installed plugins from node_modules
58
- */
59
- private discoverInstalledPlugins;
60
- /**
61
- * Discover plugins in a specific directory
62
- */
63
- private discoverPluginsInDirectory;
64
- /**
65
- * Validate manifest structure
66
- */
67
- private validateManifest;
68
- /**
69
- * Generic Factory Method - Creates type-safe MCP instances
70
- * Core implementation of the research blueprint
71
- */
72
- createInstance<T extends MCP>(name: string, config: unknown): Promise<T>;
73
- /**
74
- * Get or load constructor for an MCP
75
- */
76
- private getConstructor;
77
- /**
78
- * List all discovered MCPs
79
- */
80
- listDiscovered(): MCPMetadata[];
81
- /**
82
- * Get metadata for a specific MCP
83
- */
84
- getMetadata(name: string): MCPMetadata | null;
85
- /**
86
- * Get discovery statistics
87
- */
88
- getDiscoveryStats(): Record<string, number>;
89
- /**
90
- * Dispose of all instances and cleanup
91
- */
92
- dispose(): Promise<void>;
93
- }
94
- /**
95
- * Export singleton instance getter
96
- */
97
- export declare const pluginManager: PluginManager;
98
- export {};
@@ -1,296 +0,0 @@
1
- /**
2
- * PluginManager - Central Orchestrator for MCP Lifecycle
3
- * Implements generic factory pattern with manifest-based discovery
4
- * Based on research blueprint for extensible plugin architecture
5
- */
6
- import * as fs from "fs/promises";
7
- import * as path from "path";
8
- import { fileURLToPath } from "url";
9
- import { dirname } from "path";
10
- // ES Module compatibility
11
- const __filename = fileURLToPath(import.meta.url);
12
- const __dirname = dirname(__filename);
13
- import { SecurityManager } from "./security-manager.js";
14
- import { mcpLogger } from "./logging.js";
15
- /**
16
- * Central Plugin Manager implementing the research blueprint
17
- */
18
- export class PluginManager {
19
- static instance;
20
- mcpConstructors = new Map();
21
- mcpInstances = new Map();
22
- discoveredMCPs = new Map();
23
- securityManager;
24
- initialized = false;
25
- config;
26
- constructor(config = {}) {
27
- this.config = {
28
- enableDiscovery: true,
29
- pluginDirectories: [],
30
- securityLevel: "moderate",
31
- maxPlugins: 50,
32
- ...config,
33
- };
34
- this.securityManager = new SecurityManager(this.config.securityLevel);
35
- }
36
- /**
37
- * Get the singleton instance
38
- */
39
- static getInstance(config) {
40
- if (!PluginManager.instance) {
41
- PluginManager.instance = new PluginManager(config);
42
- }
43
- return PluginManager.instance;
44
- }
45
- /**
46
- * Initialize the plugin manager with discovery
47
- */
48
- async initialize() {
49
- if (this.initialized) {
50
- return;
51
- }
52
- mcpLogger.info("[PluginManager] Initializing plugin discovery...");
53
- if (this.config.enableDiscovery) {
54
- await this.discoverPlugins();
55
- }
56
- this.initialized = true;
57
- mcpLogger.info(`[PluginManager] Initialized with ${this.discoveredMCPs.size} discovered plugins`);
58
- }
59
- /**
60
- * Discover plugins following research blueprint priority:
61
- * 1. Core plugins (bundled)
62
- * 2. Project plugins (./neurolink-mcp/)
63
- * 3. Installed plugins (node_modules)
64
- */
65
- async discoverPlugins() {
66
- const functionTag = "PluginManager.discoverPlugins";
67
- try {
68
- // 1. Discover core plugins
69
- await this.discoverCorePlugins();
70
- // 2. Discover project plugins
71
- await this.discoverProjectPlugins();
72
- // 3. Discover installed plugins
73
- await this.discoverInstalledPlugins();
74
- mcpLogger.debug(`[${functionTag}] Discovery completed`, {
75
- total: this.discoveredMCPs.size,
76
- bySource: this.getDiscoveryStats(),
77
- });
78
- }
79
- catch (error) {
80
- mcpLogger.error(`[${functionTag}] Discovery failed:`, error);
81
- }
82
- }
83
- /**
84
- * Discover core plugins bundled with NeuroLink
85
- */
86
- async discoverCorePlugins() {
87
- // Correctly resolve path from 'dist' to 'src'
88
- const corePluginsPath = path.resolve(__dirname, "../../src/lib/mcp/plugins/core");
89
- await this.discoverPluginsInDirectory(corePluginsPath, "core");
90
- }
91
- /**
92
- * Discover project-local plugins
93
- */
94
- async discoverProjectPlugins() {
95
- const projectPluginsPath = path.join(process.cwd(), "neurolink-mcp");
96
- await this.discoverPluginsInDirectory(projectPluginsPath, "project");
97
- }
98
- /**
99
- * Discover installed plugins from node_modules
100
- */
101
- async discoverInstalledPlugins() {
102
- const nodeModulesPath = path.join(process.cwd(), "node_modules");
103
- try {
104
- const packages = await fs.readdir(nodeModulesPath);
105
- for (const pkg of packages) {
106
- if (pkg.startsWith(".")) {
107
- continue;
108
- }
109
- const packagePath = path.join(nodeModulesPath, pkg);
110
- const packageJsonPath = path.join(packagePath, "package.json");
111
- try {
112
- const packageJson = JSON.parse(await fs.readFile(packageJsonPath, "utf-8"));
113
- // Check for neurolink-mcp keyword
114
- if (packageJson.keywords?.includes("neurolink-mcp")) {
115
- await this.discoverPluginsInDirectory(packagePath, "installed");
116
- }
117
- }
118
- catch {
119
- // Skip invalid packages
120
- }
121
- }
122
- }
123
- catch {
124
- // node_modules doesn't exist or not accessible
125
- }
126
- }
127
- /**
128
- * Discover plugins in a specific directory
129
- */
130
- async discoverPluginsInDirectory(dirPath, source) {
131
- try {
132
- const manifestPath = path.join(dirPath, "neurolink-mcp.json");
133
- const manifestExists = await fs
134
- .access(manifestPath)
135
- .then(() => true)
136
- .catch(() => false);
137
- if (!manifestExists) {
138
- return;
139
- }
140
- const manifest = JSON.parse(await fs.readFile(manifestPath, "utf-8"));
141
- // Validate manifest
142
- if (!this.validateManifest(manifest)) {
143
- mcpLogger.warn(`[PluginManager] Invalid manifest in ${dirPath}`);
144
- return;
145
- }
146
- // Now we know manifest is MCPMetadata due to type guard
147
- const validatedManifest = manifest;
148
- const entryPath = path
149
- .resolve(dirPath, validatedManifest.main)
150
- .replace(`${process.cwd()}/src/lib`, `${process.cwd()}/dist`);
151
- this.discoveredMCPs.set(validatedManifest.name, {
152
- metadata: validatedManifest,
153
- entryPath,
154
- source,
155
- constructor: undefined, // Will be loaded on demand
156
- });
157
- mcpLogger.debug(`[PluginManager] Discovered ${validatedManifest.name} from ${source}`);
158
- }
159
- catch (error) {
160
- mcpLogger.debug(`[PluginManager] Failed to discover plugin in ${dirPath}:`, error);
161
- }
162
- }
163
- /**
164
- * Validate manifest structure
165
- */
166
- validateManifest(manifest) {
167
- if (!manifest || typeof manifest !== "object") {
168
- return false;
169
- }
170
- const obj = manifest;
171
- return Boolean(typeof obj.name === "string" &&
172
- typeof obj.version === "string" &&
173
- typeof obj.main === "string" &&
174
- typeof obj.engine === "object" &&
175
- obj.engine &&
176
- "neurolink" in obj.engine &&
177
- typeof obj.description === "string" &&
178
- Array.isArray(obj.permissions));
179
- }
180
- /**
181
- * Generic Factory Method - Creates type-safe MCP instances
182
- * Core implementation of the research blueprint
183
- */
184
- async createInstance(name, config) {
185
- const functionTag = "PluginManager.createInstance";
186
- if (!this.initialized) {
187
- await this.initialize();
188
- }
189
- // Check if already instantiated
190
- const existingInstance = this.mcpInstances.get(name);
191
- if (existingInstance) {
192
- mcpLogger.debug(`[${functionTag}] Returning existing instance of ${name}`);
193
- return existingInstance;
194
- }
195
- // Get constructor (load if necessary)
196
- const Constructor = await this.getConstructor(name);
197
- if (!Constructor) {
198
- throw new Error(`MCP with name "${name}" is not registered or failed validation.`);
199
- }
200
- // Security check
201
- const discovered = this.discoveredMCPs.get(name);
202
- if (discovered &&
203
- !this.securityManager.validatePermissions(discovered.metadata.permissions)) {
204
- throw new Error(`Security validation failed for MCP "${name}"`);
205
- }
206
- try {
207
- // Instantiate the class
208
- const instance = new Constructor();
209
- // Initialize with config
210
- await instance.initialize(config);
211
- // Store instance
212
- this.mcpInstances.set(name, instance);
213
- mcpLogger.info(`[${functionTag}] Created and initialized ${name}`);
214
- return instance;
215
- }
216
- catch (error) {
217
- mcpLogger.error(`[${functionTag}] Failed to create instance of ${name}:`, error);
218
- throw error;
219
- }
220
- }
221
- /**
222
- * Get or load constructor for an MCP
223
- */
224
- async getConstructor(name) {
225
- // Check if already loaded
226
- const existingConstructor = this.mcpConstructors.get(name);
227
- if (existingConstructor) {
228
- return existingConstructor;
229
- }
230
- // Load from discovered plugins
231
- const discovered = this.discoveredMCPs.get(name);
232
- if (!discovered) {
233
- return null;
234
- }
235
- try {
236
- // Dynamic import of the plugin
237
- const module = await import(discovered.entryPath);
238
- const Constructor = module.default || module[discovered.metadata.name];
239
- if (typeof Constructor !== "function") {
240
- throw new Error(`Invalid export from ${discovered.entryPath}`);
241
- }
242
- // Store constructor
243
- this.mcpConstructors.set(name, Constructor);
244
- return Constructor;
245
- }
246
- catch (error) {
247
- mcpLogger.error(`[PluginManager] Failed to load ${name} from ${discovered.entryPath}:`, error);
248
- return null;
249
- }
250
- }
251
- /**
252
- * List all discovered MCPs
253
- */
254
- listDiscovered() {
255
- return Array.from(this.discoveredMCPs.values()).map((d) => d.metadata);
256
- }
257
- /**
258
- * Get metadata for a specific MCP
259
- */
260
- getMetadata(name) {
261
- const discovered = this.discoveredMCPs.get(name);
262
- return discovered ? discovered.metadata : null;
263
- }
264
- /**
265
- * Get discovery statistics
266
- */
267
- getDiscoveryStats() {
268
- const stats = { core: 0, project: 0, installed: 0 };
269
- for (const discovered of this.discoveredMCPs.values()) {
270
- stats[discovered.source]++;
271
- }
272
- return stats;
273
- }
274
- /**
275
- * Dispose of all instances and cleanup
276
- */
277
- async dispose() {
278
- mcpLogger.info("[PluginManager] Disposing all MCP instances...");
279
- for (const [name, instance] of this.mcpInstances) {
280
- try {
281
- await instance.dispose();
282
- mcpLogger.debug(`[PluginManager] Disposed ${name}`);
283
- }
284
- catch (error) {
285
- mcpLogger.error(`[PluginManager] Failed to dispose ${name}:`, error);
286
- }
287
- }
288
- this.mcpInstances.clear();
289
- this.mcpConstructors.clear();
290
- this.initialized = false;
291
- }
292
- }
293
- /**
294
- * Export singleton instance getter
295
- */
296
- export const pluginManager = PluginManager.getInstance();
@@ -1,36 +0,0 @@
1
- /**
2
- * FileSystemMCP - Proof of Concept Plugin
3
- * Demonstrates the research blueprint implementation
4
- */
5
- import { MCP } from "../../contracts/mcp-contract.js";
6
- import type { MCPMetadata, ExecutionContext } from "../../contracts/mcp-contract.js";
7
- import type { UnknownRecord } from "../../../types/common.js";
8
- interface FileSystemConfig {
9
- basePath: string;
10
- allowedExtensions?: string[];
11
- }
12
- interface FileSystemArgs {
13
- operation: "readFile" | "writeFile" | "listFiles" | "createDir";
14
- path: string;
15
- content?: string;
16
- options?: UnknownRecord;
17
- }
18
- interface FileSystemResult {
19
- success: boolean;
20
- data?: UnknownRecord;
21
- error?: string;
22
- }
23
- /**
24
- * FileSystem MCP implementing the abstract contract
25
- */
26
- export declare class FileSystemMCP extends MCP<FileSystemConfig, FileSystemArgs, FileSystemResult> {
27
- readonly metadata: MCPMetadata;
28
- initialize(config: FileSystemConfig): Promise<void>;
29
- execute(context: ExecutionContext, args: FileSystemArgs): Promise<FileSystemResult>;
30
- private readFile;
31
- private writeFile;
32
- private listFiles;
33
- private createDirectory;
34
- dispose(): Promise<void>;
35
- }
36
- export default FileSystemMCP;
@@ -1,142 +0,0 @@
1
- /**
2
- * FileSystemMCP - Proof of Concept Plugin
3
- * Demonstrates the research blueprint implementation
4
- */
5
- import { MCP } from "../../contracts/mcp-contract.js";
6
- import * as path from "path";
7
- /**
8
- * FileSystem MCP implementing the abstract contract
9
- */
10
- export class FileSystemMCP extends MCP {
11
- metadata = {
12
- name: "@neurolink-mcp/filesystem",
13
- version: "1.0.0",
14
- main: "./filesystem-mcp.js",
15
- engine: {
16
- neurolink: ">=1.9.0 <2.0.0",
17
- },
18
- description: "Provides secure file system operations for NeuroLink agents",
19
- permissions: [
20
- "fs:read:./**/*",
21
- "fs:write:./output/**/*",
22
- "fs:write:./temp/**/*",
23
- ],
24
- };
25
- async initialize(config) {
26
- if (!config.basePath) {
27
- throw new Error("basePath is required in FileSystemMCP configuration");
28
- }
29
- this.config = {
30
- allowedExtensions: [".txt", ".json", ".md", ".js", ".ts"],
31
- ...config,
32
- };
33
- this.initialized = true;
34
- }
35
- async execute(context, args) {
36
- this.log(context, "info", "Executing FileSystemMCP", { args });
37
- this.log(context, "info", "Executing FileSystemMCP", { args });
38
- this.log(context, "info", "Executing FileSystemMCP", { args });
39
- this.ensureInitialized();
40
- try {
41
- if (!args.path) {
42
- // This is a configuration call, not an operation
43
- return { success: true, data: { configured: true } };
44
- }
45
- const fullPath = path.isAbsolute(args.path)
46
- ? args.path
47
- : context.path.join(this.config.basePath, args.path);
48
- switch (args.operation) {
49
- case "readFile":
50
- return await this.readFile(context, fullPath);
51
- case "writeFile":
52
- return await this.writeFile(context, fullPath, args.content);
53
- case "listFiles":
54
- return await this.listFiles(context, fullPath);
55
- case "createDir":
56
- return await this.createDirectory(context, fullPath);
57
- default:
58
- throw new Error(`Unsupported operation: ${args.operation}`);
59
- }
60
- }
61
- catch (error) {
62
- this.log(context, "error", "Operation failed", {
63
- operation: args.operation,
64
- error,
65
- });
66
- return {
67
- success: false,
68
- error: error instanceof Error ? error.message : String(error),
69
- };
70
- }
71
- }
72
- async readFile(context, filePath) {
73
- const content = await context.secureFS.readFile(filePath, "utf-8");
74
- const stats = await context.secureFS.stat(filePath);
75
- return {
76
- success: true,
77
- data: {
78
- content,
79
- size: stats.size,
80
- lastModified: stats.mtime ||
81
- new Date(stats.mtimeMs || Date.now()),
82
- path: filePath,
83
- },
84
- };
85
- }
86
- async writeFile(context, filePath, content) {
87
- await context.secureFS.writeFile(filePath, content);
88
- return {
89
- success: true,
90
- data: {
91
- path: filePath,
92
- size: content.length,
93
- written: true,
94
- },
95
- };
96
- }
97
- async listFiles(context, dirPath) {
98
- const items = await context.secureFS.readdir(dirPath);
99
- const itemDetails = [];
100
- for (const item of items) {
101
- const itemPath = context.path.join(dirPath, item);
102
- try {
103
- const stats = await context.secureFS.stat(itemPath);
104
- itemDetails.push({
105
- name: item,
106
- type: stats.isDirectory() ? "directory" : "file",
107
- size: stats.isFile() ? stats.size : undefined,
108
- lastModified: stats.mtime ||
109
- new Date(stats.mtimeMs ||
110
- Date.now()),
111
- });
112
- }
113
- catch {
114
- // Skip inaccessible items
115
- }
116
- }
117
- return {
118
- success: true,
119
- data: {
120
- path: dirPath,
121
- items: itemDetails,
122
- count: itemDetails.length,
123
- },
124
- };
125
- }
126
- async createDirectory(context, dirPath) {
127
- await context.secureFS.mkdir(dirPath, { recursive: true });
128
- return {
129
- success: true,
130
- data: {
131
- path: dirPath,
132
- created: true,
133
- },
134
- };
135
- }
136
- async dispose() {
137
- this.initialized = false;
138
- this.config = undefined;
139
- }
140
- }
141
- // Export as default for dynamic import
142
- export default FileSystemMCP;
@@ -1,37 +0,0 @@
1
- /**
2
- * Enhanced FileSystem MCP Plugin
3
- * Implements the new MCP contract with security sandbox
4
- * Based on research document recommendations
5
- */
6
- import { MCP, type MCPMetadata, type ExecutionContext } from "../contracts/mcp-contract.js";
7
- import type { Unknown } from "../../types/common.js";
8
- /**
9
- * FileSystem MCP Configuration
10
- */
11
- export interface FileSystemConfig {
12
- basePath: string;
13
- allowedExtensions?: string[];
14
- maxFileSize?: number;
15
- readOnly?: boolean;
16
- }
17
- /**
18
- * FileSystem Operation Arguments
19
- */
20
- export interface FileSystemArgs {
21
- operation: "readFile" | "writeFile" | "listFiles" | "getFileInfo";
22
- path: string;
23
- content?: string;
24
- encoding?: string;
25
- }
26
- /**
27
- * Enhanced FileSystem MCP Plugin
28
- */
29
- export declare class FileSystemMCP extends MCP<FileSystemConfig> {
30
- config: FileSystemConfig;
31
- readonly metadata: MCPMetadata;
32
- initialize(config: FileSystemConfig): Promise<void>;
33
- execute(context: ExecutionContext, args: FileSystemArgs): Promise<Unknown>;
34
- private resolvePath;
35
- dispose(): Promise<void>;
36
- }
37
- export declare function createFileSystemMCP(): FileSystemMCP;
@@ -1,54 +0,0 @@
1
- /**
2
- * Enhanced FileSystem MCP Plugin
3
- * Implements the new MCP contract with security sandbox
4
- * Based on research document recommendations
5
- */
6
- import path from "path";
7
- import { MCP, } from "../contracts/mcp-contract.js";
8
- /**
9
- * Enhanced FileSystem MCP Plugin
10
- */
11
- export class FileSystemMCP extends MCP {
12
- metadata = {
13
- name: "@neurolink-mcp/filesystem",
14
- version: "1.0.0",
15
- main: "./dist/filesystem-mcp.js",
16
- engine: { neurolink: ">=1.9.0 <2.0.0" },
17
- description: "Secure file system operations with permission-based access control",
18
- permissions: ["fs:read:./**/*", "fs:write:./output/**/*"],
19
- };
20
- async initialize(config) {
21
- this.config = {
22
- allowedExtensions: [".txt", ".md", ".json", ".js", ".ts"],
23
- maxFileSize: 10 * 1024 * 1024,
24
- readOnly: false,
25
- ...config,
26
- };
27
- }
28
- async execute(context, args) {
29
- const resolvedPath = this.resolvePath(args.path);
30
- switch (args.operation) {
31
- case "readFile":
32
- return await context.secureFS.readFile(resolvedPath, args.encoding || "utf-8");
33
- case "listFiles":
34
- return await context.secureFS.readdir(resolvedPath);
35
- case "getFileInfo":
36
- return await context.secureFS.stat(resolvedPath);
37
- default:
38
- throw new Error(`Unsupported operation: ${args.operation}`);
39
- }
40
- }
41
- resolvePath(inputPath) {
42
- const resolved = path.resolve(this.config.basePath, inputPath);
43
- if (!resolved.startsWith(this.config.basePath)) {
44
- throw new Error(`Path outside allowed directory: ${inputPath}`);
45
- }
46
- return resolved;
47
- }
48
- async dispose() {
49
- // Cleanup resources
50
- }
51
- }
52
- export function createFileSystemMCP() {
53
- return new FileSystemMCP();
54
- }