@juspay/neurolink 1.5.3 → 1.9.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 +241 -1
- package/README.md +113 -20
- package/dist/agent/direct-tools.d.ts +1203 -0
- package/dist/agent/direct-tools.js +387 -0
- package/dist/cli/commands/agent-generate.d.ts +2 -0
- package/dist/cli/commands/agent-generate.js +70 -0
- package/dist/cli/commands/config.d.ts +76 -9
- package/dist/cli/commands/config.js +358 -233
- package/dist/cli/commands/mcp.d.ts +2 -1
- package/dist/cli/commands/mcp.js +874 -146
- package/dist/cli/commands/ollama.d.ts +8 -0
- package/dist/cli/commands/ollama.js +333 -0
- package/dist/cli/index.js +591 -327
- package/dist/cli/utils/complete-setup.d.ts +19 -0
- package/dist/cli/utils/complete-setup.js +81 -0
- package/dist/cli/utils/env-manager.d.ts +44 -0
- package/dist/cli/utils/env-manager.js +226 -0
- package/dist/cli/utils/interactive-setup.d.ts +48 -0
- package/dist/cli/utils/interactive-setup.js +302 -0
- package/dist/core/dynamic-models.d.ts +208 -0
- package/dist/core/dynamic-models.js +250 -0
- package/dist/core/factory.d.ts +13 -6
- package/dist/core/factory.js +180 -50
- package/dist/core/types.d.ts +8 -3
- package/dist/core/types.js +7 -4
- package/dist/index.d.ts +16 -16
- package/dist/index.js +16 -16
- package/dist/lib/agent/direct-tools.d.ts +1203 -0
- package/dist/lib/agent/direct-tools.js +387 -0
- package/dist/lib/core/dynamic-models.d.ts +208 -0
- package/dist/lib/core/dynamic-models.js +250 -0
- package/dist/lib/core/factory.d.ts +13 -6
- package/dist/lib/core/factory.js +180 -50
- package/dist/lib/core/types.d.ts +8 -3
- package/dist/lib/core/types.js +7 -4
- package/dist/lib/index.d.ts +16 -16
- package/dist/lib/index.js +16 -16
- package/dist/lib/mcp/auto-discovery.d.ts +120 -0
- package/dist/lib/mcp/auto-discovery.js +793 -0
- package/dist/lib/mcp/client.d.ts +66 -0
- package/dist/lib/mcp/client.js +245 -0
- package/dist/lib/mcp/config.d.ts +31 -0
- package/dist/lib/mcp/config.js +74 -0
- package/dist/lib/mcp/context-manager.d.ts +4 -4
- package/dist/lib/mcp/context-manager.js +24 -18
- package/dist/lib/mcp/factory.d.ts +28 -11
- package/dist/lib/mcp/factory.js +36 -29
- package/dist/lib/mcp/function-calling.d.ts +51 -0
- package/dist/lib/mcp/function-calling.js +510 -0
- package/dist/lib/mcp/index.d.ts +190 -0
- package/dist/lib/mcp/index.js +156 -0
- package/dist/lib/mcp/initialize-tools.d.ts +28 -0
- package/dist/lib/mcp/initialize-tools.js +209 -0
- package/dist/lib/mcp/initialize.d.ts +17 -0
- package/dist/lib/mcp/initialize.js +51 -0
- package/dist/lib/mcp/logging.d.ts +71 -0
- package/dist/lib/mcp/logging.js +183 -0
- package/dist/lib/mcp/manager.d.ts +67 -0
- package/dist/lib/mcp/manager.js +176 -0
- package/dist/lib/mcp/neurolink-mcp-client.d.ts +96 -0
- package/dist/lib/mcp/neurolink-mcp-client.js +417 -0
- package/dist/lib/mcp/orchestrator.d.ts +3 -3
- package/dist/lib/mcp/orchestrator.js +46 -43
- package/dist/lib/mcp/registry.d.ts +2 -2
- package/dist/lib/mcp/registry.js +42 -33
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.d.ts +1 -1
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.js +205 -66
- package/dist/lib/mcp/servers/ai-providers/ai-core-server.js +143 -99
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.d.ts +6 -6
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.js +404 -251
- package/dist/lib/mcp/servers/utilities/utility-server.d.ts +8 -0
- package/dist/lib/mcp/servers/utilities/utility-server.js +326 -0
- package/dist/lib/mcp/tool-integration.d.ts +67 -0
- package/dist/lib/mcp/tool-integration.js +179 -0
- package/dist/lib/mcp/unified-registry.d.ts +269 -0
- package/dist/lib/mcp/unified-registry.js +1411 -0
- package/dist/lib/neurolink.d.ts +68 -6
- package/dist/lib/neurolink.js +314 -42
- package/dist/lib/providers/agent-enhanced-provider.d.ts +59 -0
- package/dist/lib/providers/agent-enhanced-provider.js +242 -0
- package/dist/lib/providers/amazonBedrock.d.ts +3 -3
- package/dist/lib/providers/amazonBedrock.js +54 -50
- package/dist/lib/providers/anthropic.d.ts +2 -2
- package/dist/lib/providers/anthropic.js +92 -84
- package/dist/lib/providers/azureOpenAI.d.ts +2 -2
- package/dist/lib/providers/azureOpenAI.js +97 -86
- package/dist/lib/providers/function-calling-provider.d.ts +70 -0
- package/dist/lib/providers/function-calling-provider.js +359 -0
- package/dist/lib/providers/googleAIStudio.d.ts +10 -5
- package/dist/lib/providers/googleAIStudio.js +60 -38
- package/dist/lib/providers/googleVertexAI.d.ts +3 -3
- package/dist/lib/providers/googleVertexAI.js +96 -86
- package/dist/lib/providers/huggingFace.d.ts +31 -0
- package/dist/lib/providers/huggingFace.js +362 -0
- package/dist/lib/providers/index.d.ts +14 -8
- package/dist/lib/providers/index.js +18 -12
- package/dist/lib/providers/mcp-provider.d.ts +62 -0
- package/dist/lib/providers/mcp-provider.js +183 -0
- package/dist/lib/providers/mistralAI.d.ts +32 -0
- package/dist/lib/providers/mistralAI.js +223 -0
- package/dist/lib/providers/ollama.d.ts +51 -0
- package/dist/lib/providers/ollama.js +508 -0
- package/dist/lib/providers/openAI.d.ts +7 -3
- package/dist/lib/providers/openAI.js +45 -33
- package/dist/lib/utils/logger.js +2 -2
- package/dist/lib/utils/providerUtils.js +59 -22
- package/dist/mcp/auto-discovery.d.ts +120 -0
- package/dist/mcp/auto-discovery.js +794 -0
- package/dist/mcp/client.d.ts +66 -0
- package/dist/mcp/client.js +245 -0
- package/dist/mcp/config.d.ts +31 -0
- package/dist/mcp/config.js +74 -0
- package/dist/mcp/context-manager.d.ts +4 -4
- package/dist/mcp/context-manager.js +24 -18
- package/dist/mcp/factory.d.ts +28 -11
- package/dist/mcp/factory.js +36 -29
- package/dist/mcp/function-calling.d.ts +51 -0
- package/dist/mcp/function-calling.js +510 -0
- package/dist/mcp/index.d.ts +190 -0
- package/dist/mcp/index.js +156 -0
- package/dist/mcp/initialize-tools.d.ts +28 -0
- package/dist/mcp/initialize-tools.js +210 -0
- package/dist/mcp/initialize.d.ts +17 -0
- package/dist/mcp/initialize.js +51 -0
- package/dist/mcp/logging.d.ts +71 -0
- package/dist/mcp/logging.js +183 -0
- package/dist/mcp/manager.d.ts +67 -0
- package/dist/mcp/manager.js +176 -0
- package/dist/mcp/neurolink-mcp-client.d.ts +96 -0
- package/dist/mcp/neurolink-mcp-client.js +417 -0
- package/dist/mcp/orchestrator.d.ts +3 -3
- package/dist/mcp/orchestrator.js +46 -43
- package/dist/mcp/registry.d.ts +2 -2
- package/dist/mcp/registry.js +42 -33
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.d.ts +1 -1
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.js +205 -66
- package/dist/mcp/servers/ai-providers/ai-core-server.js +143 -99
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +6 -6
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.js +404 -253
- package/dist/mcp/servers/utilities/utility-server.d.ts +8 -0
- package/dist/mcp/servers/utilities/utility-server.js +326 -0
- package/dist/mcp/tool-integration.d.ts +67 -0
- package/dist/mcp/tool-integration.js +179 -0
- package/dist/mcp/unified-registry.d.ts +269 -0
- package/dist/mcp/unified-registry.js +1411 -0
- package/dist/neurolink.d.ts +68 -6
- package/dist/neurolink.js +314 -42
- package/dist/providers/agent-enhanced-provider.d.ts +59 -0
- package/dist/providers/agent-enhanced-provider.js +242 -0
- package/dist/providers/amazonBedrock.d.ts +3 -3
- package/dist/providers/amazonBedrock.js +54 -50
- package/dist/providers/anthropic.d.ts +2 -2
- package/dist/providers/anthropic.js +92 -84
- package/dist/providers/azureOpenAI.d.ts +2 -2
- package/dist/providers/azureOpenAI.js +97 -86
- package/dist/providers/function-calling-provider.d.ts +70 -0
- package/dist/providers/function-calling-provider.js +359 -0
- package/dist/providers/googleAIStudio.d.ts +10 -5
- package/dist/providers/googleAIStudio.js +60 -38
- package/dist/providers/googleVertexAI.d.ts +3 -3
- package/dist/providers/googleVertexAI.js +96 -86
- package/dist/providers/huggingFace.d.ts +31 -0
- package/dist/providers/huggingFace.js +362 -0
- package/dist/providers/index.d.ts +14 -8
- package/dist/providers/index.js +18 -12
- package/dist/providers/mcp-provider.d.ts +62 -0
- package/dist/providers/mcp-provider.js +183 -0
- package/dist/providers/mistralAI.d.ts +32 -0
- package/dist/providers/mistralAI.js +223 -0
- package/dist/providers/ollama.d.ts +51 -0
- package/dist/providers/ollama.js +508 -0
- package/dist/providers/openAI.d.ts +7 -3
- package/dist/providers/openAI.js +45 -33
- package/dist/utils/logger.js +2 -2
- package/dist/utils/providerUtils.js +59 -22
- package/package.json +28 -4
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NeuroLink MCP (Model Context Protocol) Module
|
|
3
|
+
*
|
|
4
|
+
* This module exports the MCP configuration and initialization utilities
|
|
5
|
+
* for use throughout the application, following Lighthouse's patterns.
|
|
6
|
+
*/
|
|
7
|
+
import { getMCPManager, removeMCPManager } from "./manager.js";
|
|
8
|
+
import { createMCPServer } from "./factory.js";
|
|
9
|
+
import type { NeuroLinkMCPServer } from "./factory.js";
|
|
10
|
+
export { createMCPServer } from "./factory.js";
|
|
11
|
+
export { mcpConfig } from "./config.js";
|
|
12
|
+
export { getMCPManager, removeMCPManager, MCPManager } from "./manager.js";
|
|
13
|
+
export { createMCPClient } from "./client.js";
|
|
14
|
+
export { initializeMCPTools, getAllAvailableTools, initializeServerTools, } from "./initialize-tools.js";
|
|
15
|
+
export type { NeuroLinkMCPServer, NeuroLinkMCPTool, NeuroLinkExecutionContext, ToolResult, MCPServerCategory, MCPServerConfig, } from "./factory.js";
|
|
16
|
+
export type { MCPClientConfig } from "./client.js";
|
|
17
|
+
/**
|
|
18
|
+
* MCP utilities for system-wide operations
|
|
19
|
+
*/
|
|
20
|
+
export declare const MCPUtils: {
|
|
21
|
+
/**
|
|
22
|
+
* Get a formatted list of all available tools across all registered MCP servers
|
|
23
|
+
* Useful for documentation or configuration UI
|
|
24
|
+
*/
|
|
25
|
+
getAvailableTools: () => Promise<{
|
|
26
|
+
serverId: string;
|
|
27
|
+
serverTitle: string;
|
|
28
|
+
serverDescription: string | undefined;
|
|
29
|
+
category: import("./factory.js").MCPServerCategory | undefined;
|
|
30
|
+
toolCount: number;
|
|
31
|
+
tools: {
|
|
32
|
+
name: string;
|
|
33
|
+
description: string;
|
|
34
|
+
isImplemented: boolean;
|
|
35
|
+
}[];
|
|
36
|
+
}[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Function to test connectivity with MCP servers
|
|
39
|
+
* Returns diagnostics about the MCP server initialization status
|
|
40
|
+
*/
|
|
41
|
+
testConnectivity: () => Promise<{
|
|
42
|
+
status: string;
|
|
43
|
+
message: string;
|
|
44
|
+
servers: {
|
|
45
|
+
serverId: string;
|
|
46
|
+
serverTitle: string;
|
|
47
|
+
status: string;
|
|
48
|
+
toolCount: number;
|
|
49
|
+
implementedTools: number;
|
|
50
|
+
}[];
|
|
51
|
+
timestamp: string;
|
|
52
|
+
} | {
|
|
53
|
+
status: string;
|
|
54
|
+
message: string;
|
|
55
|
+
timestamp: string;
|
|
56
|
+
servers?: undefined;
|
|
57
|
+
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Get statistics about MCP usage
|
|
60
|
+
*/
|
|
61
|
+
getStatistics: () => Promise<{
|
|
62
|
+
servers: {
|
|
63
|
+
total: number;
|
|
64
|
+
byCategory: Record<string, number>;
|
|
65
|
+
};
|
|
66
|
+
tools: {
|
|
67
|
+
totalTools: number;
|
|
68
|
+
implementedTools: number;
|
|
69
|
+
byCategory: Record<string, number>;
|
|
70
|
+
};
|
|
71
|
+
sessions: {
|
|
72
|
+
instanceCount: number;
|
|
73
|
+
maxInstances: number;
|
|
74
|
+
instances: Record<string, any>;
|
|
75
|
+
};
|
|
76
|
+
}>;
|
|
77
|
+
/**
|
|
78
|
+
* Initialize MCP for a session
|
|
79
|
+
* Convenience method that sets up everything needed for a session
|
|
80
|
+
*/
|
|
81
|
+
initializeSession: (sessionId: string, config?: {
|
|
82
|
+
userId?: string;
|
|
83
|
+
aiProvider?: string;
|
|
84
|
+
modelId?: string;
|
|
85
|
+
}) => Promise<{
|
|
86
|
+
sessionId: string;
|
|
87
|
+
client: import("./client.js").NeuroLinkMCPClient;
|
|
88
|
+
context: import("./factory.js").NeuroLinkExecutionContext;
|
|
89
|
+
toolCount: number;
|
|
90
|
+
}>;
|
|
91
|
+
/**
|
|
92
|
+
* Clean up a session
|
|
93
|
+
*/
|
|
94
|
+
cleanupSession: (sessionId: string) => Promise<boolean>;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Default export for convenience
|
|
98
|
+
*/
|
|
99
|
+
declare const _default: {
|
|
100
|
+
config: {
|
|
101
|
+
getServers: () => Promise<NeuroLinkMCPServer[]>;
|
|
102
|
+
getAllTools: () => Promise<{
|
|
103
|
+
name: string;
|
|
104
|
+
description: string;
|
|
105
|
+
serverId: string;
|
|
106
|
+
serverTitle: string;
|
|
107
|
+
category?: string;
|
|
108
|
+
}[]>;
|
|
109
|
+
};
|
|
110
|
+
utils: {
|
|
111
|
+
/**
|
|
112
|
+
* Get a formatted list of all available tools across all registered MCP servers
|
|
113
|
+
* Useful for documentation or configuration UI
|
|
114
|
+
*/
|
|
115
|
+
getAvailableTools: () => Promise<{
|
|
116
|
+
serverId: string;
|
|
117
|
+
serverTitle: string;
|
|
118
|
+
serverDescription: string | undefined;
|
|
119
|
+
category: import("./factory.js").MCPServerCategory | undefined;
|
|
120
|
+
toolCount: number;
|
|
121
|
+
tools: {
|
|
122
|
+
name: string;
|
|
123
|
+
description: string;
|
|
124
|
+
isImplemented: boolean;
|
|
125
|
+
}[];
|
|
126
|
+
}[]>;
|
|
127
|
+
/**
|
|
128
|
+
* Function to test connectivity with MCP servers
|
|
129
|
+
* Returns diagnostics about the MCP server initialization status
|
|
130
|
+
*/
|
|
131
|
+
testConnectivity: () => Promise<{
|
|
132
|
+
status: string;
|
|
133
|
+
message: string;
|
|
134
|
+
servers: {
|
|
135
|
+
serverId: string;
|
|
136
|
+
serverTitle: string;
|
|
137
|
+
status: string;
|
|
138
|
+
toolCount: number;
|
|
139
|
+
implementedTools: number;
|
|
140
|
+
}[];
|
|
141
|
+
timestamp: string;
|
|
142
|
+
} | {
|
|
143
|
+
status: string;
|
|
144
|
+
message: string;
|
|
145
|
+
timestamp: string;
|
|
146
|
+
servers?: undefined;
|
|
147
|
+
}>;
|
|
148
|
+
/**
|
|
149
|
+
* Get statistics about MCP usage
|
|
150
|
+
*/
|
|
151
|
+
getStatistics: () => Promise<{
|
|
152
|
+
servers: {
|
|
153
|
+
total: number;
|
|
154
|
+
byCategory: Record<string, number>;
|
|
155
|
+
};
|
|
156
|
+
tools: {
|
|
157
|
+
totalTools: number;
|
|
158
|
+
implementedTools: number;
|
|
159
|
+
byCategory: Record<string, number>;
|
|
160
|
+
};
|
|
161
|
+
sessions: {
|
|
162
|
+
instanceCount: number;
|
|
163
|
+
maxInstances: number;
|
|
164
|
+
instances: Record<string, any>;
|
|
165
|
+
};
|
|
166
|
+
}>;
|
|
167
|
+
/**
|
|
168
|
+
* Initialize MCP for a session
|
|
169
|
+
* Convenience method that sets up everything needed for a session
|
|
170
|
+
*/
|
|
171
|
+
initializeSession: (sessionId: string, config?: {
|
|
172
|
+
userId?: string;
|
|
173
|
+
aiProvider?: string;
|
|
174
|
+
modelId?: string;
|
|
175
|
+
}) => Promise<{
|
|
176
|
+
sessionId: string;
|
|
177
|
+
client: import("./client.js").NeuroLinkMCPClient;
|
|
178
|
+
context: import("./factory.js").NeuroLinkExecutionContext;
|
|
179
|
+
toolCount: number;
|
|
180
|
+
}>;
|
|
181
|
+
/**
|
|
182
|
+
* Clean up a session
|
|
183
|
+
*/
|
|
184
|
+
cleanupSession: (sessionId: string) => Promise<boolean>;
|
|
185
|
+
};
|
|
186
|
+
createServer: typeof createMCPServer;
|
|
187
|
+
getManager: typeof getMCPManager;
|
|
188
|
+
removeManager: typeof removeMCPManager;
|
|
189
|
+
};
|
|
190
|
+
export default _default;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NeuroLink MCP (Model Context Protocol) Module
|
|
3
|
+
*
|
|
4
|
+
* This module exports the MCP configuration and initialization utilities
|
|
5
|
+
* for use throughout the application, following Lighthouse's patterns.
|
|
6
|
+
*/
|
|
7
|
+
import { mcpConfig } from "./config.js";
|
|
8
|
+
import { getMCPManager, removeMCPManager, MCPManager } from "./manager.js";
|
|
9
|
+
import { initializeMCPTools, getAllAvailableTools, initializeServerTools, } from "./initialize-tools.js";
|
|
10
|
+
import { createMCPServer } from "./factory.js";
|
|
11
|
+
import { logger } from "../utils/logger.js";
|
|
12
|
+
// Re-export core components
|
|
13
|
+
export { createMCPServer } from "./factory.js";
|
|
14
|
+
export { mcpConfig } from "./config.js";
|
|
15
|
+
export { getMCPManager, removeMCPManager, MCPManager } from "./manager.js";
|
|
16
|
+
export { createMCPClient } from "./client.js";
|
|
17
|
+
export { initializeMCPTools, getAllAvailableTools, initializeServerTools, } from "./initialize-tools.js";
|
|
18
|
+
/**
|
|
19
|
+
* MCP utilities for system-wide operations
|
|
20
|
+
*/
|
|
21
|
+
export const MCPUtils = {
|
|
22
|
+
/**
|
|
23
|
+
* Get a formatted list of all available tools across all registered MCP servers
|
|
24
|
+
* Useful for documentation or configuration UI
|
|
25
|
+
*/
|
|
26
|
+
getAvailableTools: async () => {
|
|
27
|
+
const servers = await mcpConfig.getServers();
|
|
28
|
+
return servers.map((server) => ({
|
|
29
|
+
serverId: server.id,
|
|
30
|
+
serverTitle: server.title,
|
|
31
|
+
serverDescription: server.description,
|
|
32
|
+
category: server.category,
|
|
33
|
+
toolCount: Object.keys(server.tools).length,
|
|
34
|
+
tools: Object.entries(server.tools).map(([name, tool]) => ({
|
|
35
|
+
name,
|
|
36
|
+
description: tool.description,
|
|
37
|
+
isImplemented: tool.isImplemented !== false,
|
|
38
|
+
})),
|
|
39
|
+
}));
|
|
40
|
+
},
|
|
41
|
+
/**
|
|
42
|
+
* Function to test connectivity with MCP servers
|
|
43
|
+
* Returns diagnostics about the MCP server initialization status
|
|
44
|
+
*/
|
|
45
|
+
testConnectivity: async () => {
|
|
46
|
+
try {
|
|
47
|
+
const servers = await mcpConfig.getServers();
|
|
48
|
+
const results = servers.map((server) => ({
|
|
49
|
+
serverId: server.id,
|
|
50
|
+
serverTitle: server.title,
|
|
51
|
+
status: "connected",
|
|
52
|
+
toolCount: Object.keys(server.tools).length,
|
|
53
|
+
implementedTools: Object.values(server.tools).filter((tool) => tool.isImplemented !== false).length,
|
|
54
|
+
}));
|
|
55
|
+
const totalToolCount = results.reduce((acc, server) => acc + server.toolCount, 0);
|
|
56
|
+
const totalImplemented = results.reduce((acc, server) => acc + server.implementedTools, 0);
|
|
57
|
+
logger.info("[MCP Utils] Connectivity test successful", {
|
|
58
|
+
serverCount: results.length,
|
|
59
|
+
totalToolCount,
|
|
60
|
+
totalImplemented,
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
status: "ok",
|
|
64
|
+
message: `Connected to ${results.length} MCP servers with ${totalToolCount} total tools (${totalImplemented} implemented)`,
|
|
65
|
+
servers: results,
|
|
66
|
+
timestamp: new Date().toISOString(),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
71
|
+
logger.error("[MCP Utils] Connectivity test failed", {
|
|
72
|
+
error: errorMessage,
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
status: "error",
|
|
76
|
+
message: `Failed to connect to MCP servers: ${errorMessage}`,
|
|
77
|
+
timestamp: new Date().toISOString(),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
/**
|
|
82
|
+
* Get statistics about MCP usage
|
|
83
|
+
*/
|
|
84
|
+
getStatistics: async () => {
|
|
85
|
+
const servers = await mcpConfig.getServers();
|
|
86
|
+
const managerStats = MCPManager.getAllStats();
|
|
87
|
+
const toolStats = servers.reduce((acc, server) => {
|
|
88
|
+
const tools = Object.values(server.tools);
|
|
89
|
+
acc.totalTools += tools.length;
|
|
90
|
+
acc.implementedTools += tools.filter((t) => t.isImplemented !== false).length;
|
|
91
|
+
// Count by category
|
|
92
|
+
if (server.category) {
|
|
93
|
+
acc.byCategory[server.category] =
|
|
94
|
+
(acc.byCategory[server.category] || 0) + tools.length;
|
|
95
|
+
}
|
|
96
|
+
return acc;
|
|
97
|
+
}, {
|
|
98
|
+
totalTools: 0,
|
|
99
|
+
implementedTools: 0,
|
|
100
|
+
byCategory: {},
|
|
101
|
+
});
|
|
102
|
+
return {
|
|
103
|
+
servers: {
|
|
104
|
+
total: servers.length,
|
|
105
|
+
byCategory: servers.reduce((acc, server) => {
|
|
106
|
+
const category = server.category || "custom";
|
|
107
|
+
acc[category] = (acc[category] || 0) + 1;
|
|
108
|
+
return acc;
|
|
109
|
+
}, {}),
|
|
110
|
+
},
|
|
111
|
+
tools: toolStats,
|
|
112
|
+
sessions: managerStats,
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
/**
|
|
116
|
+
* Initialize MCP for a session
|
|
117
|
+
* Convenience method that sets up everything needed for a session
|
|
118
|
+
*/
|
|
119
|
+
initializeSession: async (sessionId, config) => {
|
|
120
|
+
// Get or create MCP client for session
|
|
121
|
+
const client = getMCPManager(sessionId, config);
|
|
122
|
+
// Create context for tool execution
|
|
123
|
+
const context = {
|
|
124
|
+
sessionId,
|
|
125
|
+
userId: config?.userId,
|
|
126
|
+
aiProvider: config?.aiProvider,
|
|
127
|
+
modelId: config?.modelId,
|
|
128
|
+
timestamp: Date.now(),
|
|
129
|
+
};
|
|
130
|
+
// Initialize all tools
|
|
131
|
+
initializeMCPTools(sessionId, client, context);
|
|
132
|
+
// Return session info
|
|
133
|
+
return {
|
|
134
|
+
sessionId,
|
|
135
|
+
client,
|
|
136
|
+
context,
|
|
137
|
+
toolCount: Object.keys(client.getTools()).length,
|
|
138
|
+
};
|
|
139
|
+
},
|
|
140
|
+
/**
|
|
141
|
+
* Clean up a session
|
|
142
|
+
*/
|
|
143
|
+
cleanupSession: async (sessionId) => {
|
|
144
|
+
return removeMCPManager(sessionId);
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Default export for convenience
|
|
149
|
+
*/
|
|
150
|
+
export default {
|
|
151
|
+
config: mcpConfig,
|
|
152
|
+
utils: MCPUtils,
|
|
153
|
+
createServer: createMCPServer,
|
|
154
|
+
getManager: getMCPManager,
|
|
155
|
+
removeManager: removeMCPManager,
|
|
156
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NeuroLink MCP Tool Initialization
|
|
3
|
+
* Following Lighthouse's pattern for registering MCP server tools with the client
|
|
4
|
+
*/
|
|
5
|
+
import type { NeuroLinkMCPClient } from "./client.js";
|
|
6
|
+
import type { NeuroLinkExecutionContext } from "./factory.js";
|
|
7
|
+
/**
|
|
8
|
+
* Initialize and register tools from MCP Servers with the MCP client
|
|
9
|
+
* Following Lighthouse's pattern for tool registration
|
|
10
|
+
*/
|
|
11
|
+
export declare const initializeMCPTools: (sessionId: string, client: NeuroLinkMCPClient, context: NeuroLinkExecutionContext) => Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Get all available tools across all servers
|
|
14
|
+
* Useful for documentation and discovery
|
|
15
|
+
*/
|
|
16
|
+
export declare function getAllAvailableTools(): Promise<Array<{
|
|
17
|
+
serverId: string;
|
|
18
|
+
serverTitle: string;
|
|
19
|
+
toolName: string;
|
|
20
|
+
namespacedName: string;
|
|
21
|
+
description: string;
|
|
22
|
+
isImplemented: boolean;
|
|
23
|
+
}>>;
|
|
24
|
+
/**
|
|
25
|
+
* Initialize tools for a specific server only
|
|
26
|
+
* Useful for selective tool registration
|
|
27
|
+
*/
|
|
28
|
+
export declare function initializeServerTools(serverId: string, client: NeuroLinkMCPClient, context: NeuroLinkExecutionContext): Promise<number>;
|
|
@@ -0,0 +1,210 @@
|
|
|
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 { z } from "zod";
|
|
8
|
+
import { logger } from "../utils/logger.js";
|
|
9
|
+
/**
|
|
10
|
+
* Sanitize tool name for compatibility
|
|
11
|
+
* Following Lighthouse's pattern of ensuring valid tool names
|
|
12
|
+
*/
|
|
13
|
+
const sanitizeToolName = (name) => {
|
|
14
|
+
return name.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Check if a schema is a Zod schema
|
|
18
|
+
*/
|
|
19
|
+
const isZodSchema = (schema) => {
|
|
20
|
+
if (typeof schema !== "object" || schema === null) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return "_def" in schema || "parse" in schema;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Initialize and register tools from MCP Servers with the MCP client
|
|
27
|
+
* Following Lighthouse's pattern for tool registration
|
|
28
|
+
*/
|
|
29
|
+
export const initializeMCPTools = async (sessionId, client, context) => {
|
|
30
|
+
try {
|
|
31
|
+
logger.info(`[MCP Tools] Initializing tools for session: ${sessionId}`);
|
|
32
|
+
// Get all registered servers
|
|
33
|
+
const servers = await mcpConfig.getServers();
|
|
34
|
+
if (!servers || servers.length === 0) {
|
|
35
|
+
logger.warn("[MCP Tools] No MCP servers found to register tools from");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
let totalToolsRegistered = 0;
|
|
39
|
+
// Process each server
|
|
40
|
+
servers.forEach((server) => {
|
|
41
|
+
if (!server || !server.id || !server.tools) {
|
|
42
|
+
logger.warn(`[MCP Tools] Skipping invalid server configuration: ${JSON.stringify(server)}`);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const serverId = server.id;
|
|
46
|
+
logger.info(`[MCP Tools] Registering tools from server: ${serverId}`);
|
|
47
|
+
// Process each tool in the server
|
|
48
|
+
Object.entries(server.tools).forEach(([originalToolName, tool]) => {
|
|
49
|
+
if (!tool || typeof tool.execute !== "function") {
|
|
50
|
+
logger.warn(`[MCP Tools] Skipping invalid tool definition for ${originalToolName} in server ${serverId}`);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
// Create namespaced tool name (serverId_toolName)
|
|
54
|
+
let finalToolName = originalToolName;
|
|
55
|
+
const prefix = `${serverId}_`;
|
|
56
|
+
const maxToolNameLength = 64 - prefix.length;
|
|
57
|
+
// Truncate if necessary
|
|
58
|
+
if (finalToolName.length > maxToolNameLength) {
|
|
59
|
+
finalToolName = finalToolName.substring(0, maxToolNameLength);
|
|
60
|
+
logger.info(`[MCP Tools] Truncated tool name: ${originalToolName} -> ${finalToolName}`);
|
|
61
|
+
}
|
|
62
|
+
// Sanitize and combine
|
|
63
|
+
const namespacedToolName = sanitizeToolName(`${prefix}${finalToolName}`);
|
|
64
|
+
// Validate final length
|
|
65
|
+
if (namespacedToolName.length > 64) {
|
|
66
|
+
logger.warn(`[MCP Tools] Tool name too long after sanitization: ${namespacedToolName}. Skipping.`);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// Prepare description
|
|
70
|
+
const description = tool.description ||
|
|
71
|
+
`Tool ${originalToolName} from server ${serverId}`;
|
|
72
|
+
// Convert schema if needed
|
|
73
|
+
let schemaForClient = undefined;
|
|
74
|
+
if (tool.inputSchema) {
|
|
75
|
+
if (isZodSchema(tool.inputSchema)) {
|
|
76
|
+
try {
|
|
77
|
+
const jsonSchemaOutput = zodToJsonSchema(tool.inputSchema);
|
|
78
|
+
if (typeof jsonSchemaOutput === "object" &&
|
|
79
|
+
jsonSchemaOutput !== null &&
|
|
80
|
+
"type" in jsonSchemaOutput &&
|
|
81
|
+
jsonSchemaOutput.type === "object") {
|
|
82
|
+
schemaForClient = jsonSchemaOutput;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
logger.warn(`[MCP Tools] Converted schema for ${originalToolName} is not a root object type`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (schemaError) {
|
|
89
|
+
logger.error(`[MCP Tools] Error converting Zod schema for tool ${originalToolName}: ${schemaError}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else if (typeof tool.inputSchema === "object" &&
|
|
93
|
+
tool.inputSchema !== null) {
|
|
94
|
+
if (tool.inputSchema.type === "object") {
|
|
95
|
+
schemaForClient = tool.inputSchema;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
logger.warn(`[MCP Tools] Input schema for ${originalToolName} is not type 'object'`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
// Register tool with client
|
|
104
|
+
client.registerTool(namespacedToolName, async (_name, input) => {
|
|
105
|
+
// Execute the tool with full context
|
|
106
|
+
const result = await tool.execute(input, context);
|
|
107
|
+
// Convert to Lighthouse-style response
|
|
108
|
+
if (result.success) {
|
|
109
|
+
return {
|
|
110
|
+
content: [{ text: JSON.stringify(result.data ?? {}) }],
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
return {
|
|
115
|
+
content: [
|
|
116
|
+
{ text: `Error: ${result.error || "Unknown error"}` },
|
|
117
|
+
],
|
|
118
|
+
isError: true,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}, description, schemaForClient);
|
|
122
|
+
logger.debug(`[MCP Tools] Registered tool: ${namespacedToolName}`, {
|
|
123
|
+
serverId,
|
|
124
|
+
originalToolName,
|
|
125
|
+
});
|
|
126
|
+
totalToolsRegistered++;
|
|
127
|
+
}
|
|
128
|
+
catch (registrationError) {
|
|
129
|
+
logger.error(`[MCP Tools] Failed to register tool ${originalToolName} from server ${serverId}: ${registrationError}`);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
logger.info(`[MCP Tools] Successfully registered ${totalToolsRegistered} tools for session: ${sessionId}`);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
logger.error(`[MCP Tools] Error during tool initialization for session ${sessionId}: ${error}`);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Get all available tools across all servers
|
|
141
|
+
* Useful for documentation and discovery
|
|
142
|
+
*/
|
|
143
|
+
export async function getAllAvailableTools() {
|
|
144
|
+
const tools = [];
|
|
145
|
+
const servers = await mcpConfig.getServers();
|
|
146
|
+
servers.forEach((server) => {
|
|
147
|
+
Object.entries(server.tools).forEach(([toolName, tool]) => {
|
|
148
|
+
const prefix = `${server.id}_`;
|
|
149
|
+
const finalToolName = toolName.length > 64 - prefix.length
|
|
150
|
+
? toolName.substring(0, 64 - prefix.length)
|
|
151
|
+
: toolName;
|
|
152
|
+
const namespacedName = sanitizeToolName(`${prefix}${finalToolName}`);
|
|
153
|
+
tools.push({
|
|
154
|
+
serverId: server.id,
|
|
155
|
+
serverTitle: server.title,
|
|
156
|
+
toolName,
|
|
157
|
+
namespacedName,
|
|
158
|
+
description: tool.description || "",
|
|
159
|
+
isImplemented: tool.isImplemented !== false,
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
return tools;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Initialize tools for a specific server only
|
|
167
|
+
* Useful for selective tool registration
|
|
168
|
+
*/
|
|
169
|
+
export async function initializeServerTools(serverId, client, context) {
|
|
170
|
+
const servers = await mcpConfig.getServers();
|
|
171
|
+
const server = servers.find((s) => s.id === serverId);
|
|
172
|
+
if (!server) {
|
|
173
|
+
logger.warn(`[MCP Tools] Server not found: ${serverId}`);
|
|
174
|
+
return 0;
|
|
175
|
+
}
|
|
176
|
+
let toolsRegistered = 0;
|
|
177
|
+
Object.entries(server.tools).forEach(([toolName, tool]) => {
|
|
178
|
+
if (!tool || typeof tool.execute !== "function") {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const prefix = `${serverId}_`;
|
|
182
|
+
const finalToolName = toolName.length > 64 - prefix.length
|
|
183
|
+
? toolName.substring(0, 64 - prefix.length)
|
|
184
|
+
: toolName;
|
|
185
|
+
const namespacedToolName = sanitizeToolName(`${prefix}${finalToolName}`);
|
|
186
|
+
if (namespacedToolName.length > 64) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
try {
|
|
190
|
+
client.registerTool(namespacedToolName, async (_name, input) => {
|
|
191
|
+
const result = await tool.execute(input, context);
|
|
192
|
+
if (result.success) {
|
|
193
|
+
return { content: [{ text: JSON.stringify(result.data ?? {}) }] };
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
return {
|
|
197
|
+
content: [{ text: `Error: ${result.error || "Unknown error"}` }],
|
|
198
|
+
isError: true,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}, tool.description || `Tool ${toolName} from server ${serverId}`, tool.inputSchema);
|
|
202
|
+
toolsRegistered++;
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
logger.error(`[MCP Tools] Failed to register tool ${toolName}: ${error}`);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
logger.info(`[MCP Tools] Registered ${toolsRegistered} tools from server ${serverId}`);
|
|
209
|
+
return toolsRegistered;
|
|
210
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
/**
|
|
7
|
+
* Initialize NeuroLink MCP system by registering built-in servers
|
|
8
|
+
*/
|
|
9
|
+
export declare function initializeNeuroLinkMCP(): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Get initialization status
|
|
12
|
+
*/
|
|
13
|
+
export declare function isNeuroLinkMCPInitialized(): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Reset initialization status (for testing)
|
|
16
|
+
*/
|
|
17
|
+
export declare function resetInitialization(): void;
|
|
@@ -0,0 +1,51 @@
|
|
|
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 { defaultToolRegistry } from "./registry.js";
|
|
7
|
+
import { mcpLogger } from "./logging.js";
|
|
8
|
+
let isInitialized = false;
|
|
9
|
+
/**
|
|
10
|
+
* Initialize NeuroLink MCP system by registering built-in servers
|
|
11
|
+
*/
|
|
12
|
+
export async function initializeNeuroLinkMCP() {
|
|
13
|
+
if (isInitialized) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
mcpLogger.debug("Initializing built-in MCP servers...");
|
|
17
|
+
try {
|
|
18
|
+
// Import utility server dynamically to avoid circular dependencies
|
|
19
|
+
// Note: AI core server temporarily disabled due to circular dependency issues
|
|
20
|
+
const { utilityServer } = await import("./servers/utilities/utility-server.js");
|
|
21
|
+
// Register built-in NeuroLink servers with default registry
|
|
22
|
+
await defaultToolRegistry.registerServer(utilityServer);
|
|
23
|
+
mcpLogger.debug("Registered neurolink-utility server with built-in tools");
|
|
24
|
+
// TODO: Re-enable AI core server once circular dependencies are resolved
|
|
25
|
+
// const { aiCoreServer } = await import('./servers/ai-providers/ai-core-server.js');
|
|
26
|
+
// await defaultToolRegistry.registerServer(aiCoreServer);
|
|
27
|
+
// mcpLogger.debug('Registered neurolink-ai-core server with AI tools');
|
|
28
|
+
const stats = defaultToolRegistry.getStats();
|
|
29
|
+
mcpLogger.info(`Initialization complete: ${stats.totalServers} servers, ${stats.totalTools} tools available`);
|
|
30
|
+
isInitialized = true;
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
mcpLogger.error("Failed to initialize built-in servers:", error instanceof Error ? error.message : String(error));
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get initialization status
|
|
39
|
+
*/
|
|
40
|
+
export function isNeuroLinkMCPInitialized() {
|
|
41
|
+
return isInitialized;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Reset initialization status (for testing)
|
|
45
|
+
*/
|
|
46
|
+
export function resetInitialization() {
|
|
47
|
+
isInitialized = false;
|
|
48
|
+
defaultToolRegistry.clear();
|
|
49
|
+
}
|
|
50
|
+
// Note: Auto-initialization removed to prevent circular dependencies
|
|
51
|
+
// Call initializeNeuroLinkMCP() explicitly where needed
|