@juspay/neurolink 6.0.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 +14 -3
- 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 +2 -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,261 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NeuroLink MCP Tool Initialization
|
|
3
|
-
* Following Lighthouse's pattern for registering MCP server tools with the client
|
|
4
|
-
*/
|
|
5
|
-
import { mcpConfig } from "./config.js";
|
|
6
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
7
|
-
import { logger } from "../utils/logger.js";
|
|
8
|
-
/**
|
|
9
|
-
* Sanitize tool name for compatibility
|
|
10
|
-
* Following Lighthouse's pattern of ensuring valid tool names
|
|
11
|
-
*/
|
|
12
|
-
const sanitizeToolName = (name) => {
|
|
13
|
-
return name.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Check if a schema is a Zod schema
|
|
17
|
-
*/
|
|
18
|
-
const isZodSchema = (schema) => {
|
|
19
|
-
if (typeof schema !== "object" || schema === null) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
return "_def" in schema || "parse" in schema;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Initialize and register tools from MCP Servers with the MCP client
|
|
26
|
-
* Following Lighthouse's pattern for tool registration
|
|
27
|
-
*/
|
|
28
|
-
export const initializeMCPTools = async (sessionId, client, context) => {
|
|
29
|
-
try {
|
|
30
|
-
logger.info(`[MCP Tools] Initializing tools for session: ${sessionId}`);
|
|
31
|
-
// Get all registered servers
|
|
32
|
-
const servers = await mcpConfig.getServers();
|
|
33
|
-
if (!servers || servers.length === 0) {
|
|
34
|
-
logger.warn("[MCP Tools] No MCP servers found to register tools from");
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
let totalToolsRegistered = 0;
|
|
38
|
-
// Process each server
|
|
39
|
-
servers.forEach((server) => {
|
|
40
|
-
if (!server || !server.id || !server.tools) {
|
|
41
|
-
logger.warn(`[MCP Tools] Skipping invalid server configuration: ${JSON.stringify(server)}`);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const serverId = server.id;
|
|
45
|
-
logger.info(`[MCP Tools] Registering tools from server: ${serverId}`);
|
|
46
|
-
// Process each tool in the server
|
|
47
|
-
Object.entries(server.tools).forEach(([originalToolName, tool]) => {
|
|
48
|
-
if (!tool || typeof tool.execute !== "function") {
|
|
49
|
-
logger.warn(`[MCP Tools] Skipping invalid tool definition for ${originalToolName} in server ${serverId}`);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
// Create namespaced tool name (serverId_toolName)
|
|
53
|
-
let finalToolName = originalToolName;
|
|
54
|
-
const prefix = `${serverId}_`;
|
|
55
|
-
const maxToolNameLength = 64 - prefix.length;
|
|
56
|
-
// Truncate if necessary
|
|
57
|
-
if (finalToolName.length > maxToolNameLength) {
|
|
58
|
-
finalToolName = finalToolName.substring(0, maxToolNameLength);
|
|
59
|
-
logger.info(`[MCP Tools] Truncated tool name: ${originalToolName} -> ${finalToolName}`);
|
|
60
|
-
}
|
|
61
|
-
// Sanitize and combine
|
|
62
|
-
const namespacedToolName = sanitizeToolName(`${prefix}${finalToolName}`);
|
|
63
|
-
// Validate final length
|
|
64
|
-
if (namespacedToolName.length > 64) {
|
|
65
|
-
logger.warn(`[MCP Tools] Tool name too long after sanitization: ${namespacedToolName}. Skipping.`);
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
// Prepare description
|
|
69
|
-
const description = tool.description ||
|
|
70
|
-
`Tool ${originalToolName} from server ${serverId}`;
|
|
71
|
-
// Convert schema if needed
|
|
72
|
-
let schemaForClient = undefined;
|
|
73
|
-
if (tool.inputSchema) {
|
|
74
|
-
if (isZodSchema(tool.inputSchema)) {
|
|
75
|
-
try {
|
|
76
|
-
const jsonSchemaOutput = zodToJsonSchema(tool.inputSchema);
|
|
77
|
-
if (typeof jsonSchemaOutput === "object" &&
|
|
78
|
-
jsonSchemaOutput !== null &&
|
|
79
|
-
"type" in jsonSchemaOutput &&
|
|
80
|
-
jsonSchemaOutput.type === "object") {
|
|
81
|
-
schemaForClient = jsonSchemaOutput;
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
logger.warn(`[MCP Tools] Converted schema for ${originalToolName} is not a root object type`);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
catch (schemaError) {
|
|
88
|
-
logger.error(`[MCP Tools] Error converting Zod schema for tool ${originalToolName}: ${schemaError}`);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
else if (typeof tool.inputSchema === "object" &&
|
|
92
|
-
tool.inputSchema !== null) {
|
|
93
|
-
if (tool.inputSchema.type === "object") {
|
|
94
|
-
schemaForClient = tool.inputSchema;
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
logger.warn(`[MCP Tools] Input schema for ${originalToolName} is not type 'object'`);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
try {
|
|
102
|
-
// Register tool with client
|
|
103
|
-
client.registerTool(namespacedToolName, async (_name, input) => {
|
|
104
|
-
// Execute the tool with full context
|
|
105
|
-
const result = await tool.execute(input, context);
|
|
106
|
-
// Convert to Lighthouse-style response
|
|
107
|
-
if (result.success) {
|
|
108
|
-
return {
|
|
109
|
-
content: [{ text: JSON.stringify(result.data ?? {}) }],
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
return {
|
|
114
|
-
content: [
|
|
115
|
-
{ text: `Error: ${result.error || "Unknown error"}` },
|
|
116
|
-
],
|
|
117
|
-
isError: true,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
}, description, schemaForClient);
|
|
121
|
-
logger.debug(`[MCP Tools] Registered tool: ${namespacedToolName}`, {
|
|
122
|
-
serverId,
|
|
123
|
-
originalToolName,
|
|
124
|
-
});
|
|
125
|
-
totalToolsRegistered++;
|
|
126
|
-
}
|
|
127
|
-
catch (registrationError) {
|
|
128
|
-
logger.error(`[MCP Tools] Failed to register tool ${originalToolName} from server ${serverId}: ${registrationError}`);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
logger.info(`[MCP Tools] Successfully registered ${totalToolsRegistered} tools for session: ${sessionId}`);
|
|
133
|
-
}
|
|
134
|
-
catch (error) {
|
|
135
|
-
logger.error(`[MCP Tools] Error during tool initialization for session ${sessionId}: ${error}`);
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
/**
|
|
139
|
-
* Get all available tools across all servers
|
|
140
|
-
* Useful for documentation and discovery
|
|
141
|
-
*/
|
|
142
|
-
export async function getAllAvailableTools(inMemoryServers) {
|
|
143
|
-
const tools = [];
|
|
144
|
-
// Add in-memory server tools first
|
|
145
|
-
if (inMemoryServers) {
|
|
146
|
-
for (const [serverId, serverConfig] of inMemoryServers) {
|
|
147
|
-
const server = serverConfig.server;
|
|
148
|
-
if (server &&
|
|
149
|
-
typeof server === "object" &&
|
|
150
|
-
"tools" in server &&
|
|
151
|
-
server.tools) {
|
|
152
|
-
// Handle both Map and object formats
|
|
153
|
-
const toolEntries = server.tools instanceof Map
|
|
154
|
-
? Array.from(server.tools.entries())
|
|
155
|
-
: Object.entries(server.tools || {});
|
|
156
|
-
for (const [toolName, toolInfo] of toolEntries) {
|
|
157
|
-
const prefix = `${serverId}_`;
|
|
158
|
-
const finalToolName = toolName.length > 64 - prefix.length
|
|
159
|
-
? toolName.substring(0, 64 - prefix.length)
|
|
160
|
-
: toolName;
|
|
161
|
-
const namespacedName = sanitizeToolName(`${prefix}${finalToolName}`);
|
|
162
|
-
// Handle different tool info structures
|
|
163
|
-
let description = `Tool from ${serverId}`;
|
|
164
|
-
let isImplemented = true;
|
|
165
|
-
if (toolInfo) {
|
|
166
|
-
// Check if it's a tool info object with description
|
|
167
|
-
if (typeof toolInfo.description === "string") {
|
|
168
|
-
description = toolInfo.description;
|
|
169
|
-
}
|
|
170
|
-
else if (typeof toolInfo === "function") {
|
|
171
|
-
// It's a raw function, no description available
|
|
172
|
-
description = `${toolName} from ${serverId}`;
|
|
173
|
-
}
|
|
174
|
-
// Check implementation status
|
|
175
|
-
if (typeof toolInfo.isImplemented === "boolean") {
|
|
176
|
-
isImplemented = toolInfo.isImplemented;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
tools.push({
|
|
180
|
-
serverId,
|
|
181
|
-
serverTitle: typeof server === "object" &&
|
|
182
|
-
server &&
|
|
183
|
-
"title" in server &&
|
|
184
|
-
typeof server.title === "string"
|
|
185
|
-
? server.title
|
|
186
|
-
: serverId,
|
|
187
|
-
toolName,
|
|
188
|
-
namespacedName,
|
|
189
|
-
description,
|
|
190
|
-
isImplemented,
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
const servers = await mcpConfig.getServers();
|
|
197
|
-
servers.forEach((server) => {
|
|
198
|
-
Object.entries(server.tools).forEach(([toolName, tool]) => {
|
|
199
|
-
const prefix = `${server.id}_`;
|
|
200
|
-
const finalToolName = toolName.length > 64 - prefix.length
|
|
201
|
-
? toolName.substring(0, 64 - prefix.length)
|
|
202
|
-
: toolName;
|
|
203
|
-
const namespacedName = sanitizeToolName(`${prefix}${finalToolName}`);
|
|
204
|
-
tools.push({
|
|
205
|
-
serverId: server.id,
|
|
206
|
-
serverTitle: server.title,
|
|
207
|
-
toolName,
|
|
208
|
-
namespacedName,
|
|
209
|
-
description: tool.description || "",
|
|
210
|
-
isImplemented: tool.isImplemented !== false,
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
return tools;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Initialize tools for a specific server only
|
|
218
|
-
* Useful for selective tool registration
|
|
219
|
-
*/
|
|
220
|
-
export async function initializeServerTools(serverId, client, context) {
|
|
221
|
-
const servers = await mcpConfig.getServers();
|
|
222
|
-
const server = servers.find((s) => s.id === serverId);
|
|
223
|
-
if (!server) {
|
|
224
|
-
logger.warn(`[MCP Tools] Server not found: ${serverId}`);
|
|
225
|
-
return 0;
|
|
226
|
-
}
|
|
227
|
-
let toolsRegistered = 0;
|
|
228
|
-
Object.entries(server.tools).forEach(([toolName, tool]) => {
|
|
229
|
-
if (!tool || typeof tool.execute !== "function") {
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
const prefix = `${serverId}_`;
|
|
233
|
-
const finalToolName = toolName.length > 64 - prefix.length
|
|
234
|
-
? toolName.substring(0, 64 - prefix.length)
|
|
235
|
-
: toolName;
|
|
236
|
-
const namespacedToolName = sanitizeToolName(`${prefix}${finalToolName}`);
|
|
237
|
-
if (namespacedToolName.length > 64) {
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
try {
|
|
241
|
-
client.registerTool(namespacedToolName, async (_name, input) => {
|
|
242
|
-
const result = await tool.execute(input, context);
|
|
243
|
-
if (result.success) {
|
|
244
|
-
return { content: [{ text: JSON.stringify(result.data ?? {}) }] };
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
return {
|
|
248
|
-
content: [{ text: `Error: ${result.error || "Unknown error"}` }],
|
|
249
|
-
isError: true,
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
}, tool.description || `Tool ${toolName} from server ${serverId}`, tool.inputSchema);
|
|
253
|
-
toolsRegistered++;
|
|
254
|
-
}
|
|
255
|
-
catch (error) {
|
|
256
|
-
logger.error(`[MCP Tools] Failed to register tool ${toolName}: ${error}`);
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
logger.info(`[MCP Tools] Registered ${toolsRegistered} tools from server ${serverId}`);
|
|
260
|
-
return toolsRegistered;
|
|
261
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NeuroLink MCP Initialization System
|
|
3
|
-
* Automatically registers built-in NeuroLink servers with the default registry
|
|
4
|
-
* Ensures built-in tools are always available without manual configuration
|
|
5
|
-
*/
|
|
6
|
-
import { type MCPToolRegistry } from "./tool-registry.js";
|
|
7
|
-
/**
|
|
8
|
-
* Initialize NeuroLink MCP system by registering built-in servers
|
|
9
|
-
*/
|
|
10
|
-
export declare function initializeNeuroLinkMCP(targetRegistry?: MCPToolRegistry): Promise<void>;
|
|
11
|
-
/**
|
|
12
|
-
* Get initialization status
|
|
13
|
-
*/
|
|
14
|
-
export declare function isNeuroLinkMCPInitialized(): boolean;
|
|
15
|
-
/**
|
|
16
|
-
* Reset initialization status (for testing)
|
|
17
|
-
*/
|
|
18
|
-
export declare function resetInitialization(): void;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NeuroLink MCP Initialization System
|
|
3
|
-
* Automatically registers built-in NeuroLink servers with the default registry
|
|
4
|
-
* Ensures built-in tools are always available without manual configuration
|
|
5
|
-
*/
|
|
6
|
-
import { toolRegistry, defaultToolRegistry, } from "./tool-registry.js";
|
|
7
|
-
import { mcpLogger } from "./logging.js";
|
|
8
|
-
import { ServiceRegistry } from "../core/service-registry.js";
|
|
9
|
-
let isInitialized = false;
|
|
10
|
-
/**
|
|
11
|
-
* Initialize NeuroLink MCP system by registering built-in servers
|
|
12
|
-
*/
|
|
13
|
-
export async function initializeNeuroLinkMCP(targetRegistry) {
|
|
14
|
-
if (isInitialized) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
mcpLogger.debug("Initializing built-in MCP servers...");
|
|
18
|
-
try {
|
|
19
|
-
// First, register AIProviderFactory in ServiceRegistry to break circular dependencies
|
|
20
|
-
ServiceRegistry.register("AIProviderFactory", async () => {
|
|
21
|
-
const { AIProviderFactory } = await import("../core/factory.js");
|
|
22
|
-
return AIProviderFactory;
|
|
23
|
-
});
|
|
24
|
-
mcpLogger.debug("Registered AIProviderFactory in ServiceRegistry");
|
|
25
|
-
// Import utility server dynamically to avoid circular dependencies
|
|
26
|
-
const { utilityServer } = await import("./servers/utilities/utility-server.js");
|
|
27
|
-
// Register built-in NeuroLink servers with specified registry (or default)
|
|
28
|
-
const registry = targetRegistry || toolRegistry;
|
|
29
|
-
await registry.registerServer(utilityServer.id, utilityServer);
|
|
30
|
-
mcpLogger.debug(`Registered neurolink-utility server with built-in tools in ${targetRegistry ? "target" : "default"} registry`);
|
|
31
|
-
// Now safe to import and register AI core server
|
|
32
|
-
const { aiCoreServer } = await import("./servers/ai-providers/ai-core-server.js");
|
|
33
|
-
await registry.registerServer(aiCoreServer.id, aiCoreServer);
|
|
34
|
-
mcpLogger.debug("Registered neurolink-ai-core server with AI tools");
|
|
35
|
-
// Register direct tools server
|
|
36
|
-
const { directToolsServer } = await import("./servers/agent/direct-tools-server.js");
|
|
37
|
-
await registry.registerServer(directToolsServer.id, directToolsServer);
|
|
38
|
-
mcpLogger.debug("Registered neurolink-direct server with direct tools");
|
|
39
|
-
const stats = await registry.getStats();
|
|
40
|
-
mcpLogger.info(`Initialization complete: ${stats.totalServers} servers, ${stats.totalTools} tools available`);
|
|
41
|
-
isInitialized = true;
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
mcpLogger.error("Failed to initialize built-in servers:", error instanceof Error ? error.message : String(error));
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Get initialization status
|
|
50
|
-
*/
|
|
51
|
-
export function isNeuroLinkMCPInitialized() {
|
|
52
|
-
return isInitialized;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Reset initialization status (for testing)
|
|
56
|
-
*/
|
|
57
|
-
export function resetInitialization() {
|
|
58
|
-
isInitialized = false;
|
|
59
|
-
defaultToolRegistry.clear();
|
|
60
|
-
}
|
|
61
|
-
// Note: Auto-initialization removed to prevent circular dependencies
|
|
62
|
-
// Call initializeNeuroLinkMCP() explicitly where needed
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NeuroLink MCP Manager
|
|
3
|
-
* Manages MCP client instances following Lighthouse's session-based pattern
|
|
4
|
-
*/
|
|
5
|
-
import { NeuroLinkMCPClient } from "./client.js";
|
|
6
|
-
import type { MCPClientConfig } from "./client.js";
|
|
7
|
-
import type { UnknownRecord } from "../types/common.js";
|
|
8
|
-
/**
|
|
9
|
-
* MCP Manager - Factory pattern for managing multiple client instances
|
|
10
|
-
* Following Lighthouse's session-based architecture
|
|
11
|
-
*/
|
|
12
|
-
export declare class NeuroLinkMCPManager {
|
|
13
|
-
private static instances;
|
|
14
|
-
private static lastCleanup;
|
|
15
|
-
private static cleanupInterval;
|
|
16
|
-
/**
|
|
17
|
-
* Get or create an MCP client instance for a session
|
|
18
|
-
*/
|
|
19
|
-
static getInstance(sessionId: string, config?: Partial<MCPClientConfig>): NeuroLinkMCPClient;
|
|
20
|
-
/**
|
|
21
|
-
* Remove the oldest instance based on creation time
|
|
22
|
-
*/
|
|
23
|
-
private static removeOldestInstance;
|
|
24
|
-
/**
|
|
25
|
-
* Clean up instances that haven't been used recently
|
|
26
|
-
*/
|
|
27
|
-
private static cleanupOldInstances;
|
|
28
|
-
/**
|
|
29
|
-
* Get list of active session IDs
|
|
30
|
-
*/
|
|
31
|
-
static getActiveSessionIds(): string[];
|
|
32
|
-
/**
|
|
33
|
-
* Remove a specific instance
|
|
34
|
-
*/
|
|
35
|
-
static removeInstance(sessionId: string): Promise<boolean>;
|
|
36
|
-
/**
|
|
37
|
-
* Get instance count
|
|
38
|
-
*/
|
|
39
|
-
static getInstanceCount(): number;
|
|
40
|
-
/**
|
|
41
|
-
* Get maximum allowed instances
|
|
42
|
-
*/
|
|
43
|
-
static getMaxInstances(): number;
|
|
44
|
-
/**
|
|
45
|
-
* Get statistics for all instances
|
|
46
|
-
*/
|
|
47
|
-
static getAllStats(): {
|
|
48
|
-
instanceCount: number;
|
|
49
|
-
maxInstances: number;
|
|
50
|
-
instances: Record<string, UnknownRecord>;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Clear all instances (for testing or shutdown)
|
|
54
|
-
*/
|
|
55
|
-
static clearAll(): Promise<void>;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Convenience function to get MCP manager instance
|
|
59
|
-
*/
|
|
60
|
-
export declare function getMCPManager(sessionId: string, config?: Partial<MCPClientConfig>): NeuroLinkMCPClient;
|
|
61
|
-
/**
|
|
62
|
-
* Convenience function to remove MCP manager instance
|
|
63
|
-
*/
|
|
64
|
-
export declare function removeMCPManager(sessionId: string): Promise<boolean>;
|
|
65
|
-
/**
|
|
66
|
-
* Export manager for direct access if needed
|
|
67
|
-
*/
|
|
68
|
-
export { NeuroLinkMCPManager as MCPManager };
|
package/dist/lib/mcp/manager.js
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NeuroLink MCP Manager
|
|
3
|
-
* Manages MCP client instances following Lighthouse's session-based pattern
|
|
4
|
-
*/
|
|
5
|
-
import { createMCPClient } from "./client.js";
|
|
6
|
-
import { logger } from "../utils/logger.js";
|
|
7
|
-
/**
|
|
8
|
-
* Maximum number of concurrent MCP instances
|
|
9
|
-
*/
|
|
10
|
-
const MAX_MCP_INSTANCES = 50;
|
|
11
|
-
/**
|
|
12
|
-
* Default MCP configuration
|
|
13
|
-
*/
|
|
14
|
-
const DEFAULT_MCP_CONFIG = {
|
|
15
|
-
logLevel: "info",
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* MCP Manager - Factory pattern for managing multiple client instances
|
|
19
|
-
* Following Lighthouse's session-based architecture
|
|
20
|
-
*/
|
|
21
|
-
export class NeuroLinkMCPManager {
|
|
22
|
-
static instances = new Map();
|
|
23
|
-
static lastCleanup = Date.now();
|
|
24
|
-
static cleanupInterval = 60000; // 1 minute
|
|
25
|
-
/**
|
|
26
|
-
* Get or create an MCP client instance for a session
|
|
27
|
-
*/
|
|
28
|
-
static getInstance(sessionId, config) {
|
|
29
|
-
// Periodic cleanup of old instances
|
|
30
|
-
if (Date.now() - this.lastCleanup > this.cleanupInterval) {
|
|
31
|
-
this.cleanupOldInstances();
|
|
32
|
-
}
|
|
33
|
-
// Return existing instance if available
|
|
34
|
-
if (this.instances.has(sessionId)) {
|
|
35
|
-
const instance = this.instances.get(sessionId);
|
|
36
|
-
logger.debug(`[MCP Manager] Returning existing instance for session ${sessionId}`);
|
|
37
|
-
return instance;
|
|
38
|
-
}
|
|
39
|
-
// Check if we've reached the maximum number of instances
|
|
40
|
-
if (this.instances.size >= MAX_MCP_INSTANCES) {
|
|
41
|
-
// Remove the oldest instance to make room
|
|
42
|
-
this.removeOldestInstance();
|
|
43
|
-
}
|
|
44
|
-
// Create new instance
|
|
45
|
-
const fullConfig = {
|
|
46
|
-
sessionId,
|
|
47
|
-
...DEFAULT_MCP_CONFIG,
|
|
48
|
-
...config,
|
|
49
|
-
};
|
|
50
|
-
const instance = createMCPClient(fullConfig);
|
|
51
|
-
this.instances.set(sessionId, instance);
|
|
52
|
-
logger.info(`[MCP Manager] Created new instance for session ${sessionId}`, {
|
|
53
|
-
instanceCount: this.instances.size,
|
|
54
|
-
config: fullConfig,
|
|
55
|
-
});
|
|
56
|
-
return instance;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Remove the oldest instance based on creation time
|
|
60
|
-
*/
|
|
61
|
-
static removeOldestInstance() {
|
|
62
|
-
let oldestSessionId = null;
|
|
63
|
-
let oldestTime = Date.now();
|
|
64
|
-
// Find the oldest instance
|
|
65
|
-
for (const [sessionId, instance] of this.instances.entries()) {
|
|
66
|
-
const stats = instance.getStats();
|
|
67
|
-
const creationTime = Date.now() - stats.uptime;
|
|
68
|
-
if (creationTime < oldestTime) {
|
|
69
|
-
oldestTime = creationTime;
|
|
70
|
-
oldestSessionId = sessionId;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (oldestSessionId) {
|
|
74
|
-
const instance = this.instances.get(oldestSessionId);
|
|
75
|
-
instance.disconnect();
|
|
76
|
-
this.instances.delete(oldestSessionId);
|
|
77
|
-
logger.info(`[MCP Manager] Removed oldest instance`, {
|
|
78
|
-
sessionId: oldestSessionId,
|
|
79
|
-
remainingInstances: this.instances.size,
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Clean up instances that haven't been used recently
|
|
85
|
-
*/
|
|
86
|
-
static cleanupOldInstances() {
|
|
87
|
-
const now = Date.now();
|
|
88
|
-
const maxIdleTime = 300000; // 5 minutes
|
|
89
|
-
const toRemove = [];
|
|
90
|
-
for (const [sessionId, instance] of this.instances.entries()) {
|
|
91
|
-
const stats = instance.getStats();
|
|
92
|
-
// If no executions in the last 5 minutes, mark for removal
|
|
93
|
-
if (stats.executionCount === 0 && now - stats.uptime > maxIdleTime) {
|
|
94
|
-
toRemove.push(sessionId);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
for (const sessionId of toRemove) {
|
|
98
|
-
const instance = this.instances.get(sessionId);
|
|
99
|
-
instance.disconnect();
|
|
100
|
-
this.instances.delete(sessionId);
|
|
101
|
-
}
|
|
102
|
-
if (toRemove.length > 0) {
|
|
103
|
-
logger.info(`[MCP Manager] Cleaned up ${toRemove.length} idle instances`);
|
|
104
|
-
}
|
|
105
|
-
this.lastCleanup = now;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Get list of active session IDs
|
|
109
|
-
*/
|
|
110
|
-
static getActiveSessionIds() {
|
|
111
|
-
return Array.from(this.instances.keys());
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Remove a specific instance
|
|
115
|
-
*/
|
|
116
|
-
static async removeInstance(sessionId) {
|
|
117
|
-
const instance = this.instances.get(sessionId);
|
|
118
|
-
if (instance) {
|
|
119
|
-
await instance.disconnect();
|
|
120
|
-
return this.instances.delete(sessionId);
|
|
121
|
-
}
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Get instance count
|
|
126
|
-
*/
|
|
127
|
-
static getInstanceCount() {
|
|
128
|
-
return this.instances.size;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Get maximum allowed instances
|
|
132
|
-
*/
|
|
133
|
-
static getMaxInstances() {
|
|
134
|
-
return MAX_MCP_INSTANCES;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Get statistics for all instances
|
|
138
|
-
*/
|
|
139
|
-
static getAllStats() {
|
|
140
|
-
const stats = {};
|
|
141
|
-
for (const [sessionId, instance] of this.instances.entries()) {
|
|
142
|
-
stats[sessionId] = instance.getStats();
|
|
143
|
-
}
|
|
144
|
-
return {
|
|
145
|
-
instanceCount: this.instances.size,
|
|
146
|
-
maxInstances: MAX_MCP_INSTANCES,
|
|
147
|
-
instances: stats,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Clear all instances (for testing or shutdown)
|
|
152
|
-
*/
|
|
153
|
-
static async clearAll() {
|
|
154
|
-
for (const instance of this.instances.values()) {
|
|
155
|
-
await instance.disconnect();
|
|
156
|
-
}
|
|
157
|
-
this.instances.clear();
|
|
158
|
-
logger.info("[MCP Manager] Cleared all instances");
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Convenience function to get MCP manager instance
|
|
163
|
-
*/
|
|
164
|
-
export function getMCPManager(sessionId, config) {
|
|
165
|
-
return NeuroLinkMCPManager.getInstance(sessionId, config);
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Convenience function to remove MCP manager instance
|
|
169
|
-
*/
|
|
170
|
-
export async function removeMCPManager(sessionId) {
|
|
171
|
-
return NeuroLinkMCPManager.removeInstance(sessionId);
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Export manager for direct access if needed
|
|
175
|
-
*/
|
|
176
|
-
export { NeuroLinkMCPManager as MCPManager };
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NeuroLink MCP Client with Automatic Tool Detection
|
|
3
|
-
* Implements automatic tool execution based on prompt analysis
|
|
4
|
-
* Following Lighthouse's pattern of prompt-based tool invocation
|
|
5
|
-
*/
|
|
6
|
-
import { EventEmitter } from "events";
|
|
7
|
-
import type { AIProvider } from "../core/types.js";
|
|
8
|
-
import type { NeuroLinkMCPTool } from "./factory.js";
|
|
9
|
-
/**
|
|
10
|
-
* Tool Detection Pattern
|
|
11
|
-
*/
|
|
12
|
-
interface ToolDetectionPattern {
|
|
13
|
-
patterns: RegExp[];
|
|
14
|
-
toolName: string;
|
|
15
|
-
paramExtractor?: (prompt: string) => Record<string, unknown>;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* MCP Client Configuration
|
|
19
|
-
*/
|
|
20
|
-
export interface NeuroLinkMCPClientConfig {
|
|
21
|
-
provider: AIProvider;
|
|
22
|
-
providerName?: string;
|
|
23
|
-
modelName?: string;
|
|
24
|
-
sessionId?: string;
|
|
25
|
-
userId?: string;
|
|
26
|
-
organizationId?: string;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* NeuroLink MCP Client with Automatic Tool Detection
|
|
30
|
-
*/
|
|
31
|
-
export declare class NeuroLinkMCPClient extends EventEmitter {
|
|
32
|
-
private provider;
|
|
33
|
-
private tools;
|
|
34
|
-
private toolPatterns;
|
|
35
|
-
private config;
|
|
36
|
-
private sessionId;
|
|
37
|
-
private executionCount;
|
|
38
|
-
constructor(config: NeuroLinkMCPClientConfig);
|
|
39
|
-
/**
|
|
40
|
-
* Initialize default tool detection patterns
|
|
41
|
-
*/
|
|
42
|
-
private initializeDefaultPatterns;
|
|
43
|
-
/**
|
|
44
|
-
* Register a tool with automatic detection patterns
|
|
45
|
-
*/
|
|
46
|
-
registerTool(tool: NeuroLinkMCPTool, patterns?: ToolDetectionPattern): void;
|
|
47
|
-
/**
|
|
48
|
-
* Extract tool parameters using AI
|
|
49
|
-
* No hardcoded patterns - let AI figure out the parameters
|
|
50
|
-
*/
|
|
51
|
-
private extractToolParameters;
|
|
52
|
-
/**
|
|
53
|
-
* Analyze prompt to detect required tools
|
|
54
|
-
* TRUE AUTOMATIC DETECTION - AI decides which tools to use
|
|
55
|
-
*/
|
|
56
|
-
private analyzePrompt;
|
|
57
|
-
/**
|
|
58
|
-
* Execute detected tools
|
|
59
|
-
*/
|
|
60
|
-
private executeTools;
|
|
61
|
-
/**
|
|
62
|
-
* Generate response with tool results incorporated
|
|
63
|
-
*/
|
|
64
|
-
private generateResponse;
|
|
65
|
-
/**
|
|
66
|
-
* Send a prompt and automatically execute any needed tools
|
|
67
|
-
*/
|
|
68
|
-
sendPrompt(prompt: string): Promise<string>;
|
|
69
|
-
/**
|
|
70
|
-
* Get registered tools
|
|
71
|
-
*/
|
|
72
|
-
getTools(): Record<string, {
|
|
73
|
-
name: string;
|
|
74
|
-
description?: string;
|
|
75
|
-
inputSchema?: unknown;
|
|
76
|
-
}>;
|
|
77
|
-
/**
|
|
78
|
-
* Get session statistics
|
|
79
|
-
*/
|
|
80
|
-
getStats(): {
|
|
81
|
-
sessionId: string;
|
|
82
|
-
toolCount: number;
|
|
83
|
-
patternCount: number;
|
|
84
|
-
executionCount: number;
|
|
85
|
-
provider: string | undefined;
|
|
86
|
-
model: string | undefined;
|
|
87
|
-
};
|
|
88
|
-
/**
|
|
89
|
-
* Clean up resources
|
|
90
|
-
*/
|
|
91
|
-
cleanup(): Promise<void>;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Create a new NeuroLink MCP Client instance
|
|
95
|
-
*/
|
|
96
|
-
export declare function createNeuroLinkMCPClient(config: NeuroLinkMCPClientConfig): NeuroLinkMCPClient;
|
|
97
|
-
export {};
|