@juspay/neurolink 4.0.0 → 4.1.1

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 (56) hide show
  1. package/CHANGELOG.md +20 -5
  2. package/README.md +59 -1
  3. package/dist/lib/mcp/dynamic-chain-executor.d.ts +201 -0
  4. package/dist/lib/mcp/dynamic-chain-executor.js +489 -0
  5. package/dist/lib/mcp/dynamic-orchestrator.d.ts +109 -0
  6. package/dist/lib/mcp/dynamic-orchestrator.js +351 -0
  7. package/dist/lib/mcp/error-manager.d.ts +254 -0
  8. package/dist/lib/mcp/error-manager.js +501 -0
  9. package/dist/lib/mcp/error-recovery.d.ts +158 -0
  10. package/dist/lib/mcp/error-recovery.js +405 -0
  11. package/dist/lib/mcp/health-monitor.d.ts +256 -0
  12. package/dist/lib/mcp/health-monitor.js +621 -0
  13. package/dist/lib/mcp/orchestrator.d.ts +136 -5
  14. package/dist/lib/mcp/orchestrator.js +316 -9
  15. package/dist/lib/mcp/registry.d.ts +22 -0
  16. package/dist/lib/mcp/registry.js +24 -0
  17. package/dist/lib/mcp/semaphore-manager.d.ts +137 -0
  18. package/dist/lib/mcp/semaphore-manager.js +329 -0
  19. package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
  20. package/dist/lib/mcp/session-manager.d.ts +186 -0
  21. package/dist/lib/mcp/session-manager.js +400 -0
  22. package/dist/lib/mcp/session-persistence.d.ts +93 -0
  23. package/dist/lib/mcp/session-persistence.js +298 -0
  24. package/dist/lib/mcp/transport-manager.d.ts +153 -0
  25. package/dist/lib/mcp/transport-manager.js +330 -0
  26. package/dist/lib/mcp/unified-registry.d.ts +42 -1
  27. package/dist/lib/mcp/unified-registry.js +122 -2
  28. package/dist/lib/neurolink.d.ts +75 -0
  29. package/dist/lib/neurolink.js +104 -0
  30. package/dist/mcp/dynamic-chain-executor.d.ts +201 -0
  31. package/dist/mcp/dynamic-chain-executor.js +489 -0
  32. package/dist/mcp/dynamic-orchestrator.d.ts +109 -0
  33. package/dist/mcp/dynamic-orchestrator.js +351 -0
  34. package/dist/mcp/error-manager.d.ts +254 -0
  35. package/dist/mcp/error-manager.js +501 -0
  36. package/dist/mcp/error-recovery.d.ts +158 -0
  37. package/dist/mcp/error-recovery.js +405 -0
  38. package/dist/mcp/health-monitor.d.ts +256 -0
  39. package/dist/mcp/health-monitor.js +621 -0
  40. package/dist/mcp/orchestrator.d.ts +136 -5
  41. package/dist/mcp/orchestrator.js +316 -9
  42. package/dist/mcp/registry.d.ts +22 -0
  43. package/dist/mcp/registry.js +24 -0
  44. package/dist/mcp/semaphore-manager.d.ts +137 -0
  45. package/dist/mcp/semaphore-manager.js +329 -0
  46. package/dist/mcp/session-manager.d.ts +186 -0
  47. package/dist/mcp/session-manager.js +400 -0
  48. package/dist/mcp/session-persistence.d.ts +93 -0
  49. package/dist/mcp/session-persistence.js +299 -0
  50. package/dist/mcp/transport-manager.d.ts +153 -0
  51. package/dist/mcp/transport-manager.js +331 -0
  52. package/dist/mcp/unified-registry.d.ts +42 -1
  53. package/dist/mcp/unified-registry.js +122 -2
  54. package/dist/neurolink.d.ts +75 -0
  55. package/dist/neurolink.js +104 -0
  56. package/package.json +2 -1
