@juspay/neurolink 7.29.1 → 7.29.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.
- package/CHANGELOG.md +12 -0
- package/dist/cli/commands/config.d.ts +86 -86
- package/dist/cli/commands/mcp.js +64 -9
- package/dist/cli/commands/models.js +25 -21
- package/dist/cli/commands/ollama.js +2 -2
- package/dist/cli/factories/commandFactory.d.ts +9 -0
- package/dist/cli/factories/commandFactory.js +177 -83
- package/dist/cli/factories/ollamaCommandFactory.js +3 -1
- package/dist/cli/factories/sagemakerCommandFactory.js +3 -2
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +19 -11
- package/dist/cli/utils/envManager.js +5 -5
- package/dist/cli/utils/ollamaUtils.d.ts +12 -0
- package/dist/cli/utils/ollamaUtils.js +58 -42
- package/dist/config/configManager.js +5 -2
- package/dist/core/analytics.d.ts +2 -24
- package/dist/core/analytics.js +12 -17
- package/dist/core/baseProvider.d.ts +30 -1
- package/dist/core/baseProvider.js +180 -198
- package/dist/core/dynamicModels.d.ts +4 -4
- package/dist/core/dynamicModels.js +7 -7
- package/dist/core/evaluation.d.ts +9 -9
- package/dist/core/evaluation.js +117 -65
- package/dist/core/evaluationProviders.d.ts +18 -2
- package/dist/core/evaluationProviders.js +15 -13
- package/dist/core/factory.js +77 -4
- package/dist/core/modelConfiguration.d.ts +63 -0
- package/dist/core/modelConfiguration.js +354 -290
- package/dist/core/streamAnalytics.d.ts +10 -5
- package/dist/core/streamAnalytics.js +10 -10
- package/dist/core/types.d.ts +19 -109
- package/dist/core/types.js +13 -0
- package/dist/factories/providerFactory.js +4 -1
- package/dist/factories/providerRegistry.js +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/lib/config/configManager.js +5 -2
- package/dist/lib/core/analytics.d.ts +2 -24
- package/dist/lib/core/analytics.js +12 -17
- package/dist/lib/core/baseProvider.d.ts +30 -1
- package/dist/lib/core/baseProvider.js +180 -198
- package/dist/lib/core/dynamicModels.js +7 -7
- package/dist/lib/core/evaluation.d.ts +9 -9
- package/dist/lib/core/evaluation.js +117 -65
- package/dist/lib/core/evaluationProviders.d.ts +18 -2
- package/dist/lib/core/evaluationProviders.js +15 -13
- package/dist/lib/core/factory.js +77 -4
- package/dist/lib/core/modelConfiguration.d.ts +63 -0
- package/dist/lib/core/modelConfiguration.js +354 -290
- package/dist/lib/core/streamAnalytics.d.ts +10 -5
- package/dist/lib/core/streamAnalytics.js +10 -10
- package/dist/lib/core/types.d.ts +19 -109
- package/dist/lib/core/types.js +13 -0
- package/dist/lib/factories/providerFactory.js +4 -1
- package/dist/lib/factories/providerRegistry.js +2 -2
- package/dist/lib/index.d.ts +2 -1
- package/dist/lib/mcp/externalServerManager.js +14 -6
- package/dist/lib/mcp/factory.js +1 -1
- package/dist/lib/mcp/flexibleToolValidator.d.ts +50 -0
- package/dist/lib/mcp/flexibleToolValidator.js +161 -0
- package/dist/lib/mcp/index.d.ts +1 -1
- package/dist/lib/mcp/index.js +1 -1
- package/dist/lib/mcp/mcpCircuitBreaker.js +5 -1
- package/dist/lib/mcp/mcpClientFactory.js +3 -0
- package/dist/lib/mcp/registry.d.ts +3 -3
- package/dist/lib/mcp/registry.js +3 -3
- package/dist/lib/mcp/servers/aiProviders/aiAnalysisTools.js +5 -5
- package/dist/lib/mcp/servers/aiProviders/aiWorkflowTools.js +6 -6
- package/dist/lib/mcp/servers/utilities/utilityServer.js +1 -1
- package/dist/lib/mcp/toolDiscoveryService.js +8 -2
- package/dist/lib/mcp/toolRegistry.d.ts +2 -2
- package/dist/lib/mcp/toolRegistry.js +29 -54
- package/dist/lib/middleware/builtin/analytics.js +4 -4
- package/dist/lib/middleware/builtin/guardrails.js +2 -2
- package/dist/lib/middleware/registry.js +11 -2
- package/dist/lib/models/modelRegistry.d.ts +1 -1
- package/dist/lib/models/modelRegistry.js +3 -3
- package/dist/lib/models/modelResolver.d.ts +1 -1
- package/dist/lib/models/modelResolver.js +2 -2
- package/dist/lib/neurolink.d.ts +118 -0
- package/dist/lib/neurolink.js +814 -952
- package/dist/lib/providers/amazonBedrock.d.ts +47 -6
- package/dist/lib/providers/amazonBedrock.js +282 -23
- package/dist/lib/providers/amazonSagemaker.d.ts +1 -1
- package/dist/lib/providers/amazonSagemaker.js +12 -3
- package/dist/lib/providers/anthropic.d.ts +1 -1
- package/dist/lib/providers/anthropic.js +7 -6
- package/dist/lib/providers/anthropicBaseProvider.d.ts +1 -1
- package/dist/lib/providers/anthropicBaseProvider.js +4 -3
- package/dist/lib/providers/aws/credentialProvider.d.ts +58 -0
- package/dist/lib/providers/aws/credentialProvider.js +267 -0
- package/dist/lib/providers/aws/credentialTester.d.ts +49 -0
- package/dist/lib/providers/aws/credentialTester.js +394 -0
- package/dist/lib/providers/azureOpenai.d.ts +1 -1
- package/dist/lib/providers/azureOpenai.js +1 -1
- package/dist/lib/providers/googleAiStudio.d.ts +1 -1
- package/dist/lib/providers/googleAiStudio.js +2 -2
- package/dist/lib/providers/googleVertex.d.ts +40 -0
- package/dist/lib/providers/googleVertex.js +330 -274
- package/dist/lib/providers/huggingFace.js +1 -1
- package/dist/lib/providers/mistral.d.ts +1 -1
- package/dist/lib/providers/mistral.js +2 -2
- package/dist/lib/providers/ollama.d.ts +4 -0
- package/dist/lib/providers/ollama.js +38 -18
- package/dist/lib/providers/openAI.d.ts +1 -1
- package/dist/lib/providers/openAI.js +2 -2
- package/dist/lib/providers/sagemaker/adaptive-semaphore.js +7 -4
- package/dist/lib/providers/sagemaker/client.js +13 -3
- package/dist/lib/providers/sagemaker/config.js +5 -1
- package/dist/lib/providers/sagemaker/detection.js +19 -9
- package/dist/lib/providers/sagemaker/errors.d.ts +8 -1
- package/dist/lib/providers/sagemaker/errors.js +103 -20
- package/dist/lib/providers/sagemaker/language-model.d.ts +3 -3
- package/dist/lib/providers/sagemaker/language-model.js +4 -4
- package/dist/lib/providers/sagemaker/parsers.js +14 -6
- package/dist/lib/providers/sagemaker/streaming.js +14 -3
- package/dist/lib/providers/sagemaker/types.d.ts +1 -1
- package/dist/lib/proxy/awsProxyIntegration.d.ts +23 -0
- package/dist/lib/proxy/awsProxyIntegration.js +285 -0
- package/dist/lib/proxy/proxyFetch.d.ts +9 -5
- package/dist/lib/proxy/proxyFetch.js +232 -98
- package/dist/lib/proxy/utils/noProxyUtils.d.ts +39 -0
- package/dist/lib/proxy/utils/noProxyUtils.js +149 -0
- package/dist/lib/sdk/toolRegistration.d.ts +1 -1
- package/dist/lib/types/cli.d.ts +80 -8
- package/dist/lib/types/contextTypes.js +2 -2
- package/dist/lib/types/generateTypes.d.ts +4 -6
- package/dist/lib/types/providers.d.ts +124 -19
- package/dist/lib/types/providers.js +6 -6
- package/dist/lib/types/streamTypes.d.ts +4 -6
- package/dist/lib/types/typeAliases.d.ts +1 -1
- package/dist/lib/utils/analyticsUtils.d.ts +33 -0
- package/dist/lib/utils/analyticsUtils.js +76 -0
- package/dist/lib/utils/errorHandling.js +4 -1
- package/dist/lib/utils/evaluationUtils.d.ts +27 -0
- package/dist/lib/utils/evaluationUtils.js +131 -0
- package/dist/lib/utils/optionsUtils.js +10 -1
- package/dist/lib/utils/performance.d.ts +1 -1
- package/dist/lib/utils/performance.js +15 -3
- package/dist/lib/utils/providerConfig.d.ts +1 -0
- package/dist/lib/utils/providerConfig.js +2 -1
- package/dist/lib/utils/providerHealth.d.ts +48 -0
- package/dist/lib/utils/providerHealth.js +221 -158
- package/dist/lib/utils/providerUtils.js +2 -2
- package/dist/lib/utils/timeout.js +8 -3
- package/dist/mcp/externalServerManager.js +14 -6
- package/dist/mcp/factory.js +1 -1
- package/dist/mcp/flexibleToolValidator.d.ts +50 -0
- package/dist/mcp/flexibleToolValidator.js +161 -0
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/mcpCircuitBreaker.js +5 -1
- package/dist/mcp/mcpClientFactory.js +3 -0
- package/dist/mcp/registry.d.ts +3 -3
- package/dist/mcp/registry.js +3 -3
- package/dist/mcp/servers/aiProviders/aiAnalysisTools.js +5 -5
- package/dist/mcp/servers/aiProviders/aiWorkflowTools.js +6 -6
- package/dist/mcp/servers/utilities/utilityServer.js +1 -1
- package/dist/mcp/toolDiscoveryService.js +8 -2
- package/dist/mcp/toolRegistry.d.ts +2 -2
- package/dist/mcp/toolRegistry.js +29 -54
- package/dist/middleware/builtin/analytics.js +4 -4
- package/dist/middleware/builtin/guardrails.js +2 -2
- package/dist/middleware/registry.js +11 -2
- package/dist/models/modelRegistry.d.ts +1 -1
- package/dist/models/modelRegistry.js +3 -3
- package/dist/models/modelResolver.d.ts +1 -1
- package/dist/models/modelResolver.js +2 -2
- package/dist/neurolink.d.ts +118 -0
- package/dist/neurolink.js +814 -952
- package/dist/providers/amazonBedrock.d.ts +47 -6
- package/dist/providers/amazonBedrock.js +282 -23
- package/dist/providers/amazonSagemaker.d.ts +1 -1
- package/dist/providers/amazonSagemaker.js +12 -3
- package/dist/providers/anthropic.d.ts +1 -1
- package/dist/providers/anthropic.js +7 -6
- package/dist/providers/anthropicBaseProvider.d.ts +1 -1
- package/dist/providers/anthropicBaseProvider.js +4 -3
- package/dist/providers/aws/credentialProvider.d.ts +58 -0
- package/dist/providers/aws/credentialProvider.js +267 -0
- package/dist/providers/aws/credentialTester.d.ts +49 -0
- package/dist/providers/aws/credentialTester.js +394 -0
- package/dist/providers/azureOpenai.d.ts +1 -1
- package/dist/providers/azureOpenai.js +1 -1
- package/dist/providers/googleAiStudio.d.ts +1 -1
- package/dist/providers/googleAiStudio.js +2 -2
- package/dist/providers/googleVertex.d.ts +40 -0
- package/dist/providers/googleVertex.js +330 -274
- package/dist/providers/huggingFace.js +1 -1
- package/dist/providers/mistral.d.ts +1 -1
- package/dist/providers/mistral.js +2 -2
- package/dist/providers/ollama.d.ts +4 -0
- package/dist/providers/ollama.js +38 -18
- package/dist/providers/openAI.d.ts +1 -1
- package/dist/providers/openAI.js +2 -2
- package/dist/providers/sagemaker/adaptive-semaphore.js +7 -4
- package/dist/providers/sagemaker/client.js +13 -3
- package/dist/providers/sagemaker/config.js +5 -1
- package/dist/providers/sagemaker/detection.js +19 -9
- package/dist/providers/sagemaker/errors.d.ts +8 -1
- package/dist/providers/sagemaker/errors.js +103 -20
- package/dist/providers/sagemaker/language-model.d.ts +3 -3
- package/dist/providers/sagemaker/language-model.js +4 -4
- package/dist/providers/sagemaker/parsers.js +14 -6
- package/dist/providers/sagemaker/streaming.js +14 -3
- package/dist/providers/sagemaker/types.d.ts +1 -1
- package/dist/proxy/awsProxyIntegration.d.ts +23 -0
- package/dist/proxy/awsProxyIntegration.js +285 -0
- package/dist/proxy/proxyFetch.d.ts +9 -5
- package/dist/proxy/proxyFetch.js +232 -98
- package/dist/proxy/utils/noProxyUtils.d.ts +39 -0
- package/dist/proxy/utils/noProxyUtils.js +149 -0
- package/dist/sdk/toolRegistration.d.ts +1 -1
- package/dist/types/cli.d.ts +80 -8
- package/dist/types/contextTypes.js +2 -2
- package/dist/types/generateTypes.d.ts +4 -6
- package/dist/types/providers.d.ts +124 -19
- package/dist/types/providers.js +6 -6
- package/dist/types/streamTypes.d.ts +4 -6
- package/dist/types/typeAliases.d.ts +1 -1
- package/dist/utils/analyticsUtils.d.ts +33 -0
- package/dist/utils/analyticsUtils.js +76 -0
- package/dist/utils/errorHandling.js +4 -1
- package/dist/utils/evaluationUtils.d.ts +27 -0
- package/dist/utils/evaluationUtils.js +131 -0
- package/dist/utils/optionsUtils.js +10 -1
- package/dist/utils/performance.d.ts +1 -1
- package/dist/utils/performance.js +15 -3
- package/dist/utils/providerConfig.d.ts +1 -0
- package/dist/utils/providerConfig.js +2 -1
- package/dist/utils/providerHealth.d.ts +48 -0
- package/dist/utils/providerHealth.js +221 -158
- package/dist/utils/providerUtils.js +2 -2
- package/dist/utils/timeout.js +8 -3
- package/package.json +5 -1
|
@@ -357,6 +357,9 @@ export class ExternalServerManager extends EventEmitter {
|
|
|
357
357
|
// Start the server
|
|
358
358
|
await this.startServer(serverId);
|
|
359
359
|
const finalInstance = this.servers.get(serverId);
|
|
360
|
+
if (!finalInstance) {
|
|
361
|
+
throw new Error(`Server ${serverId} not found after registration`);
|
|
362
|
+
}
|
|
360
363
|
// Convert RuntimeMCPServerInfo to ExternalMCPServerInstance for return
|
|
361
364
|
const convertedInstance = {
|
|
362
365
|
config: finalInstance.config,
|
|
@@ -664,6 +667,9 @@ export class ExternalServerManager extends EventEmitter {
|
|
|
664
667
|
const delay = Math.min(1000 *
|
|
665
668
|
Math.pow(this.config.restartBackoffMultiplier, instance.reconnectAttempts - 1), 30000);
|
|
666
669
|
mcpLogger.info(`[ExternalServerManager] Scheduling restart for ${serverId} in ${delay}ms (attempt ${instance.reconnectAttempts})`);
|
|
670
|
+
if (instance.restartTimer) {
|
|
671
|
+
return;
|
|
672
|
+
} // already scheduled
|
|
667
673
|
instance.restartTimer = setTimeout(async () => {
|
|
668
674
|
try {
|
|
669
675
|
await this.stopServer(serverId);
|
|
@@ -914,6 +920,7 @@ export class ExternalServerManager extends EventEmitter {
|
|
|
914
920
|
}
|
|
915
921
|
try {
|
|
916
922
|
mcpLogger.debug(`[ExternalServerManager] Registering ${instance.toolsMap.size} tools with main registry for server: ${serverId}`);
|
|
923
|
+
const registrations = [];
|
|
917
924
|
for (const [toolName, tool] of instance.toolsMap.entries()) {
|
|
918
925
|
const toolId = `${serverId}.${toolName}`;
|
|
919
926
|
const toolInfo = {
|
|
@@ -923,21 +930,23 @@ export class ExternalServerManager extends EventEmitter {
|
|
|
923
930
|
serverId: serverId,
|
|
924
931
|
category: detectCategory({ isExternal: true, serverId }),
|
|
925
932
|
};
|
|
926
|
-
// Register with main tool registry
|
|
927
933
|
try {
|
|
928
|
-
toolRegistry.registerTool(toolId, toolInfo, {
|
|
929
|
-
execute: async (params,
|
|
934
|
+
registrations.push(toolRegistry.registerTool(toolId, toolInfo, {
|
|
935
|
+
execute: async (params, _context) => {
|
|
930
936
|
// Execute tool via ExternalServerManager for proper lifecycle management
|
|
931
937
|
return await this.executeTool(serverId, toolName, params, { timeout: this.config.defaultTimeout });
|
|
932
938
|
},
|
|
933
|
-
});
|
|
939
|
+
}));
|
|
934
940
|
mcpLogger.debug(`[ExternalServerManager] Registered tool with main registry: ${toolId}`);
|
|
935
941
|
}
|
|
936
942
|
catch (registrationError) {
|
|
937
943
|
mcpLogger.warn(`[ExternalServerManager] Failed to register tool ${toolId} with main registry:`, registrationError);
|
|
938
944
|
}
|
|
939
945
|
}
|
|
940
|
-
|
|
946
|
+
const results = await Promise.allSettled(registrations);
|
|
947
|
+
const ok = results.filter((r) => r.status === "fulfilled").length;
|
|
948
|
+
const failed = results.length - ok;
|
|
949
|
+
mcpLogger.info(`[ExternalServerManager] Registered ${ok}/${results.length} tools with main registry for ${serverId}${failed ? ` (${failed} failed)` : ""}`);
|
|
941
950
|
}
|
|
942
951
|
catch (error) {
|
|
943
952
|
mcpLogger.error(`[ExternalServerManager] Failed to register tools with main registry for ${serverId}:`, error);
|
|
@@ -1010,7 +1019,6 @@ export class ExternalServerManager extends EventEmitter {
|
|
|
1010
1019
|
}
|
|
1011
1020
|
}
|
|
1012
1021
|
catch (error) {
|
|
1013
|
-
const duration = Date.now() - startTime;
|
|
1014
1022
|
instance.metrics.totalErrors++;
|
|
1015
1023
|
mcpLogger.error(`[ExternalServerManager] Tool execution failed: ${toolName} on ${serverId}`, error);
|
|
1016
1024
|
throw error;
|
package/dist/mcp/factory.js
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FlexibleToolValidator - Universal Safety Checks Only
|
|
3
|
+
*
|
|
4
|
+
* Following Anthropic's MCP specification which intentionally leaves tool naming flexible,
|
|
5
|
+
* this validator only blocks truly dangerous cases to support maximum MCP tool compatibility.
|
|
6
|
+
*
|
|
7
|
+
* Phase 1 Implementation:
|
|
8
|
+
* - Universal safety checks only (empty names, control characters, excessive length)
|
|
9
|
+
* - No context-specific validation or arbitrary pattern restrictions
|
|
10
|
+
* - Designed to support ALL legitimate MCP tools (github.create_repo, filesystem.read_file, etc.)
|
|
11
|
+
*/
|
|
12
|
+
export interface FlexibleValidationResult {
|
|
13
|
+
isValid: boolean;
|
|
14
|
+
error?: string;
|
|
15
|
+
warnings?: string[];
|
|
16
|
+
}
|
|
17
|
+
export declare class FlexibleToolValidator {
|
|
18
|
+
private static readonly MAX_TOOL_NAME_LENGTH;
|
|
19
|
+
private static readonly MIN_TOOL_NAME_LENGTH;
|
|
20
|
+
/**
|
|
21
|
+
* Validate tool name with universal safety checks only
|
|
22
|
+
*
|
|
23
|
+
* This method only blocks truly dangerous cases:
|
|
24
|
+
* 1. Empty or whitespace-only names
|
|
25
|
+
* 2. Control characters that could break systems
|
|
26
|
+
* 3. Excessively long names that could cause memory issues
|
|
27
|
+
*
|
|
28
|
+
* Everything else is allowed to support maximum MCP tool compatibility.
|
|
29
|
+
*/
|
|
30
|
+
static validateToolName(toolId: string): FlexibleValidationResult;
|
|
31
|
+
/**
|
|
32
|
+
* Validate tool information with minimal safety checks
|
|
33
|
+
*/
|
|
34
|
+
static validateToolInfo(toolId: string, toolInfo: {
|
|
35
|
+
description?: string;
|
|
36
|
+
serverId?: string;
|
|
37
|
+
}): FlexibleValidationResult;
|
|
38
|
+
/**
|
|
39
|
+
* Get information about what this validator checks
|
|
40
|
+
*/
|
|
41
|
+
static getValidationInfo(): {
|
|
42
|
+
philosophy: string;
|
|
43
|
+
checks: string[];
|
|
44
|
+
whatIsAllowed: string[];
|
|
45
|
+
examples: {
|
|
46
|
+
valid: string[];
|
|
47
|
+
invalid: string[];
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FlexibleToolValidator - Universal Safety Checks Only
|
|
3
|
+
*
|
|
4
|
+
* Following Anthropic's MCP specification which intentionally leaves tool naming flexible,
|
|
5
|
+
* this validator only blocks truly dangerous cases to support maximum MCP tool compatibility.
|
|
6
|
+
*
|
|
7
|
+
* Phase 1 Implementation:
|
|
8
|
+
* - Universal safety checks only (empty names, control characters, excessive length)
|
|
9
|
+
* - No context-specific validation or arbitrary pattern restrictions
|
|
10
|
+
* - Designed to support ALL legitimate MCP tools (github.create_repo, filesystem.read_file, etc.)
|
|
11
|
+
*/
|
|
12
|
+
import { registryLogger } from "../utils/logger.js";
|
|
13
|
+
export class FlexibleToolValidator {
|
|
14
|
+
// Universal safety limits (generous to support all legitimate tools)
|
|
15
|
+
static MAX_TOOL_NAME_LENGTH = 1000; // Much more generous than npm's 214
|
|
16
|
+
static MIN_TOOL_NAME_LENGTH = 1;
|
|
17
|
+
/**
|
|
18
|
+
* Validate tool name with universal safety checks only
|
|
19
|
+
*
|
|
20
|
+
* This method only blocks truly dangerous cases:
|
|
21
|
+
* 1. Empty or whitespace-only names
|
|
22
|
+
* 2. Control characters that could break systems
|
|
23
|
+
* 3. Excessively long names that could cause memory issues
|
|
24
|
+
*
|
|
25
|
+
* Everything else is allowed to support maximum MCP tool compatibility.
|
|
26
|
+
*/
|
|
27
|
+
static validateToolName(toolId) {
|
|
28
|
+
const warnings = [];
|
|
29
|
+
// Safety Check 1: Empty or whitespace-only names
|
|
30
|
+
if (!toolId || typeof toolId !== "string") {
|
|
31
|
+
return {
|
|
32
|
+
isValid: false,
|
|
33
|
+
error: "Tool name is required and must be a string",
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
// Safety Check 2: Control characters that could break systems (check BEFORE trimming!)
|
|
37
|
+
// Only block truly dangerous control characters, not printable characters
|
|
38
|
+
//
|
|
39
|
+
// This regex blocks dangerous C0 control characters and DEL:
|
|
40
|
+
// - \x00-\x08: NULL, SOH, STX, ETX, EOT, ENQ, ACK, BEL, BS
|
|
41
|
+
// - \x0B: Vertical Tab (VT)
|
|
42
|
+
// - \x0C: Form Feed (FF)
|
|
43
|
+
// - \x0E-\x1F: SO, SI, DLE, DC1-4, NAK, SYN, ETB, CAN, EM, SUB, ESC, FS-US
|
|
44
|
+
// - \x7F: DEL
|
|
45
|
+
//
|
|
46
|
+
// Explicitly ALLOWS these printable control characters:
|
|
47
|
+
// - \x09: TAB (horizontal tab) - commonly used in text
|
|
48
|
+
// - \x0A: LF (line feed) - commonly used in text
|
|
49
|
+
// - \x0D: CR (carriage return) - commonly used in text
|
|
50
|
+
// eslint-disable-next-line no-control-regex
|
|
51
|
+
const hasControlCharacters = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/.test(toolId);
|
|
52
|
+
if (hasControlCharacters) {
|
|
53
|
+
return {
|
|
54
|
+
isValid: false,
|
|
55
|
+
error: "Tool name contains control characters that could break systems",
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const trimmedName = toolId.trim();
|
|
59
|
+
if (trimmedName.length === 0) {
|
|
60
|
+
return {
|
|
61
|
+
isValid: false,
|
|
62
|
+
error: "Tool name cannot be empty or whitespace-only",
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
// Safety Check 3: Length limits (very generous)
|
|
66
|
+
if (trimmedName.length < this.MIN_TOOL_NAME_LENGTH) {
|
|
67
|
+
return {
|
|
68
|
+
isValid: false,
|
|
69
|
+
error: `Tool name must be at least ${this.MIN_TOOL_NAME_LENGTH} character long`,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (trimmedName.length > this.MAX_TOOL_NAME_LENGTH) {
|
|
73
|
+
return {
|
|
74
|
+
isValid: false,
|
|
75
|
+
error: `Tool name exceeds maximum length of ${this.MAX_TOOL_NAME_LENGTH} characters`,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
// Optional warnings for unusual but not dangerous patterns
|
|
79
|
+
if (trimmedName !== toolId) {
|
|
80
|
+
warnings.push("Tool name has leading/trailing whitespace (will be trimmed)");
|
|
81
|
+
}
|
|
82
|
+
if (trimmedName.length > 200) {
|
|
83
|
+
warnings.push("Tool name is unusually long but allowed");
|
|
84
|
+
}
|
|
85
|
+
registryLogger.debug(`✅ FlexibleToolValidator: Tool '${toolId}' passed universal safety checks`);
|
|
86
|
+
return {
|
|
87
|
+
isValid: true,
|
|
88
|
+
warnings: warnings.length > 0 ? warnings : undefined,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Validate tool information with minimal safety checks
|
|
93
|
+
*/
|
|
94
|
+
static validateToolInfo(toolId, toolInfo) {
|
|
95
|
+
// First validate the tool name
|
|
96
|
+
const nameValidation = this.validateToolName(toolId);
|
|
97
|
+
if (!nameValidation.isValid) {
|
|
98
|
+
return nameValidation;
|
|
99
|
+
}
|
|
100
|
+
const warnings = [...(nameValidation.warnings || [])];
|
|
101
|
+
// Minimal safety checks for tool info
|
|
102
|
+
if (toolInfo.description && typeof toolInfo.description !== "string") {
|
|
103
|
+
return {
|
|
104
|
+
isValid: false,
|
|
105
|
+
error: "Tool description must be a string if provided",
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
if (toolInfo.serverId && typeof toolInfo.serverId !== "string") {
|
|
109
|
+
return {
|
|
110
|
+
isValid: false,
|
|
111
|
+
error: "Tool serverId must be a string if provided",
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
registryLogger.debug(`✅ FlexibleToolValidator: Tool info for '${toolId}' passed validation`);
|
|
115
|
+
return {
|
|
116
|
+
isValid: true,
|
|
117
|
+
warnings: warnings.length > 0 ? warnings : undefined,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get information about what this validator checks
|
|
122
|
+
*/
|
|
123
|
+
static getValidationInfo() {
|
|
124
|
+
return {
|
|
125
|
+
philosophy: "Maximum flexibility with universal safety only - following Anthropic's MCP specification",
|
|
126
|
+
checks: [
|
|
127
|
+
"Empty or whitespace-only names",
|
|
128
|
+
"Excessive length (over 1000 characters)",
|
|
129
|
+
"Control characters that could break systems",
|
|
130
|
+
],
|
|
131
|
+
whatIsAllowed: [
|
|
132
|
+
"Dots (github.create_repo, filesystem.read_file)",
|
|
133
|
+
"Hyphens and underscores (my-tool, user_helper)",
|
|
134
|
+
"Numbers (tool1, my_tool_v2)",
|
|
135
|
+
"Unicode characters (🚀_tool, café_manager)",
|
|
136
|
+
"Mixed case (createRepo, ReadFile)",
|
|
137
|
+
"Long descriptive names (enterprise_database_connection_manager)",
|
|
138
|
+
"Any legitimate MCP tool naming pattern",
|
|
139
|
+
],
|
|
140
|
+
examples: {
|
|
141
|
+
valid: [
|
|
142
|
+
"github.create_repo",
|
|
143
|
+
"filesystem.read_file",
|
|
144
|
+
"my-custom-tool",
|
|
145
|
+
"user_helper",
|
|
146
|
+
"tool1",
|
|
147
|
+
"🚀_rocket_tool",
|
|
148
|
+
"enterprise.database.connection.manager",
|
|
149
|
+
"UPPERCASE_TOOL",
|
|
150
|
+
"mixed_Case.Tool-Name_123",
|
|
151
|
+
],
|
|
152
|
+
invalid: [
|
|
153
|
+
"", // Empty
|
|
154
|
+
" ", // Whitespace only
|
|
155
|
+
"tool\x00", // Control character
|
|
156
|
+
"a".repeat(1001), // Too long
|
|
157
|
+
],
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
package/dist/mcp/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare function listMCPs(): Promise<McpMetadata[]>;
|
|
|
18
18
|
/**
|
|
19
19
|
* Execute an MCP operation - simplified
|
|
20
20
|
*/
|
|
21
|
-
export declare function executeMCP<T = unknown>(
|
|
21
|
+
export declare function executeMCP<T = unknown>(_name: string, _config: unknown, _args: unknown, _context?: {
|
|
22
22
|
sessionId?: string;
|
|
23
23
|
userId?: string;
|
|
24
24
|
}): Promise<T>;
|
package/dist/mcp/index.js
CHANGED
|
@@ -21,7 +21,7 @@ export async function listMCPs() {
|
|
|
21
21
|
/**
|
|
22
22
|
* Execute an MCP operation - simplified
|
|
23
23
|
*/
|
|
24
|
-
export async function executeMCP(
|
|
24
|
+
export async function executeMCP(_name, _config, _args, _context) {
|
|
25
25
|
throw new Error("MCP execution not available - ecosystem removed");
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
@@ -285,7 +285,11 @@ export class CircuitBreakerManager {
|
|
|
285
285
|
this.breakers.set(name, breaker);
|
|
286
286
|
mcpLogger.debug(`[CircuitBreakerManager] Created circuit breaker: ${name}`);
|
|
287
287
|
}
|
|
288
|
-
|
|
288
|
+
const breaker = this.breakers.get(name);
|
|
289
|
+
if (!breaker) {
|
|
290
|
+
throw new Error(`Circuit breaker ${name} not found after creation`);
|
|
291
|
+
}
|
|
292
|
+
return breaker;
|
|
289
293
|
}
|
|
290
294
|
/**
|
|
291
295
|
* Remove a circuit breaker and clean up its resources
|
|
@@ -192,6 +192,9 @@ export class MCPClientFactory {
|
|
|
192
192
|
throw new Error("Process failed to start or exited immediately");
|
|
193
193
|
}
|
|
194
194
|
// Create transport
|
|
195
|
+
if (!config.command) {
|
|
196
|
+
throw new Error(`Command is required for stdio transport`);
|
|
197
|
+
}
|
|
195
198
|
const transport = new StdioClientTransport({
|
|
196
199
|
command: config.command,
|
|
197
200
|
args: config.args || [],
|
package/dist/mcp/registry.d.ts
CHANGED
|
@@ -44,15 +44,15 @@ export declare class MCPRegistry implements McpRegistry {
|
|
|
44
44
|
/**
|
|
45
45
|
* Register a server (compatible with new interface)
|
|
46
46
|
*/
|
|
47
|
-
registerServer(serverId: string, serverConfig?: unknown,
|
|
47
|
+
registerServer(serverId: string, serverConfig?: unknown, _context?: ExecutionContext): Promise<void>;
|
|
48
48
|
/**
|
|
49
49
|
* Execute a tool (mock implementation for tests)
|
|
50
50
|
*/
|
|
51
|
-
executeTool<T = unknown>(toolName: string, args?: unknown,
|
|
51
|
+
executeTool<T = unknown>(toolName: string, args?: unknown, _context?: ExecutionContext): Promise<T>;
|
|
52
52
|
/**
|
|
53
53
|
* List all tools (compatible with new interface)
|
|
54
54
|
*/
|
|
55
|
-
listTools(
|
|
55
|
+
listTools(_context?: ExecutionContext): Promise<ToolInfo[]>;
|
|
56
56
|
/**
|
|
57
57
|
* Register a server (legacy sync version)
|
|
58
58
|
*/
|
package/dist/mcp/registry.js
CHANGED
|
@@ -53,7 +53,7 @@ export class MCPRegistry {
|
|
|
53
53
|
/**
|
|
54
54
|
* Register a server (compatible with new interface)
|
|
55
55
|
*/
|
|
56
|
-
async registerServer(serverId, serverConfig,
|
|
56
|
+
async registerServer(serverId, serverConfig, _context) {
|
|
57
57
|
const plugin = {
|
|
58
58
|
metadata: {
|
|
59
59
|
name: serverId,
|
|
@@ -74,14 +74,14 @@ export class MCPRegistry {
|
|
|
74
74
|
/**
|
|
75
75
|
* Execute a tool (mock implementation for tests)
|
|
76
76
|
*/
|
|
77
|
-
async executeTool(toolName, args,
|
|
77
|
+
async executeTool(toolName, args, _context) {
|
|
78
78
|
registryLogger.info(`Executing tool: ${toolName}`);
|
|
79
79
|
return { result: `Mock execution of ${toolName}`, args };
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
82
|
* List all tools (compatible with new interface)
|
|
83
83
|
*/
|
|
84
|
-
async listTools(
|
|
84
|
+
async listTools(_context) {
|
|
85
85
|
const tools = this.list().map((plugin) => ({
|
|
86
86
|
name: plugin.metadata.name,
|
|
87
87
|
description: plugin.metadata.description || "No description",
|
|
@@ -78,7 +78,7 @@ const OptimizeParametersSchema = z.object({
|
|
|
78
78
|
* AI Usage Analysis Tool
|
|
79
79
|
* Analyzes AI usage patterns, token consumption, and cost optimization opportunities
|
|
80
80
|
*/
|
|
81
|
-
const
|
|
81
|
+
const _analyzeAIUsageTool = {
|
|
82
82
|
name: "analyze-ai-usage",
|
|
83
83
|
description: "Analyze AI usage patterns, token consumption, and cost optimization opportunities",
|
|
84
84
|
category: "ai-analysis",
|
|
@@ -163,7 +163,7 @@ const analyzeAIUsageTool = {
|
|
|
163
163
|
* Provider Performance Benchmarking Tool
|
|
164
164
|
* Benchmarks AI provider performance across latency, quality, and cost metrics
|
|
165
165
|
*/
|
|
166
|
-
const
|
|
166
|
+
const _benchmarkProviderPerformanceTool = {
|
|
167
167
|
name: "benchmark-provider-performance",
|
|
168
168
|
description: "Benchmark AI provider performance across latency, quality, and cost metrics",
|
|
169
169
|
category: "ai-analysis",
|
|
@@ -199,7 +199,7 @@ const benchmarkProviderPerformanceTool = {
|
|
|
199
199
|
});
|
|
200
200
|
if (result && result.usage) {
|
|
201
201
|
totalLatency += Date.now() - testStartTime;
|
|
202
|
-
totalTokens += result.usage.
|
|
202
|
+
totalTokens += result.usage.total || 0;
|
|
203
203
|
successfulTests++;
|
|
204
204
|
}
|
|
205
205
|
}
|
|
@@ -210,7 +210,7 @@ const benchmarkProviderPerformanceTool = {
|
|
|
210
210
|
avgLatency: successfulTests > 0
|
|
211
211
|
? Math.round(totalLatency / successfulTests)
|
|
212
212
|
: 0,
|
|
213
|
-
|
|
213
|
+
total: totalTokens,
|
|
214
214
|
successRate: (successfulTests /
|
|
215
215
|
(testPrompts.length * typedParams.iterations)) *
|
|
216
216
|
100,
|
|
@@ -259,7 +259,7 @@ const benchmarkProviderPerformanceTool = {
|
|
|
259
259
|
* Prompt Parameter Optimization Tool
|
|
260
260
|
* Optimizes prompt parameters (temperature, max tokens) for better AI output quality and efficiency
|
|
261
261
|
*/
|
|
262
|
-
const
|
|
262
|
+
const _optimizePromptParametersTool = {
|
|
263
263
|
name: "optimize-prompt-parameters",
|
|
264
264
|
description: "Optimize prompt parameters (temperature, max tokens) for better AI output quality and efficiency",
|
|
265
265
|
category: "ai-optimization",
|
|
@@ -99,7 +99,7 @@ const debugAIOutputSchema = z.object({
|
|
|
99
99
|
/**
|
|
100
100
|
* Generate test cases for code functions
|
|
101
101
|
*/
|
|
102
|
-
const
|
|
102
|
+
const _generateTestCasesTool = {
|
|
103
103
|
name: "generate-test-cases",
|
|
104
104
|
description: "Generate comprehensive test cases for code functions with various test types and frameworks",
|
|
105
105
|
category: "ai-workflow",
|
|
@@ -203,7 +203,7 @@ Generate 3-5 comprehensive test cases covering the requested types.`;
|
|
|
203
203
|
/**
|
|
204
204
|
* Refactor code for improved quality
|
|
205
205
|
*/
|
|
206
|
-
const
|
|
206
|
+
const _refactorCodeTool = {
|
|
207
207
|
name: "refactor-code",
|
|
208
208
|
description: "AI-powered code refactoring for improved readability, performance, and maintainability",
|
|
209
209
|
category: "ai-workflow",
|
|
@@ -316,7 +316,7 @@ Focus on real, actionable improvements based on the specified objectives.`;
|
|
|
316
316
|
/**
|
|
317
317
|
* Generate documentation from code
|
|
318
318
|
*/
|
|
319
|
-
const
|
|
319
|
+
const _generateDocumentationTool = {
|
|
320
320
|
name: "generate-documentation",
|
|
321
321
|
description: "Automatically generate comprehensive documentation from code",
|
|
322
322
|
category: "ai-workflow",
|
|
@@ -427,7 +427,7 @@ Focus on creating accurate, useful documentation that explains the code's purpos
|
|
|
427
427
|
/**
|
|
428
428
|
* Debug AI-generated output
|
|
429
429
|
*/
|
|
430
|
-
const
|
|
430
|
+
const _debugAIOutputTool = {
|
|
431
431
|
name: "debug-ai-output",
|
|
432
432
|
description: "Analyze and debug AI-generated output to identify issues and suggest improvements",
|
|
433
433
|
category: "ai-workflow",
|
|
@@ -549,13 +549,13 @@ Provide thorough, actionable analysis focused on improving AI output quality.`;
|
|
|
549
549
|
},
|
|
550
550
|
};
|
|
551
551
|
// Helper functions
|
|
552
|
-
function
|
|
552
|
+
function _extractFunctionName(code) {
|
|
553
553
|
const match = code.match(/function\s+(\w+)|const\s+(\w+)\s*=|(\w+)\s*\(/);
|
|
554
554
|
return match
|
|
555
555
|
? match[1] || match[2] || match[3] || "processData"
|
|
556
556
|
: "processData";
|
|
557
557
|
}
|
|
558
|
-
function
|
|
558
|
+
function _simulateRefactoring(code, objectives, _styleGuide) {
|
|
559
559
|
// Simulate basic refactoring
|
|
560
560
|
let refactored = code;
|
|
561
561
|
if (objectives.includes("readability")) {
|
|
@@ -61,7 +61,7 @@ utilityServer.registerTool({
|
|
|
61
61
|
});
|
|
62
62
|
resultData.actualTimezone = timezone;
|
|
63
63
|
}
|
|
64
|
-
catch
|
|
64
|
+
catch {
|
|
65
65
|
const fallbackTimezone = "Asia/Kolkata";
|
|
66
66
|
logger.warn(`[Utility] Invalid timezone '${timezone}', falling back to ${fallbackTimezone}`);
|
|
67
67
|
resultData.localTime = now.toLocaleString("en-US", {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { EventEmitter } from "events";
|
|
7
7
|
import { mcpLogger } from "../utils/logger.js";
|
|
8
8
|
import { globalCircuitBreakerManager } from "./mcpCircuitBreaker.js";
|
|
9
|
-
import { isObject, isNullish
|
|
9
|
+
import { isObject, isNullish } from "../utils/typeUtils.js";
|
|
10
10
|
import { validateToolName, validateToolDescription, } from "../utils/parameterValidation.js";
|
|
11
11
|
/**
|
|
12
12
|
* ToolDiscoveryService
|
|
@@ -133,6 +133,9 @@ export class ToolDiscoveryService extends EventEmitter {
|
|
|
133
133
|
this.serverToolStorage.set(serverId, []);
|
|
134
134
|
}
|
|
135
135
|
const serverTools = this.serverToolStorage.get(serverId);
|
|
136
|
+
if (!serverTools) {
|
|
137
|
+
throw new Error(`Server tools storage not found for ${serverId}`);
|
|
138
|
+
}
|
|
136
139
|
// Add tool if not already present
|
|
137
140
|
if (!serverTools.find((t) => t.name === tool.name)) {
|
|
138
141
|
serverTools.push({
|
|
@@ -145,7 +148,10 @@ export class ToolDiscoveryService extends EventEmitter {
|
|
|
145
148
|
if (!this.serverTools.has(serverId)) {
|
|
146
149
|
this.serverTools.set(serverId, new Set());
|
|
147
150
|
}
|
|
148
|
-
this.serverTools.get(serverId)
|
|
151
|
+
const serverToolSet = this.serverTools.get(serverId);
|
|
152
|
+
if (serverToolSet) {
|
|
153
|
+
serverToolSet.add(tool.name);
|
|
154
|
+
}
|
|
149
155
|
registeredTools.push(toolInfo);
|
|
150
156
|
// Emit tool registered event
|
|
151
157
|
this.emit("toolRegistered", {
|
|
@@ -29,7 +29,7 @@ export interface ToolExecutionOptions {
|
|
|
29
29
|
}
|
|
30
30
|
export declare class MCPToolRegistry extends MCPRegistry {
|
|
31
31
|
private tools;
|
|
32
|
-
private
|
|
32
|
+
private toolImplementations;
|
|
33
33
|
private toolExecutionStats;
|
|
34
34
|
private builtInServerInfos;
|
|
35
35
|
constructor();
|
|
@@ -122,7 +122,7 @@ export declare class MCPToolRegistry extends MCPRegistry {
|
|
|
122
122
|
* Register a tool with implementation directly
|
|
123
123
|
* This is used for external MCP server tools
|
|
124
124
|
*/
|
|
125
|
-
registerTool(toolId: string, toolInfo: ToolInfo, toolImpl: ToolImplementation): void
|
|
125
|
+
registerTool(toolId: string, toolInfo: ToolInfo, toolImpl: ToolImplementation): Promise<void>;
|
|
126
126
|
/**
|
|
127
127
|
* Remove a tool
|
|
128
128
|
*/
|