@juspay/neurolink 8.28.0 → 8.30.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 +12 -0
- package/README.md +23 -2
- package/dist/adapters/video/vertexVideoHandler.d.ts +12 -2
- package/dist/adapters/video/vertexVideoHandler.js +12 -2
- package/dist/core/baseProvider.d.ts +19 -0
- package/dist/core/baseProvider.js +174 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +7 -1
- package/dist/lib/adapters/video/vertexVideoHandler.d.ts +12 -2
- package/dist/lib/adapters/video/vertexVideoHandler.js +12 -2
- package/dist/lib/core/baseProvider.d.ts +19 -0
- package/dist/lib/core/baseProvider.js +174 -0
- package/dist/lib/index.d.ts +3 -3
- package/dist/lib/index.js +7 -1
- package/dist/lib/mcp/auth/index.d.ts +6 -0
- package/dist/lib/mcp/auth/index.js +12 -0
- package/dist/lib/mcp/auth/oauthClientProvider.d.ts +93 -0
- package/dist/lib/mcp/auth/oauthClientProvider.js +326 -0
- package/dist/lib/mcp/auth/tokenStorage.d.ts +56 -0
- package/dist/lib/mcp/auth/tokenStorage.js +135 -0
- package/dist/lib/mcp/externalServerManager.d.ts +5 -1
- package/dist/lib/mcp/externalServerManager.js +84 -22
- package/dist/lib/mcp/httpRateLimiter.d.ts +152 -0
- package/dist/lib/mcp/httpRateLimiter.js +365 -0
- package/dist/lib/mcp/httpRetryHandler.d.ts +62 -0
- package/dist/lib/mcp/httpRetryHandler.js +154 -0
- package/dist/lib/mcp/index.d.ts +5 -0
- package/dist/lib/mcp/index.js +8 -0
- package/dist/lib/mcp/mcpClientFactory.d.ts +25 -2
- package/dist/lib/mcp/mcpClientFactory.js +206 -10
- package/dist/lib/mcp/toolRegistry.d.ts +1 -2
- package/dist/lib/mcp/toolRegistry.js +1 -5
- package/dist/lib/neurolink.js +3 -0
- package/dist/lib/providers/amazonBedrock.js +4 -1
- package/dist/lib/providers/ollama.js +4 -1
- package/dist/lib/sdk/toolRegistration.d.ts +3 -25
- package/dist/lib/types/cli.d.ts +42 -42
- package/dist/lib/types/externalMcp.d.ts +55 -3
- package/dist/lib/types/externalMcp.js +0 -1
- package/dist/lib/types/generateTypes.d.ts +37 -0
- package/dist/lib/types/hitlTypes.d.ts +38 -0
- package/dist/lib/types/index.d.ts +6 -8
- package/dist/lib/types/index.js +4 -4
- package/dist/lib/types/mcpTypes.d.ts +235 -27
- package/dist/lib/types/providers.d.ts +16 -16
- package/dist/lib/types/sdkTypes.d.ts +2 -2
- package/dist/lib/types/tools.d.ts +42 -3
- package/dist/lib/types/utilities.d.ts +19 -0
- package/dist/mcp/auth/index.d.ts +6 -0
- package/dist/mcp/auth/index.js +11 -0
- package/dist/mcp/auth/oauthClientProvider.d.ts +93 -0
- package/dist/mcp/auth/oauthClientProvider.js +325 -0
- package/dist/mcp/auth/tokenStorage.d.ts +56 -0
- package/dist/mcp/auth/tokenStorage.js +134 -0
- package/dist/mcp/externalServerManager.d.ts +5 -1
- package/dist/mcp/externalServerManager.js +84 -22
- package/dist/mcp/httpRateLimiter.d.ts +152 -0
- package/dist/mcp/httpRateLimiter.js +364 -0
- package/dist/mcp/httpRetryHandler.d.ts +62 -0
- package/dist/mcp/httpRetryHandler.js +153 -0
- package/dist/mcp/index.d.ts +5 -0
- package/dist/mcp/index.js +8 -0
- package/dist/mcp/mcpClientFactory.d.ts +25 -2
- package/dist/mcp/mcpClientFactory.js +206 -10
- package/dist/mcp/toolRegistry.d.ts +1 -2
- package/dist/mcp/toolRegistry.js +1 -5
- package/dist/neurolink.js +3 -0
- package/dist/providers/amazonBedrock.js +4 -1
- package/dist/providers/ollama.js +4 -1
- package/dist/sdk/toolRegistration.d.ts +3 -25
- package/dist/types/cli.d.ts +42 -42
- package/dist/types/externalMcp.d.ts +55 -3
- package/dist/types/externalMcp.js +0 -1
- package/dist/types/generateTypes.d.ts +37 -0
- package/dist/types/hitlTypes.d.ts +38 -0
- package/dist/types/index.d.ts +6 -8
- package/dist/types/index.js +4 -4
- package/dist/types/mcpTypes.d.ts +235 -27
- package/dist/types/providers.d.ts +16 -16
- package/dist/types/sdkTypes.d.ts +2 -2
- package/dist/types/tools.d.ts +42 -3
- package/dist/types/utilities.d.ts +19 -0
- package/package.json +2 -1
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* MCP Client Factory
|
|
3
3
|
* Creates and manages MCP clients for external servers
|
|
4
|
-
* Supports stdio, SSE, and
|
|
4
|
+
* Supports stdio, SSE, WebSocket, and HTTP transports
|
|
5
|
+
* Enhanced with retry, rate limiting, and OAuth 2.1 support
|
|
5
6
|
*/
|
|
6
7
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
7
8
|
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
8
9
|
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
9
10
|
import { WebSocketClientTransport } from "@modelcontextprotocol/sdk/client/websocket.js";
|
|
10
|
-
import {
|
|
11
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
12
|
+
import { spawn } from "child_process";
|
|
11
13
|
import { mcpLogger } from "../utils/logger.js";
|
|
12
14
|
import { globalCircuitBreakerManager } from "./mcpCircuitBreaker.js";
|
|
15
|
+
import { withHTTPRetry, DEFAULT_HTTP_RETRY_CONFIG, } from "./httpRetryHandler.js";
|
|
16
|
+
import { globalRateLimiterManager } from "./httpRateLimiter.js";
|
|
17
|
+
import { NeuroLinkOAuthProvider, InMemoryTokenStorage } from "./auth/index.js";
|
|
13
18
|
/**
|
|
14
19
|
* MCPClientFactory
|
|
15
20
|
* Factory class for creating MCP clients with different transports
|
|
@@ -27,6 +32,7 @@ export class MCPClientFactory {
|
|
|
27
32
|
};
|
|
28
33
|
/**
|
|
29
34
|
* Create an MCP client for the given server configuration
|
|
35
|
+
* Enhanced with retry logic, rate limiting, and circuit breaker protection
|
|
30
36
|
*/
|
|
31
37
|
static async createClient(config, timeout = 10000) {
|
|
32
38
|
const startTime = Date.now();
|
|
@@ -34,17 +40,56 @@ export class MCPClientFactory {
|
|
|
34
40
|
mcpLogger.info(`[MCPClientFactory] Creating client for ${config.id}`, {
|
|
35
41
|
transport: config.transport,
|
|
36
42
|
command: config.command,
|
|
43
|
+
hasRetryConfig: !!config.retryConfig,
|
|
44
|
+
hasRateLimiting: !!config.rateLimiting,
|
|
45
|
+
hasAuth: !!config.auth,
|
|
37
46
|
});
|
|
47
|
+
// Acquire rate limit token if rate limiting is configured for HTTP transport
|
|
48
|
+
if ((config.transport === "http" || config.transport === "sse") &&
|
|
49
|
+
config.rateLimiting) {
|
|
50
|
+
const rateLimiter = globalRateLimiterManager.getLimiter(config.id, {
|
|
51
|
+
requestsPerWindow: config.rateLimiting.requestsPerMinute ?? 60,
|
|
52
|
+
windowMs: 60000,
|
|
53
|
+
maxBurst: config.rateLimiting.maxBurst ?? 10,
|
|
54
|
+
useTokenBucket: config.rateLimiting.useTokenBucket ?? true,
|
|
55
|
+
refillRate: (config.rateLimiting.requestsPerMinute ?? 60) / 60,
|
|
56
|
+
});
|
|
57
|
+
await rateLimiter.acquire();
|
|
58
|
+
mcpLogger.debug(`[MCPClientFactory] Rate limit token acquired for ${config.id}`);
|
|
59
|
+
}
|
|
38
60
|
// Create circuit breaker for this server
|
|
39
61
|
const circuitBreaker = globalCircuitBreakerManager.getBreaker(`mcp-client-${config.id}`, {
|
|
40
62
|
failureThreshold: 3,
|
|
41
63
|
resetTimeout: 30000,
|
|
42
64
|
operationTimeout: timeout,
|
|
43
65
|
});
|
|
44
|
-
//
|
|
45
|
-
const
|
|
46
|
-
return await
|
|
47
|
-
|
|
66
|
+
// Define the client creation operation
|
|
67
|
+
const createClientOperation = async () => {
|
|
68
|
+
return await circuitBreaker.execute(async () => {
|
|
69
|
+
return await this.createClientInternal(config, timeout);
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
// Wrap with retry logic if retry config is provided for HTTP transport
|
|
73
|
+
let result;
|
|
74
|
+
if ((config.transport === "http" || config.transport === "sse") &&
|
|
75
|
+
config.retryConfig) {
|
|
76
|
+
mcpLogger.debug(`[MCPClientFactory] Using retry logic for ${config.id}`, {
|
|
77
|
+
maxAttempts: config.retryConfig.maxAttempts ??
|
|
78
|
+
DEFAULT_HTTP_RETRY_CONFIG.maxAttempts,
|
|
79
|
+
});
|
|
80
|
+
result = await withHTTPRetry(createClientOperation, {
|
|
81
|
+
maxAttempts: config.retryConfig.maxAttempts ??
|
|
82
|
+
DEFAULT_HTTP_RETRY_CONFIG.maxAttempts,
|
|
83
|
+
initialDelay: config.retryConfig.initialDelay ??
|
|
84
|
+
DEFAULT_HTTP_RETRY_CONFIG.initialDelay,
|
|
85
|
+
maxDelay: config.retryConfig.maxDelay ?? DEFAULT_HTTP_RETRY_CONFIG.maxDelay,
|
|
86
|
+
backoffMultiplier: config.retryConfig.backoffMultiplier ??
|
|
87
|
+
DEFAULT_HTTP_RETRY_CONFIG.backoffMultiplier,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
result = await createClientOperation();
|
|
92
|
+
}
|
|
48
93
|
mcpLogger.info(`[MCPClientFactory] Client created successfully for ${config.id}`, {
|
|
49
94
|
duration: Date.now() - startTime,
|
|
50
95
|
capabilities: result.capabilities,
|
|
@@ -122,6 +167,8 @@ export class MCPClientFactory {
|
|
|
122
167
|
return this.createSSETransport(config);
|
|
123
168
|
case "websocket":
|
|
124
169
|
return this.createWebSocketTransport(config);
|
|
170
|
+
case "http":
|
|
171
|
+
return this.createHTTPTransport(config);
|
|
125
172
|
default:
|
|
126
173
|
throw new Error(`Unsupported transport type: ${config.transport}`);
|
|
127
174
|
}
|
|
@@ -244,6 +291,153 @@ export class MCPClientFactory {
|
|
|
244
291
|
throw new Error(`Invalid WebSocket URL: ${error instanceof Error ? error.message : String(error)}`);
|
|
245
292
|
}
|
|
246
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* Create HTTP transport (Streamable HTTP)
|
|
296
|
+
* Enhanced with OAuth 2.1, rate limiting, and configurable timeouts
|
|
297
|
+
*/
|
|
298
|
+
static async createHTTPTransport(config) {
|
|
299
|
+
if (!config.url) {
|
|
300
|
+
throw new Error("URL is required for HTTP transport");
|
|
301
|
+
}
|
|
302
|
+
// Extract HTTP options with defaults
|
|
303
|
+
const httpOptions = {
|
|
304
|
+
connectionTimeout: config.httpOptions?.connectionTimeout ?? 30000,
|
|
305
|
+
requestTimeout: config.httpOptions?.requestTimeout ?? 60000,
|
|
306
|
+
idleTimeout: config.httpOptions?.idleTimeout ?? 120000,
|
|
307
|
+
keepAliveTimeout: config.httpOptions?.keepAliveTimeout ?? 30000,
|
|
308
|
+
};
|
|
309
|
+
mcpLogger.debug(`[MCPClientFactory] Creating HTTP transport for ${config.id}`, {
|
|
310
|
+
url: config.url,
|
|
311
|
+
hasHeaders: !!config.headers,
|
|
312
|
+
hasAuth: !!config.auth,
|
|
313
|
+
authType: config.auth?.type,
|
|
314
|
+
httpOptions,
|
|
315
|
+
});
|
|
316
|
+
try {
|
|
317
|
+
const url = new URL(config.url);
|
|
318
|
+
// Set up OAuth provider if configured
|
|
319
|
+
const oauthProvider = await this.setupAuthProvider(config);
|
|
320
|
+
// Build headers including authentication
|
|
321
|
+
const headers = {
|
|
322
|
+
...(config.headers ?? {}),
|
|
323
|
+
};
|
|
324
|
+
// Add authentication headers based on auth type
|
|
325
|
+
if (config.auth) {
|
|
326
|
+
const authHeader = await this.getAuthorizationHeader(config, oauthProvider);
|
|
327
|
+
if (authHeader) {
|
|
328
|
+
headers["Authorization"] = authHeader;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
// Create custom fetch wrapper with timeout and rate limiting support
|
|
332
|
+
const fetchWithEnhancements = this.createEnhancedFetch(config, httpOptions.requestTimeout, oauthProvider);
|
|
333
|
+
// Create request init with custom headers
|
|
334
|
+
const requestInit = {
|
|
335
|
+
headers: Object.keys(headers).length > 0 ? headers : undefined,
|
|
336
|
+
};
|
|
337
|
+
const transport = new StreamableHTTPClientTransport(url, {
|
|
338
|
+
requestInit,
|
|
339
|
+
fetch: fetchWithEnhancements,
|
|
340
|
+
});
|
|
341
|
+
return { transport };
|
|
342
|
+
}
|
|
343
|
+
catch (error) {
|
|
344
|
+
throw new Error(`Invalid HTTP URL: ${error instanceof Error ? error.message : String(error)}`);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Create a fetch wrapper with timeout support
|
|
349
|
+
*/
|
|
350
|
+
static createFetchWithTimeout(timeoutMs) {
|
|
351
|
+
return async (input, init) => {
|
|
352
|
+
const controller = new AbortController();
|
|
353
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
354
|
+
try {
|
|
355
|
+
return await fetch(input, { ...init, signal: controller.signal });
|
|
356
|
+
}
|
|
357
|
+
finally {
|
|
358
|
+
clearTimeout(timeoutId);
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Create an enhanced fetch function with timeout and optional retry
|
|
364
|
+
*/
|
|
365
|
+
static createEnhancedFetch(config, timeoutMs, oauthProvider) {
|
|
366
|
+
const fetchWithTimeout = this.createFetchWithTimeout(timeoutMs);
|
|
367
|
+
return async (input, init) => {
|
|
368
|
+
// If OAuth is configured, ensure we have valid tokens
|
|
369
|
+
if (oauthProvider && config.auth?.type === "oauth2") {
|
|
370
|
+
try {
|
|
371
|
+
const authHeader = await oauthProvider.getAuthorizationHeader(config.id);
|
|
372
|
+
if (authHeader) {
|
|
373
|
+
const existingHeaders = init?.headers ?? {};
|
|
374
|
+
const headers = new Headers(existingHeaders);
|
|
375
|
+
headers.set("Authorization", authHeader);
|
|
376
|
+
init = {
|
|
377
|
+
...init,
|
|
378
|
+
headers,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
catch (error) {
|
|
383
|
+
mcpLogger.warn(`[MCPClientFactory] OAuth token refresh failed for ${config.id}:`, error instanceof Error ? error.message : String(error));
|
|
384
|
+
// Continue without auth - let the request fail naturally
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return fetchWithTimeout(input, init);
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Set up OAuth provider if configured
|
|
392
|
+
*/
|
|
393
|
+
static async setupAuthProvider(config) {
|
|
394
|
+
if (config.auth?.type === "oauth2" && config.auth.oauth) {
|
|
395
|
+
const tokenStorage = new InMemoryTokenStorage();
|
|
396
|
+
const oauthConfig = {
|
|
397
|
+
clientId: config.auth.oauth.clientId,
|
|
398
|
+
clientSecret: config.auth.oauth.clientSecret,
|
|
399
|
+
authorizationUrl: config.auth.oauth.authorizationUrl,
|
|
400
|
+
tokenUrl: config.auth.oauth.tokenUrl,
|
|
401
|
+
redirectUrl: config.auth.oauth.redirectUrl,
|
|
402
|
+
scope: config.auth.oauth.scope,
|
|
403
|
+
usePKCE: config.auth.oauth.usePKCE ?? true,
|
|
404
|
+
};
|
|
405
|
+
const provider = new NeuroLinkOAuthProvider(oauthConfig, tokenStorage);
|
|
406
|
+
mcpLogger.debug(`[MCPClientFactory] OAuth provider created for ${config.id}`, {
|
|
407
|
+
clientId: oauthConfig.clientId,
|
|
408
|
+
usePKCE: oauthConfig.usePKCE,
|
|
409
|
+
});
|
|
410
|
+
return provider;
|
|
411
|
+
}
|
|
412
|
+
return undefined;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Get authorization header based on auth configuration
|
|
416
|
+
*/
|
|
417
|
+
static async getAuthorizationHeader(config, oauthProvider) {
|
|
418
|
+
if (!config.auth) {
|
|
419
|
+
return undefined;
|
|
420
|
+
}
|
|
421
|
+
switch (config.auth.type) {
|
|
422
|
+
case "oauth2":
|
|
423
|
+
if (oauthProvider) {
|
|
424
|
+
const header = await oauthProvider.getAuthorizationHeader(config.id);
|
|
425
|
+
return header ?? undefined;
|
|
426
|
+
}
|
|
427
|
+
return undefined;
|
|
428
|
+
case "bearer":
|
|
429
|
+
if (config.auth.token) {
|
|
430
|
+
return `Bearer ${config.auth.token}`;
|
|
431
|
+
}
|
|
432
|
+
return undefined;
|
|
433
|
+
case "api-key":
|
|
434
|
+
// API key is typically sent as a custom header, not Authorization
|
|
435
|
+
// But if needed, we can return it here
|
|
436
|
+
return undefined;
|
|
437
|
+
default:
|
|
438
|
+
return undefined;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
247
441
|
/**
|
|
248
442
|
* Perform MCP handshake and get server capabilities
|
|
249
443
|
*/
|
|
@@ -427,11 +621,13 @@ export class MCPClientFactory {
|
|
|
427
621
|
if (!config.transport) {
|
|
428
622
|
errors.push("Transport is required");
|
|
429
623
|
}
|
|
430
|
-
if (!["stdio", "sse", "websocket"].includes(config.transport)) {
|
|
431
|
-
errors.push("Transport must be stdio, sse, or
|
|
624
|
+
if (!["stdio", "sse", "websocket", "http"].includes(config.transport)) {
|
|
625
|
+
errors.push("Transport must be stdio, sse, websocket, or http");
|
|
432
626
|
}
|
|
433
627
|
// Transport-specific validation
|
|
434
|
-
if (config.transport === "sse" ||
|
|
628
|
+
if (config.transport === "sse" ||
|
|
629
|
+
config.transport === "websocket" ||
|
|
630
|
+
config.transport === "http") {
|
|
435
631
|
if (!config.url) {
|
|
436
632
|
errors.push(`URL is required for ${config.transport} transport`);
|
|
437
633
|
}
|
|
@@ -458,7 +654,7 @@ export class MCPClientFactory {
|
|
|
458
654
|
* Get supported transport types
|
|
459
655
|
*/
|
|
460
656
|
static getSupportedTransports() {
|
|
461
|
-
return ["stdio", "sse", "websocket"];
|
|
657
|
+
return ["stdio", "sse", "websocket", "http"];
|
|
462
658
|
}
|
|
463
659
|
/**
|
|
464
660
|
* Get default client capabilities
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import type { MCPServerInfo } from "../types/mcpTypes.js";
|
|
6
6
|
import type { ToolImplementation, ToolInfo, ExecutionContext } from "../types/tools.js";
|
|
7
7
|
import { MCPRegistry } from "./registry.js";
|
|
8
|
-
import type { HITLManager } from "../
|
|
8
|
+
import type { HITLManager } from "../types/hitlTypes.js";
|
|
9
9
|
export declare class MCPToolRegistry extends MCPRegistry {
|
|
10
10
|
private tools;
|
|
11
11
|
private toolImplementations;
|
|
@@ -141,4 +141,3 @@ export declare class MCPToolRegistry extends MCPRegistry {
|
|
|
141
141
|
}
|
|
142
142
|
export declare const toolRegistry: MCPToolRegistry;
|
|
143
143
|
export declare const defaultToolRegistry: MCPToolRegistry;
|
|
144
|
-
export type { ToolInfo } from "../types/tools.js";
|
|
@@ -100,14 +100,12 @@ export class MCPToolRegistry extends MCPRegistry {
|
|
|
100
100
|
}
|
|
101
101
|
registryLogger.debug(`Auto-registered ${Object.keys(directAgentTools).length} direct tools`);
|
|
102
102
|
}
|
|
103
|
-
async registerServer(serverInfoOrId,
|
|
103
|
+
async registerServer(serverInfoOrId, _serverConfigOrContext, _context) {
|
|
104
104
|
// Handle both signatures for backward compatibility
|
|
105
105
|
let serverInfo;
|
|
106
|
-
let _finalContext;
|
|
107
106
|
if (typeof serverInfoOrId === "string") {
|
|
108
107
|
// Legacy signature: registerServer(serverId, serverConfig, context)
|
|
109
108
|
const serverId = serverInfoOrId;
|
|
110
|
-
_finalContext = context;
|
|
111
109
|
// Convert legacy call to MCPServerInfo format using smart defaults
|
|
112
110
|
serverInfo = createMCPServerInfo({
|
|
113
111
|
id: serverId,
|
|
@@ -119,7 +117,6 @@ export class MCPToolRegistry extends MCPRegistry {
|
|
|
119
117
|
else {
|
|
120
118
|
// New signature: registerServer(serverInfo, context)
|
|
121
119
|
serverInfo = serverInfoOrId;
|
|
122
|
-
_finalContext = serverConfigOrContext;
|
|
123
120
|
}
|
|
124
121
|
const serverId = serverInfo.id;
|
|
125
122
|
// Use MCPServerInfo.tools array directly - ZERO conversions!
|
|
@@ -231,7 +228,6 @@ export class MCPToolRegistry extends MCPRegistry {
|
|
|
231
228
|
async executeTool(toolName, args, context) {
|
|
232
229
|
const startTime = Date.now();
|
|
233
230
|
try {
|
|
234
|
-
registryLogger.info(`🔧 [TOOL_EXECUTION] Starting execution: ${toolName}`);
|
|
235
231
|
registryLogger.info(`🔧 [TOOL_EXECUTION] Starting execution: ${toolName}`, { args, context });
|
|
236
232
|
// Try to find the tool by fully-qualified name first
|
|
237
233
|
let tool = this.tools.get(toolName);
|
package/dist/lib/neurolink.js
CHANGED
|
@@ -1362,6 +1362,7 @@ Current user's request: ${currentInput}`;
|
|
|
1362
1362
|
}
|
|
1363
1363
|
: undefined,
|
|
1364
1364
|
audio: textResult.audio,
|
|
1365
|
+
video: textResult.video,
|
|
1365
1366
|
};
|
|
1366
1367
|
if (this.conversationMemoryConfig?.conversationMemory?.mem0Enabled &&
|
|
1367
1368
|
options.context?.userId &&
|
|
@@ -1662,6 +1663,7 @@ Current user's request: ${currentInput}`;
|
|
|
1662
1663
|
enhancedWithTools: Boolean(hasToolExecutions), // Mark as enhanced if tools were actually used
|
|
1663
1664
|
availableTools: transformToolsForMCP(transformToolsToExpectedFormat(availableTools)),
|
|
1664
1665
|
audio: result.audio,
|
|
1666
|
+
video: result.video,
|
|
1665
1667
|
// Include analytics and evaluation from BaseProvider
|
|
1666
1668
|
analytics: result.analytics,
|
|
1667
1669
|
evaluation: result.evaluation,
|
|
@@ -1755,6 +1757,7 @@ Current user's request: ${currentInput}`;
|
|
|
1755
1757
|
analytics: result.analytics,
|
|
1756
1758
|
evaluation: result.evaluation,
|
|
1757
1759
|
audio: result.audio,
|
|
1760
|
+
video: result.video,
|
|
1758
1761
|
};
|
|
1759
1762
|
}
|
|
1760
1763
|
catch (error) {
|
|
@@ -474,7 +474,10 @@ export class AmazonBedrockProvider extends BaseProvider {
|
|
|
474
474
|
}
|
|
475
475
|
}
|
|
476
476
|
else if (result.error) {
|
|
477
|
-
|
|
477
|
+
const errorMessage = typeof result.error === "string"
|
|
478
|
+
? result.error
|
|
479
|
+
: result.error.message || "Tool execution failed";
|
|
480
|
+
throw new Error(errorMessage);
|
|
478
481
|
}
|
|
479
482
|
}
|
|
480
483
|
// Fallback for non-ToolResult return types
|
|
@@ -1194,7 +1194,10 @@ export class OllamaProvider extends BaseProvider {
|
|
|
1194
1194
|
}
|
|
1195
1195
|
}
|
|
1196
1196
|
else if (result.error) {
|
|
1197
|
-
|
|
1197
|
+
const errorMessage = typeof result.error === "string"
|
|
1198
|
+
? result.error
|
|
1199
|
+
: result.error.message || "Tool execution failed";
|
|
1200
|
+
throw new Error(errorMessage);
|
|
1198
1201
|
}
|
|
1199
1202
|
}
|
|
1200
1203
|
// Fallback for non-ToolResult return types
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
* Simple interface for developers to register custom tools
|
|
4
4
|
*/
|
|
5
5
|
import { z } from "zod";
|
|
6
|
-
import { logger } from "../utils/logger.js";
|
|
7
6
|
import type { MCPServerInfo, MCPServerCategory } from "../types/mcpTypes.js";
|
|
8
|
-
import type { ToolArgs,
|
|
7
|
+
import type { ToolArgs, SimpleTool as CoreSimpleTool, ZodUnknownSchema, SDKToolContext } from "../types/tools.js";
|
|
9
8
|
import type { JsonValue } from "../types/common.js";
|
|
10
9
|
/**
|
|
11
10
|
* Enhanced validation configuration
|
|
@@ -21,30 +20,9 @@ declare const VALIDATION_CONFIG: {
|
|
|
21
20
|
};
|
|
22
21
|
/**
|
|
23
22
|
* Context provided to tools during execution
|
|
24
|
-
*
|
|
23
|
+
* Type alias for backward compatibility
|
|
25
24
|
*/
|
|
26
|
-
export
|
|
27
|
-
/**
|
|
28
|
-
* Current session ID
|
|
29
|
-
*/
|
|
30
|
-
sessionId: string;
|
|
31
|
-
/**
|
|
32
|
-
* AI provider being used
|
|
33
|
-
*/
|
|
34
|
-
provider?: string;
|
|
35
|
-
/**
|
|
36
|
-
* Model being used
|
|
37
|
-
*/
|
|
38
|
-
model?: string;
|
|
39
|
-
/**
|
|
40
|
-
* Call another tool
|
|
41
|
-
*/
|
|
42
|
-
callTool?: (name: string, params: ToolArgs) => Promise<ToolResult>;
|
|
43
|
-
/**
|
|
44
|
-
* Logger instance
|
|
45
|
-
*/
|
|
46
|
-
logger: typeof logger;
|
|
47
|
-
}
|
|
25
|
+
export type ToolContext = SDKToolContext;
|
|
48
26
|
/**
|
|
49
27
|
* Simple tool interface for SDK users
|
|
50
28
|
* Extends the core SimpleTool with specific types
|
package/dist/lib/types/cli.d.ts
CHANGED
|
@@ -582,139 +582,139 @@ export type CLIMCPServerConfig = {
|
|
|
582
582
|
* OpenAI setup configuration types
|
|
583
583
|
*/
|
|
584
584
|
export declare namespace OpenAISetup {
|
|
585
|
-
|
|
585
|
+
type SetupOptions = {
|
|
586
586
|
checkOnly?: boolean;
|
|
587
587
|
interactive?: boolean;
|
|
588
|
-
}
|
|
589
|
-
|
|
588
|
+
};
|
|
589
|
+
type SetupArgv = {
|
|
590
590
|
check?: boolean;
|
|
591
591
|
nonInteractive?: boolean;
|
|
592
|
-
}
|
|
593
|
-
|
|
592
|
+
};
|
|
593
|
+
type Config = {
|
|
594
594
|
apiKey?: string;
|
|
595
595
|
organization?: string;
|
|
596
596
|
model?: string;
|
|
597
597
|
isReconfiguring?: boolean;
|
|
598
|
-
}
|
|
598
|
+
};
|
|
599
599
|
}
|
|
600
600
|
/**
|
|
601
601
|
* Anthropic setup configuration types
|
|
602
602
|
*/
|
|
603
603
|
export declare namespace AnthropicSetup {
|
|
604
|
-
|
|
604
|
+
type SetupOptions = {
|
|
605
605
|
checkOnly?: boolean;
|
|
606
606
|
interactive?: boolean;
|
|
607
|
-
}
|
|
608
|
-
|
|
607
|
+
};
|
|
608
|
+
type SetupArgv = {
|
|
609
609
|
check?: boolean;
|
|
610
610
|
nonInteractive?: boolean;
|
|
611
|
-
}
|
|
612
|
-
|
|
611
|
+
};
|
|
612
|
+
type Config = {
|
|
613
613
|
apiKey?: string;
|
|
614
614
|
model?: string;
|
|
615
615
|
isReconfiguring?: boolean;
|
|
616
|
-
}
|
|
616
|
+
};
|
|
617
617
|
}
|
|
618
618
|
/**
|
|
619
619
|
* Google AI setup configuration types
|
|
620
620
|
*/
|
|
621
621
|
export declare namespace GoogleAISetup {
|
|
622
|
-
|
|
622
|
+
type SetupOptions = {
|
|
623
623
|
checkOnly?: boolean;
|
|
624
624
|
interactive?: boolean;
|
|
625
|
-
}
|
|
626
|
-
|
|
625
|
+
};
|
|
626
|
+
type SetupArgv = {
|
|
627
627
|
check?: boolean;
|
|
628
628
|
nonInteractive?: boolean;
|
|
629
|
-
}
|
|
630
|
-
|
|
629
|
+
};
|
|
630
|
+
type Config = {
|
|
631
631
|
apiKey?: string;
|
|
632
632
|
model?: string;
|
|
633
633
|
isReconfiguring?: boolean;
|
|
634
|
-
}
|
|
634
|
+
};
|
|
635
635
|
}
|
|
636
636
|
/**
|
|
637
637
|
* Azure setup configuration types
|
|
638
638
|
*/
|
|
639
639
|
export declare namespace AzureSetup {
|
|
640
|
-
|
|
640
|
+
type SetupOptions = {
|
|
641
641
|
checkOnly?: boolean;
|
|
642
642
|
interactive?: boolean;
|
|
643
|
-
}
|
|
644
|
-
|
|
643
|
+
};
|
|
644
|
+
type SetupArgv = {
|
|
645
645
|
check?: boolean;
|
|
646
646
|
nonInteractive?: boolean;
|
|
647
|
-
}
|
|
648
|
-
|
|
647
|
+
};
|
|
648
|
+
type Config = {
|
|
649
649
|
apiKey?: string;
|
|
650
650
|
endpoint?: string;
|
|
651
651
|
deploymentName?: string;
|
|
652
652
|
apiVersion?: string;
|
|
653
653
|
model?: string;
|
|
654
654
|
isReconfiguring?: boolean;
|
|
655
|
-
}
|
|
655
|
+
};
|
|
656
656
|
}
|
|
657
657
|
/**
|
|
658
658
|
* AWS Bedrock setup configuration types
|
|
659
659
|
*/
|
|
660
660
|
export declare namespace BedrockSetup {
|
|
661
|
-
|
|
661
|
+
type SetupOptions = {
|
|
662
662
|
checkOnly?: boolean;
|
|
663
663
|
interactive?: boolean;
|
|
664
|
-
}
|
|
665
|
-
|
|
664
|
+
};
|
|
665
|
+
type SetupArgv = {
|
|
666
666
|
check?: boolean;
|
|
667
667
|
nonInteractive?: boolean;
|
|
668
|
-
}
|
|
669
|
-
|
|
668
|
+
};
|
|
669
|
+
type ConfigData = {
|
|
670
670
|
region?: string;
|
|
671
671
|
accessKeyId?: string;
|
|
672
672
|
secretAccessKey?: string;
|
|
673
673
|
model?: string;
|
|
674
|
-
}
|
|
675
|
-
|
|
674
|
+
};
|
|
675
|
+
type ConfigStatus = {
|
|
676
676
|
hasCredentials: boolean;
|
|
677
677
|
hasRegion: boolean;
|
|
678
678
|
hasModel: boolean;
|
|
679
679
|
isReconfiguring?: boolean;
|
|
680
|
-
}
|
|
680
|
+
};
|
|
681
681
|
}
|
|
682
682
|
/**
|
|
683
683
|
* GCP/Vertex AI setup configuration types
|
|
684
684
|
*/
|
|
685
685
|
export declare namespace GCPSetup {
|
|
686
|
-
|
|
686
|
+
type SetupOptions = {
|
|
687
687
|
checkOnly?: boolean;
|
|
688
688
|
interactive?: boolean;
|
|
689
|
-
}
|
|
690
|
-
|
|
689
|
+
};
|
|
690
|
+
type SetupArgv = {
|
|
691
691
|
check?: boolean;
|
|
692
692
|
nonInteractive?: boolean;
|
|
693
|
-
}
|
|
694
|
-
|
|
693
|
+
};
|
|
694
|
+
type AuthMethodStatus = {
|
|
695
695
|
hasServiceAccount: boolean;
|
|
696
696
|
hasGcloudAuth: boolean;
|
|
697
697
|
hasApplicationDefault: boolean;
|
|
698
698
|
preferredMethod?: "service-account" | "gcloud" | "adc";
|
|
699
|
-
}
|
|
699
|
+
};
|
|
700
700
|
}
|
|
701
701
|
/**
|
|
702
702
|
* Hugging Face setup configuration types
|
|
703
703
|
*/
|
|
704
704
|
export declare namespace HuggingFaceSetup {
|
|
705
|
-
|
|
705
|
+
type SetupArgs = {
|
|
706
706
|
check?: boolean;
|
|
707
707
|
nonInteractive?: boolean;
|
|
708
708
|
help?: boolean;
|
|
709
|
-
}
|
|
709
|
+
};
|
|
710
710
|
}
|
|
711
711
|
/**
|
|
712
712
|
* Mistral setup configuration types
|
|
713
713
|
*/
|
|
714
714
|
export declare namespace MistralSetup {
|
|
715
|
-
|
|
715
|
+
type SetupArgs = {
|
|
716
716
|
check?: boolean;
|
|
717
717
|
nonInteractive?: boolean;
|
|
718
718
|
help?: boolean;
|
|
719
|
-
}
|
|
719
|
+
};
|
|
720
720
|
}
|
|
@@ -8,9 +8,10 @@ import type { ChildProcess } from "child_process";
|
|
|
8
8
|
import type { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
9
9
|
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
10
10
|
/**
|
|
11
|
-
* Supported MCP transport protocols
|
|
11
|
+
* Supported MCP transport protocols - imported from mcpTypes.js (canonical definition)
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
import type { MCPTransportType } from "./mcpTypes.js";
|
|
14
|
+
export type { MCPTransportType } from "./mcpTypes.js";
|
|
14
15
|
/**
|
|
15
16
|
* External MCP server configuration for process spawning
|
|
16
17
|
*/
|
|
@@ -35,8 +36,10 @@ export type ExternalMCPServerConfig = {
|
|
|
35
36
|
autoRestart?: boolean;
|
|
36
37
|
/** Working directory for the process */
|
|
37
38
|
cwd?: string;
|
|
38
|
-
/** URL for SSE/WebSocket transports */
|
|
39
|
+
/** URL for SSE/WebSocket/HTTP transports */
|
|
39
40
|
url?: string;
|
|
41
|
+
/** HTTP headers for authentication and configuration (HTTP/SSE/WebSocket) */
|
|
42
|
+
headers?: Record<string, string>;
|
|
40
43
|
/** List of tool names to block/blacklist from this server */
|
|
41
44
|
blockedTools?: string[];
|
|
42
45
|
/** Additional metadata */
|
|
@@ -288,3 +291,52 @@ export type ExternalMCPManagerConfig = {
|
|
|
288
291
|
/** Log level for external MCP operations */
|
|
289
292
|
logLevel?: "debug" | "info" | "warn" | "error";
|
|
290
293
|
};
|
|
294
|
+
/**
|
|
295
|
+
* Extended MCPServerInfo with runtime state for external servers
|
|
296
|
+
* Represents the transition towards zero-conversion architecture by combining
|
|
297
|
+
* configuration fields from MCPServerInfo with runtime-only state needed for
|
|
298
|
+
* active server management (process handles, clients, metrics, etc.)
|
|
299
|
+
*/
|
|
300
|
+
export type RuntimeMCPServerInfo = import("./mcpTypes.js").MCPServerInfo & {
|
|
301
|
+
/** Child process handle (for stdio transport, null for HTTP transports) */
|
|
302
|
+
process: import("child_process").ChildProcess | null;
|
|
303
|
+
/** MCP client instance for communication */
|
|
304
|
+
client: Client | null;
|
|
305
|
+
/** Transport instance (renamed from 'transport' to avoid conflict with MCPServerInfo.transport) */
|
|
306
|
+
transportInstance: Transport | null;
|
|
307
|
+
/** Last error message if any */
|
|
308
|
+
lastError?: string;
|
|
309
|
+
/** When the server was started */
|
|
310
|
+
startTime?: Date;
|
|
311
|
+
/** When the server was last seen healthy */
|
|
312
|
+
lastHealthCheck?: Date;
|
|
313
|
+
/** Number of reconnection attempts */
|
|
314
|
+
reconnectAttempts: number;
|
|
315
|
+
/** Maximum reconnection attempts before giving up */
|
|
316
|
+
maxReconnectAttempts: number;
|
|
317
|
+
/** Server capabilities reported during MCP handshake */
|
|
318
|
+
capabilities?: Record<string, JsonValue>;
|
|
319
|
+
/** Health monitoring timer */
|
|
320
|
+
healthTimer?: NodeJS.Timeout;
|
|
321
|
+
/** Restart backoff timer */
|
|
322
|
+
restartTimer?: NodeJS.Timeout;
|
|
323
|
+
/** Performance metrics for this server */
|
|
324
|
+
metrics: {
|
|
325
|
+
totalConnections: number;
|
|
326
|
+
totalDisconnections: number;
|
|
327
|
+
totalErrors: number;
|
|
328
|
+
totalToolCalls: number;
|
|
329
|
+
averageResponseTime: number;
|
|
330
|
+
lastResponseTime: number;
|
|
331
|
+
};
|
|
332
|
+
/** Legacy compatibility - maintain tools map for now */
|
|
333
|
+
toolsMap: Map<string, ExternalMCPToolInfo>;
|
|
334
|
+
/** Cached tools array for ZERO conversion - MCP format */
|
|
335
|
+
toolsArray?: Array<{
|
|
336
|
+
name: string;
|
|
337
|
+
description: string;
|
|
338
|
+
inputSchema?: object;
|
|
339
|
+
}>;
|
|
340
|
+
/** Compatibility field for existing code - stores MCPServerInfo config */
|
|
341
|
+
config: import("./mcpTypes.js").MCPServerInfo;
|
|
342
|
+
};
|