@@ -0,0 +1,331 @@
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 || httpModule.HTTPClientTransport;
165
+ return new HTTPClientTransport(new URL(config.url), {
166
+ requestInit: {
167
+ headers: config.headers,
168
+ timeout: config.timeout * 1000, // Convert seconds to milliseconds
169
+ },
170
+ });
171
+ }
172
+ /**
173
+ * Set up health monitoring
174
+ */
175
+ setupHealthMonitoring() {
176
+ if (!this.client) {
177
+ return;
178
+ }
179
+ // Clear any existing health check timer
180
+ if (this.healthCheckTimer) {
181
+ clearInterval(this.healthCheckTimer);
182
+ }
183
+ // Set up periodic health checks
184
+ this.healthCheckTimer = setInterval(async () => {
185
+ if (!this.client) {
186
+ return;
187
+ }
188
+ try {
189
+ // Simple health check - list tools
190
+ await this.client.request({ method: "tools/list" }, z.object({ tools: z.array(z.any()) }));
191
+ }
192
+ catch (error) {
193
+ // Health check failed, trigger reconnection if enabled
194
+ if (this.options.autoReconnect && this.config) {
195
+ this.handleConnectionError(error);
196
+ }
197
+ }
198
+ }, this.options.healthCheckInterval);
199
+ }
200
+ /**
201
+ * Handle connection errors
202
+ */
203
+ handleConnectionError(error) {
204
+ const err = error instanceof Error ? error : new Error(String(error));
205
+ this.status.connected = false;
206
+ this.status.lastError = err;
207
+ // Record error
208
+ this.errorManager.recordError(err, {
209
+ category: ErrorCategory.CONNECTION_ERROR,
210
+ severity: ErrorSeverity.HIGH,
211
+ toolName: "transport-manager",
212
+ parameters: {
213
+ transport: this.status.type,
214
+ reconnectAttempts: this.status.reconnectAttempts,
215
+ },
216
+ });
217
+ // Attempt reconnection if enabled
218
+ if (this.options.autoReconnect &&
219
+ this.status.reconnectAttempts < this.options.maxReconnectAttempts) {
220
+ // Schedule reconnection attempt
221
+ this.scheduleReconnect();
222
+ }
223
+ }
224
+ /**
225
+ * Schedule reconnection attempt
226
+ */
227
+ scheduleReconnect() {
228
+ if (this.reconnectTimer) {
229
+ clearTimeout(this.reconnectTimer);
230
+ }
231
+ // Increment attempts BEFORE calculating delay (uses updated attempt count)
232
+ this.status.reconnectAttempts++;
233
+ const delay = this.calculateReconnectDelay();
234
+ this.reconnectTimer = setTimeout(() => {
235
+ this.reconnect().catch((error) => {
236
+ console.error("Reconnection failed:", error);
237
+ });
238
+ }, delay);
239
+ }
240
+ /**
241
+ * Calculate reconnect delay with exponential backoff
242
+ */
243
+ calculateReconnectDelay() {
244
+ const baseDelay = this.options.reconnectDelay || 1000;
245
+ const maxDelay = 30000; // 30 seconds max
246
+ const delay = Math.min(baseDelay * Math.pow(2, this.status.reconnectAttempts), maxDelay);
247
+ // Add configurable jitter to prevent thundering herd
248
+ if (this.options.jitterEnabled === true) {
249
+ const maxJitter = this.options.maxJitter || 1000;
250
+ return delay + Math.random() * maxJitter;
251
+ }
252
+ return delay;
253
+ }
254
+ /**
255
+ * Reconnect to server
256
+ */
257
+ async reconnect() {
258
+ // Prevent concurrent reconnection attempts
259
+ if (this.reconnectPromise) {
260
+ return this.reconnectPromise;
261
+ }
262
+ this.reconnectPromise = this._reconnect();
263
+ try {
264
+ await this.reconnectPromise;
265
+ }
266
+ finally {
267
+ this.reconnectPromise = undefined;
268
+ }
269
+ }
270
+ async _reconnect() {
271
+ if (!this.config) {
272
+ throw new Error("No configuration available for reconnection");
273
+ }
274
+ try {
275
+ await this.connect(this.config);
276
+ console.log(`Reconnected successfully after ${this.status.reconnectAttempts} attempts`);
277
+ }
278
+ catch (error) {
279
+ if (this.status.reconnectAttempts >= this.options.maxReconnectAttempts) {
280
+ throw new Error(`Max reconnection attempts (${this.options.maxReconnectAttempts}) reached`);
281
+ }
282
+ throw error;
283
+ }
284
+ }
285
+ /**
286
+ * Disconnect from server
287
+ */
288
+ async disconnect() {
289
+ // Clear reconnection timer
290
+ if (this.reconnectTimer) {
291
+ clearTimeout(this.reconnectTimer);
292
+ this.reconnectTimer = undefined;
293
+ }
294
+ // Stop health monitoring
295
+ if (this.healthCheckTimer) {
296
+ clearInterval(this.healthCheckTimer);
297
+ this.healthCheckTimer = undefined;
298
+ }
299
+ // Close client connection
300
+ if (this.client) {
301
+ await this.client.close();
302
+ this.client = undefined;
303
+ }
304
+ // Update status
305
+ this.status.connected = false;
306
+ }
307
+ /**
308
+ * Get current transport status
309
+ */
310
+ getStatus() {
311
+ return { ...this.status };
312
+ }
313
+ /**
314
+ * Get connected client
315
+ */
316
+ getClient() {
317
+ return this.client;
318
+ }
319
+ /**
320
+ * Check if connected
321
+ */
322
+ isConnected() {
323
+ return this.status.connected && this.client !== undefined;
324
+ }
325
+ /**
326
+ * Reset reconnection attempts
327
+ */
328
+ resetReconnectAttempts() {
329
+ this.status.reconnectAttempts = 0;
330
+ }
331
+ }
@@ -4,14 +4,20 @@
4
4
  import type { DiscoveredMCP, ExecutionContext } from "./contracts/mcp-contract.js";
