@juspay/neurolink 6.1.0 → 6.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -6
- package/dist/agent/direct-tools.js +6 -5
- package/dist/cli/commands/config.d.ts +13 -13
- package/dist/cli/index.js +3 -9
- package/dist/config/configManager.js +11 -10
- 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/agent/direct-tools.js +6 -5
- package/dist/lib/config/configManager.js +11 -10
- 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 +9 -21
- package/dist/lib/mcp/index.js +16 -57
- package/dist/lib/mcp/registry.js +1 -1
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.js +2 -1
- package/dist/lib/mcp/tool-registry.js +1 -1
- package/dist/lib/neurolink.d.ts +1 -9
- package/dist/lib/neurolink.js +22 -71
- 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 +6 -3
- 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/telemetry/index.js +2 -1
- package/dist/lib/utils/logger.d.ts +62 -2
- package/dist/lib/utils/logger.js +174 -9
- 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 +9 -21
- package/dist/mcp/index.js +16 -57
- package/dist/mcp/registry.js +1 -1
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.js +2 -1
- package/dist/mcp/tool-registry.js +1 -1
- package/dist/neurolink.d.ts +1 -9
- package/dist/neurolink.js +22 -71
- 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 +6 -3
- 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/telemetry/index.js +2 -1
- package/dist/utils/logger.d.ts +62 -2
- package/dist/utils/logger.js +174 -9
- package/dist/utils/providerConfig.d.ts +117 -0
- package/dist/utils/providerConfig.js +353 -0
- package/dist/utils/providerUtils.d.ts +2 -1
- package/dist/utils/providerUtils.js +53 -36
- package/dist/utils/timeout.d.ts +72 -1
- package/dist/utils/timeout.js +203 -2
- package/package.json +1 -1
- package/dist/chat/client-utils.d.ts +0 -95
- package/dist/chat/client-utils.js +0 -315
- package/dist/chat/index.d.ts +0 -24
- package/dist/chat/index.js +0 -33
- package/dist/chat/session-storage.d.ts +0 -77
- package/dist/chat/session-storage.js +0 -233
- package/dist/chat/session.d.ts +0 -96
- package/dist/chat/session.js +0 -257
- package/dist/chat/sse-handler.d.ts +0 -49
- package/dist/chat/sse-handler.js +0 -259
- package/dist/chat/types.d.ts +0 -74
- package/dist/chat/types.js +0 -5
- package/dist/chat/websocket-chat-handler.d.ts +0 -37
- package/dist/chat/websocket-chat-handler.js +0 -262
- package/dist/cli/commands/mcp.d.ts +0 -20
- package/dist/cli/commands/mcp.js +0 -1272
- package/dist/core/defaults.d.ts +0 -19
- package/dist/core/defaults.js +0 -29
- package/dist/core/evaluation-config.d.ts +0 -29
- package/dist/core/evaluation-config.js +0 -144
- package/dist/factories/compatibility-factory.d.ts +0 -35
- package/dist/factories/compatibility-factory.js +0 -71
- package/dist/factories/provider-generate-factory.d.ts +0 -20
- package/dist/factories/provider-generate-factory.js +0 -93
- package/dist/lib/chat/client-utils.d.ts +0 -95
- package/dist/lib/chat/client-utils.js +0 -315
- package/dist/lib/chat/index.d.ts +0 -24
- package/dist/lib/chat/index.js +0 -33
- package/dist/lib/chat/session-storage.d.ts +0 -77
- package/dist/lib/chat/session-storage.js +0 -233
- package/dist/lib/chat/session.d.ts +0 -96
- package/dist/lib/chat/session.js +0 -257
- package/dist/lib/chat/sse-handler.d.ts +0 -49
- package/dist/lib/chat/sse-handler.js +0 -259
- package/dist/lib/chat/types.d.ts +0 -74
- package/dist/lib/chat/types.js +0 -5
- package/dist/lib/chat/websocket-chat-handler.d.ts +0 -37
- package/dist/lib/chat/websocket-chat-handler.js +0 -262
- package/dist/lib/core/defaults.d.ts +0 -19
- package/dist/lib/core/defaults.js +0 -29
- package/dist/lib/core/evaluation-config.d.ts +0 -29
- package/dist/lib/core/evaluation-config.js +0 -144
- package/dist/lib/factories/compatibility-factory.d.ts +0 -35
- package/dist/lib/factories/compatibility-factory.js +0 -71
- package/dist/lib/factories/provider-generate-factory.d.ts +0 -20
- package/dist/lib/factories/provider-generate-factory.js +0 -93
- package/dist/lib/mcp/adapters/plugin-bridge.d.ts +0 -40
- package/dist/lib/mcp/adapters/plugin-bridge.js +0 -89
- package/dist/lib/mcp/auto-discovery.d.ts +0 -62
- package/dist/lib/mcp/auto-discovery.js +0 -149
- package/dist/lib/mcp/client.d.ts +0 -68
- package/dist/lib/mcp/client.js +0 -248
- package/dist/lib/mcp/config.d.ts +0 -31
- package/dist/lib/mcp/config.js +0 -99
- package/dist/lib/mcp/context-manager.d.ts +0 -171
- package/dist/lib/mcp/context-manager.js +0 -362
- package/dist/lib/mcp/contracts/mcp-contract.d.ts +0 -169
- package/dist/lib/mcp/contracts/mcp-contract.js +0 -58
- package/dist/lib/mcp/core/plugin-manager.d.ts +0 -46
- package/dist/lib/mcp/core/plugin-manager.js +0 -110
- package/dist/lib/mcp/demo/plugin-demo.d.ts +0 -20
- package/dist/lib/mcp/demo/plugin-demo.js +0 -118
- package/dist/lib/mcp/dynamic-chain-executor.d.ts +0 -225
- package/dist/lib/mcp/dynamic-chain-executor.js +0 -489
- package/dist/lib/mcp/dynamic-orchestrator.d.ts +0 -115
- package/dist/lib/mcp/dynamic-orchestrator.js +0 -351
- package/dist/lib/mcp/ecosystem.d.ts +0 -75
- package/dist/lib/mcp/ecosystem.js +0 -161
- package/dist/lib/mcp/error-manager.d.ts +0 -254
- package/dist/lib/mcp/error-manager.js +0 -501
- package/dist/lib/mcp/error-recovery.d.ts +0 -159
- package/dist/lib/mcp/error-recovery.js +0 -405
- package/dist/lib/mcp/external-client.d.ts +0 -88
- package/dist/lib/mcp/external-client.js +0 -331
- package/dist/lib/mcp/external-manager.d.ts +0 -112
- package/dist/lib/mcp/external-manager.js +0 -308
- package/dist/lib/mcp/function-calling.d.ts +0 -65
- package/dist/lib/mcp/function-calling.js +0 -642
- package/dist/lib/mcp/health-monitor.d.ts +0 -257
- package/dist/lib/mcp/health-monitor.js +0 -630
- package/dist/lib/mcp/initialize-tools.d.ts +0 -29
- package/dist/lib/mcp/initialize-tools.js +0 -261
- package/dist/lib/mcp/initialize.d.ts +0 -18
- package/dist/lib/mcp/initialize.js +0 -62
- package/dist/lib/mcp/logging.d.ts +0 -38
- package/dist/lib/mcp/logging.js +0 -100
- 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/logging.d.ts +0 -38
- package/dist/mcp/logging.js +0 -100
- 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,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP Logging Utility
|
|
3
|
-
* Centralized logging for the MCP ecosystem
|
|
4
|
-
*/
|
|
5
|
-
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
6
|
-
interface LogEntry {
|
|
7
|
-
level: LogLevel;
|
|
8
|
-
message: string;
|
|
9
|
-
timestamp: Date;
|
|
10
|
-
data?: unknown;
|
|
11
|
-
}
|
|
12
|
-
declare class MCPLogger {
|
|
13
|
-
private logLevel;
|
|
14
|
-
private logs;
|
|
15
|
-
private maxLogs;
|
|
16
|
-
constructor();
|
|
17
|
-
setLogLevel(level: LogLevel): void;
|
|
18
|
-
private shouldLog;
|
|
19
|
-
private log;
|
|
20
|
-
debug(message: string, data?: unknown): void;
|
|
21
|
-
info(message: string, data?: unknown): void;
|
|
22
|
-
warn(message: string, data?: unknown): void;
|
|
23
|
-
error(message: string, data?: unknown): void;
|
|
24
|
-
getLogs(level?: LogLevel): LogEntry[];
|
|
25
|
-
clearLogs(): void;
|
|
26
|
-
}
|
|
27
|
-
export declare const mcpLogger: MCPLogger;
|
|
28
|
-
export declare const autoDiscoveryLogger: MCPLogger;
|
|
29
|
-
export declare const registryLogger: MCPLogger;
|
|
30
|
-
export declare const unifiedRegistryLogger: MCPLogger;
|
|
31
|
-
export declare function setGlobalMCPLogLevel(level: LogLevel): void;
|
|
32
|
-
export declare const LogLevels: {
|
|
33
|
-
readonly debug: "debug";
|
|
34
|
-
readonly info: "info";
|
|
35
|
-
readonly warn: "warn";
|
|
36
|
-
readonly error: "error";
|
|
37
|
-
};
|
|
38
|
-
export {};
|
package/dist/lib/mcp/logging.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP Logging Utility
|
|
3
|
-
* Centralized logging for the MCP ecosystem
|
|
4
|
-
*/
|
|
5
|
-
class MCPLogger {
|
|
6
|
-
logLevel = "info";
|
|
7
|
-
logs = [];
|
|
8
|
-
maxLogs = 1000;
|
|
9
|
-
constructor() {
|
|
10
|
-
// Set log level from environment
|
|
11
|
-
const envLevel = process.env.MCP_LOG_LEVEL?.toLowerCase();
|
|
12
|
-
if (envLevel && ["debug", "info", "warn", "error"].includes(envLevel)) {
|
|
13
|
-
this.logLevel = envLevel;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
setLogLevel(level) {
|
|
17
|
-
this.logLevel = level;
|
|
18
|
-
}
|
|
19
|
-
shouldLog(level) {
|
|
20
|
-
// CRITICAL: Respect CLI debug flag - hide all logs except errors unless debugging
|
|
21
|
-
const isDebugMode = process.argv.includes("--debug");
|
|
22
|
-
if (!isDebugMode && level !== "error") {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
const levels = ["debug", "info", "warn", "error"];
|
|
26
|
-
return levels.indexOf(level) >= levels.indexOf(this.logLevel);
|
|
27
|
-
}
|
|
28
|
-
log(level, message, data) {
|
|
29
|
-
if (!this.shouldLog(level)) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const entry = {
|
|
33
|
-
level,
|
|
34
|
-
message,
|
|
35
|
-
timestamp: new Date(),
|
|
36
|
-
data,
|
|
37
|
-
};
|
|
38
|
-
// Store log entry
|
|
39
|
-
this.logs.push(entry);
|
|
40
|
-
// Trim old logs
|
|
41
|
-
if (this.logs.length > this.maxLogs) {
|
|
42
|
-
this.logs = this.logs.slice(-this.maxLogs);
|
|
43
|
-
}
|
|
44
|
-
// Console output
|
|
45
|
-
const timestamp = entry.timestamp.toISOString();
|
|
46
|
-
const prefix = `[${timestamp}] [MCP:${level.toUpperCase()}]`;
|
|
47
|
-
switch (level) {
|
|
48
|
-
case "debug":
|
|
49
|
-
console.debug(prefix, message, data ? data : "");
|
|
50
|
-
break;
|
|
51
|
-
case "info":
|
|
52
|
-
console.info(prefix, message, data ? data : "");
|
|
53
|
-
break;
|
|
54
|
-
case "warn":
|
|
55
|
-
console.warn(prefix, message, data ? data : "");
|
|
56
|
-
break;
|
|
57
|
-
case "error":
|
|
58
|
-
console.error(prefix, message, data ? data : "");
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
debug(message, data) {
|
|
63
|
-
this.log("debug", message, data);
|
|
64
|
-
}
|
|
65
|
-
info(message, data) {
|
|
66
|
-
this.log("info", message, data);
|
|
67
|
-
}
|
|
68
|
-
warn(message, data) {
|
|
69
|
-
this.log("warn", message, data);
|
|
70
|
-
}
|
|
71
|
-
error(message, data) {
|
|
72
|
-
this.log("error", message, data);
|
|
73
|
-
}
|
|
74
|
-
getLogs(level) {
|
|
75
|
-
if (level) {
|
|
76
|
-
return this.logs.filter((log) => log.level === level);
|
|
77
|
-
}
|
|
78
|
-
return [...this.logs];
|
|
79
|
-
}
|
|
80
|
-
clearLogs() {
|
|
81
|
-
this.logs = [];
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
// Export singleton instance
|
|
85
|
-
export const mcpLogger = new MCPLogger();
|
|
86
|
-
// Additional logger instances for different modules
|
|
87
|
-
export const autoDiscoveryLogger = mcpLogger;
|
|
88
|
-
export const registryLogger = mcpLogger;
|
|
89
|
-
export const unifiedRegistryLogger = mcpLogger;
|
|
90
|
-
// Global log level setter
|
|
91
|
-
export function setGlobalMCPLogLevel(level) {
|
|
92
|
-
mcpLogger.setLogLevel(level);
|
|
93
|
-
}
|
|
94
|
-
// Export LogLevel enum for runtime use
|
|
95
|
-
export const LogLevels = {
|
|
96
|
-
debug: "debug",
|
|
97
|
-
info: "info",
|
|
98
|
-
warn: "warn",
|
|
99
|
-
error: "error",
|
|
100
|
-
};
|
|
@@ -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 };
|