@juspay/neurolink 1.6.0 → 1.9.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.
- package/CHANGELOG.md +193 -7
- package/README.md +100 -17
- package/dist/agent/direct-tools.d.ts +1203 -0
- package/dist/agent/direct-tools.js +387 -0
- package/dist/cli/commands/agent-generate.d.ts +2 -0
- package/dist/cli/commands/agent-generate.js +70 -0
- package/dist/cli/commands/config.d.ts +6 -6
- package/dist/cli/commands/config.js +326 -273
- package/dist/cli/commands/mcp.d.ts +2 -1
- package/dist/cli/commands/mcp.js +874 -146
- package/dist/cli/commands/ollama.d.ts +1 -1
- package/dist/cli/commands/ollama.js +153 -143
- package/dist/cli/index.js +589 -323
- package/dist/cli/utils/complete-setup.d.ts +19 -0
- package/dist/cli/utils/complete-setup.js +81 -0
- package/dist/cli/utils/env-manager.d.ts +44 -0
- package/dist/cli/utils/env-manager.js +226 -0
- package/dist/cli/utils/interactive-setup.d.ts +48 -0
- package/dist/cli/utils/interactive-setup.js +302 -0
- package/dist/core/dynamic-models.d.ts +208 -0
- package/dist/core/dynamic-models.js +250 -0
- package/dist/core/factory.d.ts +13 -6
- package/dist/core/factory.js +176 -61
- package/dist/core/types.d.ts +4 -2
- package/dist/core/types.js +4 -4
- package/dist/index.d.ts +16 -16
- package/dist/index.js +16 -16
- package/dist/lib/agent/direct-tools.d.ts +1203 -0
- package/dist/lib/agent/direct-tools.js +387 -0
- package/dist/lib/core/dynamic-models.d.ts +208 -0
- package/dist/lib/core/dynamic-models.js +250 -0
- package/dist/lib/core/factory.d.ts +13 -6
- package/dist/lib/core/factory.js +176 -61
- package/dist/lib/core/types.d.ts +4 -2
- package/dist/lib/core/types.js +4 -4
- package/dist/lib/index.d.ts +16 -16
- package/dist/lib/index.js +16 -16
- package/dist/lib/mcp/auto-discovery.d.ts +120 -0
- package/dist/lib/mcp/auto-discovery.js +793 -0
- package/dist/lib/mcp/client.d.ts +66 -0
- package/dist/lib/mcp/client.js +245 -0
- package/dist/lib/mcp/config.d.ts +31 -0
- package/dist/lib/mcp/config.js +74 -0
- package/dist/lib/mcp/context-manager.d.ts +4 -4
- package/dist/lib/mcp/context-manager.js +24 -18
- package/dist/lib/mcp/factory.d.ts +28 -11
- package/dist/lib/mcp/factory.js +36 -29
- package/dist/lib/mcp/function-calling.d.ts +51 -0
- package/dist/lib/mcp/function-calling.js +510 -0
- package/dist/lib/mcp/index.d.ts +190 -0
- package/dist/lib/mcp/index.js +156 -0
- package/dist/lib/mcp/initialize-tools.d.ts +28 -0
- package/dist/lib/mcp/initialize-tools.js +209 -0
- package/dist/lib/mcp/initialize.d.ts +17 -0
- package/dist/lib/mcp/initialize.js +51 -0
- package/dist/lib/mcp/logging.d.ts +71 -0
- package/dist/lib/mcp/logging.js +183 -0
- package/dist/lib/mcp/manager.d.ts +67 -0
- package/dist/lib/mcp/manager.js +176 -0
- package/dist/lib/mcp/neurolink-mcp-client.d.ts +96 -0
- package/dist/lib/mcp/neurolink-mcp-client.js +417 -0
- package/dist/lib/mcp/orchestrator.d.ts +3 -3
- package/dist/lib/mcp/orchestrator.js +46 -43
- package/dist/lib/mcp/registry.d.ts +2 -2
- package/dist/lib/mcp/registry.js +42 -33
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.d.ts +1 -1
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.js +204 -65
- package/dist/lib/mcp/servers/ai-providers/ai-core-server.js +142 -102
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.d.ts +6 -6
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.js +197 -142
- package/dist/lib/mcp/servers/utilities/utility-server.d.ts +8 -0
- package/dist/lib/mcp/servers/utilities/utility-server.js +326 -0
- package/dist/lib/mcp/tool-integration.d.ts +67 -0
- package/dist/lib/mcp/tool-integration.js +179 -0
- package/dist/lib/mcp/unified-registry.d.ts +269 -0
- package/dist/lib/mcp/unified-registry.js +1411 -0
- package/dist/lib/neurolink.d.ts +68 -6
- package/dist/lib/neurolink.js +304 -42
- package/dist/lib/providers/agent-enhanced-provider.d.ts +59 -0
- package/dist/lib/providers/agent-enhanced-provider.js +242 -0
- package/dist/lib/providers/amazonBedrock.d.ts +3 -3
- package/dist/lib/providers/amazonBedrock.js +54 -50
- package/dist/lib/providers/anthropic.d.ts +2 -2
- package/dist/lib/providers/anthropic.js +92 -84
- package/dist/lib/providers/azureOpenAI.d.ts +2 -2
- package/dist/lib/providers/azureOpenAI.js +97 -86
- package/dist/lib/providers/function-calling-provider.d.ts +70 -0
- package/dist/lib/providers/function-calling-provider.js +359 -0
- package/dist/lib/providers/googleAIStudio.d.ts +10 -5
- package/dist/lib/providers/googleAIStudio.js +60 -38
- package/dist/lib/providers/googleVertexAI.d.ts +3 -3
- package/dist/lib/providers/googleVertexAI.js +96 -86
- package/dist/lib/providers/huggingFace.d.ts +3 -3
- package/dist/lib/providers/huggingFace.js +70 -63
- package/dist/lib/providers/index.d.ts +11 -11
- package/dist/lib/providers/index.js +18 -18
- package/dist/lib/providers/mcp-provider.d.ts +62 -0
- package/dist/lib/providers/mcp-provider.js +183 -0
- package/dist/lib/providers/mistralAI.d.ts +3 -3
- package/dist/lib/providers/mistralAI.js +42 -36
- package/dist/lib/providers/ollama.d.ts +4 -4
- package/dist/lib/providers/ollama.js +113 -98
- package/dist/lib/providers/openAI.d.ts +7 -3
- package/dist/lib/providers/openAI.js +45 -33
- package/dist/lib/utils/logger.js +2 -2
- package/dist/lib/utils/providerUtils.js +53 -31
- package/dist/mcp/auto-discovery.d.ts +120 -0
- package/dist/mcp/auto-discovery.js +794 -0
- package/dist/mcp/client.d.ts +66 -0
- package/dist/mcp/client.js +245 -0
- package/dist/mcp/config.d.ts +31 -0
- package/dist/mcp/config.js +74 -0
- package/dist/mcp/context-manager.d.ts +4 -4
- package/dist/mcp/context-manager.js +24 -18
- package/dist/mcp/factory.d.ts +28 -11
- package/dist/mcp/factory.js +36 -29
- package/dist/mcp/function-calling.d.ts +51 -0
- package/dist/mcp/function-calling.js +510 -0
- package/dist/mcp/index.d.ts +190 -0
- package/dist/mcp/index.js +156 -0
- package/dist/mcp/initialize-tools.d.ts +28 -0
- package/dist/mcp/initialize-tools.js +210 -0
- package/dist/mcp/initialize.d.ts +17 -0
- package/dist/mcp/initialize.js +51 -0
- package/dist/mcp/logging.d.ts +71 -0
- package/dist/mcp/logging.js +183 -0
- package/dist/mcp/manager.d.ts +67 -0
- package/dist/mcp/manager.js +176 -0
- package/dist/mcp/neurolink-mcp-client.d.ts +96 -0
- package/dist/mcp/neurolink-mcp-client.js +417 -0
- package/dist/mcp/orchestrator.d.ts +3 -3
- package/dist/mcp/orchestrator.js +46 -43
- package/dist/mcp/registry.d.ts +2 -2
- package/dist/mcp/registry.js +42 -33
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.d.ts +1 -1
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.js +204 -65
- package/dist/mcp/servers/ai-providers/ai-core-server.js +142 -102
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +6 -6
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.js +197 -142
- package/dist/mcp/servers/utilities/utility-server.d.ts +8 -0
- package/dist/mcp/servers/utilities/utility-server.js +326 -0
- package/dist/mcp/tool-integration.d.ts +67 -0
- package/dist/mcp/tool-integration.js +179 -0
- package/dist/mcp/unified-registry.d.ts +269 -0
- package/dist/mcp/unified-registry.js +1411 -0
- package/dist/neurolink.d.ts +68 -6
- package/dist/neurolink.js +304 -42
- package/dist/providers/agent-enhanced-provider.d.ts +59 -0
- package/dist/providers/agent-enhanced-provider.js +242 -0
- package/dist/providers/amazonBedrock.d.ts +3 -3
- package/dist/providers/amazonBedrock.js +54 -50
- package/dist/providers/anthropic.d.ts +2 -2
- package/dist/providers/anthropic.js +92 -84
- package/dist/providers/azureOpenAI.d.ts +2 -2
- package/dist/providers/azureOpenAI.js +97 -86
- package/dist/providers/function-calling-provider.d.ts +70 -0
- package/dist/providers/function-calling-provider.js +359 -0
- package/dist/providers/googleAIStudio.d.ts +10 -5
- package/dist/providers/googleAIStudio.js +60 -38
- package/dist/providers/googleVertexAI.d.ts +3 -3
- package/dist/providers/googleVertexAI.js +96 -86
- package/dist/providers/huggingFace.d.ts +3 -3
- package/dist/providers/huggingFace.js +70 -63
- package/dist/providers/index.d.ts +11 -11
- package/dist/providers/index.js +18 -18
- package/dist/providers/mcp-provider.d.ts +62 -0
- package/dist/providers/mcp-provider.js +183 -0
- package/dist/providers/mistralAI.d.ts +3 -3
- package/dist/providers/mistralAI.js +42 -36
- package/dist/providers/ollama.d.ts +4 -4
- package/dist/providers/ollama.js +113 -98
- package/dist/providers/openAI.d.ts +7 -3
- package/dist/providers/openAI.js +45 -33
- package/dist/utils/logger.js +2 -2
- package/dist/utils/providerUtils.js +53 -31
- package/package.json +175 -161
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NeuroLink Utility Server
|
|
3
|
+
* Provides general utility tools following Lighthouse patterns
|
|
4
|
+
*/
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { createMCPServer } from "../../factory.js";
|
|
7
|
+
import { logger } from "../../../utils/logger.js";
|
|
8
|
+
/**
|
|
9
|
+
* Utility Server - General utility tools
|
|
10
|
+
*/
|
|
11
|
+
export const utilityServer = createMCPServer({
|
|
12
|
+
id: "neurolink-utility",
|
|
13
|
+
title: "NeuroLink Utility Server",
|
|
14
|
+
description: "Provides general utility tools for common operations",
|
|
15
|
+
category: "integrations",
|
|
16
|
+
version: "1.0.0",
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Get Current Time Input Schema
|
|
20
|
+
*/
|
|
21
|
+
const GetCurrentTimeSchema = z.object({
|
|
22
|
+
format: z
|
|
23
|
+
.enum(["ISO", "UTC", "local"])
|
|
24
|
+
.default("local")
|
|
25
|
+
.optional()
|
|
26
|
+
.describe("Output format. If 'local', uses the specified timezone."),
|
|
27
|
+
timezone: z
|
|
28
|
+
.string()
|
|
29
|
+
.default("Asia/Kolkata")
|
|
30
|
+
.optional()
|
|
31
|
+
.describe("Timezone for 'local' format (e.g., Asia/Kolkata, UTC)."),
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* Register Get Current Time Tool
|
|
35
|
+
*/
|
|
36
|
+
utilityServer.registerTool({
|
|
37
|
+
name: "get-current-time",
|
|
38
|
+
description: "Get the current time in the specified timezone. Defaults to Indian Standard Time (IST/Asia/Kolkata).",
|
|
39
|
+
category: "time",
|
|
40
|
+
inputSchema: GetCurrentTimeSchema,
|
|
41
|
+
isImplemented: true,
|
|
42
|
+
execute: async (params, context) => {
|
|
43
|
+
const startTime = Date.now();
|
|
44
|
+
try {
|
|
45
|
+
const validatedInput = GetCurrentTimeSchema.parse(params);
|
|
46
|
+
const { format, timezone } = validatedInput;
|
|
47
|
+
logger.debug(`[Utility] Getting current time with format: ${format}, timezone: ${timezone}`);
|
|
48
|
+
const now = new Date();
|
|
49
|
+
const resultData = {
|
|
50
|
+
isoTime: now.toISOString(),
|
|
51
|
+
utcTime: now.toUTCString(),
|
|
52
|
+
timestamp: now.getTime(),
|
|
53
|
+
requestedFormat: format,
|
|
54
|
+
requestedTimezone: timezone,
|
|
55
|
+
};
|
|
56
|
+
let effectiveTimezone = timezone;
|
|
57
|
+
if (format === "local") {
|
|
58
|
+
try {
|
|
59
|
+
resultData.localTime = now.toLocaleString("en-US", {
|
|
60
|
+
timeZone: timezone,
|
|
61
|
+
});
|
|
62
|
+
resultData.actualTimezone = timezone;
|
|
63
|
+
}
|
|
64
|
+
catch (tzError) {
|
|
65
|
+
const fallbackTimezone = "Asia/Kolkata";
|
|
66
|
+
logger.warn(`[Utility] Invalid timezone '${timezone}', falling back to ${fallbackTimezone}`);
|
|
67
|
+
resultData.localTime = now.toLocaleString("en-US", {
|
|
68
|
+
timeZone: fallbackTimezone,
|
|
69
|
+
});
|
|
70
|
+
resultData.actualTimezone = fallbackTimezone;
|
|
71
|
+
resultData.timezoneError = `Invalid timezone: ${timezone}. Fell back to ${fallbackTimezone}.`;
|
|
72
|
+
effectiveTimezone = fallbackTimezone;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// Add human-readable display string
|
|
76
|
+
const displayDateString = now.toLocaleString("en-US", {
|
|
77
|
+
timeZone: effectiveTimezone,
|
|
78
|
+
});
|
|
79
|
+
resultData.displayString = `The current time is ${displayDateString} in ${effectiveTimezone}`;
|
|
80
|
+
const executionTime = Date.now() - startTime;
|
|
81
|
+
logger.debug(`[Utility] Time retrieved successfully in ${executionTime}ms`);
|
|
82
|
+
return {
|
|
83
|
+
success: true,
|
|
84
|
+
data: resultData,
|
|
85
|
+
usage: {
|
|
86
|
+
executionTime,
|
|
87
|
+
},
|
|
88
|
+
metadata: {
|
|
89
|
+
toolName: "get-current-time",
|
|
90
|
+
serverId: "neurolink-utility",
|
|
91
|
+
sessionId: context.sessionId,
|
|
92
|
+
timestamp: Date.now(),
|
|
93
|
+
executionTime,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
const executionTime = Date.now() - startTime;
|
|
99
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
100
|
+
logger.error(`[Utility] Get current time failed: ${errorMessage}`);
|
|
101
|
+
return {
|
|
102
|
+
success: false,
|
|
103
|
+
error: errorMessage,
|
|
104
|
+
metadata: {
|
|
105
|
+
toolName: "get-current-time",
|
|
106
|
+
serverId: "neurolink-utility",
|
|
107
|
+
sessionId: context.sessionId,
|
|
108
|
+
timestamp: Date.now(),
|
|
109
|
+
executionTime,
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
/**
|
|
116
|
+
* Calculate Date Difference Schema
|
|
117
|
+
*/
|
|
118
|
+
const CalculateDateDifferenceSchema = z.object({
|
|
119
|
+
date1: z.string().describe("First date in ISO format or parseable string"),
|
|
120
|
+
date2: z.string().describe("Second date in ISO format or parseable string"),
|
|
121
|
+
unit: z
|
|
122
|
+
.enum(["seconds", "minutes", "hours", "days", "weeks", "months", "years"])
|
|
123
|
+
.default("days")
|
|
124
|
+
.optional()
|
|
125
|
+
.describe("Unit for the difference calculation"),
|
|
126
|
+
});
|
|
127
|
+
/**
|
|
128
|
+
* Register Calculate Date Difference Tool
|
|
129
|
+
*/
|
|
130
|
+
utilityServer.registerTool({
|
|
131
|
+
name: "calculate-date-difference",
|
|
132
|
+
description: "Calculate the difference between two dates in various units",
|
|
133
|
+
category: "time",
|
|
134
|
+
inputSchema: CalculateDateDifferenceSchema,
|
|
135
|
+
isImplemented: true,
|
|
136
|
+
execute: async (params, context) => {
|
|
137
|
+
const startTime = Date.now();
|
|
138
|
+
try {
|
|
139
|
+
const validatedInput = CalculateDateDifferenceSchema.parse(params);
|
|
140
|
+
const { date1, date2, unit } = validatedInput;
|
|
141
|
+
logger.debug(`[Utility] Calculating date difference between ${date1} and ${date2} in ${unit}`);
|
|
142
|
+
const d1 = new Date(date1);
|
|
143
|
+
const d2 = new Date(date2);
|
|
144
|
+
if (isNaN(d1.getTime())) {
|
|
145
|
+
throw new Error(`Invalid date format for date1: ${date1}`);
|
|
146
|
+
}
|
|
147
|
+
if (isNaN(d2.getTime())) {
|
|
148
|
+
throw new Error(`Invalid date format for date2: ${date2}`);
|
|
149
|
+
}
|
|
150
|
+
const diffMs = Math.abs(d2.getTime() - d1.getTime());
|
|
151
|
+
let difference;
|
|
152
|
+
switch (unit) {
|
|
153
|
+
case "seconds":
|
|
154
|
+
difference = diffMs / 1000;
|
|
155
|
+
break;
|
|
156
|
+
case "minutes":
|
|
157
|
+
difference = diffMs / (1000 * 60);
|
|
158
|
+
break;
|
|
159
|
+
case "hours":
|
|
160
|
+
difference = diffMs / (1000 * 60 * 60);
|
|
161
|
+
break;
|
|
162
|
+
case "days":
|
|
163
|
+
difference = diffMs / (1000 * 60 * 60 * 24);
|
|
164
|
+
break;
|
|
165
|
+
case "weeks":
|
|
166
|
+
difference = diffMs / (1000 * 60 * 60 * 24 * 7);
|
|
167
|
+
break;
|
|
168
|
+
case "months":
|
|
169
|
+
difference = diffMs / (1000 * 60 * 60 * 24 * 30.44); // Average month
|
|
170
|
+
break;
|
|
171
|
+
case "years":
|
|
172
|
+
difference = diffMs / (1000 * 60 * 60 * 24 * 365.25); // Account for leap years
|
|
173
|
+
break;
|
|
174
|
+
default:
|
|
175
|
+
difference = diffMs / (1000 * 60 * 60 * 24); // Default to days
|
|
176
|
+
}
|
|
177
|
+
const resultData = {
|
|
178
|
+
date1: d1.toISOString(),
|
|
179
|
+
date2: d2.toISOString(),
|
|
180
|
+
difference: Math.round(difference * 100) / 100, // Round to 2 decimal places
|
|
181
|
+
unit,
|
|
182
|
+
milliseconds: diffMs,
|
|
183
|
+
displayString: `The difference between ${d1.toLocaleDateString()} and ${d2.toLocaleDateString()} is ${Math.round(difference * 100) / 100} ${unit}`,
|
|
184
|
+
};
|
|
185
|
+
const executionTime = Date.now() - startTime;
|
|
186
|
+
logger.debug(`[Utility] Date difference calculated successfully in ${executionTime}ms`);
|
|
187
|
+
return {
|
|
188
|
+
success: true,
|
|
189
|
+
data: resultData,
|
|
190
|
+
usage: {
|
|
191
|
+
executionTime,
|
|
192
|
+
},
|
|
193
|
+
metadata: {
|
|
194
|
+
toolName: "calculate-date-difference",
|
|
195
|
+
serverId: "neurolink-utility",
|
|
196
|
+
sessionId: context.sessionId,
|
|
197
|
+
timestamp: Date.now(),
|
|
198
|
+
executionTime,
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
const executionTime = Date.now() - startTime;
|
|
204
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
205
|
+
logger.error(`[Utility] Calculate date difference failed: ${errorMessage}`);
|
|
206
|
+
return {
|
|
207
|
+
success: false,
|
|
208
|
+
error: errorMessage,
|
|
209
|
+
metadata: {
|
|
210
|
+
toolName: "calculate-date-difference",
|
|
211
|
+
serverId: "neurolink-utility",
|
|
212
|
+
sessionId: context.sessionId,
|
|
213
|
+
timestamp: Date.now(),
|
|
214
|
+
executionTime,
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
/**
|
|
221
|
+
* Format Number Schema
|
|
222
|
+
*/
|
|
223
|
+
const FormatNumberSchema = z.object({
|
|
224
|
+
number: z.number().describe("Number to format"),
|
|
225
|
+
style: z
|
|
226
|
+
.enum(["decimal", "currency", "percent"])
|
|
227
|
+
.default("decimal")
|
|
228
|
+
.optional()
|
|
229
|
+
.describe("Formatting style"),
|
|
230
|
+
currency: z
|
|
231
|
+
.string()
|
|
232
|
+
.default("USD")
|
|
233
|
+
.optional()
|
|
234
|
+
.describe("Currency code when style is 'currency'"),
|
|
235
|
+
locale: z
|
|
236
|
+
.string()
|
|
237
|
+
.default("en-US")
|
|
238
|
+
.optional()
|
|
239
|
+
.describe("Locale for formatting"),
|
|
240
|
+
minimumFractionDigits: z
|
|
241
|
+
.number()
|
|
242
|
+
.min(0)
|
|
243
|
+
.max(20)
|
|
244
|
+
.optional()
|
|
245
|
+
.describe("Minimum number of decimal places"),
|
|
246
|
+
maximumFractionDigits: z
|
|
247
|
+
.number()
|
|
248
|
+
.min(0)
|
|
249
|
+
.max(20)
|
|
250
|
+
.optional()
|
|
251
|
+
.describe("Maximum number of decimal places"),
|
|
252
|
+
});
|
|
253
|
+
/**
|
|
254
|
+
* Register Format Number Tool
|
|
255
|
+
*/
|
|
256
|
+
utilityServer.registerTool({
|
|
257
|
+
name: "format-number",
|
|
258
|
+
description: "Format numbers in various styles (decimal, currency, percent, scientific)",
|
|
259
|
+
category: "formatting",
|
|
260
|
+
inputSchema: FormatNumberSchema,
|
|
261
|
+
isImplemented: true,
|
|
262
|
+
execute: async (params, context) => {
|
|
263
|
+
const startTime = Date.now();
|
|
264
|
+
try {
|
|
265
|
+
const validatedInput = FormatNumberSchema.parse(params);
|
|
266
|
+
const { number, style, currency, locale, minimumFractionDigits, maximumFractionDigits, } = validatedInput;
|
|
267
|
+
logger.debug(`[Utility] Formatting number ${number} with style: ${style}, locale: ${locale}`);
|
|
268
|
+
const options = {
|
|
269
|
+
style,
|
|
270
|
+
};
|
|
271
|
+
if (style === "currency") {
|
|
272
|
+
options.currency = currency;
|
|
273
|
+
}
|
|
274
|
+
if (minimumFractionDigits !== undefined) {
|
|
275
|
+
options.minimumFractionDigits = minimumFractionDigits;
|
|
276
|
+
}
|
|
277
|
+
if (maximumFractionDigits !== undefined) {
|
|
278
|
+
options.maximumFractionDigits = maximumFractionDigits;
|
|
279
|
+
}
|
|
280
|
+
const formatter = new Intl.NumberFormat(locale, options);
|
|
281
|
+
const formatted = formatter.format(number);
|
|
282
|
+
const resultData = {
|
|
283
|
+
original: number,
|
|
284
|
+
formatted,
|
|
285
|
+
style,
|
|
286
|
+
locale,
|
|
287
|
+
currency: style === "currency" ? currency : undefined,
|
|
288
|
+
displayString: `${number} formatted as ${formatted}`,
|
|
289
|
+
};
|
|
290
|
+
const executionTime = Date.now() - startTime;
|
|
291
|
+
logger.debug(`[Utility] Number formatted successfully in ${executionTime}ms`);
|
|
292
|
+
return {
|
|
293
|
+
success: true,
|
|
294
|
+
data: resultData,
|
|
295
|
+
usage: {
|
|
296
|
+
executionTime,
|
|
297
|
+
},
|
|
298
|
+
metadata: {
|
|
299
|
+
toolName: "format-number",
|
|
300
|
+
serverId: "neurolink-utility",
|
|
301
|
+
sessionId: context.sessionId,
|
|
302
|
+
timestamp: Date.now(),
|
|
303
|
+
executionTime,
|
|
304
|
+
},
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
const executionTime = Date.now() - startTime;
|
|
309
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
310
|
+
logger.error(`[Utility] Format number failed: ${errorMessage}`);
|
|
311
|
+
return {
|
|
312
|
+
success: false,
|
|
313
|
+
error: errorMessage,
|
|
314
|
+
metadata: {
|
|
315
|
+
toolName: "format-number",
|
|
316
|
+
serverId: "neurolink-utility",
|
|
317
|
+
sessionId: context.sessionId,
|
|
318
|
+
timestamp: Date.now(),
|
|
319
|
+
executionTime,
|
|
320
|
+
},
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
});
|
|
325
|
+
// Log successful server creation
|
|
326
|
+
logger.debug("[Utility] NeuroLink Utility Server v1.0.0 created with 3 tools:", Object.keys(utilityServer.tools));
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Tool Integration Layer
|
|
3
|
+
* Connects MCP tools to NeuroLink AI providers following Lighthouse patterns
|
|
4
|
+
*/
|
|
5
|
+
import type { NeuroLinkExecutionContext, ToolResult } from "./factory.js";
|
|
6
|
+
/**
|
|
7
|
+
* Tool Integration System
|
|
8
|
+
* Provides natural language tool discovery and execution
|
|
9
|
+
*/
|
|
10
|
+
export declare class MCPToolIntegration {
|
|
11
|
+
private registry;
|
|
12
|
+
private context;
|
|
13
|
+
constructor(context?: Partial<NeuroLinkExecutionContext>);
|
|
14
|
+
/**
|
|
15
|
+
* Initialize tools from all active servers
|
|
16
|
+
*/
|
|
17
|
+
private initializeTools;
|
|
18
|
+
/**
|
|
19
|
+
* Get all available tools
|
|
20
|
+
*/
|
|
21
|
+
getAvailableTools(): {
|
|
22
|
+
name: string;
|
|
23
|
+
qualifiedName: string;
|
|
24
|
+
description: string;
|
|
25
|
+
server: string;
|
|
26
|
+
serverTitle: string;
|
|
27
|
+
category?: string;
|
|
28
|
+
serverCategory?: string;
|
|
29
|
+
permissions?: string[];
|
|
30
|
+
isImplemented?: boolean;
|
|
31
|
+
}[];
|
|
32
|
+
/**
|
|
33
|
+
* Find tools that match a query
|
|
34
|
+
*/
|
|
35
|
+
findTools(query: string): Array<{
|
|
36
|
+
name: string;
|
|
37
|
+
description: string;
|
|
38
|
+
serverId: string;
|
|
39
|
+
relevance: number;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Execute a tool by name
|
|
43
|
+
*/
|
|
44
|
+
executeTool(toolName: string, params: any, serverId?: string): Promise<ToolResult>;
|
|
45
|
+
/**
|
|
46
|
+
* Enhance AI prompt with tool context
|
|
47
|
+
*/
|
|
48
|
+
createToolAwarePrompt(userPrompt: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Analyze AI response for tool usage requests
|
|
51
|
+
*/
|
|
52
|
+
analyzeForToolUsage(aiResponse: string): Array<{
|
|
53
|
+
toolName: string;
|
|
54
|
+
params: any;
|
|
55
|
+
confidence: number;
|
|
56
|
+
}>;
|
|
57
|
+
/**
|
|
58
|
+
* Update context for tool execution
|
|
59
|
+
*/
|
|
60
|
+
updateContext(updates: Partial<NeuroLinkExecutionContext>): void;
|
|
61
|
+
}
|
|
62
|
+
export declare function getToolIntegration(context?: Partial<NeuroLinkExecutionContext>): MCPToolIntegration;
|
|
63
|
+
/**
|
|
64
|
+
* Initialize MCP tools for a session
|
|
65
|
+
* Following Lighthouse's initialization pattern
|
|
66
|
+
*/
|
|
67
|
+
export declare function initializeMCPTools(sessionId: string, context?: Partial<NeuroLinkExecutionContext>): Promise<MCPToolIntegration>;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Tool Integration Layer
|
|
3
|
+
* Connects MCP tools to NeuroLink AI providers following Lighthouse patterns
|
|
4
|
+
*/
|
|
5
|
+
import { mcpConfig } from "./config.js";
|
|
6
|
+
import { logger } from "../utils/logger.js";
|
|
7
|
+
import { MCPToolRegistry } from "./registry.js";
|
|
8
|
+
/**
|
|
9
|
+
* Tool Integration System
|
|
10
|
+
* Provides natural language tool discovery and execution
|
|
11
|
+
*/
|
|
12
|
+
export class MCPToolIntegration {
|
|
13
|
+
registry;
|
|
14
|
+
context;
|
|
15
|
+
constructor(context) {
|
|
16
|
+
this.registry = new MCPToolRegistry();
|
|
17
|
+
this.context = {
|
|
18
|
+
sessionId: context?.sessionId || `session-${Date.now()}`,
|
|
19
|
+
userId: context?.userId,
|
|
20
|
+
aiProvider: context?.aiProvider,
|
|
21
|
+
...context,
|
|
22
|
+
};
|
|
23
|
+
// Initialize with all active servers
|
|
24
|
+
this.initializeTools();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Initialize tools from all active servers
|
|
28
|
+
*/
|
|
29
|
+
async initializeTools() {
|
|
30
|
+
const servers = await mcpConfig.getServers();
|
|
31
|
+
for (const server of servers) {
|
|
32
|
+
await this.registry.registerServer(server);
|
|
33
|
+
}
|
|
34
|
+
logger.debug("[Tool Integration] Initialized with servers:", {
|
|
35
|
+
serverCount: servers.length,
|
|
36
|
+
toolCount: this.registry.listTools().length,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get all available tools
|
|
41
|
+
*/
|
|
42
|
+
getAvailableTools() {
|
|
43
|
+
return this.registry.listTools();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Find tools that match a query
|
|
47
|
+
*/
|
|
48
|
+
findTools(query) {
|
|
49
|
+
const allTools = this.registry.listTools();
|
|
50
|
+
const queryLower = query.toLowerCase();
|
|
51
|
+
const results = [];
|
|
52
|
+
for (const toolInfo of allTools) {
|
|
53
|
+
let relevance = 0;
|
|
54
|
+
// Check tool name
|
|
55
|
+
if (toolInfo.name.toLowerCase().includes(queryLower)) {
|
|
56
|
+
relevance += 10;
|
|
57
|
+
}
|
|
58
|
+
// Check tool description
|
|
59
|
+
if (toolInfo.description.toLowerCase().includes(queryLower)) {
|
|
60
|
+
relevance += 5;
|
|
61
|
+
}
|
|
62
|
+
// Check category if present
|
|
63
|
+
if (toolInfo.category?.toLowerCase().includes(queryLower)) {
|
|
64
|
+
relevance += 3;
|
|
65
|
+
}
|
|
66
|
+
if (relevance > 0) {
|
|
67
|
+
results.push({
|
|
68
|
+
name: toolInfo.name,
|
|
69
|
+
description: toolInfo.description,
|
|
70
|
+
serverId: toolInfo.server,
|
|
71
|
+
relevance,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// Sort by relevance
|
|
76
|
+
return results.sort((a, b) => b.relevance - a.relevance);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Execute a tool by name
|
|
80
|
+
*/
|
|
81
|
+
async executeTool(toolName, params, serverId) {
|
|
82
|
+
try {
|
|
83
|
+
// If serverId is provided, use qualified name
|
|
84
|
+
const qualifiedName = serverId ? `${serverId}.${toolName}` : toolName;
|
|
85
|
+
const result = await this.registry.executeTool(qualifiedName, params, this.context, {
|
|
86
|
+
validateInput: true,
|
|
87
|
+
validatePermissions: true,
|
|
88
|
+
trackMetrics: true,
|
|
89
|
+
});
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
logger.error("[Tool Integration] Tool execution failed:", error);
|
|
94
|
+
return {
|
|
95
|
+
success: false,
|
|
96
|
+
error: error instanceof Error ? error.message : String(error),
|
|
97
|
+
metadata: {
|
|
98
|
+
toolName,
|
|
99
|
+
serverId,
|
|
100
|
+
timestamp: Date.now(),
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Enhance AI prompt with tool context
|
|
107
|
+
*/
|
|
108
|
+
createToolAwarePrompt(userPrompt) {
|
|
109
|
+
const tools = this.getAvailableTools();
|
|
110
|
+
const toolDescriptions = tools
|
|
111
|
+
.map((t) => `- ${t.name}: ${t.description}`)
|
|
112
|
+
.join("\n");
|
|
113
|
+
return `${userPrompt}
|
|
114
|
+
|
|
115
|
+
Available tools:
|
|
116
|
+
${toolDescriptions}
|
|
117
|
+
|
|
118
|
+
You can use these tools to provide more accurate and real-time information.`;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Analyze AI response for tool usage requests
|
|
122
|
+
*/
|
|
123
|
+
analyzeForToolUsage(aiResponse) {
|
|
124
|
+
const toolRequests = [];
|
|
125
|
+
// Simple pattern matching for tool requests
|
|
126
|
+
// This can be enhanced with more sophisticated NLP
|
|
127
|
+
const toolPattern = /<tool[^>]*>([^<]+)<\/tool>/g;
|
|
128
|
+
let match;
|
|
129
|
+
while ((match = toolPattern.exec(aiResponse)) !== null) {
|
|
130
|
+
try {
|
|
131
|
+
const toolData = JSON.parse(match[1]);
|
|
132
|
+
toolRequests.push({
|
|
133
|
+
toolName: toolData.name,
|
|
134
|
+
params: toolData.params || {},
|
|
135
|
+
confidence: 1.0,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
logger.warn("[Tool Integration] Failed to parse tool request:", match[1]);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return toolRequests;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Update context for tool execution
|
|
146
|
+
*/
|
|
147
|
+
updateContext(updates) {
|
|
148
|
+
this.context = {
|
|
149
|
+
...this.context,
|
|
150
|
+
...updates,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Create a global tool integration instance
|
|
156
|
+
* This can be initialized once and reused
|
|
157
|
+
*/
|
|
158
|
+
let globalToolIntegration = null;
|
|
159
|
+
export function getToolIntegration(context) {
|
|
160
|
+
if (!globalToolIntegration) {
|
|
161
|
+
globalToolIntegration = new MCPToolIntegration(context);
|
|
162
|
+
}
|
|
163
|
+
else if (context) {
|
|
164
|
+
globalToolIntegration.updateContext(context);
|
|
165
|
+
}
|
|
166
|
+
return globalToolIntegration;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Initialize MCP tools for a session
|
|
170
|
+
* Following Lighthouse's initialization pattern
|
|
171
|
+
*/
|
|
172
|
+
export async function initializeMCPTools(sessionId, context) {
|
|
173
|
+
const integration = getToolIntegration({
|
|
174
|
+
sessionId,
|
|
175
|
+
...context,
|
|
176
|
+
});
|
|
177
|
+
logger.debug("[Tool Integration] MCP tools initialized for session:", sessionId);
|
|
178
|
+
return integration;
|
|
179
|
+
}
|