5
5
  import type { DiscoveryOptions } from "./auto-discovery.js";
6
6
  import { MCPToolRegistry, type ToolInfo } from "./tool-registry.js";
7
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
8
+ import { ErrorManager } from "./error-manager.js";
7
9
  /**
8
10
  * Unified registry combining multiple sources
9
11
  */
10
12
  export declare class UnifiedMCPRegistry extends MCPToolRegistry {
13
+ private errorManager;
11
14
  private autoDiscoveryEnabled;
12
15
  private autoDiscoveredServers;
13
16
  private manualServers;
14
17
  private availableServers;
18
+ private transportManager;
19
+ private activeConnections;
20
+ constructor(errorManager?: ErrorManager);
15
21
  /**
16
22
  * Initialize with auto-discovery
17
23
  */
@@ -80,9 +86,44 @@ export declare class UnifiedMCPRegistry extends MCPToolRegistry {
80
86
  tools?: number;
81
87
  }>;
82
88
  /**
83
- * Clear all registries
89
+ * Add external MCP server programmatically
90
+ *
91
+ * @param serverId - Unique server identifier
92
+ * @param config - Server configuration (stdio, sse, or http)
93
+ */
94
+ addExternalServer(serverId: string, config: {
95
+ type: "stdio" | "sse" | "http";
96
+ command?: string;
97
+ args?: string[];
98
+ env?: Record<string, string>;
99
+ cwd?: string;
100
+ url?: string;
101
+ headers?: Record<string, string>;
102
+ timeout?: number;
103
+ }): Promise<void>;
104
+ /**
105
+ * Get active connection for a server
106
+ */
107
+ getConnection(serverId: string): Client | undefined;
108
+ /**
109
+ * Check if server is actively connected
110
+ */
111
+ isConnected(serverId: string): boolean;
112
+ /**
113
+ * Clear all registries and active connections (synchronous, preserves base API contract)
114
+ */
115
+ /**
116
+ * Clear registries without closing connections (internal use)
117
+ */
118
+ private clearRegistriesOnly;
119
+ /**
120
+ * Clear all registries and initiate async connection cleanup
84
121
  */
85
122
  clear(): void;
123
+ /**
124
+ * Clear all registries and close active connections asynchronously
125
+ */
126
+ clearAsync(): Promise<void>;
86
127
  }
87
128
  /**
88
129
  * Default unified registry instance
@@ -5,14 +5,25 @@ import { MCPRegistry } from "./registry.js";
5
5
  import { discoverMCPServers, autoRegisterMCPServers, } from "./auto-discovery.js";
6
6
  import { unifiedRegistryLogger } from "./logging.js";
7
7
  import { MCPToolRegistry, } from "./tool-registry.js";
8
+ import { TransportManager, TransportConfigSchema, } from "./transport-manager.js";
9
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
10
+ import { ErrorManager } from "./error-manager.js";
8
11
  /**
9
12
  * Unified registry combining multiple sources
10
13
  */
