@juspay/neurolink 7.14.2 → 7.14.3

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 (99) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cli/commands/config.d.ts +66 -66
  3. package/dist/core/baseProvider.d.ts +12 -7
  4. package/dist/core/baseProvider.js +118 -125
  5. package/dist/core/constants.d.ts +5 -0
  6. package/dist/core/constants.js +6 -0
  7. package/dist/core/dynamicModels.d.ts +4 -4
  8. package/dist/core/factory.d.ts +2 -4
  9. package/dist/core/types.d.ts +8 -22
  10. package/dist/index.d.ts +1 -4
  11. package/dist/lib/core/baseProvider.d.ts +12 -7
  12. package/dist/lib/core/baseProvider.js +118 -125
  13. package/dist/lib/core/constants.d.ts +5 -0
  14. package/dist/lib/core/constants.js +6 -0
  15. package/dist/lib/core/dynamicModels.d.ts +8 -8
  16. package/dist/lib/core/factory.d.ts +2 -4
  17. package/dist/lib/core/types.d.ts +8 -22
  18. package/dist/lib/index.d.ts +1 -4
  19. package/dist/lib/mcp/contracts/mcpContract.d.ts +6 -19
  20. package/dist/lib/mcp/externalServerManager.d.ts +2 -4
  21. package/dist/lib/mcp/externalServerManager.js +7 -8
  22. package/dist/lib/mcp/factory.d.ts +61 -7
  23. package/dist/lib/mcp/factory.js +36 -23
  24. package/dist/lib/mcp/mcpClientFactory.d.ts +2 -1
  25. package/dist/lib/mcp/mcpClientFactory.js +73 -26
  26. package/dist/lib/mcp/registry.d.ts +1 -1
  27. package/dist/lib/mcp/toolDiscoveryService.d.ts +1 -1
  28. package/dist/lib/mcp/toolDiscoveryService.js +50 -19
  29. package/dist/lib/mcp/toolRegistry.d.ts +23 -1
  30. package/dist/lib/mcp/toolRegistry.js +108 -17
  31. package/dist/lib/models/modelResolver.js +2 -1
  32. package/dist/lib/neurolink.d.ts +12 -8
  33. package/dist/lib/neurolink.js +130 -134
  34. package/dist/lib/providers/amazonBedrock.d.ts +2 -2
  35. package/dist/lib/providers/anthropic.d.ts +3 -3
  36. package/dist/lib/providers/googleAiStudio.d.ts +2 -2
  37. package/dist/lib/providers/mistral.d.ts +3 -3
  38. package/dist/lib/providers/ollama.d.ts +2 -2
  39. package/dist/lib/providers/openAI.d.ts +3 -3
  40. package/dist/lib/providers/openaiCompatible.d.ts +2 -2
  41. package/dist/lib/providers/sagemaker/client.d.ts +2 -5
  42. package/dist/lib/providers/sagemaker/language-model.d.ts +4 -6
  43. package/dist/lib/providers/sagemaker/parsers.js +5 -4
  44. package/dist/lib/sdk/toolRegistration.d.ts +6 -6
  45. package/dist/lib/sdk/toolRegistration.js +17 -56
  46. package/dist/lib/types/generateTypes.d.ts +9 -9
  47. package/dist/lib/types/streamTypes.d.ts +4 -4
  48. package/dist/lib/types/tools.d.ts +15 -7
  49. package/dist/lib/types/typeAliases.d.ts +412 -0
  50. package/dist/lib/types/typeAliases.js +48 -0
  51. package/dist/lib/utils/factoryProcessing.d.ts +2 -1
  52. package/dist/lib/utils/factoryProcessing.js +4 -3
  53. package/dist/lib/utils/parameterValidation.d.ts +97 -0
  54. package/dist/lib/utils/parameterValidation.js +452 -0
  55. package/dist/lib/utils/transformationUtils.d.ts +204 -0
  56. package/dist/lib/utils/transformationUtils.js +334 -0
  57. package/dist/lib/utils/typeUtils.d.ts +77 -0
  58. package/dist/lib/utils/typeUtils.js +97 -0
  59. package/dist/mcp/contracts/mcpContract.d.ts +6 -19
  60. package/dist/mcp/externalServerManager.d.ts +2 -4
  61. package/dist/mcp/externalServerManager.js +7 -8
  62. package/dist/mcp/factory.d.ts +61 -7
  63. package/dist/mcp/factory.js +36 -23
  64. package/dist/mcp/mcpClientFactory.d.ts +2 -1
  65. package/dist/mcp/mcpClientFactory.js +73 -26
  66. package/dist/mcp/registry.d.ts +1 -1
  67. package/dist/mcp/toolDiscoveryService.d.ts +1 -1
  68. package/dist/mcp/toolDiscoveryService.js +50 -19
  69. package/dist/mcp/toolRegistry.d.ts +23 -1
  70. package/dist/mcp/toolRegistry.js +108 -17
  71. package/dist/models/modelResolver.js +2 -1
  72. package/dist/neurolink.d.ts +12 -8
  73. package/dist/neurolink.js +130 -134
  74. package/dist/providers/amazonBedrock.d.ts +2 -2
  75. package/dist/providers/anthropic.d.ts +3 -3
  76. package/dist/providers/googleAiStudio.d.ts +2 -2
  77. package/dist/providers/mistral.d.ts +3 -3
  78. package/dist/providers/ollama.d.ts +2 -2
  79. package/dist/providers/openAI.d.ts +3 -3
  80. package/dist/providers/openaiCompatible.d.ts +2 -2
  81. package/dist/providers/sagemaker/client.d.ts +2 -5
  82. package/dist/providers/sagemaker/language-model.d.ts +4 -6
  83. package/dist/providers/sagemaker/parsers.js +5 -4
  84. package/dist/sdk/toolRegistration.d.ts +6 -6
  85. package/dist/sdk/toolRegistration.js +17 -56
  86. package/dist/types/generateTypes.d.ts +9 -9
  87. package/dist/types/streamTypes.d.ts +4 -4
  88. package/dist/types/tools.d.ts +15 -7
  89. package/dist/types/typeAliases.d.ts +412 -0
  90. package/dist/types/typeAliases.js +48 -0
  91. package/dist/utils/factoryProcessing.d.ts +2 -1
  92. package/dist/utils/factoryProcessing.js +4 -3
  93. package/dist/utils/parameterValidation.d.ts +97 -0
  94. package/dist/utils/parameterValidation.js +452 -0
  95. package/dist/utils/transformationUtils.d.ts +204 -0
  96. package/dist/utils/transformationUtils.js +334 -0
  97. package/dist/utils/typeUtils.d.ts +77 -0
  98. package/dist/utils/typeUtils.js +97 -0
  99. package/package.json +1 -1
