@juspay/neurolink 4.0.0 → 4.1.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 +14 -5
- package/README.md +150 -92
- package/dist/lib/mcp/dynamic-chain-executor.d.ts +201 -0
- package/dist/lib/mcp/dynamic-chain-executor.js +489 -0
- package/dist/lib/mcp/dynamic-orchestrator.d.ts +109 -0
- package/dist/lib/mcp/dynamic-orchestrator.js +351 -0
- package/dist/lib/mcp/error-manager.d.ts +254 -0
- package/dist/lib/mcp/error-manager.js +501 -0
- package/dist/lib/mcp/error-recovery.d.ts +158 -0
- package/dist/lib/mcp/error-recovery.js +405 -0
- package/dist/lib/mcp/health-monitor.d.ts +256 -0
- package/dist/lib/mcp/health-monitor.js +621 -0
- package/dist/lib/mcp/orchestrator.d.ts +136 -5
- package/dist/lib/mcp/orchestrator.js +316 -9
- package/dist/lib/mcp/registry.d.ts +22 -0
- package/dist/lib/mcp/registry.js +24 -0
- package/dist/lib/mcp/semaphore-manager.d.ts +137 -0
- package/dist/lib/mcp/semaphore-manager.js +329 -0
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
- package/dist/lib/mcp/session-manager.d.ts +186 -0
- package/dist/lib/mcp/session-manager.js +400 -0
- package/dist/lib/mcp/session-persistence.d.ts +93 -0
- package/dist/lib/mcp/session-persistence.js +298 -0
- package/dist/lib/mcp/transport-manager.d.ts +153 -0
- package/dist/lib/mcp/transport-manager.js +330 -0
- package/dist/lib/mcp/unified-registry.d.ts +42 -1
- package/dist/lib/mcp/unified-registry.js +122 -2
- package/dist/lib/neurolink.d.ts +75 -0
- package/dist/lib/neurolink.js +104 -0
- package/dist/mcp/dynamic-chain-executor.d.ts +201 -0
- package/dist/mcp/dynamic-chain-executor.js +489 -0
- package/dist/mcp/dynamic-orchestrator.d.ts +109 -0
- package/dist/mcp/dynamic-orchestrator.js +351 -0
- package/dist/mcp/error-manager.d.ts +254 -0
- package/dist/mcp/error-manager.js +501 -0
- package/dist/mcp/error-recovery.d.ts +158 -0
- package/dist/mcp/error-recovery.js +405 -0
- package/dist/mcp/health-monitor.d.ts +256 -0
- package/dist/mcp/health-monitor.js +621 -0
- package/dist/mcp/orchestrator.d.ts +136 -5
- package/dist/mcp/orchestrator.js +316 -9
- package/dist/mcp/plugins/core/neurolink-mcp.json +15 -15
- package/dist/mcp/registry.d.ts +22 -0
- package/dist/mcp/registry.js +24 -0
- package/dist/mcp/semaphore-manager.d.ts +137 -0
- package/dist/mcp/semaphore-manager.js +329 -0
- package/dist/mcp/session-manager.d.ts +186 -0
- package/dist/mcp/session-manager.js +400 -0
- package/dist/mcp/session-persistence.d.ts +93 -0
- package/dist/mcp/session-persistence.js +299 -0
- package/dist/mcp/transport-manager.d.ts +153 -0
- package/dist/mcp/transport-manager.js +331 -0
- package/dist/mcp/unified-registry.d.ts +42 -1
- package/dist/mcp/unified-registry.js +122 -2
- package/dist/neurolink.d.ts +75 -0
- package/dist/neurolink.js +104 -0
- package/package.json +245 -244
package/dist/lib/neurolink.js
CHANGED
|
@@ -472,6 +472,94 @@ Note: Tool integration is currently in development. Please provide helpful respo
|
|
|
472
472
|
})),
|
|
473
473
|
};
|
|
474
474
|
}
|
|
475
|
+
/**
|
|
476
|
+
* Add a new MCP server programmatically
|
|
477
|
+
*
|
|
478
|
+
* Allows dynamic registration of MCP servers at runtime for enhanced
|
|
479
|
+
* tool ecosystem management. Perfect for integrating external services
|
|
480
|
+
* like Bitbucket, Slack, databases, etc.
|
|
481
|
+
*
|
|
482
|
+
* @param serverId - Unique identifier for the server (e.g., 'bitbucket', 'slack-api')
|
|
483
|
+
* @param config - Server configuration with command and execution parameters
|
|
484
|
+
* @returns Promise that resolves when server is successfully added and connected
|
|
485
|
+
*
|
|
486
|
+
* @example
|
|
487
|
+
* ```typescript
|
|
488
|
+
* // Add Bitbucket MCP server
|
|
489
|
+
* await neurolink.addMCPServer('bitbucket', {
|
|
490
|
+
* command: 'npx',
|
|
491
|
+
* args: ['-y', '@nexus2520/bitbucket-mcp-server'],
|
|
492
|
+
* env: {
|
|
493
|
+
* BITBUCKET_USERNAME: 'your-username',
|
|
494
|
+
* BITBUCKET_APP_PASSWORD: 'your-app-password'
|
|
495
|
+
* }
|
|
496
|
+
* });
|
|
497
|
+
*
|
|
498
|
+
* // Add custom database connector
|
|
499
|
+
* await neurolink.addMCPServer('database', {
|
|
500
|
+
* command: 'node',
|
|
501
|
+
* args: ['./custom-db-mcp-server.js'],
|
|
502
|
+
* env: { DB_CONNECTION_STRING: 'postgresql://...' }
|
|
503
|
+
* });
|
|
504
|
+
* ```
|
|
505
|
+
*/
|
|
506
|
+
async addMCPServer(serverId, config) {
|
|
507
|
+
const functionTag = "NeuroLink.addMCPServer";
|
|
508
|
+
mcpLogger.info(`[${functionTag}] Adding MCP server: ${serverId}`, {
|
|
509
|
+
command: config.command,
|
|
510
|
+
argsCount: config.args?.length || 0,
|
|
511
|
+
hasEnv: Object.keys(config.env || {}).length > 0,
|
|
512
|
+
});
|
|
513
|
+
try {
|
|
514
|
+
// Ensure MCP is initialized
|
|
515
|
+
await this.initializeMCP();
|
|
516
|
+
// Add server to unified registry with configurable transport type
|
|
517
|
+
const transportType = config.type || "stdio";
|
|
518
|
+
// Validate URL requirement for non-stdio transports
|
|
519
|
+
if ((transportType === "sse" || transportType === "http") &&
|
|
520
|
+
!config.url) {
|
|
521
|
+
throw new Error(`URL is required for ${transportType} transport. Please provide config.url for server '${serverId}'.`);
|
|
522
|
+
}
|
|
523
|
+
const transportConfig = {
|
|
524
|
+
type: transportType,
|
|
525
|
+
...(transportType === "stdio" && {
|
|
526
|
+
command: config.command,
|
|
527
|
+
args: config.args || [],
|
|
528
|
+
env: config.env || {},
|
|
529
|
+
cwd: config.cwd,
|
|
530
|
+
}),
|
|
531
|
+
...(transportType === "sse" && {
|
|
532
|
+
url: config.url,
|
|
533
|
+
headers: config.headers,
|
|
534
|
+
timeout: config.timeout,
|
|
535
|
+
}),
|
|
536
|
+
...(transportType === "http" && {
|
|
537
|
+
url: config.url,
|
|
538
|
+
headers: config.headers,
|
|
539
|
+
timeout: config.timeout,
|
|
540
|
+
}),
|
|
541
|
+
};
|
|
542
|
+
await unifiedRegistry.addExternalServer(serverId, transportConfig);
|
|
543
|
+
// Check if server is actually connected vs just registered
|
|
544
|
+
const isConnected = unifiedRegistry.isConnected(serverId);
|
|
545
|
+
if (isConnected) {
|
|
546
|
+
mcpLogger.info(`[${functionTag}] Successfully connected to MCP server: ${serverId}`);
|
|
547
|
+
}
|
|
548
|
+
else {
|
|
549
|
+
mcpLogger.info(`[${functionTag}] MCP server registered: ${serverId} (connection failed, but server available for retry)`);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
catch (error) {
|
|
553
|
+
mcpLogger.error(`[${functionTag}] Failed to add MCP server: ${serverId}`, {
|
|
554
|
+
error: error instanceof Error ? error.message : String(error),
|
|
555
|
+
});
|
|
556
|
+
const newError = new Error(`Failed to add MCP server '${serverId}': ${error instanceof Error ? error.message : String(error)}`);
|
|
557
|
+
if (error instanceof Error && error.stack) {
|
|
558
|
+
newError.stack = `${newError.stack}\nCaused by: ${error.stack}`;
|
|
559
|
+
}
|
|
560
|
+
throw newError;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
475
563
|
/**
|
|
476
564
|
* Alias for generateText() - CLI-SDK consistency
|
|
477
565
|
* @param options - Text generation options
|
|
@@ -488,4 +576,20 @@ Note: Tool integration is currently in development. Please provide helpful respo
|
|
|
488
576
|
async gen(options) {
|
|
489
577
|
return this.generateText(options);
|
|
490
578
|
}
|
|
579
|
+
/**
|
|
580
|
+
* Get the connection client for a specific MCP server
|
|
581
|
+
* @param serverId - The ID of the server to get connection for
|
|
582
|
+
* @returns Client connection object or undefined if not connected
|
|
583
|
+
*/
|
|
584
|
+
getConnection(serverId) {
|
|
585
|
+
return unifiedRegistry.getConnection(serverId);
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Check if a specific MCP server is currently connected
|
|
589
|
+
* @param serverId - The ID of the server to check
|
|
590
|
+
* @returns True if server is connected, false otherwise
|
|
591
|
+
*/
|
|
592
|
+
isConnected(serverId) {
|
|
593
|
+
return unifiedRegistry.isConnected(serverId);
|
|
594
|
+
}
|
|
491
595
|
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamic AI Tool Chain Executor
|
|
3
|
+
* Allows AI to dynamically decide tool execution sequences based on context and results
|
|
4
|
+
*/
|
|
5
|
+
import type { MCPOrchestrator } from "./orchestrator.js";
|
|
6
|
+
import type { MCPRegistry } from "./registry.js";
|
|
7
|
+
import type { NeuroLinkExecutionContext } from "./factory.js";
|
|
8
|
+
import { ErrorManager } from "./error-manager.js";
|
|
9
|
+
/**
|
|
10
|
+
* Tool execution result with metadata
|
|
11
|
+
*/
|
|
12
|
+
export interface ToolExecutionResult {
|
|
13
|
+
toolName: string;
|
|
14
|
+
success: boolean;
|
|
15
|
+
result?: any;
|
|
16
|
+
error?: Error;
|
|
17
|
+
timestamp: number;
|
|
18
|
+
executionTime: number;
|
|
19
|
+
context?: Record<string, any>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Chain execution step
|
|
23
|
+
*/
|
|
24
|
+
export interface ChainStep {
|
|
25
|
+
stepId: string;
|
|
26
|
+
toolName: string;
|
|
27
|
+
parameters: any;
|
|
28
|
+
reasoning: string;
|
|
29
|
+
confidence: number;
|
|
30
|
+
expectedOutcome: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Chain execution context
|
|
34
|
+
*/
|
|
35
|
+
export interface ChainExecutionContext {
|
|
36
|
+
goal: string;
|
|
37
|
+
currentStep: number;
|
|
38
|
+
totalSteps?: number;
|
|
39
|
+
executionHistory: ToolExecutionResult[];
|
|
40
|
+
accumulatedContext: Record<string, any>;
|
|
41
|
+
userContext?: NeuroLinkExecutionContext;
|
|
42
|
+
maxSteps: number;
|
|
43
|
+
aiModel?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Chain execution result
|
|
47
|
+
*/
|
|
48
|
+
export interface ChainExecutionResult {
|
|
49
|
+
success: boolean;
|
|
50
|
+
goal: string;
|
|
51
|
+
totalSteps: number;
|
|
52
|
+
executionTime: number;
|
|
53
|
+
results: ToolExecutionResult[];
|
|
54
|
+
finalResult?: any;
|
|
55
|
+
reasoning: string;
|
|
56
|
+
error?: Error;
|
|
57
|
+
metadata: {
|
|
58
|
+
toolsUsed: string[];
|
|
59
|
+
averageConfidence: number;
|
|
60
|
+
contextEvolution: Record<string, any>[];
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* AI Tool Chain Planner interface
|
|
65
|
+
*/
|
|
66
|
+
export interface AIChainPlanner {
|
|
67
|
+
name: string;
|
|
68
|
+
planNextStep(goal: string, availableTools: Array<{
|
|
69
|
+
name: string;
|
|
70
|
+
description: string;
|
|
71
|
+
inputSchema: any;
|
|
72
|
+
}>, executionHistory: ToolExecutionResult[], accumulatedContext: Record<string, any>): Promise<ChainStep | null>;
|
|
73
|
+
evaluateResult(step: ChainStep, result: ToolExecutionResult, goal: string): Promise<{
|
|
74
|
+
goalAchieved: boolean;
|
|
75
|
+
confidence: number;
|
|
76
|
+
nextAction: "continue" | "retry" | "abort" | "complete";
|
|
77
|
+
reasoning: string;
|
|
78
|
+
}>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Simple AI Chain Planner using heuristics
|
|
82
|
+
*/
|
|
83
|
+
export declare class HeuristicChainPlanner implements AIChainPlanner {
|
|
84
|
+
name: string;
|
|
85
|
+
planNextStep(goal: string, availableTools: Array<{
|
|
86
|
+
name: string;
|
|
87
|
+
description: string;
|
|
88
|
+
inputSchema: any;
|
|
89
|
+
}>, executionHistory: ToolExecutionResult[], accumulatedContext: Record<string, any>): Promise<ChainStep | null>;
|
|
90
|
+
evaluateResult(step: ChainStep, result: ToolExecutionResult, goal: string): Promise<{
|
|
91
|
+
goalAchieved: boolean;
|
|
92
|
+
confidence: number;
|
|
93
|
+
nextAction: "continue" | "retry" | "abort" | "complete";
|
|
94
|
+
reasoning: string;
|
|
95
|
+
}>;
|
|
96
|
+
private generateParameters;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Advanced AI Chain Planner using actual AI model
|
|
100
|
+
*/
|
|
101
|
+
export declare class AIModelChainPlanner implements AIChainPlanner {
|
|
102
|
+
name: string;
|
|
103
|
+
private aiModel;
|
|
104
|
+
constructor(aiModel?: string);
|
|
105
|
+
planNextStep(goal: string, availableTools: Array<{
|
|
106
|
+
name: string;
|
|
107
|
+
description: string;
|
|
108
|
+
inputSchema: any;
|
|
109
|
+
}>, executionHistory: ToolExecutionResult[], accumulatedContext: Record<string, any>): Promise<ChainStep | null>;
|
|
110
|
+
evaluateResult(step: ChainStep, result: ToolExecutionResult, goal: string): Promise<{
|
|
111
|
+
goalAchieved: boolean;
|
|
112
|
+
confidence: number;
|
|
113
|
+
nextAction: "continue" | "retry" | "abort" | "complete";
|
|
114
|
+
reasoning: string;
|
|
115
|
+
}>;
|
|
116
|
+
private buildPlanningPrompt;
|
|
117
|
+
private buildEvaluationPrompt;
|
|
118
|
+
private callAIModel;
|
|
119
|
+
private parseAIResponse;
|
|
120
|
+
private parseEvaluationResponse;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Dynamic Chain Executor
|
|
124
|
+
*/
|
|
125
|
+
export declare class DynamicChainExecutor {
|
|
126
|
+
private orchestrator;
|
|
127
|
+
private registry;
|
|
128
|
+
private errorManager;
|
|
129
|
+
private planner;
|
|
130
|
+
constructor(orchestrator: MCPOrchestrator, registry: MCPRegistry, errorManager: ErrorManager, planner?: AIChainPlanner);
|
|
131
|
+
/**
|
|
132
|
+
* Execute dynamic tool chain to achieve a goal
|
|
133
|
+
*
|
|
134
|
+
* @param goal The goal to achieve
|
|
135
|
+
* @param initialContext Initial context data
|
|
136
|
+
* @param userContext User execution context
|
|
137
|
+
* @param options Execution options
|
|
138
|
+
* @returns Chain execution result
|
|
139
|
+
*/
|
|
140
|
+
executeChain(goal: string, initialContext?: Record<string, any>, userContext?: NeuroLinkExecutionContext, options?: {
|
|
141
|
+
maxSteps?: number;
|
|
142
|
+
aiModel?: string;
|
|
143
|
+
timeout?: number;
|
|
144
|
+
}): Promise<ChainExecutionResult>;
|
|
145
|
+
/**
|
|
146
|
+
* Execute chain steps iteratively
|
|
147
|
+
*
|
|
148
|
+
* @private
|
|
149
|
+
*/
|
|
150
|
+
private executeChainSteps;
|
|
151
|
+
/**
|
|
152
|
+
* Execute a single step
|
|
153
|
+
*
|
|
154
|
+
* @private
|
|
155
|
+
*/
|
|
156
|
+
private executeStep;
|
|
157
|
+
/**
|
|
158
|
+
* Update accumulated context with new result
|
|
159
|
+
*
|
|
160
|
+
* @private
|
|
161
|
+
*/
|
|
162
|
+
private updateAccumulatedContext;
|
|
163
|
+
/**
|
|
164
|
+
* Calculate average confidence across execution history
|
|
165
|
+
*
|
|
166
|
+
* @private
|
|
167
|
+
*/
|
|
168
|
+
private calculateAverageConfidence;
|
|
169
|
+
/**
|
|
170
|
+
* Track context evolution through execution
|
|
171
|
+
*
|
|
172
|
+
* @private
|
|
173
|
+
*/
|
|
174
|
+
private trackContextEvolution;
|
|
175
|
+
/**
|
|
176
|
+
* Set AI planner
|
|
177
|
+
*
|
|
178
|
+
* @param planner AI chain planner instance
|
|
179
|
+
*/
|
|
180
|
+
setPlanner(planner: AIChainPlanner): void;
|
|
181
|
+
/**
|
|
182
|
+
* Get current planner
|
|
183
|
+
*
|
|
184
|
+
* @returns Current AI chain planner
|
|
185
|
+
*/
|
|
186
|
+
getPlanner(): AIChainPlanner;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Default dynamic chain executor instance
|
|
190
|
+
*/
|
|
191
|
+
export declare let defaultDynamicChainExecutor: DynamicChainExecutor | null;
|
|
192
|
+
/**
|
|
193
|
+
* Initialize default dynamic chain executor
|
|
194
|
+
*
|
|
195
|
+
* @param orchestrator MCP orchestrator
|
|
196
|
+
* @param registry Tool registry
|
|
197
|
+
* @param errorManager Error manager
|
|
198
|
+
* @param planner Optional AI planner
|
|
199
|
+
* @returns Dynamic chain executor instance
|
|
200
|
+
*/
|
|
201
|
+
export declare function initializeDynamicChainExecutor(orchestrator: MCPOrchestrator, registry: MCPRegistry, errorManager: ErrorManager, planner?: AIChainPlanner): DynamicChainExecutor;
|