11
14
  export class UnifiedMCPRegistry extends MCPToolRegistry {
15
+ errorManager;
12
16
  autoDiscoveryEnabled = true;
13
17
  autoDiscoveredServers = [];
14
18
  manualServers = new Map();
15
19
  availableServers = new Set();
20
+ transportManager;
21
+ activeConnections = new Map();
22
+ constructor(errorManager = new ErrorManager()) {
23
+ super();
24
+ this.errorManager = errorManager;
25
+ this.transportManager = new TransportManager(this.errorManager);
26
+ }
16
27
  /**
17
28
  * Initialize with auto-discovery
18
29
  */
@@ -160,14 +171,123 @@ export class UnifiedMCPRegistry extends MCPToolRegistry {
160
171
  };
161
172
  }
162
173
  /**
163
- * Clear all registries
174
+ * Add external MCP server programmatically
175
+ *
176
+ * @param serverId - Unique server identifier
177
+ * @param config - Server configuration (stdio, sse, or http)
164
178
  */
165
- clear() {
179
+ async addExternalServer(serverId, config) {
180
+ unifiedRegistryLogger.info(`Adding external server: ${serverId} (${config.type})`);
181
+ // Create server metadata
182
+ const serverMeta = {
183
+ metadata: {
184
+ name: serverId,
185
+ version: "1.0.0",
186
+ main: "index.js",
187
+ engine: { neurolink: ">=4.0.0" },
188
+ description: `External ${config.type} server: ${serverId}`,
189
+ permissions: ["network", "filesystem"],
190
+ },
191
+ entryPath: "",
192
+ source: "installed",
193
+ constructor: undefined,
194
+ };
195
+ // Register in internal registry
196
+ this.register(serverMeta);
197
+ this.manualServers.set(serverId, config);
198
+ this.availableServers.add(serverId);
199
+ // Establish actual connection to make server immediately reachable
200
+ try {
201
+ // Validate config for stdio transport (most common case)
202
+ if (config.type === "stdio" && !config.command) {
203
+ throw new Error("Command is required for stdio transport");
204
+ }
205
+ // Create transport with proper type validation
206
+ // Validate config shape before creating transport
207
+ const validatedConfig = TransportConfigSchema.parse(config);
208
+ const transport = await this.transportManager.createTransport(validatedConfig);
209
+ const client = new Client({
210
+ name: "neurolink-client",
211
+ version: "4.1.0",
212
+ }, {
213
+ capabilities: {
214
+ tools: {},
215
+ logging: {},
216
+ },
217
+ });
218
+ // Connect the client
219
+ await client.connect(transport);
220
+ this.activeConnections.set(serverId, client);
221
+ unifiedRegistryLogger.info(`Successfully connected to external server: ${serverId}`);
222
+ unifiedRegistryLogger.info(`Successfully added external server: ${serverId}`);
223
+ }
224
+ catch (error) {
225
+ const errorMessage = error instanceof Error ? error.message : String(error);
226
+ unifiedRegistryLogger.warn(`Failed to establish connection to ${serverId}: ${errorMessage}. Server registered but not connected.`);
227
+ unifiedRegistryLogger.info(`Successfully registered external server: ${serverId} but connection failed.`);
228
+ }
229
+ }
230
+ /**
231
+ * Get active connection for a server
232
+ */
233
+ getConnection(serverId) {
234
+ return this.activeConnections.get(serverId);
235
+ }
236
+ /**
237
+ * Check if server is actively connected
238
+ */
239
+ isConnected(serverId) {
240
+ return this.activeConnections.has(serverId);
241
+ }
242
+ /**
243
+ * Clear all registries and active connections (synchronous, preserves base API contract)
244
+ */
245
+ /**
246
+ * Clear registries without closing connections (internal use)
247
+ */
248
+ clearRegistriesOnly() {
166
249
  super.clear();
167
250
  this.autoDiscoveredServers = [];
168
251
  this.manualServers.clear();
169
252
  this.availableServers.clear();
170
253
  }
254
+ /**
255
+ * Clear all registries and initiate async connection cleanup
256
+ */
257
+ clear() {
258
+ // Close all active connections before clearing registries to prevent resource leaks
259
+ const closePromises = [];
260
+ for (const [serverId, client] of this.activeConnections) {
261
+ closePromises.push(client.close().catch((error) => {
262
+ const errorMessage = error instanceof Error ? error.message : String(error);
263
+ unifiedRegistryLogger.warn(`Failed to close connection for ${serverId}: ${errorMessage}`);
264
+ }));
265
+ }
266
+ // Handle async cleanup without blocking synchronous clear()
267
+ Promise.allSettled(closePromises).then(() => {
268
+ this.activeConnections.clear();
269
+ });
270
+ // Clear registries after initiating connection cleanup
271
+ this.clearRegistriesOnly();
272
+ }
273
+ /**
274
+ * Clear all registries and close active connections asynchronously
275
+ */
276
+ async clearAsync() {
277
+ // Close all active connections first
278
+ for (const [serverId, client] of this.activeConnections) {
279
+ try {
280
+ await client.close();
281
+ }
282
+ catch (error) {
283
+ const errorMessage = error instanceof Error ? error.message : String(error);
284
+ unifiedRegistryLogger.warn(`Failed to close connection for ${serverId}: ${errorMessage}`);
285
+ }
286
+ }
287
+ this.activeConnections.clear();
288
+ // Clear registries without attempting to close connections again
289
+ this.clearRegistriesOnly();
290
+ }
171
291
  }
