@juspay/neurolink 7.14.0 → 7.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/agent/directTools.d.ts +3 -3
- package/dist/agent/directTools.js +1 -1
- package/dist/cli/commands/mcp.js +67 -207
- package/dist/cli/factories/commandFactory.js +7 -1
- package/dist/cli/utils/interactiveSetup.js +1 -1
- package/dist/core/baseProvider.d.ts +6 -40
- package/dist/core/baseProvider.js +102 -75
- package/dist/core/dynamicModels.d.ts +14 -14
- package/dist/core/dynamicModels.js +1 -1
- package/dist/core/evaluation.js +1 -1
- package/dist/core/factory.js +1 -12
- package/dist/index.d.ts +23 -4
- package/dist/index.js +22 -1
- package/dist/lib/agent/directTools.js +1 -1
- package/dist/lib/core/baseProvider.d.ts +6 -40
- package/dist/lib/core/baseProvider.js +102 -75
- package/dist/lib/core/dynamicModels.js +1 -1
- package/dist/lib/core/evaluation.js +1 -1
- package/dist/lib/core/factory.js +1 -12
- package/dist/lib/index.d.ts +23 -4
- package/dist/lib/index.js +22 -1
- package/dist/lib/mcp/externalServerManager.d.ts +46 -13
- package/dist/lib/mcp/externalServerManager.js +393 -32
- package/dist/lib/mcp/mcpClientFactory.d.ts +5 -4
- package/dist/lib/mcp/mcpClientFactory.js +8 -3
- package/dist/lib/mcp/toolDiscoveryService.d.ts +1 -0
- package/dist/lib/mcp/toolDiscoveryService.js +76 -8
- package/dist/lib/mcp/toolRegistry.d.ts +15 -11
- package/dist/lib/mcp/toolRegistry.js +118 -55
- package/dist/lib/models/modelResolver.js +1 -1
- package/dist/lib/neurolink.d.ts +32 -31
- package/dist/lib/neurolink.js +173 -210
- package/dist/lib/providers/googleVertex.d.ts +6 -0
- package/dist/lib/providers/googleVertex.js +11 -0
- package/dist/lib/providers/huggingFace.js +1 -1
- package/dist/lib/providers/mistral.js +3 -3
- package/dist/lib/providers/ollama.js +1 -1
- package/dist/lib/providers/openAI.d.ts +3 -2
- package/dist/lib/providers/openAI.js +2 -2
- package/dist/lib/providers/openaiCompatible.d.ts +1 -1
- package/dist/lib/providers/openaiCompatible.js +2 -2
- package/dist/lib/providers/sagemaker/config.js +1 -1
- package/dist/lib/sdk/toolRegistration.d.ts +4 -13
- package/dist/lib/sdk/toolRegistration.js +19 -66
- package/dist/lib/types/cli.d.ts +0 -1
- package/dist/lib/types/cli.js +0 -1
- package/dist/lib/types/common.d.ts +1 -2
- package/dist/lib/types/common.js +0 -1
- package/dist/lib/types/contextTypes.d.ts +1 -1
- package/dist/lib/types/contextTypes.js +3 -3
- package/dist/lib/types/externalMcp.d.ts +6 -0
- package/dist/lib/types/externalMcp.js +1 -0
- package/dist/lib/types/index.d.ts +2 -3
- package/dist/lib/types/index.js +0 -1
- package/dist/lib/types/mcpTypes.d.ts +53 -99
- package/dist/lib/types/providers.d.ts +0 -1
- package/dist/lib/types/providers.js +0 -1
- package/dist/lib/types/tools.d.ts +2 -2
- package/dist/lib/types/tools.js +2 -2
- package/dist/lib/utils/factoryProcessing.js +1 -1
- package/dist/lib/utils/mcpDefaults.d.ts +54 -0
- package/dist/lib/utils/mcpDefaults.js +125 -0
- package/dist/lib/utils/providerConfig.d.ts +1 -1
- package/dist/lib/utils/providerConfig.js +2 -2
- package/dist/lib/utils/providerHealth.js +6 -6
- package/dist/mcp/externalServerManager.d.ts +46 -13
- package/dist/mcp/externalServerManager.js +393 -32
- package/dist/mcp/mcpClientFactory.d.ts +5 -4
- package/dist/mcp/mcpClientFactory.js +8 -3
- package/dist/mcp/toolDiscoveryService.d.ts +1 -0
- package/dist/mcp/toolDiscoveryService.js +76 -8
- package/dist/mcp/toolRegistry.d.ts +15 -11
- package/dist/mcp/toolRegistry.js +118 -55
- package/dist/models/modelResolver.js +1 -1
- package/dist/neurolink.d.ts +32 -31
- package/dist/neurolink.js +173 -210
- package/dist/providers/googleVertex.d.ts +6 -0
- package/dist/providers/googleVertex.js +11 -0
- package/dist/providers/huggingFace.js +1 -1
- package/dist/providers/mistral.js +3 -3
- package/dist/providers/ollama.js +1 -1
- package/dist/providers/openAI.d.ts +3 -2
- package/dist/providers/openAI.js +2 -2
- package/dist/providers/openaiCompatible.d.ts +1 -1
- package/dist/providers/openaiCompatible.js +2 -2
- package/dist/providers/sagemaker/config.js +1 -1
- package/dist/sdk/toolRegistration.d.ts +4 -13
- package/dist/sdk/toolRegistration.js +19 -66
- package/dist/types/cli.d.ts +0 -1
- package/dist/types/cli.js +0 -1
- package/dist/types/common.d.ts +1 -2
- package/dist/types/common.js +0 -1
- package/dist/types/contextTypes.d.ts +1 -1
- package/dist/types/contextTypes.js +3 -3
- package/dist/types/externalMcp.d.ts +6 -0
- package/dist/types/externalMcp.js +1 -0
- package/dist/types/index.d.ts +2 -3
- package/dist/types/index.js +0 -1
- package/dist/types/mcpTypes.d.ts +53 -99
- package/dist/types/providers.d.ts +0 -1
- package/dist/types/providers.js +0 -1
- package/dist/types/tools.d.ts +2 -2
- package/dist/types/tools.js +2 -2
- package/dist/utils/factoryProcessing.js +1 -1
- package/dist/utils/mcpDefaults.d.ts +54 -0
- package/dist/utils/mcpDefaults.js +125 -0
- package/dist/utils/providerConfig.d.ts +1 -1
- package/dist/utils/providerConfig.js +2 -2
- package/dist/utils/providerHealth.js +6 -6
- package/package.json +1 -1
|
@@ -11,6 +11,7 @@ import { globalCircuitBreakerManager, } from "./mcpCircuitBreaker.js";
|
|
|
11
11
|
* Handles automatic tool discovery and registration from external MCP servers
|
|
12
12
|
*/
|
|
13
13
|
export class ToolDiscoveryService extends EventEmitter {
|
|
14
|
+
serverToolStorage = new Map();
|
|
14
15
|
toolRegistry = new Map();
|
|
15
16
|
serverTools = new Map();
|
|
16
17
|
discoveryInProgress = new Set();
|
|
@@ -126,7 +127,19 @@ export class ToolDiscoveryService extends EventEmitter {
|
|
|
126
127
|
// Register the tool
|
|
127
128
|
const toolKey = this.createToolKey(serverId, tool.name);
|
|
128
129
|
this.toolRegistry.set(toolKey, toolInfo);
|
|
129
|
-
|
|
130
|
+
if (!this.serverToolStorage.has(serverId)) {
|
|
131
|
+
this.serverToolStorage.set(serverId, []);
|
|
132
|
+
}
|
|
133
|
+
const serverTools = this.serverToolStorage.get(serverId);
|
|
134
|
+
// Add tool if not already present
|
|
135
|
+
if (!serverTools.find((t) => t.name === tool.name)) {
|
|
136
|
+
serverTools.push({
|
|
137
|
+
name: tool.name,
|
|
138
|
+
description: tool.description || "",
|
|
139
|
+
inputSchema: tool.inputSchema,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
// Track server tools (legacy)
|
|
130
143
|
if (!this.serverTools.has(serverId)) {
|
|
131
144
|
this.serverTools.set(serverId, new Set());
|
|
132
145
|
}
|
|
@@ -475,6 +488,24 @@ export class ToolDiscoveryService extends EventEmitter {
|
|
|
475
488
|
* Get all tools for a server
|
|
476
489
|
*/
|
|
477
490
|
getServerTools(serverId) {
|
|
491
|
+
const serverTools = this.serverToolStorage.get(serverId);
|
|
492
|
+
if (serverTools) {
|
|
493
|
+
return serverTools.map((tool) => ({
|
|
494
|
+
name: tool.name,
|
|
495
|
+
description: tool.description,
|
|
496
|
+
serverId,
|
|
497
|
+
inputSchema: tool.inputSchema,
|
|
498
|
+
isAvailable: true,
|
|
499
|
+
stats: {
|
|
500
|
+
totalCalls: 0,
|
|
501
|
+
successfulCalls: 0,
|
|
502
|
+
failedCalls: 0,
|
|
503
|
+
averageExecutionTime: 0,
|
|
504
|
+
lastExecutionTime: 0,
|
|
505
|
+
},
|
|
506
|
+
}));
|
|
507
|
+
}
|
|
508
|
+
// Fallback to legacy storage
|
|
478
509
|
const tools = [];
|
|
479
510
|
const serverToolNames = this.serverTools.get(serverId);
|
|
480
511
|
if (serverToolNames) {
|
|
@@ -492,23 +523,60 @@ export class ToolDiscoveryService extends EventEmitter {
|
|
|
492
523
|
* Get all registered tools
|
|
493
524
|
*/
|
|
494
525
|
getAllTools() {
|
|
495
|
-
|
|
526
|
+
const allTools = [];
|
|
527
|
+
// Add tools from server-based storage (preferred)
|
|
528
|
+
for (const [serverId, serverTools] of this.serverToolStorage.entries()) {
|
|
529
|
+
for (const tool of serverTools) {
|
|
530
|
+
allTools.push({
|
|
531
|
+
name: tool.name,
|
|
532
|
+
description: tool.description,
|
|
533
|
+
serverId,
|
|
534
|
+
inputSchema: tool.inputSchema,
|
|
535
|
+
isAvailable: true,
|
|
536
|
+
stats: {
|
|
537
|
+
totalCalls: 0,
|
|
538
|
+
successfulCalls: 0,
|
|
539
|
+
failedCalls: 0,
|
|
540
|
+
averageExecutionTime: 0,
|
|
541
|
+
lastExecutionTime: 0,
|
|
542
|
+
},
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
// Fallback to legacy storage for any tools not in server-based storage
|
|
547
|
+
const legacyTools = Array.from(this.toolRegistry.values()).filter((tool) => !allTools.some((t) => t.name === tool.name && t.serverId === tool.serverId));
|
|
548
|
+
return [...allTools, ...legacyTools];
|
|
496
549
|
}
|
|
497
550
|
/**
|
|
498
551
|
* Clear tools for a server
|
|
499
552
|
*/
|
|
500
553
|
clearServerTools(serverId) {
|
|
554
|
+
const serverTools = this.serverToolStorage.get(serverId);
|
|
555
|
+
if (serverTools) {
|
|
556
|
+
// Emit unregistered events for server-based tools
|
|
557
|
+
for (const tool of serverTools) {
|
|
558
|
+
this.emit("toolUnregistered", {
|
|
559
|
+
serverId,
|
|
560
|
+
toolName: tool.name,
|
|
561
|
+
timestamp: new Date(),
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
this.serverToolStorage.delete(serverId);
|
|
565
|
+
}
|
|
566
|
+
// Legacy cleanup
|
|
501
567
|
const serverToolNames = this.serverTools.get(serverId);
|
|
502
568
|
if (serverToolNames) {
|
|
503
569
|
for (const toolName of serverToolNames) {
|
|
504
570
|
const toolKey = this.createToolKey(serverId, toolName);
|
|
505
571
|
this.toolRegistry.delete(toolKey);
|
|
506
|
-
// Emit tool unregistered event
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
572
|
+
// Emit tool unregistered event (only if not already emitted above)
|
|
573
|
+
if (!serverTools || !serverTools.find((t) => t.name === toolName)) {
|
|
574
|
+
this.emit("toolUnregistered", {
|
|
575
|
+
serverId,
|
|
576
|
+
toolName,
|
|
577
|
+
timestamp: new Date(),
|
|
578
|
+
});
|
|
579
|
+
}
|
|
512
580
|
}
|
|
513
581
|
this.serverTools.delete(serverId);
|
|
514
582
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { ExecutionContext, ToolInfo } from "./contracts/mcpContract.js";
|
|
6
6
|
import type { ToolResult } from "./factory.js";
|
|
7
|
+
import type { MCPServerInfo } from "../types/mcpTypes.js";
|
|
7
8
|
import { MCPRegistry } from "./registry.js";
|
|
8
9
|
interface ToolImplementation {
|
|
9
10
|
execute: (params: unknown, context?: ExecutionContext) => Promise<unknown> | unknown;
|
|
@@ -13,15 +14,6 @@ interface ToolImplementation {
|
|
|
13
14
|
category?: string;
|
|
14
15
|
permissions?: string[];
|
|
15
16
|
}
|
|
16
|
-
interface ServerRegistration {
|
|
17
|
-
id?: string;
|
|
18
|
-
serverId?: string;
|
|
19
|
-
description?: string;
|
|
20
|
-
title?: string;
|
|
21
|
-
category?: string;
|
|
22
|
-
tools?: Record<string, ToolImplementation>;
|
|
23
|
-
configuration?: Record<string, unknown>;
|
|
24
|
-
}
|
|
25
17
|
export type ToolExecutionResult = ToolResult;
|
|
26
18
|
/**
|
|
27
19
|
* Tool execution options
|
|
@@ -39,15 +31,17 @@ export declare class MCPToolRegistry extends MCPRegistry {
|
|
|
39
31
|
private tools;
|
|
40
32
|
private toolImpls;
|
|
41
33
|
private toolExecutionStats;
|
|
34
|
+
private builtInServerInfos;
|
|
42
35
|
constructor();
|
|
43
36
|
/**
|
|
44
37
|
* Register all direct tools from directAgentTools
|
|
45
38
|
*/
|
|
46
39
|
private registerDirectTools;
|
|
47
40
|
/**
|
|
48
|
-
* Register a server with its tools (
|
|
41
|
+
* Register a server with its tools - ONLY accepts MCPServerInfo (zero conversions)
|
|
49
42
|
*/
|
|
50
|
-
registerServer(
|
|
43
|
+
registerServer(serverInfo: MCPServerInfo, context?: ExecutionContext): Promise<void>;
|
|
44
|
+
registerServer(serverId: string, serverConfig?: unknown, context?: ExecutionContext): Promise<void>;
|
|
51
45
|
/**
|
|
52
46
|
* Execute a tool with enhanced context
|
|
53
47
|
*/
|
|
@@ -89,6 +83,11 @@ export declare class MCPToolRegistry extends MCPRegistry {
|
|
|
89
83
|
* Clear execution statistics
|
|
90
84
|
*/
|
|
91
85
|
clearStats(): void;
|
|
86
|
+
/**
|
|
87
|
+
* Get built-in servers
|
|
88
|
+
* @returns Array of MCPServerInfo for built-in tools
|
|
89
|
+
*/
|
|
90
|
+
getBuiltInServerInfos(): MCPServerInfo[];
|
|
92
91
|
/**
|
|
93
92
|
* Get tools by category
|
|
94
93
|
*/
|
|
@@ -97,6 +96,11 @@ export declare class MCPToolRegistry extends MCPRegistry {
|
|
|
97
96
|
* Check if tool exists
|
|
98
97
|
*/
|
|
99
98
|
hasTool(toolName: string): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Register a tool with implementation directly
|
|
101
|
+
* This is used for external MCP server tools
|
|
102
|
+
*/
|
|
103
|
+
registerTool(toolId: string, toolInfo: ToolInfo, toolImpl: ToolImplementation): void;
|
|
100
104
|
/**
|
|
101
105
|
* Remove a tool
|
|
102
106
|
*/
|
package/dist/mcp/toolRegistry.js
CHANGED
|
@@ -7,10 +7,12 @@ import { registryLogger } from "../utils/logger.js";
|
|
|
7
7
|
import { randomUUID } from "crypto";
|
|
8
8
|
import { shouldDisableBuiltinTools } from "../utils/toolUtils.js";
|
|
9
9
|
import { directAgentTools } from "../agent/directTools.js";
|
|
10
|
+
import { detectCategory, createMCPServerInfo } from "../utils/mcpDefaults.js";
|
|
10
11
|
export class MCPToolRegistry extends MCPRegistry {
|
|
11
12
|
tools = new Map();
|
|
12
13
|
toolImpls = new Map(); // Store actual tool implementations
|
|
13
14
|
toolExecutionStats = new Map();
|
|
15
|
+
builtInServerInfos = []; // DIRECT storage for MCPServerInfo
|
|
14
16
|
constructor() {
|
|
15
17
|
super();
|
|
16
18
|
// 🔧 CONDITIONAL: Only auto-register direct tools if not disabled via configuration
|
|
@@ -33,7 +35,7 @@ export class MCPToolRegistry extends MCPRegistry {
|
|
|
33
35
|
description: toolDef.description || `Direct tool: ${toolName}`,
|
|
34
36
|
inputSchema: {},
|
|
35
37
|
serverId: "direct",
|
|
36
|
-
category: "
|
|
38
|
+
category: detectCategory({ isBuiltIn: true, serverId: "direct" }),
|
|
37
39
|
};
|
|
38
40
|
this.tools.set(toolId, toolInfo);
|
|
39
41
|
this.toolImpls.set(toolId, {
|
|
@@ -75,69 +77,109 @@ export class MCPToolRegistry extends MCPRegistry {
|
|
|
75
77
|
}
|
|
76
78
|
registryLogger.debug(`Auto-registered ${Object.keys(directAgentTools).length} direct tools`);
|
|
77
79
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
"No description"
|
|
94
|
-
: "No description",
|
|
95
|
-
},
|
|
96
|
-
tools: typeof serverConfig === "object" && serverConfig
|
|
97
|
-
? serverConfig.tools
|
|
98
|
-
: {},
|
|
99
|
-
configuration: typeof serverConfig === "object" && serverConfig
|
|
100
|
-
? serverConfig
|
|
101
|
-
: {},
|
|
102
|
-
};
|
|
80
|
+
async registerServer(serverInfoOrId, serverConfigOrContext, context) {
|
|
81
|
+
// Handle both signatures for backward compatibility
|
|
82
|
+
let serverInfo;
|
|
83
|
+
let finalContext;
|
|
84
|
+
if (typeof serverInfoOrId === "string") {
|
|
85
|
+
// Legacy signature: registerServer(serverId, serverConfig, context)
|
|
86
|
+
const serverId = serverInfoOrId;
|
|
87
|
+
finalContext = context;
|
|
88
|
+
// Convert legacy call to MCPServerInfo format using smart defaults
|
|
89
|
+
serverInfo = createMCPServerInfo({
|
|
90
|
+
id: serverId,
|
|
91
|
+
name: serverId,
|
|
92
|
+
tools: [],
|
|
93
|
+
isExternal: true,
|
|
94
|
+
});
|
|
103
95
|
}
|
|
104
96
|
else {
|
|
105
|
-
// New
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
97
|
+
// New signature: registerServer(serverInfo, context)
|
|
98
|
+
serverInfo = serverInfoOrId;
|
|
99
|
+
finalContext = serverConfigOrContext;
|
|
100
|
+
}
|
|
101
|
+
const serverId = serverInfo.id;
|
|
102
|
+
registryLogger.info(`Registering MCPServerInfo directly: ${serverId}`);
|
|
103
|
+
// Use MCPServerInfo.tools array directly - ZERO conversions!
|
|
104
|
+
const toolsObject = {};
|
|
105
|
+
for (const tool of serverInfo.tools) {
|
|
106
|
+
toolsObject[tool.name] = {
|
|
107
|
+
execute: tool.execute ||
|
|
108
|
+
(async () => {
|
|
109
|
+
throw new Error(`Tool ${tool.name} has no execute function`);
|
|
110
|
+
}),
|
|
111
|
+
description: tool.description,
|
|
112
|
+
inputSchema: tool.inputSchema,
|
|
113
|
+
category: detectCategory({
|
|
114
|
+
existingCategory: serverInfo.metadata?.category,
|
|
115
|
+
serverId: serverInfo.id,
|
|
116
|
+
}),
|
|
118
117
|
};
|
|
119
118
|
}
|
|
119
|
+
const plugin = {
|
|
120
|
+
metadata: {
|
|
121
|
+
name: serverInfo.name,
|
|
122
|
+
description: serverInfo.description,
|
|
123
|
+
category: detectCategory({
|
|
124
|
+
existingCategory: serverInfo.metadata?.category,
|
|
125
|
+
serverId: serverInfo.id,
|
|
126
|
+
}),
|
|
127
|
+
},
|
|
128
|
+
tools: toolsObject,
|
|
129
|
+
configuration: {},
|
|
130
|
+
};
|
|
120
131
|
// Call the parent register method
|
|
121
132
|
this.register(plugin);
|
|
122
|
-
//
|
|
123
|
-
const tools =
|
|
124
|
-
registryLogger.debug(`Registering ${
|
|
125
|
-
for (const
|
|
126
|
-
|
|
133
|
+
// Use MCPServerInfo.tools array directly - ZERO conversions!
|
|
134
|
+
const tools = serverInfo.tools;
|
|
135
|
+
registryLogger.debug(`Registering ${tools.length} tools for server ${serverId}:`, tools.map((t) => t.name));
|
|
136
|
+
for (const tool of tools) {
|
|
137
|
+
// For custom tools, use just the tool name to avoid redundant serverId.toolName format
|
|
138
|
+
// For other tools, use fully-qualified serverId.toolName to avoid collisions
|
|
139
|
+
const isCustomTool = serverId.startsWith("custom-tool-");
|
|
140
|
+
const toolId = isCustomTool ? tool.name : `${serverId}.${tool.name}`;
|
|
127
141
|
const toolInfo = {
|
|
128
|
-
name:
|
|
129
|
-
description:
|
|
130
|
-
inputSchema:
|
|
131
|
-
outputSchema:
|
|
142
|
+
name: tool.name,
|
|
143
|
+
description: tool.description,
|
|
144
|
+
inputSchema: tool.inputSchema,
|
|
145
|
+
outputSchema: undefined, // MCPServerInfo.tools doesn't have outputSchema
|
|
132
146
|
serverId,
|
|
133
|
-
category:
|
|
134
|
-
|
|
147
|
+
category: detectCategory({
|
|
148
|
+
existingCategory: serverInfo.metadata?.category,
|
|
149
|
+
serverId: serverInfo.id,
|
|
150
|
+
}),
|
|
151
|
+
permissions: [], // MCPServerInfo.tools doesn't have permissions
|
|
135
152
|
};
|
|
136
153
|
// Register only with fully-qualified toolId to avoid collisions
|
|
137
154
|
this.tools.set(toolId, toolInfo);
|
|
138
155
|
// Store the actual tool implementation for execution using toolId as key
|
|
139
|
-
this.toolImpls.set(toolId,
|
|
140
|
-
|
|
156
|
+
this.toolImpls.set(toolId, {
|
|
157
|
+
execute: tool.execute ||
|
|
158
|
+
(async () => {
|
|
159
|
+
throw new Error(`Tool ${tool.name} has no execute function`);
|
|
160
|
+
}),
|
|
161
|
+
description: tool.description,
|
|
162
|
+
inputSchema: tool.inputSchema,
|
|
163
|
+
category: detectCategory({
|
|
164
|
+
existingCategory: serverInfo.metadata?.category,
|
|
165
|
+
serverId: serverInfo.id,
|
|
166
|
+
}),
|
|
167
|
+
});
|
|
168
|
+
registryLogger.debug(`Registered tool '${tool.name}' with execute function:`, typeof tool.execute);
|
|
169
|
+
}
|
|
170
|
+
// Store MCPServerInfo directly - NO recreation needed!
|
|
171
|
+
if (tools.length > 0) {
|
|
172
|
+
const category = detectCategory({
|
|
173
|
+
existingCategory: serverInfo.metadata?.category,
|
|
174
|
+
serverId: serverInfo.id,
|
|
175
|
+
});
|
|
176
|
+
// Only store in builtInServerInfos if it's a real in-memory MCP server
|
|
177
|
+
// Do NOT create fake servers for built-in direct tools
|
|
178
|
+
if (category === "in-memory") {
|
|
179
|
+
// Use the original MCPServerInfo directly - ZERO conversions!
|
|
180
|
+
this.builtInServerInfos.push(serverInfo);
|
|
181
|
+
registryLogger.debug(`Added ${category} server to builtInServerInfos: ${serverId} with ${tools.length} tools`);
|
|
182
|
+
}
|
|
141
183
|
}
|
|
142
184
|
}
|
|
143
185
|
/**
|
|
@@ -323,6 +365,13 @@ export class MCPToolRegistry extends MCPRegistry {
|
|
|
323
365
|
clearStats() {
|
|
324
366
|
this.toolExecutionStats.clear();
|
|
325
367
|
}
|
|
368
|
+
/**
|
|
369
|
+
* Get built-in servers
|
|
370
|
+
* @returns Array of MCPServerInfo for built-in tools
|
|
371
|
+
*/
|
|
372
|
+
getBuiltInServerInfos() {
|
|
373
|
+
return this.builtInServerInfos;
|
|
374
|
+
}
|
|
326
375
|
/**
|
|
327
376
|
* Get tools by category
|
|
328
377
|
*/
|
|
@@ -340,7 +389,7 @@ export class MCPToolRegistry extends MCPRegistry {
|
|
|
340
389
|
* Check if tool exists
|
|
341
390
|
*/
|
|
342
391
|
hasTool(toolName) {
|
|
343
|
-
// Check by fully-qualified name first, then fallback to
|
|
392
|
+
// Check by fully-qualified name first, then fallback to first matching tool name
|
|
344
393
|
if (this.tools.has(toolName)) {
|
|
345
394
|
return true;
|
|
346
395
|
}
|
|
@@ -351,11 +400,21 @@ export class MCPToolRegistry extends MCPRegistry {
|
|
|
351
400
|
}
|
|
352
401
|
return false;
|
|
353
402
|
}
|
|
403
|
+
/**
|
|
404
|
+
* Register a tool with implementation directly
|
|
405
|
+
* This is used for external MCP server tools
|
|
406
|
+
*/
|
|
407
|
+
registerTool(toolId, toolInfo, toolImpl) {
|
|
408
|
+
registryLogger.debug(`Registering tool: ${toolId}`);
|
|
409
|
+
this.tools.set(toolId, toolInfo);
|
|
410
|
+
this.toolImpls.set(toolId, toolImpl);
|
|
411
|
+
registryLogger.debug(`Successfully registered tool: ${toolId}`);
|
|
412
|
+
}
|
|
354
413
|
/**
|
|
355
414
|
* Remove a tool
|
|
356
415
|
*/
|
|
357
416
|
removeTool(toolName) {
|
|
358
|
-
// Remove by fully-qualified name first, then fallback to
|
|
417
|
+
// Remove by fully-qualified name first, then fallback to first matching tool name
|
|
359
418
|
let removed = false;
|
|
360
419
|
if (this.tools.has(toolName)) {
|
|
361
420
|
this.tools.delete(toolName);
|
|
@@ -420,9 +479,13 @@ export class MCPToolRegistry extends MCPRegistry {
|
|
|
420
479
|
removedTools.push(toolId);
|
|
421
480
|
}
|
|
422
481
|
}
|
|
482
|
+
// Remove from builtInServerInfos storage
|
|
483
|
+
const originalLength = this.builtInServerInfos.length;
|
|
484
|
+
this.builtInServerInfos = this.builtInServerInfos.filter((server) => server.id !== serverId);
|
|
485
|
+
const removedFromBuiltIn = originalLength > this.builtInServerInfos.length;
|
|
423
486
|
// Remove from parent registry
|
|
424
487
|
const removed = this.unregister(serverId);
|
|
425
|
-
registryLogger.info(`Unregistered server ${serverId}, removed ${removedTools.length} tools`);
|
|
488
|
+
registryLogger.info(`Unregistered server ${serverId}, removed ${removedTools.length} tools${removedFromBuiltIn ? " and server from builtInServerInfos" : ""}`);
|
|
426
489
|
return removed;
|
|
427
490
|
}
|
|
428
491
|
}
|
|
@@ -294,7 +294,7 @@ export class ModelResolver {
|
|
|
294
294
|
}
|
|
295
295
|
// Base relevance score
|
|
296
296
|
if (score === 0) {
|
|
297
|
-
score = 1; // Minimal relevance for
|
|
297
|
+
score = 1; // Minimal relevance for model
|
|
298
298
|
matchReasons.push("Basic match");
|
|
299
299
|
}
|
|
300
300
|
return { model, score, matchReasons };
|
package/dist/neurolink.d.ts
CHANGED
|
@@ -8,11 +8,10 @@
|
|
|
8
8
|
import type { TextGenerationOptions, TextGenerationResult } from "./core/types.js";
|
|
9
9
|
import type { GenerateOptions, GenerateResult } from "./types/generateTypes.js";
|
|
10
10
|
import type { StreamOptions, StreamResult } from "./types/streamTypes.js";
|
|
11
|
-
import type {
|
|
12
|
-
import type { InMemoryMCPServerConfig } from "./types/mcpTypes.js";
|
|
11
|
+
import type { MCPServerInfo, MCPExecutableTool } from "./types/mcpTypes.js";
|
|
13
12
|
import { EventEmitter } from "events";
|
|
14
13
|
import type { ConversationMemoryConfig } from "./types/conversationTypes.js";
|
|
15
|
-
import type {
|
|
14
|
+
import type { ExternalMCPServerInstance, ExternalMCPOperationResult, ExternalMCPToolInfo } from "./types/externalMcp.js";
|
|
16
15
|
export interface ProviderStatus {
|
|
17
16
|
provider: string;
|
|
18
17
|
status: "working" | "failed" | "not-configured";
|
|
@@ -38,21 +37,12 @@ export interface MCPStatus {
|
|
|
38
37
|
error?: string;
|
|
39
38
|
[key: string]: unknown;
|
|
40
39
|
}
|
|
41
|
-
export interface MCPServerInfo {
|
|
42
|
-
id: string;
|
|
43
|
-
name: string;
|
|
44
|
-
source: string;
|
|
45
|
-
status: "connected" | "discovered" | "failed";
|
|
46
|
-
hasServer: boolean;
|
|
47
|
-
metadata?: unknown;
|
|
48
|
-
}
|
|
49
40
|
import type { ContextManagerConfig } from "./context/types.js";
|
|
50
41
|
export declare class NeuroLink {
|
|
51
42
|
private mcpInitialized;
|
|
52
43
|
private emitter;
|
|
53
44
|
private contextManager;
|
|
54
|
-
private
|
|
55
|
-
private inMemoryServers;
|
|
45
|
+
private autoDiscoveredServerInfos;
|
|
56
46
|
private externalServerManager;
|
|
57
47
|
private toolCircuitBreakers;
|
|
58
48
|
private toolExecutionMetrics;
|
|
@@ -148,19 +138,19 @@ export declare class NeuroLink {
|
|
|
148
138
|
/**
|
|
149
139
|
* Register a custom tool that will be available to all AI providers
|
|
150
140
|
* @param name - Unique name for the tool
|
|
151
|
-
* @param tool - Tool
|
|
141
|
+
* @param tool - Tool in MCPExecutableTool format (unified MCP protocol type)
|
|
152
142
|
*/
|
|
153
|
-
registerTool(name: string, tool:
|
|
143
|
+
registerTool(name: string, tool: MCPExecutableTool): void;
|
|
154
144
|
/**
|
|
155
145
|
* Register multiple tools at once - Supports both object and array formats
|
|
156
|
-
* @param tools - Object mapping tool names to
|
|
146
|
+
* @param tools - Object mapping tool names to MCPExecutableTool format OR Array of tools with names
|
|
157
147
|
*
|
|
158
|
-
* Object format (existing): { toolName:
|
|
159
|
-
* Array format (Lighthouse compatible): [{ name: string, tool:
|
|
148
|
+
* Object format (existing): { toolName: MCPExecutableTool, ... }
|
|
149
|
+
* Array format (Lighthouse compatible): [{ name: string, tool: MCPExecutableTool }, ...]
|
|
160
150
|
*/
|
|
161
|
-
registerTools(tools: Record<string,
|
|
151
|
+
registerTools(tools: Record<string, MCPExecutableTool> | Array<{
|
|
162
152
|
name: string;
|
|
163
|
-
tool:
|
|
153
|
+
tool: MCPExecutableTool;
|
|
164
154
|
}>): void;
|
|
165
155
|
/**
|
|
166
156
|
* Unregister a custom tool
|
|
@@ -170,21 +160,32 @@ export declare class NeuroLink {
|
|
|
170
160
|
unregisterTool(name: string): boolean;
|
|
171
161
|
/**
|
|
172
162
|
* Get all registered custom tools
|
|
173
|
-
* @returns Map of tool names to
|
|
163
|
+
* @returns Map of tool names to MCPExecutableTool format
|
|
174
164
|
*/
|
|
175
|
-
getCustomTools(): Map<string,
|
|
165
|
+
getCustomTools(): Map<string, MCPExecutableTool>;
|
|
176
166
|
/**
|
|
177
167
|
* Add an in-memory MCP server (from git diff)
|
|
178
168
|
* Allows registration of pre-instantiated server objects
|
|
179
169
|
* @param serverId - Unique identifier for the server
|
|
180
|
-
* @param
|
|
170
|
+
* @param serverInfo - Server configuration
|
|
181
171
|
*/
|
|
182
|
-
addInMemoryMCPServer(serverId: string,
|
|
172
|
+
addInMemoryMCPServer(serverId: string, serverInfo: MCPServerInfo): Promise<void>;
|
|
183
173
|
/**
|
|
184
174
|
* Get all registered in-memory servers
|
|
185
|
-
* @returns Map of server IDs to
|
|
175
|
+
* @returns Map of server IDs to MCPServerInfo
|
|
176
|
+
*/
|
|
177
|
+
getInMemoryServers(): Map<string, MCPServerInfo>;
|
|
178
|
+
/**
|
|
179
|
+
* Get in-memory servers as MCPServerInfo - ZERO conversion needed
|
|
180
|
+
* Now fetches from centralized tool registry instead of local duplication
|
|
181
|
+
* @returns Array of MCPServerInfo
|
|
186
182
|
*/
|
|
187
|
-
|
|
183
|
+
getInMemoryServerInfos(): MCPServerInfo[];
|
|
184
|
+
/**
|
|
185
|
+
* Get auto-discovered servers as MCPServerInfo - ZERO conversion needed
|
|
186
|
+
* @returns Array of MCPServerInfo
|
|
187
|
+
*/
|
|
188
|
+
getAutoDiscoveredServerInfos(): MCPServerInfo[];
|
|
188
189
|
/**
|
|
189
190
|
* Execute a specific tool by name with robust error handling
|
|
190
191
|
* Supports both custom tools and MCP server tools with timeout, retry, and circuit breaker patterns
|
|
@@ -360,7 +361,7 @@ export declare class NeuroLink {
|
|
|
360
361
|
* Get comprehensive tool health report
|
|
361
362
|
* @returns Detailed health report for all tools
|
|
362
363
|
*/
|
|
363
|
-
getToolHealthReport(): {
|
|
364
|
+
getToolHealthReport(): Promise<{
|
|
364
365
|
totalTools: number;
|
|
365
366
|
healthyTools: number;
|
|
366
367
|
unhealthyTools: number;
|
|
@@ -380,7 +381,7 @@ export declare class NeuroLink {
|
|
|
380
381
|
issues: string[];
|
|
381
382
|
recommendations: string[];
|
|
382
383
|
}>;
|
|
383
|
-
}
|
|
384
|
+
}>;
|
|
384
385
|
/**
|
|
385
386
|
* Get conversation memory statistics (public API)
|
|
386
387
|
*/
|
|
@@ -400,7 +401,7 @@ export declare class NeuroLink {
|
|
|
400
401
|
* @param config - External MCP server configuration
|
|
401
402
|
* @returns Operation result with server instance
|
|
402
403
|
*/
|
|
403
|
-
addExternalMCPServer(serverId: string, config:
|
|
404
|
+
addExternalMCPServer(serverId: string, config: MCPServerInfo): Promise<ExternalMCPOperationResult<ExternalMCPServerInstance>>;
|
|
404
405
|
/**
|
|
405
406
|
* Remove an external MCP server
|
|
406
407
|
* Stops the server and removes all its tools
|
|
@@ -418,7 +419,7 @@ export declare class NeuroLink {
|
|
|
418
419
|
toolCount: number;
|
|
419
420
|
uptime: number;
|
|
420
421
|
isHealthy: boolean;
|
|
421
|
-
config:
|
|
422
|
+
config: MCPServerInfo;
|
|
422
423
|
}>;
|
|
423
424
|
/**
|
|
424
425
|
* Get external MCP server status
|
|
@@ -453,7 +454,7 @@ export declare class NeuroLink {
|
|
|
453
454
|
* @param config - Server configuration to test
|
|
454
455
|
* @returns Test result with connection status
|
|
455
456
|
*/
|
|
456
|
-
testExternalMCPConnection(config:
|
|
457
|
+
testExternalMCPConnection(config: MCPServerInfo): Promise<{
|
|
457
458
|
success: boolean;
|
|
458
459
|
error?: string;
|
|
459
460
|
toolCount?: number;
|