@juspay/neurolink 6.1.0 → 6.2.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 (283) hide show
  1. package/CHANGELOG.md +10 -6
  2. package/dist/cli/commands/config.d.ts +13 -13
  3. package/dist/cli/index.js +3 -9
  4. package/dist/core/analytics.d.ts +11 -1
  5. package/dist/core/analytics.js +2 -2
  6. package/dist/core/base-provider.js +4 -18
  7. package/dist/core/dynamic-models.d.ts +8 -8
  8. package/dist/core/factory.js +3 -11
  9. package/dist/index.d.ts +2 -4
  10. package/dist/index.js +2 -11
  11. package/dist/lib/core/analytics.d.ts +11 -1
  12. package/dist/lib/core/analytics.js +2 -2
  13. package/dist/lib/core/base-provider.js +4 -18
  14. package/dist/lib/core/dynamic-models.d.ts +8 -8
  15. package/dist/lib/core/factory.js +3 -11
  16. package/dist/lib/index.d.ts +2 -4
  17. package/dist/lib/index.js +2 -11
  18. package/dist/lib/mcp/factory.d.ts +1 -1
  19. package/dist/lib/mcp/index.d.ts +7 -19
  20. package/dist/lib/mcp/index.js +15 -56
  21. package/dist/lib/neurolink.d.ts +1 -9
  22. package/dist/lib/neurolink.js +21 -70
  23. package/dist/lib/providers/amazon-bedrock.js +5 -16
  24. package/dist/lib/providers/anthropic-baseprovider.js +3 -21
  25. package/dist/lib/providers/anthropic.js +4 -7
  26. package/dist/lib/providers/azure-openai.js +4 -2
  27. package/dist/lib/providers/google-vertex.js +5 -9
  28. package/dist/lib/providers/huggingFace.js +5 -10
  29. package/dist/lib/providers/mistral.js +5 -8
  30. package/dist/lib/providers/openAI.js +4 -7
  31. package/dist/lib/utils/providerConfig.d.ts +117 -0
  32. package/dist/lib/utils/providerConfig.js +353 -0
  33. package/dist/lib/utils/providerUtils.d.ts +2 -1
  34. package/dist/lib/utils/providerUtils.js +53 -36
  35. package/dist/lib/utils/timeout.d.ts +72 -1
  36. package/dist/lib/utils/timeout.js +203 -2
  37. package/dist/mcp/factory.d.ts +1 -1
  38. package/dist/mcp/index.d.ts +7 -19
  39. package/dist/mcp/index.js +15 -56
  40. package/dist/neurolink.d.ts +1 -9
  41. package/dist/neurolink.js +21 -70
  42. package/dist/providers/amazon-bedrock.js +5 -16
  43. package/dist/providers/anthropic-baseprovider.js +3 -21
  44. package/dist/providers/anthropic.js +4 -7
  45. package/dist/providers/azure-openai.js +4 -2
  46. package/dist/providers/google-vertex.js +5 -9
  47. package/dist/providers/huggingFace.js +5 -10
  48. package/dist/providers/mistral.js +5 -8
  49. package/dist/providers/openAI.js +4 -7
  50. package/dist/utils/providerConfig.d.ts +117 -0
  51. package/dist/utils/providerConfig.js +353 -0
  52. package/dist/utils/providerUtils.d.ts +2 -1
  53. package/dist/utils/providerUtils.js +53 -36
  54. package/dist/utils/timeout.d.ts +72 -1
  55. package/dist/utils/timeout.js +203 -2
  56. package/package.json +1 -1
  57. package/dist/chat/client-utils.d.ts +0 -95
  58. package/dist/chat/client-utils.js +0 -315
  59. package/dist/chat/index.d.ts +0 -24
  60. package/dist/chat/index.js +0 -33
  61. package/dist/chat/session-storage.d.ts +0 -77
  62. package/dist/chat/session-storage.js +0 -233
  63. package/dist/chat/session.d.ts +0 -96
  64. package/dist/chat/session.js +0 -257
  65. package/dist/chat/sse-handler.d.ts +0 -49
  66. package/dist/chat/sse-handler.js +0 -259
  67. package/dist/chat/types.d.ts +0 -74
  68. package/dist/chat/types.js +0 -5
  69. package/dist/chat/websocket-chat-handler.d.ts +0 -37
  70. package/dist/chat/websocket-chat-handler.js +0 -262
  71. package/dist/cli/commands/mcp.d.ts +0 -20
  72. package/dist/cli/commands/mcp.js +0 -1272
  73. package/dist/core/defaults.d.ts +0 -19
  74. package/dist/core/defaults.js +0 -29
  75. package/dist/core/evaluation-config.d.ts +0 -29
  76. package/dist/core/evaluation-config.js +0 -144
  77. package/dist/factories/compatibility-factory.d.ts +0 -35
  78. package/dist/factories/compatibility-factory.js +0 -71
  79. package/dist/factories/provider-generate-factory.d.ts +0 -20
  80. package/dist/factories/provider-generate-factory.js +0 -93
  81. package/dist/lib/chat/client-utils.d.ts +0 -95
  82. package/dist/lib/chat/client-utils.js +0 -315
  83. package/dist/lib/chat/index.d.ts +0 -24
  84. package/dist/lib/chat/index.js +0 -33
  85. package/dist/lib/chat/session-storage.d.ts +0 -77
  86. package/dist/lib/chat/session-storage.js +0 -233
  87. package/dist/lib/chat/session.d.ts +0 -96
  88. package/dist/lib/chat/session.js +0 -257
  89. package/dist/lib/chat/sse-handler.d.ts +0 -49
  90. package/dist/lib/chat/sse-handler.js +0 -259
  91. package/dist/lib/chat/types.d.ts +0 -74
  92. package/dist/lib/chat/types.js +0 -5
  93. package/dist/lib/chat/websocket-chat-handler.d.ts +0 -37
  94. package/dist/lib/chat/websocket-chat-handler.js +0 -262
  95. package/dist/lib/core/defaults.d.ts +0 -19
  96. package/dist/lib/core/defaults.js +0 -29
  97. package/dist/lib/core/evaluation-config.d.ts +0 -29
  98. package/dist/lib/core/evaluation-config.js +0 -144
  99. package/dist/lib/factories/compatibility-factory.d.ts +0 -35
  100. package/dist/lib/factories/compatibility-factory.js +0 -71
  101. package/dist/lib/factories/provider-generate-factory.d.ts +0 -20
  102. package/dist/lib/factories/provider-generate-factory.js +0 -93
  103. package/dist/lib/mcp/adapters/plugin-bridge.d.ts +0 -40
  104. package/dist/lib/mcp/adapters/plugin-bridge.js +0 -89
  105. package/dist/lib/mcp/auto-discovery.d.ts +0 -62
  106. package/dist/lib/mcp/auto-discovery.js +0 -149
  107. package/dist/lib/mcp/client.d.ts +0 -68
  108. package/dist/lib/mcp/client.js +0 -248
  109. package/dist/lib/mcp/config.d.ts +0 -31
  110. package/dist/lib/mcp/config.js +0 -99
  111. package/dist/lib/mcp/context-manager.d.ts +0 -171
  112. package/dist/lib/mcp/context-manager.js +0 -362
  113. package/dist/lib/mcp/contracts/mcp-contract.d.ts +0 -169
  114. package/dist/lib/mcp/contracts/mcp-contract.js +0 -58
  115. package/dist/lib/mcp/core/plugin-manager.d.ts +0 -46
  116. package/dist/lib/mcp/core/plugin-manager.js +0 -110
  117. package/dist/lib/mcp/demo/plugin-demo.d.ts +0 -20
  118. package/dist/lib/mcp/demo/plugin-demo.js +0 -118
  119. package/dist/lib/mcp/dynamic-chain-executor.d.ts +0 -225
  120. package/dist/lib/mcp/dynamic-chain-executor.js +0 -489
  121. package/dist/lib/mcp/dynamic-orchestrator.d.ts +0 -115
  122. package/dist/lib/mcp/dynamic-orchestrator.js +0 -351
  123. package/dist/lib/mcp/ecosystem.d.ts +0 -75
  124. package/dist/lib/mcp/ecosystem.js +0 -161
  125. package/dist/lib/mcp/error-manager.d.ts +0 -254
  126. package/dist/lib/mcp/error-manager.js +0 -501
  127. package/dist/lib/mcp/error-recovery.d.ts +0 -159
  128. package/dist/lib/mcp/error-recovery.js +0 -405
  129. package/dist/lib/mcp/external-client.d.ts +0 -88
  130. package/dist/lib/mcp/external-client.js +0 -331
  131. package/dist/lib/mcp/external-manager.d.ts +0 -112
  132. package/dist/lib/mcp/external-manager.js +0 -308
  133. package/dist/lib/mcp/function-calling.d.ts +0 -65
  134. package/dist/lib/mcp/function-calling.js +0 -642
  135. package/dist/lib/mcp/health-monitor.d.ts +0 -257
  136. package/dist/lib/mcp/health-monitor.js +0 -630
  137. package/dist/lib/mcp/initialize-tools.d.ts +0 -29
  138. package/dist/lib/mcp/initialize-tools.js +0 -261
  139. package/dist/lib/mcp/initialize.d.ts +0 -18
  140. package/dist/lib/mcp/initialize.js +0 -62
  141. package/dist/lib/mcp/manager.d.ts +0 -68
  142. package/dist/lib/mcp/manager.js +0 -176
  143. package/dist/lib/mcp/neurolink-mcp-client.d.ts +0 -97
  144. package/dist/lib/mcp/neurolink-mcp-client.js +0 -462
  145. package/dist/lib/mcp/orchestrator.d.ts +0 -302
  146. package/dist/lib/mcp/orchestrator.js +0 -703
  147. package/dist/lib/mcp/plugin-manager.d.ts +0 -98
  148. package/dist/lib/mcp/plugin-manager.js +0 -296
  149. package/dist/lib/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
  150. package/dist/lib/mcp/plugins/core/filesystem-mcp.js +0 -142
  151. package/dist/lib/mcp/plugins/filesystem-mcp.d.ts +0 -37
  152. package/dist/lib/mcp/plugins/filesystem-mcp.js +0 -54
  153. package/dist/lib/mcp/security-manager.d.ts +0 -87
  154. package/dist/lib/mcp/security-manager.js +0 -344
  155. package/dist/lib/mcp/semaphore-manager.d.ts +0 -137
  156. package/dist/lib/mcp/semaphore-manager.js +0 -329
  157. package/dist/lib/mcp/session-manager.d.ts +0 -187
  158. package/dist/lib/mcp/session-manager.js +0 -400
  159. package/dist/lib/mcp/session-persistence.d.ts +0 -93
  160. package/dist/lib/mcp/session-persistence.js +0 -301
  161. package/dist/lib/mcp/tool-integration.d.ts +0 -58
  162. package/dist/lib/mcp/tool-integration.js +0 -203
  163. package/dist/lib/mcp/transport-manager.d.ts +0 -154
  164. package/dist/lib/mcp/transport-manager.js +0 -334
  165. package/dist/lib/mcp/unified-mcp.d.ts +0 -133
  166. package/dist/lib/mcp/unified-mcp.js +0 -251
  167. package/dist/lib/mcp/unified-registry.d.ts +0 -165
  168. package/dist/lib/mcp/unified-registry.js +0 -538
  169. package/dist/lib/providers/analytics-helper.d.ts +0 -38
  170. package/dist/lib/providers/analytics-helper.js +0 -216
  171. package/dist/lib/providers/function-calling-provider.d.ts +0 -142
  172. package/dist/lib/providers/function-calling-provider.js +0 -630
  173. package/dist/lib/providers/mcp-provider.d.ts +0 -75
  174. package/dist/lib/providers/mcp-provider.js +0 -283
  175. package/dist/lib/providers/timeout-wrapper.d.ts +0 -40
  176. package/dist/lib/providers/timeout-wrapper.js +0 -100
  177. package/dist/lib/sdk/tool-extension.d.ts +0 -181
  178. package/dist/lib/sdk/tool-extension.js +0 -284
  179. package/dist/lib/services/streaming/streaming-manager.d.ts +0 -29
  180. package/dist/lib/services/streaming/streaming-manager.js +0 -245
  181. package/dist/lib/services/types.d.ts +0 -156
  182. package/dist/lib/services/types.js +0 -2
  183. package/dist/lib/services/websocket/websocket-server.d.ts +0 -34
  184. package/dist/lib/services/websocket/websocket-server.js +0 -305
  185. package/dist/lib/utils/provider-validation.d.ts +0 -36
  186. package/dist/lib/utils/provider-validation.js +0 -625
  187. package/dist/lib/utils/providerUtils-fixed.d.ts +0 -8
  188. package/dist/lib/utils/providerUtils-fixed.js +0 -94
  189. package/dist/lib/utils/streaming-utils.d.ts +0 -79
  190. package/dist/lib/utils/streaming-utils.js +0 -198
  191. package/dist/lib/utils/timeout-manager.d.ts +0 -75
  192. package/dist/lib/utils/timeout-manager.js +0 -244
  193. package/dist/mcp/adapters/plugin-bridge.d.ts +0 -40
  194. package/dist/mcp/adapters/plugin-bridge.js +0 -89
  195. package/dist/mcp/auto-discovery.d.ts +0 -62
  196. package/dist/mcp/auto-discovery.js +0 -149
  197. package/dist/mcp/client.d.ts +0 -68
  198. package/dist/mcp/client.js +0 -248
  199. package/dist/mcp/config.d.ts +0 -31
  200. package/dist/mcp/config.js +0 -99
  201. package/dist/mcp/context-manager.d.ts +0 -171
  202. package/dist/mcp/context-manager.js +0 -362
  203. package/dist/mcp/contracts/mcp-contract.d.ts +0 -169
  204. package/dist/mcp/contracts/mcp-contract.js +0 -58
  205. package/dist/mcp/core/plugin-manager.d.ts +0 -46
  206. package/dist/mcp/core/plugin-manager.js +0 -110
  207. package/dist/mcp/demo/plugin-demo.d.ts +0 -20
  208. package/dist/mcp/demo/plugin-demo.js +0 -118
  209. package/dist/mcp/dynamic-chain-executor.d.ts +0 -225
  210. package/dist/mcp/dynamic-chain-executor.js +0 -489
  211. package/dist/mcp/dynamic-orchestrator.d.ts +0 -115
  212. package/dist/mcp/dynamic-orchestrator.js +0 -351
  213. package/dist/mcp/ecosystem.d.ts +0 -75
  214. package/dist/mcp/ecosystem.js +0 -162
  215. package/dist/mcp/error-manager.d.ts +0 -254
  216. package/dist/mcp/error-manager.js +0 -501
  217. package/dist/mcp/error-recovery.d.ts +0 -159
  218. package/dist/mcp/error-recovery.js +0 -405
  219. package/dist/mcp/external-client.d.ts +0 -88
  220. package/dist/mcp/external-client.js +0 -331
  221. package/dist/mcp/external-manager.d.ts +0 -112
  222. package/dist/mcp/external-manager.js +0 -308
  223. package/dist/mcp/function-calling.d.ts +0 -65
  224. package/dist/mcp/function-calling.js +0 -642
  225. package/dist/mcp/health-monitor.d.ts +0 -257
  226. package/dist/mcp/health-monitor.js +0 -630
  227. package/dist/mcp/initialize-tools.d.ts +0 -29
  228. package/dist/mcp/initialize-tools.js +0 -262
  229. package/dist/mcp/initialize.d.ts +0 -18
  230. package/dist/mcp/initialize.js +0 -62
  231. package/dist/mcp/manager.d.ts +0 -68
  232. package/dist/mcp/manager.js +0 -176
  233. package/dist/mcp/neurolink-mcp-client.d.ts +0 -97
  234. package/dist/mcp/neurolink-mcp-client.js +0 -462
  235. package/dist/mcp/orchestrator.d.ts +0 -302
  236. package/dist/mcp/orchestrator.js +0 -703
  237. package/dist/mcp/plugin-manager.d.ts +0 -98
  238. package/dist/mcp/plugin-manager.js +0 -297
  239. package/dist/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
  240. package/dist/mcp/plugins/core/filesystem-mcp.js +0 -142
  241. package/dist/mcp/plugins/core/neurolink-mcp.json +0 -17
  242. package/dist/mcp/plugins/filesystem-mcp.d.ts +0 -37
  243. package/dist/mcp/plugins/filesystem-mcp.js +0 -54
  244. package/dist/mcp/security-manager.d.ts +0 -87
  245. package/dist/mcp/security-manager.js +0 -344
  246. package/dist/mcp/semaphore-manager.d.ts +0 -137
  247. package/dist/mcp/semaphore-manager.js +0 -329
  248. package/dist/mcp/session-manager.d.ts +0 -187
  249. package/dist/mcp/session-manager.js +0 -400
  250. package/dist/mcp/session-persistence.d.ts +0 -93
  251. package/dist/mcp/session-persistence.js +0 -302
  252. package/dist/mcp/tool-integration.d.ts +0 -58
  253. package/dist/mcp/tool-integration.js +0 -203
  254. package/dist/mcp/transport-manager.d.ts +0 -154
  255. package/dist/mcp/transport-manager.js +0 -335
  256. package/dist/mcp/unified-mcp.d.ts +0 -133
  257. package/dist/mcp/unified-mcp.js +0 -251
  258. package/dist/mcp/unified-registry.d.ts +0 -165
  259. package/dist/mcp/unified-registry.js +0 -539
  260. package/dist/providers/analytics-helper.d.ts +0 -38
  261. package/dist/providers/analytics-helper.js +0 -216
  262. package/dist/providers/function-calling-provider.d.ts +0 -142
  263. package/dist/providers/function-calling-provider.js +0 -630
  264. package/dist/providers/mcp-provider.d.ts +0 -75
  265. package/dist/providers/mcp-provider.js +0 -283
  266. package/dist/providers/timeout-wrapper.d.ts +0 -40
  267. package/dist/providers/timeout-wrapper.js +0 -100
  268. package/dist/sdk/tool-extension.d.ts +0 -181
  269. package/dist/sdk/tool-extension.js +0 -284
  270. package/dist/services/streaming/streaming-manager.d.ts +0 -29
  271. package/dist/services/streaming/streaming-manager.js +0 -245
  272. package/dist/services/types.d.ts +0 -156
  273. package/dist/services/types.js +0 -2
  274. package/dist/services/websocket/websocket-server.d.ts +0 -34
  275. package/dist/services/websocket/websocket-server.js +0 -306
  276. package/dist/utils/provider-validation.d.ts +0 -36
  277. package/dist/utils/provider-validation.js +0 -625
  278. package/dist/utils/providerUtils-fixed.d.ts +0 -8
  279. package/dist/utils/providerUtils-fixed.js +0 -94
  280. package/dist/utils/streaming-utils.d.ts +0 -79
  281. package/dist/utils/streaming-utils.js +0 -198
  282. package/dist/utils/timeout-manager.d.ts +0 -75
  283. 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
- }