@juspay/neurolink 6.1.0 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -6
- package/dist/cli/commands/config.d.ts +13 -13
- package/dist/cli/index.js +3 -9
- package/dist/core/analytics.d.ts +11 -1
- package/dist/core/analytics.js +2 -2
- package/dist/core/base-provider.js +4 -18
- package/dist/core/dynamic-models.d.ts +8 -8
- package/dist/core/factory.js +3 -11
- package/dist/index.d.ts +2 -4
- package/dist/index.js +2 -11
- package/dist/lib/core/analytics.d.ts +11 -1
- package/dist/lib/core/analytics.js +2 -2
- package/dist/lib/core/base-provider.js +4 -18
- package/dist/lib/core/dynamic-models.d.ts +8 -8
- package/dist/lib/core/factory.js +3 -11
- package/dist/lib/index.d.ts +2 -4
- package/dist/lib/index.js +2 -11
- package/dist/lib/mcp/factory.d.ts +1 -1
- package/dist/lib/mcp/index.d.ts +7 -19
- package/dist/lib/mcp/index.js +15 -56
- package/dist/lib/neurolink.d.ts +1 -9
- package/dist/lib/neurolink.js +21 -70
- package/dist/lib/providers/amazon-bedrock.js +5 -16
- package/dist/lib/providers/anthropic-baseprovider.js +3 -21
- package/dist/lib/providers/anthropic.js +4 -7
- package/dist/lib/providers/azure-openai.js +4 -2
- package/dist/lib/providers/google-vertex.js +5 -9
- package/dist/lib/providers/huggingFace.js +5 -10
- package/dist/lib/providers/mistral.js +5 -8
- package/dist/lib/providers/openAI.js +4 -7
- package/dist/lib/utils/providerConfig.d.ts +117 -0
- package/dist/lib/utils/providerConfig.js +353 -0
- package/dist/lib/utils/providerUtils.d.ts +2 -1
- package/dist/lib/utils/providerUtils.js +53 -36
- package/dist/lib/utils/timeout.d.ts +72 -1
- package/dist/lib/utils/timeout.js +203 -2
- package/dist/mcp/factory.d.ts +1 -1
- package/dist/mcp/index.d.ts +7 -19
- package/dist/mcp/index.js +15 -56
- package/dist/neurolink.d.ts +1 -9
- package/dist/neurolink.js +21 -70
- package/dist/providers/amazon-bedrock.js +5 -16
- package/dist/providers/anthropic-baseprovider.js +3 -21
- package/dist/providers/anthropic.js +4 -7
- package/dist/providers/azure-openai.js +4 -2
- package/dist/providers/google-vertex.js +5 -9
- package/dist/providers/huggingFace.js +5 -10
- package/dist/providers/mistral.js +5 -8
- package/dist/providers/openAI.js +4 -7
- package/dist/utils/providerConfig.d.ts +117 -0
- package/dist/utils/providerConfig.js +353 -0
- package/dist/utils/providerUtils.d.ts +2 -1
- package/dist/utils/providerUtils.js +53 -36
- package/dist/utils/timeout.d.ts +72 -1
- package/dist/utils/timeout.js +203 -2
- package/package.json +1 -1
- package/dist/chat/client-utils.d.ts +0 -95
- package/dist/chat/client-utils.js +0 -315
- package/dist/chat/index.d.ts +0 -24
- package/dist/chat/index.js +0 -33
- package/dist/chat/session-storage.d.ts +0 -77
- package/dist/chat/session-storage.js +0 -233
- package/dist/chat/session.d.ts +0 -96
- package/dist/chat/session.js +0 -257
- package/dist/chat/sse-handler.d.ts +0 -49
- package/dist/chat/sse-handler.js +0 -259
- package/dist/chat/types.d.ts +0 -74
- package/dist/chat/types.js +0 -5
- package/dist/chat/websocket-chat-handler.d.ts +0 -37
- package/dist/chat/websocket-chat-handler.js +0 -262
- package/dist/cli/commands/mcp.d.ts +0 -20
- package/dist/cli/commands/mcp.js +0 -1272
- package/dist/core/defaults.d.ts +0 -19
- package/dist/core/defaults.js +0 -29
- package/dist/core/evaluation-config.d.ts +0 -29
- package/dist/core/evaluation-config.js +0 -144
- package/dist/factories/compatibility-factory.d.ts +0 -35
- package/dist/factories/compatibility-factory.js +0 -71
- package/dist/factories/provider-generate-factory.d.ts +0 -20
- package/dist/factories/provider-generate-factory.js +0 -93
- package/dist/lib/chat/client-utils.d.ts +0 -95
- package/dist/lib/chat/client-utils.js +0 -315
- package/dist/lib/chat/index.d.ts +0 -24
- package/dist/lib/chat/index.js +0 -33
- package/dist/lib/chat/session-storage.d.ts +0 -77
- package/dist/lib/chat/session-storage.js +0 -233
- package/dist/lib/chat/session.d.ts +0 -96
- package/dist/lib/chat/session.js +0 -257
- package/dist/lib/chat/sse-handler.d.ts +0 -49
- package/dist/lib/chat/sse-handler.js +0 -259
- package/dist/lib/chat/types.d.ts +0 -74
- package/dist/lib/chat/types.js +0 -5
- package/dist/lib/chat/websocket-chat-handler.d.ts +0 -37
- package/dist/lib/chat/websocket-chat-handler.js +0 -262
- package/dist/lib/core/defaults.d.ts +0 -19
- package/dist/lib/core/defaults.js +0 -29
- package/dist/lib/core/evaluation-config.d.ts +0 -29
- package/dist/lib/core/evaluation-config.js +0 -144
- package/dist/lib/factories/compatibility-factory.d.ts +0 -35
- package/dist/lib/factories/compatibility-factory.js +0 -71
- package/dist/lib/factories/provider-generate-factory.d.ts +0 -20
- package/dist/lib/factories/provider-generate-factory.js +0 -93
- package/dist/lib/mcp/adapters/plugin-bridge.d.ts +0 -40
- package/dist/lib/mcp/adapters/plugin-bridge.js +0 -89
- package/dist/lib/mcp/auto-discovery.d.ts +0 -62
- package/dist/lib/mcp/auto-discovery.js +0 -149
- package/dist/lib/mcp/client.d.ts +0 -68
- package/dist/lib/mcp/client.js +0 -248
- package/dist/lib/mcp/config.d.ts +0 -31
- package/dist/lib/mcp/config.js +0 -99
- package/dist/lib/mcp/context-manager.d.ts +0 -171
- package/dist/lib/mcp/context-manager.js +0 -362
- package/dist/lib/mcp/contracts/mcp-contract.d.ts +0 -169
- package/dist/lib/mcp/contracts/mcp-contract.js +0 -58
- package/dist/lib/mcp/core/plugin-manager.d.ts +0 -46
- package/dist/lib/mcp/core/plugin-manager.js +0 -110
- package/dist/lib/mcp/demo/plugin-demo.d.ts +0 -20
- package/dist/lib/mcp/demo/plugin-demo.js +0 -118
- package/dist/lib/mcp/dynamic-chain-executor.d.ts +0 -225
- package/dist/lib/mcp/dynamic-chain-executor.js +0 -489
- package/dist/lib/mcp/dynamic-orchestrator.d.ts +0 -115
- package/dist/lib/mcp/dynamic-orchestrator.js +0 -351
- package/dist/lib/mcp/ecosystem.d.ts +0 -75
- package/dist/lib/mcp/ecosystem.js +0 -161
- package/dist/lib/mcp/error-manager.d.ts +0 -254
- package/dist/lib/mcp/error-manager.js +0 -501
- package/dist/lib/mcp/error-recovery.d.ts +0 -159
- package/dist/lib/mcp/error-recovery.js +0 -405
- package/dist/lib/mcp/external-client.d.ts +0 -88
- package/dist/lib/mcp/external-client.js +0 -331
- package/dist/lib/mcp/external-manager.d.ts +0 -112
- package/dist/lib/mcp/external-manager.js +0 -308
- package/dist/lib/mcp/function-calling.d.ts +0 -65
- package/dist/lib/mcp/function-calling.js +0 -642
- package/dist/lib/mcp/health-monitor.d.ts +0 -257
- package/dist/lib/mcp/health-monitor.js +0 -630
- package/dist/lib/mcp/initialize-tools.d.ts +0 -29
- package/dist/lib/mcp/initialize-tools.js +0 -261
- package/dist/lib/mcp/initialize.d.ts +0 -18
- package/dist/lib/mcp/initialize.js +0 -62
- package/dist/lib/mcp/manager.d.ts +0 -68
- package/dist/lib/mcp/manager.js +0 -176
- package/dist/lib/mcp/neurolink-mcp-client.d.ts +0 -97
- package/dist/lib/mcp/neurolink-mcp-client.js +0 -462
- package/dist/lib/mcp/orchestrator.d.ts +0 -302
- package/dist/lib/mcp/orchestrator.js +0 -703
- package/dist/lib/mcp/plugin-manager.d.ts +0 -98
- package/dist/lib/mcp/plugin-manager.js +0 -296
- package/dist/lib/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
- package/dist/lib/mcp/plugins/core/filesystem-mcp.js +0 -142
- package/dist/lib/mcp/plugins/filesystem-mcp.d.ts +0 -37
- package/dist/lib/mcp/plugins/filesystem-mcp.js +0 -54
- package/dist/lib/mcp/security-manager.d.ts +0 -87
- package/dist/lib/mcp/security-manager.js +0 -344
- package/dist/lib/mcp/semaphore-manager.d.ts +0 -137
- package/dist/lib/mcp/semaphore-manager.js +0 -329
- package/dist/lib/mcp/session-manager.d.ts +0 -187
- package/dist/lib/mcp/session-manager.js +0 -400
- package/dist/lib/mcp/session-persistence.d.ts +0 -93
- package/dist/lib/mcp/session-persistence.js +0 -301
- package/dist/lib/mcp/tool-integration.d.ts +0 -58
- package/dist/lib/mcp/tool-integration.js +0 -203
- package/dist/lib/mcp/transport-manager.d.ts +0 -154
- package/dist/lib/mcp/transport-manager.js +0 -334
- package/dist/lib/mcp/unified-mcp.d.ts +0 -133
- package/dist/lib/mcp/unified-mcp.js +0 -251
- package/dist/lib/mcp/unified-registry.d.ts +0 -165
- package/dist/lib/mcp/unified-registry.js +0 -538
- package/dist/lib/providers/analytics-helper.d.ts +0 -38
- package/dist/lib/providers/analytics-helper.js +0 -216
- package/dist/lib/providers/function-calling-provider.d.ts +0 -142
- package/dist/lib/providers/function-calling-provider.js +0 -630
- package/dist/lib/providers/mcp-provider.d.ts +0 -75
- package/dist/lib/providers/mcp-provider.js +0 -283
- package/dist/lib/providers/timeout-wrapper.d.ts +0 -40
- package/dist/lib/providers/timeout-wrapper.js +0 -100
- package/dist/lib/sdk/tool-extension.d.ts +0 -181
- package/dist/lib/sdk/tool-extension.js +0 -284
- package/dist/lib/services/streaming/streaming-manager.d.ts +0 -29
- package/dist/lib/services/streaming/streaming-manager.js +0 -245
- package/dist/lib/services/types.d.ts +0 -156
- package/dist/lib/services/types.js +0 -2
- package/dist/lib/services/websocket/websocket-server.d.ts +0 -34
- package/dist/lib/services/websocket/websocket-server.js +0 -305
- package/dist/lib/utils/provider-validation.d.ts +0 -36
- package/dist/lib/utils/provider-validation.js +0 -625
- package/dist/lib/utils/providerUtils-fixed.d.ts +0 -8
- package/dist/lib/utils/providerUtils-fixed.js +0 -94
- package/dist/lib/utils/streaming-utils.d.ts +0 -79
- package/dist/lib/utils/streaming-utils.js +0 -198
- package/dist/lib/utils/timeout-manager.d.ts +0 -75
- package/dist/lib/utils/timeout-manager.js +0 -244
- package/dist/mcp/adapters/plugin-bridge.d.ts +0 -40
- package/dist/mcp/adapters/plugin-bridge.js +0 -89
- package/dist/mcp/auto-discovery.d.ts +0 -62
- package/dist/mcp/auto-discovery.js +0 -149
- package/dist/mcp/client.d.ts +0 -68
- package/dist/mcp/client.js +0 -248
- package/dist/mcp/config.d.ts +0 -31
- package/dist/mcp/config.js +0 -99
- package/dist/mcp/context-manager.d.ts +0 -171
- package/dist/mcp/context-manager.js +0 -362
- package/dist/mcp/contracts/mcp-contract.d.ts +0 -169
- package/dist/mcp/contracts/mcp-contract.js +0 -58
- package/dist/mcp/core/plugin-manager.d.ts +0 -46
- package/dist/mcp/core/plugin-manager.js +0 -110
- package/dist/mcp/demo/plugin-demo.d.ts +0 -20
- package/dist/mcp/demo/plugin-demo.js +0 -118
- package/dist/mcp/dynamic-chain-executor.d.ts +0 -225
- package/dist/mcp/dynamic-chain-executor.js +0 -489
- package/dist/mcp/dynamic-orchestrator.d.ts +0 -115
- package/dist/mcp/dynamic-orchestrator.js +0 -351
- package/dist/mcp/ecosystem.d.ts +0 -75
- package/dist/mcp/ecosystem.js +0 -162
- package/dist/mcp/error-manager.d.ts +0 -254
- package/dist/mcp/error-manager.js +0 -501
- package/dist/mcp/error-recovery.d.ts +0 -159
- package/dist/mcp/error-recovery.js +0 -405
- package/dist/mcp/external-client.d.ts +0 -88
- package/dist/mcp/external-client.js +0 -331
- package/dist/mcp/external-manager.d.ts +0 -112
- package/dist/mcp/external-manager.js +0 -308
- package/dist/mcp/function-calling.d.ts +0 -65
- package/dist/mcp/function-calling.js +0 -642
- package/dist/mcp/health-monitor.d.ts +0 -257
- package/dist/mcp/health-monitor.js +0 -630
- package/dist/mcp/initialize-tools.d.ts +0 -29
- package/dist/mcp/initialize-tools.js +0 -262
- package/dist/mcp/initialize.d.ts +0 -18
- package/dist/mcp/initialize.js +0 -62
- package/dist/mcp/manager.d.ts +0 -68
- package/dist/mcp/manager.js +0 -176
- package/dist/mcp/neurolink-mcp-client.d.ts +0 -97
- package/dist/mcp/neurolink-mcp-client.js +0 -462
- package/dist/mcp/orchestrator.d.ts +0 -302
- package/dist/mcp/orchestrator.js +0 -703
- package/dist/mcp/plugin-manager.d.ts +0 -98
- package/dist/mcp/plugin-manager.js +0 -297
- package/dist/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
- package/dist/mcp/plugins/core/filesystem-mcp.js +0 -142
- package/dist/mcp/plugins/core/neurolink-mcp.json +0 -17
- package/dist/mcp/plugins/filesystem-mcp.d.ts +0 -37
- package/dist/mcp/plugins/filesystem-mcp.js +0 -54
- package/dist/mcp/security-manager.d.ts +0 -87
- package/dist/mcp/security-manager.js +0 -344
- package/dist/mcp/semaphore-manager.d.ts +0 -137
- package/dist/mcp/semaphore-manager.js +0 -329
- package/dist/mcp/session-manager.d.ts +0 -187
- package/dist/mcp/session-manager.js +0 -400
- package/dist/mcp/session-persistence.d.ts +0 -93
- package/dist/mcp/session-persistence.js +0 -302
- package/dist/mcp/tool-integration.d.ts +0 -58
- package/dist/mcp/tool-integration.js +0 -203
- package/dist/mcp/transport-manager.d.ts +0 -154
- package/dist/mcp/transport-manager.js +0 -335
- package/dist/mcp/unified-mcp.d.ts +0 -133
- package/dist/mcp/unified-mcp.js +0 -251
- package/dist/mcp/unified-registry.d.ts +0 -165
- package/dist/mcp/unified-registry.js +0 -539
- package/dist/providers/analytics-helper.d.ts +0 -38
- package/dist/providers/analytics-helper.js +0 -216
- package/dist/providers/function-calling-provider.d.ts +0 -142
- package/dist/providers/function-calling-provider.js +0 -630
- package/dist/providers/mcp-provider.d.ts +0 -75
- package/dist/providers/mcp-provider.js +0 -283
- package/dist/providers/timeout-wrapper.d.ts +0 -40
- package/dist/providers/timeout-wrapper.js +0 -100
- package/dist/sdk/tool-extension.d.ts +0 -181
- package/dist/sdk/tool-extension.js +0 -284
- package/dist/services/streaming/streaming-manager.d.ts +0 -29
- package/dist/services/streaming/streaming-manager.js +0 -245
- package/dist/services/types.d.ts +0 -156
- package/dist/services/types.js +0 -2
- package/dist/services/websocket/websocket-server.d.ts +0 -34
- package/dist/services/websocket/websocket-server.js +0 -306
- package/dist/utils/provider-validation.d.ts +0 -36
- package/dist/utils/provider-validation.js +0 -625
- package/dist/utils/providerUtils-fixed.d.ts +0 -8
- package/dist/utils/providerUtils-fixed.js +0 -94
- package/dist/utils/streaming-utils.d.ts +0 -79
- package/dist/utils/streaming-utils.js +0 -198
- package/dist/utils/timeout-manager.d.ts +0 -75
- package/dist/utils/timeout-manager.js +0 -244
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Transport Manager for MCP connections
|
|
3
|
-
* Supports stdio, SSE, and HTTP transports with reconnection logic
|
|
4
|
-
*/
|
|
5
|
-
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
6
|
-
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
7
|
-
import { z } from "zod";
|
|
8
|
-
import { ErrorManager } from "./error-manager.js";
|
|
9
|
-
export declare const TransportConfigSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
10
|
-
type: z.ZodLiteral<"stdio">;
|
|
11
|
-
command: z.ZodString;
|
|
12
|
-
args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
13
|
-
cwd: z.ZodOptional<z.ZodString>;
|
|
14
|
-
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
15
|
-
}, "strip", z.ZodTypeAny, {
|
|
16
|
-
type: "stdio";
|
|
17
|
-
command: string;
|
|
18
|
-
args?: string[] | undefined;
|
|
19
|
-
cwd?: string | undefined;
|
|
20
|
-
env?: Record<string, string> | undefined;
|
|
21
|
-
}, {
|
|
22
|
-
type: "stdio";
|
|
23
|
-
command: string;
|
|
24
|
-
args?: string[] | undefined;
|
|
25
|
-
cwd?: string | undefined;
|
|
26
|
-
env?: Record<string, string> | undefined;
|
|
27
|
-
}>, z.ZodObject<{
|
|
28
|
-
type: z.ZodLiteral<"sse">;
|
|
29
|
-
url: z.ZodString;
|
|
30
|
-
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
31
|
-
timeout: z.ZodDefault<z.ZodNumber>;
|
|
32
|
-
maxRetryTime: z.ZodDefault<z.ZodNumber>;
|
|
33
|
-
withCredentials: z.ZodDefault<z.ZodBoolean>;
|
|
34
|
-
}, "strip", z.ZodTypeAny, {
|
|
35
|
-
type: "sse";
|
|
36
|
-
timeout: number;
|
|
37
|
-
url: string;
|
|
38
|
-
maxRetryTime: number;
|
|
39
|
-
withCredentials: boolean;
|
|
40
|
-
headers?: Record<string, string> | undefined;
|
|
41
|
-
}, {
|
|
42
|
-
type: "sse";
|
|
43
|
-
url: string;
|
|
44
|
-
timeout?: number | undefined;
|
|
45
|
-
headers?: Record<string, string> | undefined;
|
|
46
|
-
maxRetryTime?: number | undefined;
|
|
47
|
-
withCredentials?: boolean | undefined;
|
|
48
|
-
}>, z.ZodObject<{
|
|
49
|
-
type: z.ZodLiteral<"http">;
|
|
50
|
-
url: z.ZodString;
|
|
51
|
-
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
52
|
-
timeout: z.ZodDefault<z.ZodNumber>;
|
|
53
|
-
}, "strip", z.ZodTypeAny, {
|
|
54
|
-
type: "http";
|
|
55
|
-
timeout: number;
|
|
56
|
-
url: string;
|
|
57
|
-
headers?: Record<string, string> | undefined;
|
|
58
|
-
}, {
|
|
59
|
-
type: "http";
|
|
60
|
-
url: string;
|
|
61
|
-
timeout?: number | undefined;
|
|
62
|
-
headers?: Record<string, string> | undefined;
|
|
63
|
-
}>]>;
|
|
64
|
-
export type TransportConfig = z.infer<typeof TransportConfigSchema>;
|
|
65
|
-
export interface TransportStatus {
|
|
66
|
-
connected: boolean;
|
|
67
|
-
type: "stdio" | "sse" | "http";
|
|
68
|
-
lastConnected?: Date;
|
|
69
|
-
lastError?: Error;
|
|
70
|
-
reconnectAttempts: number;
|
|
71
|
-
}
|
|
72
|
-
export interface TransportManagerOptions {
|
|
73
|
-
autoReconnect?: boolean;
|
|
74
|
-
maxReconnectAttempts?: number;
|
|
75
|
-
reconnectDelay?: number;
|
|
76
|
-
healthCheckInterval?: number;
|
|
77
|
-
jitterEnabled?: boolean;
|
|
78
|
-
maxJitter?: number;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Manages MCP transport connections with automatic reconnection and health monitoring
|
|
82
|
-
*/
|
|
83
|
-
export declare class TransportManager {
|
|
84
|
-
private errorManager;
|
|
85
|
-
private options;
|
|
86
|
-
private client?;
|
|
87
|
-
private config?;
|
|
88
|
-
private status;
|
|
89
|
-
private reconnectTimer?;
|
|
90
|
-
private healthCheckTimer?;
|
|
91
|
-
private reconnectPromise?;
|
|
92
|
-
constructor(errorManager: ErrorManager, options?: TransportManagerOptions);
|
|
93
|
-
/**
|
|
94
|
-
* Connect to MCP server using specified transport
|
|
95
|
-
*/
|
|
96
|
-
connect(config: TransportConfig): Promise<Client>;
|
|
97
|
-
/**
|
|
98
|
-
* Create transport based on configuration
|
|
99
|
-
*/
|
|
100
|
-
createTransport(config: TransportConfig): Promise<Transport>;
|
|
101
|
-
/**
|
|
102
|
-
* Create stdio transport
|
|
103
|
-
*/
|
|
104
|
-
private createStdioTransport;
|
|
105
|
-
/**
|
|
106
|
-
* Create SSE transport with reconnection support
|
|
107
|
-
*/
|
|
108
|
-
private createSSETransport;
|
|
109
|
-
/**
|
|
110
|
-
* Create HTTP transport
|
|
111
|
-
*/
|
|
112
|
-
private createHTTPTransport;
|
|
113
|
-
/**
|
|
114
|
-
* Set up health monitoring
|
|
115
|
-
*/
|
|
116
|
-
private setupHealthMonitoring;
|
|
117
|
-
/**
|
|
118
|
-
* Handle connection errors
|
|
119
|
-
*/
|
|
120
|
-
private handleConnectionError;
|
|
121
|
-
/**
|
|
122
|
-
* Schedule reconnection attempt
|
|
123
|
-
*/
|
|
124
|
-
private scheduleReconnect;
|
|
125
|
-
/**
|
|
126
|
-
* Calculate reconnect delay with exponential backoff
|
|
127
|
-
*/
|
|
128
|
-
private calculateReconnectDelay;
|
|
129
|
-
/**
|
|
130
|
-
* Reconnect to server
|
|
131
|
-
*/
|
|
132
|
-
reconnect(): Promise<void>;
|
|
133
|
-
private _reconnect;
|
|
134
|
-
/**
|
|
135
|
-
* Disconnect from server
|
|
136
|
-
*/
|
|
137
|
-
disconnect(): Promise<void>;
|
|
138
|
-
/**
|
|
139
|
-
* Get current transport status
|
|
140
|
-
*/
|
|
141
|
-
getStatus(): TransportStatus;
|
|
142
|
-
/**
|
|
143
|
-
* Get connected client
|
|
144
|
-
*/
|
|
145
|
-
getClient(): Client | undefined;
|
|
146
|
-
/**
|
|
147
|
-
* Check if connected
|
|
148
|
-
*/
|
|
149
|
-
isConnected(): boolean;
|
|
150
|
-
/**
|
|
151
|
-
* Reset reconnection attempts
|
|
152
|
-
*/
|
|
153
|
-
resetReconnectAttempts(): void;
|
|
154
|
-
}
|
|
@@ -1,335 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Transport Manager for MCP connections
|
|
3
|
-
* Supports stdio, SSE, and HTTP transports with reconnection logic
|
|
4
|
-
*/
|
|
5
|
-
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
6
|
-
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
7
|
-
import { z } from "zod";
|
|
8
|
-
import { ErrorManager } from "./error-manager.js";
|
|
9
|
-
import { ErrorCategory, ErrorSeverity } from "./error-manager.js";
|
|
10
|
-
// Transport configuration schemas
|
|
11
|
-
export const TransportConfigSchema = z.discriminatedUnion("type", [
|
|
12
|
-
z.object({
|
|
13
|
-
type: z.literal("stdio"),
|
|
14
|
-
command: z.string(),
|
|
15
|
-
args: z.array(z.string()).optional(),
|
|
16
|
-
cwd: z.string().optional(),
|
|
17
|
-
env: z.record(z.string()).optional(),
|
|
18
|
-
}),
|
|
19
|
-
z.object({
|
|
20
|
-
type: z.literal("sse"),
|
|
21
|
-
url: z.string().url(),
|
|
22
|
-
headers: z.record(z.string()).optional(),
|
|
23
|
-
timeout: z.number().min(5).default(30),
|
|
24
|
-
maxRetryTime: z.number().default(5000),
|
|
25
|
-
withCredentials: z.boolean().default(false),
|
|
26
|
-
}),
|
|
27
|
-
z.object({
|
|
28
|
-
type: z.literal("http"),
|
|
29
|
-
url: z.string().url(),
|
|
30
|
-
headers: z.record(z.string()).optional(),
|
|
31
|
-
timeout: z.number().min(5).default(30),
|
|
32
|
-
}),
|
|
33
|
-
]);
|
|
34
|
-
/**
|
|
35
|
-
* Manages MCP transport connections with automatic reconnection and health monitoring
|
|
36
|
-
*/
|
|
37
|
-
export class TransportManager {
|
|
38
|
-
errorManager;
|
|
39
|
-
options;
|
|
40
|
-
client;
|
|
41
|
-
config;
|
|
42
|
-
status;
|
|
43
|
-
reconnectTimer;
|
|
44
|
-
healthCheckTimer;
|
|
45
|
-
reconnectPromise;
|
|
46
|
-
constructor(errorManager, options = {}) {
|
|
47
|
-
this.errorManager = errorManager;
|
|
48
|
-
this.options = options;
|
|
49
|
-
// Initialize default options
|
|
50
|
-
this.options = {
|
|
51
|
-
jitterEnabled: true,
|
|
52
|
-
maxJitter: 1000,
|
|
53
|
-
...this.options,
|
|
54
|
-
};
|
|
55
|
-
this.status = {
|
|
56
|
-
connected: false,
|
|
57
|
-
type: "stdio",
|
|
58
|
-
reconnectAttempts: 0,
|
|
59
|
-
};
|
|
60
|
-
// Apply defaults
|
|
61
|
-
this.options = {
|
|
62
|
-
autoReconnect: true,
|
|
63
|
-
maxReconnectAttempts: 5,
|
|
64
|
-
reconnectDelay: 1000,
|
|
65
|
-
healthCheckInterval: 30000,
|
|
66
|
-
...options,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Connect to MCP server using specified transport
|
|
71
|
-
*/
|
|
72
|
-
async connect(config) {
|
|
73
|
-
try {
|
|
74
|
-
// Validate configuration
|
|
75
|
-
const validatedConfig = TransportConfigSchema.parse(config);
|
|
76
|
-
this.config = validatedConfig;
|
|
77
|
-
this.status.type = validatedConfig.type;
|
|
78
|
-
// Disconnect existing client if any
|
|
79
|
-
if (this.client) {
|
|
80
|
-
await this.disconnect();
|
|
81
|
-
}
|
|
82
|
-
// Create transport based on type
|
|
83
|
-
const transport = await this.createTransport(validatedConfig);
|
|
84
|
-
// Create MCP client
|
|
85
|
-
this.client = new Client({
|
|
86
|
-
name: "neurolink-mcp-client",
|
|
87
|
-
version: "1.0.0",
|
|
88
|
-
}, {
|
|
89
|
-
capabilities: {},
|
|
90
|
-
});
|
|
91
|
-
// Connect client
|
|
92
|
-
await this.client.connect(transport);
|
|
93
|
-
// Update status
|
|
94
|
-
this.status.connected = true;
|
|
95
|
-
this.status.lastConnected = new Date();
|
|
96
|
-
this.status.reconnectAttempts = 0;
|
|
97
|
-
// Set up health monitoring if enabled
|
|
98
|
-
if (this.options.healthCheckInterval &&
|
|
99
|
-
this.options.healthCheckInterval > 0) {
|
|
100
|
-
this.setupHealthMonitoring();
|
|
101
|
-
}
|
|
102
|
-
return this.client;
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
this.handleConnectionError(error);
|
|
106
|
-
throw error;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Create transport based on configuration
|
|
111
|
-
*/
|
|
112
|
-
async createTransport(config) {
|
|
113
|
-
switch (config.type) {
|
|
114
|
-
case "stdio":
|
|
115
|
-
return this.createStdioTransport(config);
|
|
116
|
-
case "sse":
|
|
117
|
-
return this.createSSETransport(config);
|
|
118
|
-
case "http":
|
|
119
|
-
return this.createHTTPTransport(config);
|
|
120
|
-
default:
|
|
121
|
-
throw new Error(`Unsupported transport type: ${config.type}`);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Create stdio transport
|
|
126
|
-
*/
|
|
127
|
-
createStdioTransport(config) {
|
|
128
|
-
// Filter out undefined values from process.env
|
|
129
|
-
const envWithoutUndefined = Object.fromEntries(Object.entries(process.env).filter(([_, value]) => value !== undefined));
|
|
130
|
-
// StdioClientTransport handles process creation internally
|
|
131
|
-
return new StdioClientTransport({
|
|
132
|
-
command: config.command,
|
|
133
|
-
args: config.args ?? [],
|
|
134
|
-
env: { ...envWithoutUndefined, ...config.env },
|
|
135
|
-
cwd: config.cwd,
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Create SSE transport with reconnection support
|
|
140
|
-
*/
|
|
141
|
-
async createSSETransport(config) {
|
|
142
|
-
// Dynamically import SSE transport
|
|
143
|
-
const { SSEClientTransport } = await import("@modelcontextprotocol/sdk/client/sse.js");
|
|
144
|
-
// Use ReconnectingEventSource for reliability
|
|
145
|
-
const ReconnectingEventSource = await import("reconnecting-eventsource").then((m) => m.default);
|
|
146
|
-
return new SSEClientTransport(new URL(config.url), {
|
|
147
|
-
requestInit: {
|
|
148
|
-
headers: config.headers,
|
|
149
|
-
...(config.timeout && { timeout: config.timeout }),
|
|
150
|
-
},
|
|
151
|
-
eventSourceInit: {
|
|
152
|
-
eventSource: ReconnectingEventSource,
|
|
153
|
-
max_retry_time: config.maxRetryTime,
|
|
154
|
-
withCredentials: config.withCredentials,
|
|
155
|
-
},
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Create HTTP transport
|
|
160
|
-
*/
|
|
161
|
-
async createHTTPTransport(config) {
|
|
162
|
-
// Dynamically import HTTP transport
|
|
163
|
-
const httpModule = await import("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
164
|
-
const HTTPClientTransport = httpModule.default ||
|
|
165
|
-
httpModule.HTTPClientTransport;
|
|
166
|
-
if (!HTTPClientTransport || typeof HTTPClientTransport !== "function") {
|
|
167
|
-
throw new Error("HTTPClientTransport constructor not found");
|
|
168
|
-
}
|
|
169
|
-
return new HTTPClientTransport(new URL(config.url), {
|
|
170
|
-
requestInit: {
|
|
171
|
-
headers: config.headers,
|
|
172
|
-
timeout: config.timeout * 1000, // Convert seconds to milliseconds
|
|
173
|
-
},
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Set up health monitoring
|
|
178
|
-
*/
|
|
179
|
-
setupHealthMonitoring() {
|
|
180
|
-
if (!this.client) {
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
// Clear any existing health check timer
|
|
184
|
-
if (this.healthCheckTimer) {
|
|
185
|
-
clearInterval(this.healthCheckTimer);
|
|
186
|
-
}
|
|
187
|
-
// Set up periodic health checks
|
|
188
|
-
this.healthCheckTimer = setInterval(async () => {
|
|
189
|
-
if (!this.client) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
try {
|
|
193
|
-
// Simple health check - list tools
|
|
194
|
-
await this.client.request({ method: "tools/list" }, z.object({ tools: z.array(z.any()) }));
|
|
195
|
-
}
|
|
196
|
-
catch (error) {
|
|
197
|
-
// Health check failed, trigger reconnection if enabled
|
|
198
|
-
if (this.options.autoReconnect && this.config) {
|
|
199
|
-
this.handleConnectionError(error);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}, this.options.healthCheckInterval);
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Handle connection errors
|
|
206
|
-
*/
|
|
207
|
-
handleConnectionError(error) {
|
|
208
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
209
|
-
this.status.connected = false;
|
|
210
|
-
this.status.lastError = err;
|
|
211
|
-
// Record error
|
|
212
|
-
this.errorManager.recordError(err, {
|
|
213
|
-
category: ErrorCategory.CONNECTION_ERROR,
|
|
214
|
-
severity: ErrorSeverity.HIGH,
|
|
215
|
-
toolName: "transport-manager",
|
|
216
|
-
parameters: {
|
|
217
|
-
transport: this.status.type,
|
|
218
|
-
reconnectAttempts: this.status.reconnectAttempts,
|
|
219
|
-
},
|
|
220
|
-
});
|
|
221
|
-
// Attempt reconnection if enabled
|
|
222
|
-
if (this.options.autoReconnect &&
|
|
223
|
-
this.status.reconnectAttempts < this.options.maxReconnectAttempts) {
|
|
224
|
-
// Schedule reconnection attempt
|
|
225
|
-
this.scheduleReconnect();
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Schedule reconnection attempt
|
|
230
|
-
*/
|
|
231
|
-
scheduleReconnect() {
|
|
232
|
-
if (this.reconnectTimer) {
|
|
233
|
-
clearTimeout(this.reconnectTimer);
|
|
234
|
-
}
|
|
235
|
-
// Increment attempts BEFORE calculating delay (uses updated attempt count)
|
|
236
|
-
this.status.reconnectAttempts++;
|
|
237
|
-
const delay = this.calculateReconnectDelay();
|
|
238
|
-
this.reconnectTimer = setTimeout(() => {
|
|
239
|
-
this.reconnect().catch((error) => {
|
|
240
|
-
console.error("Reconnection failed:", error);
|
|
241
|
-
});
|
|
242
|
-
}, delay);
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Calculate reconnect delay with exponential backoff
|
|
246
|
-
*/
|
|
247
|
-
calculateReconnectDelay() {
|
|
248
|
-
const baseDelay = this.options.reconnectDelay || 1000;
|
|
249
|
-
const maxDelay = 30000; // 30 seconds max
|
|
250
|
-
const delay = Math.min(baseDelay * Math.pow(2, this.status.reconnectAttempts), maxDelay);
|
|
251
|
-
// Add configurable jitter to prevent thundering herd
|
|
252
|
-
if (this.options.jitterEnabled === true) {
|
|
253
|
-
const maxJitter = this.options.maxJitter || 1000;
|
|
254
|
-
return delay + Math.random() * maxJitter;
|
|
255
|
-
}
|
|
256
|
-
return delay;
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Reconnect to server
|
|
260
|
-
*/
|
|
261
|
-
async reconnect() {
|
|
262
|
-
// Prevent concurrent reconnection attempts
|
|
263
|
-
if (this.reconnectPromise) {
|
|
264
|
-
return this.reconnectPromise;
|
|
265
|
-
}
|
|
266
|
-
this.reconnectPromise = this._reconnect();
|
|
267
|
-
try {
|
|
268
|
-
await this.reconnectPromise;
|
|
269
|
-
}
|
|
270
|
-
finally {
|
|
271
|
-
this.reconnectPromise = undefined;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
async _reconnect() {
|
|
275
|
-
if (!this.config) {
|
|
276
|
-
throw new Error("No configuration available for reconnection");
|
|
277
|
-
}
|
|
278
|
-
try {
|
|
279
|
-
await this.connect(this.config);
|
|
280
|
-
console.log(`Reconnected successfully after ${this.status.reconnectAttempts} attempts`);
|
|
281
|
-
}
|
|
282
|
-
catch (error) {
|
|
283
|
-
if (this.status.reconnectAttempts >= this.options.maxReconnectAttempts) {
|
|
284
|
-
throw new Error(`Max reconnection attempts (${this.options.maxReconnectAttempts}) reached`);
|
|
285
|
-
}
|
|
286
|
-
throw error;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Disconnect from server
|
|
291
|
-
*/
|
|
292
|
-
async disconnect() {
|
|
293
|
-
// Clear reconnection timer
|
|
294
|
-
if (this.reconnectTimer) {
|
|
295
|
-
clearTimeout(this.reconnectTimer);
|
|
296
|
-
this.reconnectTimer = undefined;
|
|
297
|
-
}
|
|
298
|
-
// Stop health monitoring
|
|
299
|
-
if (this.healthCheckTimer) {
|
|
300
|
-
clearInterval(this.healthCheckTimer);
|
|
301
|
-
this.healthCheckTimer = undefined;
|
|
302
|
-
}
|
|
303
|
-
// Close client connection
|
|
304
|
-
if (this.client) {
|
|
305
|
-
await this.client.close();
|
|
306
|
-
this.client = undefined;
|
|
307
|
-
}
|
|
308
|
-
// Update status
|
|
309
|
-
this.status.connected = false;
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Get current transport status
|
|
313
|
-
*/
|
|
314
|
-
getStatus() {
|
|
315
|
-
return { ...this.status };
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Get connected client
|
|
319
|
-
*/
|
|
320
|
-
getClient() {
|
|
321
|
-
return this.client;
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* Check if connected
|
|
325
|
-
*/
|
|
326
|
-
isConnected() {
|
|
327
|
-
return this.status.connected && this.client !== undefined;
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* Reset reconnection attempts
|
|
331
|
-
*/
|
|
332
|
-
resetReconnectAttempts() {
|
|
333
|
-
this.status.reconnectAttempts = 0;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NeuroLink Unified MCP System
|
|
3
|
-
* Combines internal MCP servers with external MCP server integration
|
|
4
|
-
* Single initialization point for the complete MCP ecosystem
|
|
5
|
-
*/
|
|
6
|
-
import { MCPToolRegistry } from "./tool-registry.js";
|
|
7
|
-
import { ExternalMCPManager } from "./external-manager.js";
|
|
8
|
-
import type { NeuroLinkExecutionContext, ToolResult } from "./factory.js";
|
|
9
|
-
/**
|
|
10
|
-
* Unified MCP System Options
|
|
11
|
-
*/
|
|
12
|
-
export interface UnifiedMCPOptions {
|
|
13
|
-
configPath?: string;
|
|
14
|
-
enableExternalServers?: boolean;
|
|
15
|
-
enableInternalServers?: boolean;
|
|
16
|
-
autoInitialize?: boolean;
|
|
17
|
-
registry?: MCPToolRegistry;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Unified MCP System Status
|
|
21
|
-
*/
|
|
22
|
-
export interface UnifiedMCPStatus {
|
|
23
|
-
isInitialized: boolean;
|
|
24
|
-
internalServers: {
|
|
25
|
-
count: number;
|
|
26
|
-
tools: number;
|
|
27
|
-
};
|
|
28
|
-
externalServers: {
|
|
29
|
-
configured: number;
|
|
30
|
-
connected: number;
|
|
31
|
-
tools: number;
|
|
32
|
-
};
|
|
33
|
-
totalTools: number;
|
|
34
|
-
registryStats: unknown;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Unified MCP System
|
|
38
|
-
* Central hub for managing both internal and external MCP servers
|
|
39
|
-
*/
|
|
40
|
-
export declare class UnifiedMCPSystem {
|
|
41
|
-
private registry;
|
|
42
|
-
private externalManager;
|
|
43
|
-
private internalServers;
|
|
44
|
-
private isInitialized;
|
|
45
|
-
private options;
|
|
46
|
-
constructor(options?: UnifiedMCPOptions);
|
|
47
|
-
/**
|
|
48
|
-
* Initialize the unified MCP system
|
|
49
|
-
*/
|
|
50
|
-
initialize(): Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* Initialize internal MCP servers
|
|
53
|
-
*/
|
|
54
|
-
private initializeInternalServers;
|
|
55
|
-
/**
|
|
56
|
-
* Initialize external MCP servers
|
|
57
|
-
*/
|
|
58
|
-
private initializeExternalServers;
|
|
59
|
-
/**
|
|
60
|
-
* Execute a tool from any registered server
|
|
61
|
-
*/
|
|
62
|
-
executeTool(toolName: string, params: unknown, context: NeuroLinkExecutionContext): Promise<ToolResult>;
|
|
63
|
-
/**
|
|
64
|
-
* List all available tools
|
|
65
|
-
*/
|
|
66
|
-
listTools(criteria?: unknown): Promise<import("./tool-registry.js").ToolInfo[]>;
|
|
67
|
-
/**
|
|
68
|
-
* Get tool information
|
|
69
|
-
*/
|
|
70
|
-
getToolInfo(toolName: string): {
|
|
71
|
-
tool: import("./tool-registry.js").ToolInfo;
|
|
72
|
-
server: {
|
|
73
|
-
id: string;
|
|
74
|
-
};
|
|
75
|
-
} | undefined;
|
|
76
|
-
/**
|
|
77
|
-
* Get registry instance
|
|
78
|
-
*/
|
|
79
|
-
getRegistry(): MCPToolRegistry;
|
|
80
|
-
/**
|
|
81
|
-
* Get external manager instance
|
|
82
|
-
*/
|
|
83
|
-
getExternalManager(): ExternalMCPManager;
|
|
84
|
-
/**
|
|
85
|
-
* Get comprehensive status
|
|
86
|
-
*/
|
|
87
|
-
getStatus(): Promise<UnifiedMCPStatus>;
|
|
88
|
-
/**
|
|
89
|
-
* Refresh external connections
|
|
90
|
-
*/
|
|
91
|
-
refreshExternalServers(): Promise<void>;
|
|
92
|
-
/**
|
|
93
|
-
* Shutdown the unified MCP system
|
|
94
|
-
*/
|
|
95
|
-
shutdown(): Promise<void>;
|
|
96
|
-
/**
|
|
97
|
-
* Check if system is initialized
|
|
98
|
-
*/
|
|
99
|
-
isSystemInitialized(): boolean;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Default unified MCP system instance
|
|
103
|
-
*/
|
|
104
|
-
export declare const defaultUnifiedMCP: UnifiedMCPSystem;
|
|
105
|
-
/**
|
|
106
|
-
* Initialize the default unified MCP system
|
|
107
|
-
*/
|
|
108
|
-
export declare function initializeMCP(options?: UnifiedMCPOptions): Promise<UnifiedMCPSystem>;
|
|
109
|
-
/**
|
|
110
|
-
* Get the default unified MCP system
|
|
111
|
-
*/
|
|
112
|
-
export declare function getMCPSystem(): UnifiedMCPSystem;
|
|
113
|
-
/**
|
|
114
|
-
* Execute a tool using the default system
|
|
115
|
-
*/
|
|
116
|
-
export declare function executeMCPTool(toolName: string, params: unknown, context: NeuroLinkExecutionContext): Promise<ToolResult>;
|
|
117
|
-
/**
|
|
118
|
-
* List all available MCP tools
|
|
119
|
-
*/
|
|
120
|
-
export declare function listMCPTools(criteria?: unknown): Promise<import("./tool-registry.js").ToolInfo[]>;
|
|
121
|
-
/**
|
|
122
|
-
* Get MCP tool information
|
|
123
|
-
*/
|
|
124
|
-
export declare function getMCPToolInfo(toolName: string): {
|
|
125
|
-
tool: import("./tool-registry.js").ToolInfo;
|
|
126
|
-
server: {
|
|
127
|
-
id: string;
|
|
128
|
-
};
|
|
129
|
-
} | undefined;
|
|
130
|
-
/**
|
|
131
|
-
* Get unified MCP system status
|
|
132
|
-
*/
|
|
133
|
-
export declare function getMCPStatus(): Promise<UnifiedMCPStatus>;
|