@@ -0,0 +1,334 @@
1
+ /**
2
+ * Object Transformation Utilities
3
+ * Centralizes repeated object transformation patterns to improve code reuse and maintainability
4
+ */
5
+ // ============================================================================
6
+ // TOOL EXECUTION TRANSFORMATIONS
7
+ // ============================================================================
8
+ /**
9
+ * Transform tool execution results from AI SDK format to NeuroLink GenerateResult format
10
+ * Handles both single execution and array formats with robust type checking
11
+ *
12
+ * @param toolExecutions - Array of tool execution results from AI SDK (optional)
13
+ * @returns Array of standardized tool execution objects with name, input, output, and duration
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const executions = transformToolExecutions([
18
+ * { name: "calculator", input: { a: 5, b: 3 }, output: 8, duration: 150 }
19
+ * ]);
20
+ * // Returns: [{ name: "calculator", input: { a: 5, b: 3 }, output: 8, duration: 150 }]
21
+ * ```
22
+ */
23
+ export function transformToolExecutions(toolExecutions) {
24
+ if (!toolExecutions || !Array.isArray(toolExecutions)) {
25
+ return [];
26
+ }
27
+ return toolExecutions.map((te) => {
28
+ const teRecord = te;
29
+ return {
30
+ name: teRecord.name || "",
31
+ input: teRecord.input || {},
32
+ output: teRecord.output || "success",
33
+ duration: teRecord.duration || 0,
34
+ };
35
+ });
36
+ }
37
+ /**
38
+ * Transform tool execution results from AI SDK format to internal format (for MCP generation)
39
+ * Used in tryMCPGeneration method
40
+ */
41
+ export function transformToolExecutionsForMCP(toolExecutions) {
42
+ if (!toolExecutions || !Array.isArray(toolExecutions)) {
43
+ return [];
44
+ }
45
+ return toolExecutions.map((te) => {
46
+ const teRecord = te;
47
+ return {
48
+ toolName: teRecord.name || "",
49
+ executionTime: teRecord.duration || 0,
50
+ success: true, // Assume success if tool executed (AI providers handle failures differently)
51
+ serverId: teRecord.serverId || undefined,
52
+ };
53
+ });
54
+ }
55
+ // ============================================================================
56
+ // AVAILABLE TOOLS TRANSFORMATIONS
57
+ // ============================================================================
58
+ /**
59
+ * Transform available tools from internal format to GenerateResult format
60
+ * Ensures consistent tool information structure across the API with schema normalization
61
+ *
62
+ * @param availableTools - Array of tool definitions from various sources (MCP servers, builtin tools, etc.)
63
+ * @returns Array of normalized tool descriptions with consistent schema format
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const tools = transformAvailableTools([
68
+ * { name: "calculator", description: "Math tool", server: "builtin", inputSchema: {...} }
69
+ * ]);
70
+ * // Returns: [{ name: "calculator", description: "Math tool", serverId: "builtin", schema: {...} }]
71
+ * ```
72
+ */
73
+ export function transformAvailableTools(availableTools) {
74
+ if (!availableTools || !Array.isArray(availableTools)) {
75
+ return [];
76
+ }
77
+ return availableTools.map((tool) => {
78
+ const toolRecord = tool;
79
+ return {
80
+ name: tool.name || "",
81
+ description: tool.description || "",
82
+ server: tool.server || "",
83
+ parameters: toolRecord.inputSchema ||
84
+ toolRecord.parameters ||
85
+ toolRecord.schema ||
86
+ {},
87
+ };
88
+ });
89
+ }
90
+ /**
91
+ * Transform tools for MCP generation format
92
+ * Simple transformation for internal MCP tool lists
93
+ */
94
+ export function transformToolsForMCP(availableTools) {
95
+ return availableTools.map((tool) => ({
96
+ name: tool.name,
97
+ description: tool.description,
98
+ server: tool.server,
99
+ category: tool.category,
100
+ }));
101
+ }
102
+ /**
103
+ * Transform tools to expected format with required properties
104
+ * Used in getAllAvailableTools method for final output
105
+ */
106
+ export function transformToolsToExpectedFormat(tools) {
107
+ return tools.map((tool) => ({
108
+ name: tool.name,
109
+ description: tool.description || "No description available",
110
+ server: tool.serverId || "unknown",
111
+ category: tool.category,
112
+ inputSchema: tool.inputSchema,
113
+ }));
114
+ }
115
+ // ============================================================================
116
+ // STRING AND ARRAY TRANSFORMATIONS
117
+ // ============================================================================
118
+ /**
119
+ * Extract tool names from tool objects
120
+ * Common pattern for creating arrays of tool names
121
+ */
122
+ export function extractToolNames(tools) {
123
+ return tools.map((tool) => tool.name);
124
+ }
125
+ /**
126
+ * Extract object keys as a comma-separated string
127
+ * Common pattern for logging and debugging
128
+ */
129
+ export function getKeysAsString(obj, fallback = "none") {
130
+ const keys = Object.keys(obj);
131
+ return keys.length > 0 ? keys.join(", ") : fallback;
132
+ }
133
+ /**
134
+ * Count object properties
135
+ * Common pattern for metrics and logging
136
+ */
137
+ export function getKeyCount(obj) {
138
+ return Object.keys(obj).length;
139
+ }
140
+ // ============================================================================
141
+ // SCHEMA TRANSFORMATIONS
142
+ // ============================================================================
143
+ /**
144
+ * Transform schema properties to parameter descriptions
145
+ * Used in tool-aware system prompt generation
146
+ */
147
+ export function transformSchemaToParameterDescription(schema) {
148
+ if (!schema?.properties) {
149
+ return "";
150
+ }
151
+ const requiredParams = new Set(schema.required || []);
152
+ return Object.entries(schema.properties)
153
+ .map(([key, value]) => {
154
+ const typedValue = value;
155
+ const required = requiredParams.has(key) ? " (required)" : "";
156
+ return ` - ${key}: ${typedValue.type || "unknown"}${required}`;
157
+ })
158
+ .join("\n");
159
+ }
160
+ /**
161
+ * Transform tools to tool descriptions for system prompts
162
+ * Consolidated pattern for creating tool-aware prompts
163
+ */
164
+ export function transformToolsToDescriptions(availableTools) {
165
+ return availableTools
166
+ .map((tool) => {
167
+ const schema = tool.inputSchema;
168
+ let params = "";
169
+ if (schema?.properties) {
170
+ params = transformSchemaToParameterDescription(schema);
171
+ }
172
+ return `- ${tool.name}: ${tool.description} (from ${tool.server})\n${params}`;
173
+ })
174
+ .join("\n\n");
175
+ }
176
+ // ============================================================================
177
+ // VALIDATION TRANSFORMATIONS
178
+ // ============================================================================
179
+ /**
180
+ * Transform parameters for validation
181
+ * Common pattern when logging or checking parameter structures
182
+ */
183
+ export function transformParamsForLogging(params) {
184
+ if (!params || typeof params !== "object") {
185
+ return String(params);
186
+ }
187
+ const record = params;
188
+ return `${Object.keys(record).length} params`;
189
+ }
190
+ /**
191
+ * Safe property extraction from unknown objects
192
+ * Common pattern for safely accessing properties from unknown structures
193
+ */
194
+ export function safeExtractProperty(obj, key, fallback) {
195
+ if (!obj || typeof obj !== "object" || obj === null) {
196
+ return fallback;
197
+ }
198
+ const record = obj;
199
+ const value = record[key];
200
+ return value !== undefined ? value : fallback;
201
+ }
202
+ /**
203
+ * Safe extraction of string properties
204
+ * Specialized version for string properties with fallback
205
+ */
206
+ export function safeExtractString(obj, key, fallback = "") {
207
+ const value = safeExtractProperty(obj, key, fallback);
208
+ return typeof value === "string" ? value : fallback;
209
+ }
210
+ /**
211
+ * Safe extraction of number properties
212
+ * Specialized version for number properties with fallback
213
+ */
214
+ export function safeExtractNumber(obj, key, fallback = 0) {
215
+ const value = safeExtractProperty(obj, key, fallback);
216
+ return typeof value === "number" ? value : fallback;
217
+ }
218
+ /**
219
+ * Safe extraction of boolean properties
220
+ * Specialized version for boolean properties with fallback
221
+ */
222
+ export function safeExtractBoolean(obj, key, fallback = false) {
223
+ const value = safeExtractProperty(obj, key, fallback);
224
+ return typeof value === "boolean" ? value : fallback;
225
+ }
226
+ // ============================================================================
227
+ // COLLECTION TRANSFORMATIONS
228
+ // ============================================================================
229
+ /**
230
+ * Transform Map to array of values
231
+ * Common pattern for converting tool maps to arrays
232
+ */
233
+ export function mapToArray(map) {
234
+ return Array.from(map.values());
235
+ }
236
+ /**
237
+ * Transform Map to array of key-value pairs
238
+ * Common pattern for processing map entries
239
+ */
240
+ export function mapToEntries(map) {
241
+ return Array.from(map.entries());
242
+ }
243
+ /**
244
+ * Group array items by a key
245
+ * Common pattern for organizing tools or other objects by category
246
+ */
247
+ export function groupBy(items, keyFn) {
248
+ const groups = new Map();
249
+ for (const item of items) {
250
+ const key = keyFn(item);
251
+ const existing = groups.get(key) || [];
252
+ existing.push(item);
253
+ groups.set(key, existing);
254
+ }
255
+ return groups;
256
+ }
257
+ /**
258
+ * Remove undefined properties from objects
259
+ * Common pattern for cleaning up object structures
260
+ */
261
+ export function removeUndefinedProperties(obj) {
262
+ const cleaned = {};
263
+ for (const [key, value] of Object.entries(obj)) {
264
+ if (value !== undefined) {
265
+ cleaned[key] = value;
266
+ }
267
+ }
268
+ return cleaned;
269
+ }
270
+ /**
271
+ * Merge objects with undefined handling
272
+ * Common pattern for combining configuration objects
273
+ */
274
+ export function mergeWithUndefinedHandling(target, ...sources) {
275
+ const result = { ...target };
276
+ for (const source of sources) {
277
+ for (const [key, value] of Object.entries(source)) {
278
+ if (value !== undefined) {
279
+ result[key] = value;
280
+ }
281
+ }
282
+ }
283
+ return result;
284
+ }
285
+ // ============================================================================
286
+ // TOOL OPTIMIZATION UTILITIES
287
+ // ============================================================================
288
+ /**
289
+ * Optimize tool information for collection with minimal object creation
290
+ * Consolidates repeated optimization patterns across different tool sources
291
+ *
292
+ * @param tool - Tool information to optimize
293
+ * @param defaults - Default values to apply if missing
294
+ * @returns Optimized tool with minimal object creation
295
+ *
296
+ * @example
297
+ * ```typescript
298
+ * const optimized = optimizeToolForCollection(tool, {
299
+ * serverId: "builtin",
300
+ * category: "math"
301
+ * });
302
+ * ```
303
+ */
304
+ export function optimizeToolForCollection(tool, defaults) {
305
+ // Check what properties actually need modification
306
+ const needsDescription = !tool.description && defaults.description;
307
+ const needsServerId = !tool.serverId && defaults.serverId;
308
+ const needsCategory = !tool.category && defaults.category;
309
+ const needsInputSchema = !tool.inputSchema && defaults.inputSchema;
310
+ const hasParametersConflict = tool.inputSchema && "parameters" in tool;
311
+ // Only create new object if modifications are actually needed
312
+ if (!needsDescription &&
313
+ !needsServerId &&
314
+ !needsCategory &&
315
+ !needsInputSchema &&
316
+ !hasParametersConflict) {
317
+ return tool; // Return original tool without modification
318
+ }
319
+ // Create optimized tool with only necessary changes
320
+ const optimizedTool = {
321
+ ...tool,
322
+ ...(needsDescription && { description: defaults.description }),
323
+ ...(needsServerId && { serverId: defaults.serverId }),
324
+ ...(needsCategory && { category: defaults.category }),
325
+ ...(needsInputSchema && { inputSchema: defaults.inputSchema }),
326
+ };
327
+ // Clean up schema conflicts if present
328
+ if (hasParametersConflict) {
329
+ const cleanedTool = { ...optimizedTool };
330
+ delete cleanedTool.parameters;
331
+ return cleanedTool;
332
+ }
333
+ return optimizedTool;
334
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Type Utilities - Centralized type checking functions
3
+ *
4
+ * Consolidates common type checking patterns to reduce code duplication
5
+ * and provide consistent type guards across the codebase.
6
+ */
7
+ /**
8
+ * Type guard to check if a value is a non-null object
9
+ * Excludes arrays and null values
10
+ *
11
+ * @param value - Value to check
12
+ * @returns true if value is a non-null object (excluding arrays)
13
+ */
14
+ export declare function isObject(value: unknown): value is Record<string, unknown>;
15
+ /**
16
+ * Type guard to check if a value is a non-null object (including arrays)
17
+ *
18
+ * @param value - Value to check
19
+ * @returns true if value is a non-null object (including arrays)
20
+ */
21
+ export declare function isNonNullObject(value: unknown): value is object;
22
+ /**
23
+ * Type guard to check if a value is a plain object with string keys
24
+ *
25
+ * @param value - Value to check
26
+ * @returns true if value is a plain object with string keys
27
+ */
28
+ export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
29
+ /**
30
+ * Type guard to check if a value is an array
31
+ *
32
+ * @param value - Value to check
33
+ * @returns true if value is an array
34
+ */
35
+ export declare function isArray(value: unknown): value is unknown[];
36
+ /**
37
+ * Type guard to check if a value is a string
38
+ *
39
+ * @param value - Value to check
40
+ * @returns true if value is a string
41
+ */
42
+ export declare function isString(value: unknown): value is string;
43
+ /**
44
+ * Type guard to check if a value is a number
45
+ *
46
+ * @param value - Value to check
47
+ * @returns true if value is a number and not NaN
48
+ */
49
+ export declare function isNumber(value: unknown): value is number;
50
+ /**
51
+ * Type guard to check if a value is a boolean
52
+ *
53
+ * @param value - Value to check
54
+ * @returns true if value is a boolean
55
+ */
56
+ export declare function isBoolean(value: unknown): value is boolean;
57
+ /**
58
+ * Type guard to check if a value is a function
59
+ *
60
+ * @param value - Value to check
61
+ * @returns true if value is a function
62
+ */
63
+ export declare function isFunction(value: unknown): value is Function;
64
+ /**
65
+ * Type guard to check if a value is null or undefined
66
+ *
67
+ * @param value - Value to check
68
+ * @returns true if value is null or undefined
69
+ */
70
+ export declare function isNullish(value: unknown): value is null | undefined;
71
+ /**
72
+ * Type guard to check if a value is defined (not undefined)
73
+ *
74
+ * @param value - Value to check
75
+ * @returns true if value is not undefined
76
+ */
77
+ export declare function isDefined<T>(value: T | undefined): value is T;
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Type Utilities - Centralized type checking functions
3
+ *
4
+ * Consolidates common type checking patterns to reduce code duplication
5
+ * and provide consistent type guards across the codebase.
6
+ */
7
+ /**
8
+ * Type guard to check if a value is a non-null object
9
+ * Excludes arrays and null values
10
+ *
11
+ * @param value - Value to check
12
+ * @returns true if value is a non-null object (excluding arrays)
13
+ */
14
+ export function isObject(value) {
15
+ return typeof value === "object" && value !== null && !Array.isArray(value);
16
+ }
17
+ /**
18
+ * Type guard to check if a value is a non-null object (including arrays)
19
+ *
20
+ * @param value - Value to check
21
+ * @returns true if value is a non-null object (including arrays)
22
+ */
23
+ export function isNonNullObject(value) {
24
+ return typeof value === "object" && value !== null;
25
+ }
26
+ /**
27
+ * Type guard to check if a value is a plain object with string keys
28
+ *
29
+ * @param value - Value to check
30
+ * @returns true if value is a plain object with string keys
31
+ */
32
+ export function isPlainObject(value) {
33
+ return isObject(value) && Object.getPrototypeOf(value) === Object.prototype;
34
+ }
35
+ /**
36
+ * Type guard to check if a value is an array
37
+ *
38
+ * @param value - Value to check
39
+ * @returns true if value is an array
40
+ */
41
+ export function isArray(value) {
42
+ return Array.isArray(value);
43
+ }
44
+ /**
45
+ * Type guard to check if a value is a string
46
+ *
47
+ * @param value - Value to check
48
+ * @returns true if value is a string
49
+ */
50
+ export function isString(value) {
51
+ return typeof value === "string";
52
+ }
53
+ /**
54
+ * Type guard to check if a value is a number
55
+ *
56
+ * @param value - Value to check
57
+ * @returns true if value is a number and not NaN
58
+ */
59
+ export function isNumber(value) {
60
+ return typeof value === "number" && !isNaN(value);
61
+ }
62
+ /**
63
+ * Type guard to check if a value is a boolean
64
+ *
65
+ * @param value - Value to check
66
+ * @returns true if value is a boolean
67
+ */
68
+ export function isBoolean(value) {
69
+ return typeof value === "boolean";
70
+ }
71
+ /**
72
+ * Type guard to check if a value is a function
73
+ *
74
+ * @param value - Value to check
75
+ * @returns true if value is a function
76
+ */
77
+ export function isFunction(value) {
78
+ return typeof value === "function";
79
+ }
80
+ /**
81
+ * Type guard to check if a value is null or undefined
82
+ *
83
+ * @param value - Value to check
84
+ * @returns true if value is null or undefined
85
+ */
86
+ export function isNullish(value) {
87
+ return value === null || value === undefined;
88
+ }
89
+ /**
90
+ * Type guard to check if a value is defined (not undefined)
91
+ *
92
+ * @param value - Value to check
93
+ * @returns true if value is not undefined
94
+ */
95
+ export function isDefined(value) {
96
+ return value !== undefined;
97
+ }
@@ -2,15 +2,16 @@
2
2
  * MCP Contract - Core Type Definitions
3
3
  * Industry standard camelCase interfaces for maximum flexibility
4
4
  */
5
+ import type { StandardRecord } from "../../types/typeAliases.js";
5
6
  /**
6
7
  * Generic execution context for MCP operations
7
8
  * All properties optional for maximum flexibility
8
9
  */
9
- export interface ExecutionContext<T = Record<string, unknown>> {
10
+ export interface ExecutionContext<T = StandardRecord> {
10
11
  sessionId?: string;
11
12
  userId?: string;
12
13
  config?: T;
13
- metadata?: Record<string, unknown>;
14
+ metadata?: StandardRecord;
14
15
  cacheOptions?: CacheOptions;
15
16
  fallbackOptions?: FallbackOptions;
16
17
  timeoutMs?: number;
@@ -41,14 +42,14 @@ export interface ToolInfo {
41
42
  description?: string;
42
43
  category?: string;
43
44
  serverId?: string;
44
- inputSchema?: Record<string, unknown>;
45
- outputSchema?: Record<string, unknown>;
45
+ inputSchema?: StandardRecord;
46
+ outputSchema?: StandardRecord;
46
47
  [key: string]: unknown;
47
48
  }
48
49
  /**
49
50
  * Discovered MCP server/plugin definition
50
51
  */
51
- export interface DiscoveredMcp<TTools = Record<string, unknown>> {
52
+ export interface DiscoveredMcp<TTools = StandardRecord> {
52
53
  metadata: McpMetadata;
53
54
  tools?: TTools;
54
55
  capabilities?: string[];
@@ -68,20 +69,6 @@ export interface McpMetadata {
68
69
  repository?: string;
69
70
  category?: string;
70
71
  }
71
- /**
72
- * Tool definition schema
73
- */
74
- export interface ToolDefinition {
75
- description?: string;
76
- inputSchema?: Record<string, unknown>;
77
- outputSchema?: Record<string, unknown>;
78
- category?: string;
79
- examples?: Array<{
80
- input: Record<string, unknown>;
81
- output: Record<string, unknown>;
82
- description?: string;
83
- }>;
84
- }
85
72
  /**
86
73
  * Tool execution result
87
74
  */
@@ -11,6 +11,7 @@ import { ToolDiscoveryService } from "./toolDiscoveryService.js";
11
11
  import type { ExternalMCPServerInstance, ExternalMCPServerHealth, ExternalMCPConfigValidation, ExternalMCPOperationResult, ExternalMCPManagerConfig, ExternalMCPToolInfo } from "../types/externalMcp.js";
12
12
  import type { MCPServerInfo } from "../types/mcpTypes.js";
13
13
  import type { JsonObject } from "../types/common.js";
14
+ import type { ServerLoadResult } from "../types/typeAliases.js";
14
15
  export declare class ExternalServerManager extends EventEmitter {
15
16
  private servers;
16
17
  private config;
@@ -26,10 +27,7 @@ export declare class ExternalServerManager extends EventEmitter {
26
27
  * @param configPath Optional path to config file (defaults to .mcp-config.json in cwd)
27
28
  * @returns Promise resolving to number of servers loaded
28
29
  */
29
- loadMCPConfiguration(configPath?: string): Promise<{
30
- serversLoaded: number;
31
- errors: string[];
32
- }>;
30
+ loadMCPConfiguration(configPath?: string): Promise<ServerLoadResult>;
33
31
  /**
34
32
  * Validate external MCP server configuration
35
33
  */
@@ -12,11 +12,12 @@ import { MCPClientFactory } from "./mcpClientFactory.js";
12
12
  import { ToolDiscoveryService } from "./toolDiscoveryService.js";
13
13
  import { toolRegistry } from "./toolRegistry.js";
14
14
  import { detectCategory } from "../utils/mcpDefaults.js";
15
+ import { isObject, isNonNullObject } from "../utils/typeUtils.js";
15
16
  /**
16
17
  * Type guard to validate if an object can be safely used as Record<string, JsonValue>
17
18
  */
18
19
  function isValidJsonRecord(value) {
19
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
20
+ if (!isObject(value)) {
20
21
  return false;
21
22
  }
22
23
  const record = value;
@@ -35,7 +36,7 @@ function isValidJsonRecord(value) {
35
36
  typeof item === "boolean" ||
36
37
  item === null);
37
38
  }
38
- if (typeof val === "object" && val !== null) {
39
+ if (isNonNullObject(val)) {
39
40
  return isValidJsonRecord(val);
40
41
  }
41
42
  return false;
@@ -51,14 +52,13 @@ function safeMetadataConversion(metadata) {
51
52
  * Type guard to validate external MCP server configuration
52
53
  */
53
54
  function isValidExternalMCPServerConfig(config) {
54
- if (typeof config !== "object" || config === null) {
55
+ if (!isNonNullObject(config)) {
55
56
  return false;
56
57
  }
57
58
  const record = config;
58
59
  return (typeof record.command === "string" &&
59
60
  (record.args === undefined || Array.isArray(record.args)) &&
60
- (record.env === undefined ||
61
- (typeof record.env === "object" && record.env !== null)) &&
61
+ (record.env === undefined || isNonNullObject(record.env)) &&
62
62
  (record.transport === undefined || typeof record.transport === "string") &&
63
63
  (record.timeout === undefined || typeof record.timeout === "number") &&
64
64
  (record.retries === undefined || typeof record.retries === "number") &&
@@ -68,8 +68,7 @@ function isValidExternalMCPServerConfig(config) {
68
68
  typeof record.autoRestart === "boolean") &&
69
69
  (record.cwd === undefined || typeof record.cwd === "string") &&
70
70
  (record.url === undefined || typeof record.url === "string") &&
71
- (record.metadata === undefined ||
72
- (typeof record.metadata === "object" && record.metadata !== null)));
71
+ (record.metadata === undefined || isNonNullObject(record.metadata)));
73
72
  }
74
73
  export class ExternalServerManager extends EventEmitter {
75
74
  servers = new Map();
@@ -150,7 +149,7 @@ export class ExternalServerManager extends EventEmitter {
150
149
  args: Array.isArray(serverConfig.args)
151
150
  ? serverConfig.args
152
151
  : [],
153
- env: typeof serverConfig.env === "object" && serverConfig.env !== null
152
+ env: isNonNullObject(serverConfig.env)
154
153
  ? serverConfig.env
155
154
  : {},
156
155
  timeout: typeof serverConfig.timeout === "number"