@juspay/neurolink 6.0.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 +14 -3
  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 +2 -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,262 +0,0 @@
1
- /**
2
- * NeuroLink MCP Tool Initialization
3
- * Following Lighthouse's pattern for registering MCP server tools with the client
4
- */
5
- import { mcpConfig } from "./config.js";
6
- import { zodToJsonSchema } from "zod-to-json-schema";
7
- import { z } from "zod";
8
- import { logger } from "../utils/logger.js";
9
- /**
10
- * Sanitize tool name for compatibility
11
- * Following Lighthouse's pattern of ensuring valid tool names
12
- */
13
- const sanitizeToolName = (name) => {
14
- return name.replace(/[^a-zA-Z0-9_-]/g, "_");
15
- };
16
- /**
17
- * Check if a schema is a Zod schema
18
- */
19
- const isZodSchema = (schema) => {
20
- if (typeof schema !== "object" || schema === null) {
21
- return false;
22
- }
23
- return "_def" in schema || "parse" in schema;
24
- };
25
- /**
26
- * Initialize and register tools from MCP Servers with the MCP client
27
- * Following Lighthouse's pattern for tool registration
28
- */
29
- export const initializeMCPTools = async (sessionId, client, context) => {
30
- try {
31
- logger.info(`[MCP Tools] Initializing tools for session: ${sessionId}`);
32
- // Get all registered servers
33
- const servers = await mcpConfig.getServers();
34
- if (!servers || servers.length === 0) {
35
- logger.warn("[MCP Tools] No MCP servers found to register tools from");
36
- return;
37
- }
38
- let totalToolsRegistered = 0;
39
- // Process each server
40
- servers.forEach((server) => {
41
- if (!server || !server.id || !server.tools) {
42
- logger.warn(`[MCP Tools] Skipping invalid server configuration: ${JSON.stringify(server)}`);
43
- return;
44
- }
45
- const serverId = server.id;
46
- logger.info(`[MCP Tools] Registering tools from server: ${serverId}`);
47
- // Process each tool in the server
48
- Object.entries(server.tools).forEach(([originalToolName, tool]) => {
49
- if (!tool || typeof tool.execute !== "function") {
50
- logger.warn(`[MCP Tools] Skipping invalid tool definition for ${originalToolName} in server ${serverId}`);
51
- return;
52
- }
53
- // Create namespaced tool name (serverId_toolName)
54
- let finalToolName = originalToolName;
55
- const prefix = `${serverId}_`;
56
- const maxToolNameLength = 64 - prefix.length;
57
- // Truncate if necessary
58
- if (finalToolName.length > maxToolNameLength) {
59
- finalToolName = finalToolName.substring(0, maxToolNameLength);
60
- logger.info(`[MCP Tools] Truncated tool name: ${originalToolName} -> ${finalToolName}`);
61
- }
62
- // Sanitize and combine
63
- const namespacedToolName = sanitizeToolName(`${prefix}${finalToolName}`);
64
- // Validate final length
65
- if (namespacedToolName.length > 64) {
66
- logger.warn(`[MCP Tools] Tool name too long after sanitization: ${namespacedToolName}. Skipping.`);
67
- return;
68
- }
69
- // Prepare description
70
- const description = tool.description ||
71
- `Tool ${originalToolName} from server ${serverId}`;
72
- // Convert schema if needed
73
- let schemaForClient = undefined;
74
- if (tool.inputSchema) {
75
- if (isZodSchema(tool.inputSchema)) {
76
- try {
77
- const jsonSchemaOutput = zodToJsonSchema(tool.inputSchema);
78
- if (typeof jsonSchemaOutput === "object" &&
79
- jsonSchemaOutput !== null &&
80
- "type" in jsonSchemaOutput &&
81
- jsonSchemaOutput.type === "object") {
82
- schemaForClient = jsonSchemaOutput;
83
- }
84
- else {
85
- logger.warn(`[MCP Tools] Converted schema for ${originalToolName} is not a root object type`);
86
- }
87
- }
88
- catch (schemaError) {
89
- logger.error(`[MCP Tools] Error converting Zod schema for tool ${originalToolName}: ${schemaError}`);
90
- }
91
- }
92
- else if (typeof tool.inputSchema === "object" &&
93
- tool.inputSchema !== null) {
94
- if (tool.inputSchema.type === "object") {
95
- schemaForClient = tool.inputSchema;
96
- }
97
- else {
98
- logger.warn(`[MCP Tools] Input schema for ${originalToolName} is not type 'object'`);
99
- }
100
- }
101
- }
102
- try {
103
- // Register tool with client
104
- client.registerTool(namespacedToolName, async (_name, input) => {
105
- // Execute the tool with full context
106
- const result = await tool.execute(input, context);
107
- // Convert to Lighthouse-style response
108
- if (result.success) {
109
- return {
110
- content: [{ text: JSON.stringify(result.data ?? {}) }],
111
- };
112
- }
113
- else {
114
- return {
115
- content: [
116
- { text: `Error: ${result.error || "Unknown error"}` },
117
- ],
118
- isError: true,
119
- };
120
- }
121
- }, description, schemaForClient);
122
- logger.debug(`[MCP Tools] Registered tool: ${namespacedToolName}`, {
123
- serverId,
124
- originalToolName,
125
- });
126
- totalToolsRegistered++;
127
- }
128
- catch (registrationError) {
129
- logger.error(`[MCP Tools] Failed to register tool ${originalToolName} from server ${serverId}: ${registrationError}`);
130
- }
131
- });
132
- });
133
- logger.info(`[MCP Tools] Successfully registered ${totalToolsRegistered} tools for session: ${sessionId}`);
134
- }
135
- catch (error) {
136
- logger.error(`[MCP Tools] Error during tool initialization for session ${sessionId}: ${error}`);
137
- }
138
- };
139
- /**
140
- * Get all available tools across all servers
141
- * Useful for documentation and discovery
142
- */
143
- export async function getAllAvailableTools(inMemoryServers) {
144
- const tools = [];
145
- // Add in-memory server tools first
146
- if (inMemoryServers) {
147
- for (const [serverId, serverConfig] of inMemoryServers) {
148
- const server = serverConfig.server;
149
- if (server &&
150
- typeof server === "object" &&
151
- "tools" in server &&
152
- server.tools) {
153
- // Handle both Map and object formats
154
- const toolEntries = server.tools instanceof Map
155
- ? Array.from(server.tools.entries())
156
- : Object.entries(server.tools || {});
157
- for (const [toolName, toolInfo] of toolEntries) {
158
- const prefix = `${serverId}_`;
159
- const finalToolName = toolName.length > 64 - prefix.length
160
- ? toolName.substring(0, 64 - prefix.length)
161
- : toolName;
162
- const namespacedName = sanitizeToolName(`${prefix}${finalToolName}`);
163
- // Handle different tool info structures
164
- let description = `Tool from ${serverId}`;
165
- let isImplemented = true;
166
- if (toolInfo) {
167
- // Check if it's a tool info object with description
168
- if (typeof toolInfo.description === "string") {
169
- description = toolInfo.description;
170
- }
171
- else if (typeof toolInfo === "function") {
172
- // It's a raw function, no description available
173
- description = `${toolName} from ${serverId}`;
174
- }
175
- // Check implementation status
176
- if (typeof toolInfo.isImplemented === "boolean") {
177
- isImplemented = toolInfo.isImplemented;
178
- }
179
- }
180
- tools.push({
181
- serverId,
182
- serverTitle: typeof server === "object" &&
183
- server &&
184
- "title" in server &&
185
- typeof server.title === "string"
186
- ? server.title
187
- : serverId,
188
- toolName,
189
- namespacedName,
190
- description,
191
- isImplemented,
192
- });
193
- }
194
- }
195
- }
196
- }
197
- const servers = await mcpConfig.getServers();
198
- servers.forEach((server) => {
199
- Object.entries(server.tools).forEach(([toolName, tool]) => {
200
- const prefix = `${server.id}_`;
201
- const finalToolName = toolName.length > 64 - prefix.length
202
- ? toolName.substring(0, 64 - prefix.length)
203
- : toolName;
204
- const namespacedName = sanitizeToolName(`${prefix}${finalToolName}`);
205
- tools.push({
206
- serverId: server.id,
207
- serverTitle: server.title,
208
- toolName,
209
- namespacedName,
210
- description: tool.description || "",
211
- isImplemented: tool.isImplemented !== false,
212
- });
213
- });
214
- });
215
- return tools;
216
- }
217
- /**
218
- * Initialize tools for a specific server only
219
- * Useful for selective tool registration
220
- */
221
- export async function initializeServerTools(serverId, client, context) {
222
- const servers = await mcpConfig.getServers();
223
- const server = servers.find((s) => s.id === serverId);
224
- if (!server) {
225
- logger.warn(`[MCP Tools] Server not found: ${serverId}`);
226
- return 0;
227
- }
228
- let toolsRegistered = 0;
229
- Object.entries(server.tools).forEach(([toolName, tool]) => {
230
- if (!tool || typeof tool.execute !== "function") {
231
- return;
232
- }
233
- const prefix = `${serverId}_`;
234
- const finalToolName = toolName.length > 64 - prefix.length
235
- ? toolName.substring(0, 64 - prefix.length)
236
- : toolName;
237
- const namespacedToolName = sanitizeToolName(`${prefix}${finalToolName}`);
238
- if (namespacedToolName.length > 64) {
239
- return;
240
- }
241
- try {
242
- client.registerTool(namespacedToolName, async (_name, input) => {
243
- const result = await tool.execute(input, context);
244
- if (result.success) {
245
- return { content: [{ text: JSON.stringify(result.data ?? {}) }] };
246
- }
247
- else {
248
- return {
249
- content: [{ text: `Error: ${result.error || "Unknown error"}` }],
250
- isError: true,
251
- };
252
- }
253
- }, tool.description || `Tool ${toolName} from server ${serverId}`, tool.inputSchema);
254
- toolsRegistered++;
255
- }
256
- catch (error) {
257
- logger.error(`[MCP Tools] Failed to register tool ${toolName}: ${error}`);
258
- }
259
- });
260
- logger.info(`[MCP Tools] Registered ${toolsRegistered} tools from server ${serverId}`);
261
- return toolsRegistered;
262
- }
@@ -1,18 +0,0 @@
1
- /**
2
- * NeuroLink MCP Initialization System
3
- * Automatically registers built-in NeuroLink servers with the default registry
4
- * Ensures built-in tools are always available without manual configuration
5
- */
6
- import { type MCPToolRegistry } from "./tool-registry.js";
7
- /**
8
- * Initialize NeuroLink MCP system by registering built-in servers
9
- */
10
- export declare function initializeNeuroLinkMCP(targetRegistry?: MCPToolRegistry): Promise<void>;
11
- /**
12
- * Get initialization status
13
- */
14
- export declare function isNeuroLinkMCPInitialized(): boolean;
15
- /**
16
- * Reset initialization status (for testing)
17
- */
18
- export declare function resetInitialization(): void;
@@ -1,62 +0,0 @@
1
- /**
2
- * NeuroLink MCP Initialization System
3
- * Automatically registers built-in NeuroLink servers with the default registry
4
- * Ensures built-in tools are always available without manual configuration
5
- */
6
- import { toolRegistry, defaultToolRegistry, } from "./tool-registry.js";
7
- import { mcpLogger } from "./logging.js";
8
- import { ServiceRegistry } from "../core/service-registry.js";
9
- let isInitialized = false;
10
- /**
11
- * Initialize NeuroLink MCP system by registering built-in servers
12
- */
13
- export async function initializeNeuroLinkMCP(targetRegistry) {
14
- if (isInitialized) {
15
- return;
16
- }
17
- mcpLogger.debug("Initializing built-in MCP servers...");
18
- try {
19
- // First, register AIProviderFactory in ServiceRegistry to break circular dependencies
20
- ServiceRegistry.register("AIProviderFactory", async () => {
21
- const { AIProviderFactory } = await import("../core/factory.js");
22
- return AIProviderFactory;
23
- });
24
- mcpLogger.debug("Registered AIProviderFactory in ServiceRegistry");
25
- // Import utility server dynamically to avoid circular dependencies
26
- const { utilityServer } = await import("./servers/utilities/utility-server.js");
27
- // Register built-in NeuroLink servers with specified registry (or default)
28
- const registry = targetRegistry || toolRegistry;
29
- await registry.registerServer(utilityServer.id, utilityServer);
30
- mcpLogger.debug(`Registered neurolink-utility server with built-in tools in ${targetRegistry ? "target" : "default"} registry`);
31
- // Now safe to import and register AI core server
32
- const { aiCoreServer } = await import("./servers/ai-providers/ai-core-server.js");
33
- await registry.registerServer(aiCoreServer.id, aiCoreServer);
34
- mcpLogger.debug("Registered neurolink-ai-core server with AI tools");
35
- // Register direct tools server
36
- const { directToolsServer } = await import("./servers/agent/direct-tools-server.js");
37
- await registry.registerServer(directToolsServer.id, directToolsServer);
38
- mcpLogger.debug("Registered neurolink-direct server with direct tools");
39
- const stats = await registry.getStats();
40
- mcpLogger.info(`Initialization complete: ${stats.totalServers} servers, ${stats.totalTools} tools available`);
41
- isInitialized = true;
42
- }
43
- catch (error) {
44
- mcpLogger.error("Failed to initialize built-in servers:", error instanceof Error ? error.message : String(error));
45
- throw error;
46
- }
47
- }
48
- /**
49
- * Get initialization status
50
- */
51
- export function isNeuroLinkMCPInitialized() {
52
- return isInitialized;
53
- }
54
- /**
55
- * Reset initialization status (for testing)
56
- */
57
- export function resetInitialization() {
58
- isInitialized = false;
59
- defaultToolRegistry.clear();
60
- }
61
- // Note: Auto-initialization removed to prevent circular dependencies
62
- // Call initializeNeuroLinkMCP() explicitly where needed
@@ -1,68 +0,0 @@
1
- /**
2
- * NeuroLink MCP Manager
3
- * Manages MCP client instances following Lighthouse's session-based pattern
4
- */
5
- import { NeuroLinkMCPClient } from "./client.js";
6
- import type { MCPClientConfig } from "./client.js";
7
- import type { UnknownRecord } from "../types/common.js";
8
- /**
9
- * MCP Manager - Factory pattern for managing multiple client instances
10
- * Following Lighthouse's session-based architecture
11
- */
12
- export declare class NeuroLinkMCPManager {
13
- private static instances;
14
- private static lastCleanup;
15
- private static cleanupInterval;
16
- /**
17
- * Get or create an MCP client instance for a session
18
- */
19
- static getInstance(sessionId: string, config?: Partial<MCPClientConfig>): NeuroLinkMCPClient;
20
- /**
21
- * Remove the oldest instance based on creation time
22
- */
23
- private static removeOldestInstance;
24
- /**
25
- * Clean up instances that haven't been used recently
26
- */
27
- private static cleanupOldInstances;
28
- /**
29
- * Get list of active session IDs
30
- */
31
- static getActiveSessionIds(): string[];
32
- /**
33
- * Remove a specific instance
34
- */
35
- static removeInstance(sessionId: string): Promise<boolean>;
36
- /**
37
- * Get instance count
38
- */
39
- static getInstanceCount(): number;
40
- /**
41
- * Get maximum allowed instances
42
- */
43
- static getMaxInstances(): number;
44
- /**
45
- * Get statistics for all instances
46
- */
47
- static getAllStats(): {
48
- instanceCount: number;
49
- maxInstances: number;
50
- instances: Record<string, UnknownRecord>;
51
- };
52
- /**
53
- * Clear all instances (for testing or shutdown)
54
- */
55
- static clearAll(): Promise<void>;
56
- }
57
- /**
58
- * Convenience function to get MCP manager instance
59
- */
60
- export declare function getMCPManager(sessionId: string, config?: Partial<MCPClientConfig>): NeuroLinkMCPClient;
61
- /**
62
- * Convenience function to remove MCP manager instance
63
- */
64
- export declare function removeMCPManager(sessionId: string): Promise<boolean>;
65
- /**
66
- * Export manager for direct access if needed
67
- */
68
- export { NeuroLinkMCPManager as MCPManager };
@@ -1,176 +0,0 @@
1
- /**
2
- * NeuroLink MCP Manager
3
- * Manages MCP client instances following Lighthouse's session-based pattern
4
- */
5
- import { NeuroLinkMCPClient, createMCPClient } from "./client.js";
6
- import { logger } from "../utils/logger.js";
7
- /**
8
- * Maximum number of concurrent MCP instances
9
- */
10
- const MAX_MCP_INSTANCES = 50;
11
- /**
12
- * Default MCP configuration
13
- */
14
- const DEFAULT_MCP_CONFIG = {
15
- logLevel: "info",
16
- };
17
- /**
18
- * MCP Manager - Factory pattern for managing multiple client instances
19
- * Following Lighthouse's session-based architecture
20
- */
21
- export class NeuroLinkMCPManager {
22
- static instances = new Map();
23
- static lastCleanup = Date.now();
24
- static cleanupInterval = 60000; // 1 minute
25
- /**
26
- * Get or create an MCP client instance for a session
27
- */
28
- static getInstance(sessionId, config) {
29
- // Periodic cleanup of old instances
30
- if (Date.now() - this.lastCleanup > this.cleanupInterval) {
31
- this.cleanupOldInstances();
32
- }
33
- // Return existing instance if available
34
- if (this.instances.has(sessionId)) {
35
- const instance = this.instances.get(sessionId);
36
- logger.debug(`[MCP Manager] Returning existing instance for session ${sessionId}`);
37
- return instance;
38
- }
39
- // Check if we've reached the maximum number of instances
40
- if (this.instances.size >= MAX_MCP_INSTANCES) {
41
- // Remove the oldest instance to make room
42
- this.removeOldestInstance();
43
- }
44
- // Create new instance
45
- const fullConfig = {
46
- sessionId,
47
- ...DEFAULT_MCP_CONFIG,
48
- ...config,
49
- };
50
- const instance = createMCPClient(fullConfig);
51
- this.instances.set(sessionId, instance);
52
- logger.info(`[MCP Manager] Created new instance for session ${sessionId}`, {
53
- instanceCount: this.instances.size,
54
- config: fullConfig,
55
- });
56
- return instance;
57
- }
58
- /**
59
- * Remove the oldest instance based on creation time
60
- */
61
- static removeOldestInstance() {
62
- let oldestSessionId = null;
63
- let oldestTime = Date.now();
64
- // Find the oldest instance
65
- for (const [sessionId, instance] of this.instances.entries()) {
66
- const stats = instance.getStats();
67
- const creationTime = Date.now() - stats.uptime;
68
- if (creationTime < oldestTime) {
69
- oldestTime = creationTime;
70
- oldestSessionId = sessionId;
71
- }
72
- }
73
- if (oldestSessionId) {
74
- const instance = this.instances.get(oldestSessionId);
75
- instance.disconnect();
76
- this.instances.delete(oldestSessionId);
77
- logger.info(`[MCP Manager] Removed oldest instance`, {
78
- sessionId: oldestSessionId,
79
- remainingInstances: this.instances.size,
80
- });
81
- }
82
- }
83
- /**
84
- * Clean up instances that haven't been used recently
85
- */
86
- static cleanupOldInstances() {
87
- const now = Date.now();
88
- const maxIdleTime = 300000; // 5 minutes
89
- const toRemove = [];
90
- for (const [sessionId, instance] of this.instances.entries()) {
91
- const stats = instance.getStats();
92
- // If no executions in the last 5 minutes, mark for removal
93
- if (stats.executionCount === 0 && now - stats.uptime > maxIdleTime) {
94
- toRemove.push(sessionId);
95
- }
96
- }
97
- for (const sessionId of toRemove) {
98
- const instance = this.instances.get(sessionId);
99
- instance.disconnect();
100
- this.instances.delete(sessionId);
101
- }
102
- if (toRemove.length > 0) {
103
- logger.info(`[MCP Manager] Cleaned up ${toRemove.length} idle instances`);
104
- }
105
- this.lastCleanup = now;
106
- }
107
- /**
108
- * Get list of active session IDs
109
- */
110
- static getActiveSessionIds() {
111
- return Array.from(this.instances.keys());
112
- }
113
- /**
114
- * Remove a specific instance
115
- */
116
- static async removeInstance(sessionId) {
117
- const instance = this.instances.get(sessionId);
118
- if (instance) {
119
- await instance.disconnect();
120
- return this.instances.delete(sessionId);
121
- }
122
- return false;
123
- }
124
- /**
125
- * Get instance count
126
- */
127
- static getInstanceCount() {
128
- return this.instances.size;
129
- }
130
- /**
131
- * Get maximum allowed instances
132
- */
133
- static getMaxInstances() {
134
- return MAX_MCP_INSTANCES;
135
- }
136
- /**
137
- * Get statistics for all instances
138
- */
139
- static getAllStats() {
140
- const stats = {};
141
- for (const [sessionId, instance] of this.instances.entries()) {
142
- stats[sessionId] = instance.getStats();
143
- }
144
- return {
145
- instanceCount: this.instances.size,
146
- maxInstances: MAX_MCP_INSTANCES,
147
- instances: stats,
148
- };
149
- }
150
- /**
151
- * Clear all instances (for testing or shutdown)
152
- */
153
- static async clearAll() {
154
- for (const instance of this.instances.values()) {
155
- await instance.disconnect();
156
- }
157
- this.instances.clear();
158
- logger.info("[MCP Manager] Cleared all instances");
159
- }
160
- }
161
- /**
162
- * Convenience function to get MCP manager instance
163
- */
164
- export function getMCPManager(sessionId, config) {
165
- return NeuroLinkMCPManager.getInstance(sessionId, config);
166
- }
167
- /**
168
- * Convenience function to remove MCP manager instance
169
- */
170
- export async function removeMCPManager(sessionId) {
171
- return NeuroLinkMCPManager.removeInstance(sessionId);
172
- }
173
- /**
174
- * Export manager for direct access if needed
175
- */
176
- export { NeuroLinkMCPManager as MCPManager };
@@ -1,97 +0,0 @@
1
- /**
2
- * NeuroLink MCP Client with Automatic Tool Detection
3
- * Implements automatic tool execution based on prompt analysis
4
- * Following Lighthouse's pattern of prompt-based tool invocation
5
- */
6
- import { EventEmitter } from "events";
7
- import type { AIProvider } from "../core/types.js";
8
- import type { NeuroLinkMCPTool } from "./factory.js";
9
- /**
10
- * Tool Detection Pattern
11
- */
12
- interface ToolDetectionPattern {
13
- patterns: RegExp[];
14
- toolName: string;
15
- paramExtractor?: (prompt: string) => Record<string, unknown>;
16
- }
17
- /**
18
- * MCP Client Configuration
19
- */
20
- export interface NeuroLinkMCPClientConfig {
21
- provider: AIProvider;
22
- providerName?: string;
23
- modelName?: string;
24
- sessionId?: string;
25
- userId?: string;
26
- organizationId?: string;
27
- }
28
- /**
29
- * NeuroLink MCP Client with Automatic Tool Detection
30
- */
31
- export declare class NeuroLinkMCPClient extends EventEmitter {
32
- private provider;
33
- private tools;
34
- private toolPatterns;
35
- private config;
36
- private sessionId;
37
- private executionCount;
38
- constructor(config: NeuroLinkMCPClientConfig);
39
- /**
40
- * Initialize default tool detection patterns
41
- */
42
- private initializeDefaultPatterns;
43
- /**
44
- * Register a tool with automatic detection patterns
45
- */
46
- registerTool(tool: NeuroLinkMCPTool, patterns?: ToolDetectionPattern): void;
47
- /**
48
- * Extract tool parameters using AI
49
- * No hardcoded patterns - let AI figure out the parameters
50
- */
51
- private extractToolParameters;
52
- /**
53
- * Analyze prompt to detect required tools
54
- * TRUE AUTOMATIC DETECTION - AI decides which tools to use
55
- */
56
- private analyzePrompt;
57
- /**
58
- * Execute detected tools
59
- */
60
- private executeTools;
61
- /**
62
- * Generate response with tool results incorporated
63
- */
64
- private generateResponse;
65
- /**
66
- * Send a prompt and automatically execute any needed tools
67
- */
68
- sendPrompt(prompt: string): Promise<string>;
69
- /**
70
- * Get registered tools
71
- */
72
- getTools(): Record<string, {
73
- name: string;
74
- description?: string;
75
- inputSchema?: unknown;
76
- }>;
77
- /**
78
- * Get session statistics
79
- */
80
- getStats(): {
81
- sessionId: string;
82
- toolCount: number;
83
- patternCount: number;
84
- executionCount: number;
85
- provider: string | undefined;
86
- model: string | undefined;
87
- };
88
- /**
89
- * Clean up resources
90
- */
91
- cleanup(): Promise<void>;
92
- }
93
- /**
94
- * Create a new NeuroLink MCP Client instance
95
- */
96
- export declare function createNeuroLinkMCPClient(config: NeuroLinkMCPClientConfig): NeuroLinkMCPClient;
97
- export {};