172
292
  /**
173
293
  * Default unified registry instance
@@ -129,6 +129,47 @@ export declare class NeuroLink {
129
129
  hasServer: boolean;
130
130
  }[];
131
131
  }>;
132
+ /**
133
+ * Add a new MCP server programmatically
134
+ *
135
+ * Allows dynamic registration of MCP servers at runtime for enhanced
136
+ * tool ecosystem management. Perfect for integrating external services
137
+ * like Bitbucket, Slack, databases, etc.
138
+ *
139
+ * @param serverId - Unique identifier for the server (e.g., 'bitbucket', 'slack-api')
140
+ * @param config - Server configuration with command and execution parameters
141
+ * @returns Promise that resolves when server is successfully added and connected
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * // Add Bitbucket MCP server
146
+ * await neurolink.addMCPServer('bitbucket', {
147
+ * command: 'npx',
148
+ * args: ['-y', '@nexus2520/bitbucket-mcp-server'],
149
+ * env: {
150
+ * BITBUCKET_USERNAME: 'your-username',
151
+ * BITBUCKET_APP_PASSWORD: 'your-app-password'
152
+ * }
153
+ * });
154
+ *
155
+ * // Add custom database connector
156
+ * await neurolink.addMCPServer('database', {
157
+ * command: 'node',
158
+ * args: ['./custom-db-mcp-server.js'],
159
+ * env: { DB_CONNECTION_STRING: 'postgresql://...' }
160
+ * });
161
+ * ```
162
+ */
163
+ addMCPServer(serverId: string, config: {
164
+ command: string;
165
+ args?: string[];
166
+ env?: Record<string, string>;
167
+ cwd?: string;
168
+ type?: "stdio" | "sse" | "http";
169
+ url?: string;
170
+ headers?: Record<string, string>;
171
+ timeout?: number;
172
+ }): Promise<void>;
132
173
  /**
133
174
  * Alias for generateText() - CLI-SDK consistency
134
175
  * @param options - Text generation options
@@ -141,4 +182,38 @@ export declare class NeuroLink {
141
182
  * @returns Promise resolving to text generation result
142
183
  */
143
184
  gen(options: TextGenerationOptions): Promise<TextGenerationResult>;
185
+ /**
186
+ * Get the connection client for a specific MCP server
187
+ * @param serverId - The ID of the server to get connection for
188
+ * @returns Client connection object or undefined if not connected
189
+ */
190
+ getConnection(serverId: string): import("@modelcontextprotocol/sdk/client/index.js").Client<{
191
+ method: string;
192
+ params?: {
193
+ [x: string]: unknown;
194
+ _meta?: {
195
+ [x: string]: unknown;
196
+ progressToken?: string | number | undefined;
197
+ } | undefined;
198
+ } | undefined;
199
+ }, {
200
+ method: string;
201
+ params?: {
202
+ [x: string]: unknown;
203
+ _meta?: {
204
+ [x: string]: unknown;
205
+ } | undefined;
206
+ } | undefined;
207
+ }, {
208
+ [x: string]: unknown;
209
+ _meta?: {
210
+ [x: string]: unknown;
211
+ } | undefined;
212
+ }> | undefined;
213
+ /**
214
+ * Check if a specific MCP server is currently connected
215
+ * @param serverId - The ID of the server to check
216
+ * @returns True if server is connected, false otherwise
217
+ */
218
+ isConnected(serverId: string): boolean;
144
219
  }