@juspay/neurolink 1.6.0 → 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 +193 -7
- package/README.md +100 -17
- 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 +6 -6
- package/dist/cli/commands/config.js +326 -273
- package/dist/cli/commands/mcp.d.ts +2 -1
- package/dist/cli/commands/mcp.js +874 -146
- package/dist/cli/commands/ollama.d.ts +1 -1
- package/dist/cli/commands/ollama.js +153 -143
- package/dist/cli/index.js +589 -323
- 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 +176 -61
- package/dist/core/types.d.ts +4 -2
- package/dist/core/types.js +4 -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 +176 -61
- package/dist/lib/core/types.d.ts +4 -2
- package/dist/lib/core/types.js +4 -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 +204 -65
- package/dist/lib/mcp/servers/ai-providers/ai-core-server.js +142 -102
- 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 +197 -142
- 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 +304 -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 +3 -3
- package/dist/lib/providers/huggingFace.js +70 -63
- package/dist/lib/providers/index.d.ts +11 -11
- package/dist/lib/providers/index.js +18 -18
- 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 +3 -3
- package/dist/lib/providers/mistralAI.js +42 -36
- package/dist/lib/providers/ollama.d.ts +4 -4
- package/dist/lib/providers/ollama.js +113 -98
- 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 +53 -31
- 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 +204 -65
- package/dist/mcp/servers/ai-providers/ai-core-server.js +142 -102
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +6 -6
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.js +197 -142
- 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 +304 -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 +3 -3
- package/dist/providers/huggingFace.js +70 -63
- package/dist/providers/index.d.ts +11 -11
- package/dist/providers/index.js +18 -18
- package/dist/providers/mcp-provider.d.ts +62 -0
- package/dist/providers/mcp-provider.js +183 -0
- package/dist/providers/mistralAI.d.ts +3 -3
- package/dist/providers/mistralAI.js +42 -36
- package/dist/providers/ollama.d.ts +4 -4
- package/dist/providers/ollama.js +113 -98
- 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 +53 -31
- package/package.json +175 -161
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NeuroLink MCP Client
|
|
3
|
+
* Following Lighthouse's pattern for MCP tool registration and execution
|
|
4
|
+
*/
|
|
5
|
+
import { EventEmitter } from "events";
|
|
6
|
+
import type { ToolResult, NeuroLinkExecutionContext } from "./factory.js";
|
|
7
|
+
/**
|
|
8
|
+
* MCP Client Configuration
|
|
9
|
+
*/
|
|
10
|
+
export interface MCPClientConfig {
|
|
11
|
+
sessionId: string;
|
|
12
|
+
userId?: string;
|
|
13
|
+
aiProvider?: string;
|
|
14
|
+
modelId?: string;
|
|
15
|
+
logLevel?: "debug" | "info" | "warn" | "error";
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* NeuroLink MCP Client
|
|
19
|
+
* Manages tool registration and execution following Lighthouse patterns
|
|
20
|
+
*/
|
|
21
|
+
export declare class NeuroLinkMCPClient extends EventEmitter {
|
|
22
|
+
private tools;
|
|
23
|
+
private config;
|
|
24
|
+
private executionCount;
|
|
25
|
+
private isConnected;
|
|
26
|
+
constructor(config: MCPClientConfig);
|
|
27
|
+
/**
|
|
28
|
+
* Register a tool with the MCP client
|
|
29
|
+
* Following Lighthouse's pattern of namespacing tools with server ID
|
|
30
|
+
*/
|
|
31
|
+
registerTool(toolName: string, execute: (name: string, params: Record<string, unknown>) => Promise<any>, description?: string, inputSchema?: unknown): void;
|
|
32
|
+
/**
|
|
33
|
+
* Get all registered tools
|
|
34
|
+
*/
|
|
35
|
+
getTools(): Record<string, {
|
|
36
|
+
description?: string;
|
|
37
|
+
inputSchema?: unknown;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* Execute a tool by name
|
|
41
|
+
*/
|
|
42
|
+
executeTool(toolName: string, params: unknown, context?: Partial<NeuroLinkExecutionContext>): Promise<ToolResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Check if connected to MCP
|
|
45
|
+
*/
|
|
46
|
+
isConnectedToMCP(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Disconnect from MCP
|
|
49
|
+
*/
|
|
50
|
+
disconnect(): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Get client statistics
|
|
53
|
+
*/
|
|
54
|
+
getStats(): {
|
|
55
|
+
sessionId: string;
|
|
56
|
+
toolCount: number;
|
|
57
|
+
executionCount: number;
|
|
58
|
+
isConnected: boolean;
|
|
59
|
+
uptime: number;
|
|
60
|
+
};
|
|
61
|
+
private startTime;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a new MCP client instance
|
|
65
|
+
*/
|
|
66
|
+
export declare function createMCPClient(config: MCPClientConfig): NeuroLinkMCPClient;
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NeuroLink MCP Client
|
|
3
|
+
* Following Lighthouse's pattern for MCP tool registration and execution
|
|
4
|
+
*/
|
|
5
|
+
import { EventEmitter } from "events";
|
|
6
|
+
import { logger } from "../utils/logger.js";
|
|
7
|
+
/**
|
|
8
|
+
* NeuroLink MCP Client
|
|
9
|
+
* Manages tool registration and execution following Lighthouse patterns
|
|
10
|
+
*/
|
|
11
|
+
export class NeuroLinkMCPClient extends EventEmitter {
|
|
12
|
+
tools = new Map();
|
|
13
|
+
config;
|
|
14
|
+
executionCount = 0;
|
|
15
|
+
isConnected = false;
|
|
16
|
+
constructor(config) {
|
|
17
|
+
super();
|
|
18
|
+
this.config = config;
|
|
19
|
+
this.isConnected = true;
|
|
20
|
+
logger.info(`[MCP Client] Initialized for session ${config.sessionId}`, {
|
|
21
|
+
userId: config.userId,
|
|
22
|
+
aiProvider: config.aiProvider,
|
|
23
|
+
modelId: config.modelId,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Register a tool with the MCP client
|
|
28
|
+
* Following Lighthouse's pattern of namespacing tools with server ID
|
|
29
|
+
*/
|
|
30
|
+
registerTool(toolName, execute, description, inputSchema) {
|
|
31
|
+
// Parse server ID from tool name (format: serverId_toolName)
|
|
32
|
+
const parts = toolName.split("_");
|
|
33
|
+
const serverId = parts[0];
|
|
34
|
+
const originalName = parts.slice(1).join("_");
|
|
35
|
+
// Create registered tool
|
|
36
|
+
const registeredTool = {
|
|
37
|
+
name: toolName,
|
|
38
|
+
originalName,
|
|
39
|
+
serverId,
|
|
40
|
+
execute: async (params, context) => {
|
|
41
|
+
try {
|
|
42
|
+
// Call the execute function with Lighthouse-style parameters
|
|
43
|
+
const result = await execute(toolName, params);
|
|
44
|
+
// Handle different response formats
|
|
45
|
+
if (result && typeof result === "object") {
|
|
46
|
+
// If it's already in NeuroLink format
|
|
47
|
+
if ("success" in result &&
|
|
48
|
+
("data" in result || "error" in result)) {
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
// If it's in Lighthouse format with content array
|
|
52
|
+
if (result.content &&
|
|
53
|
+
Array.isArray(result.content) &&
|
|
54
|
+
result.content[0]?.text) {
|
|
55
|
+
try {
|
|
56
|
+
const data = JSON.parse(result.content[0].text);
|
|
57
|
+
return {
|
|
58
|
+
success: !result.isError,
|
|
59
|
+
data,
|
|
60
|
+
metadata: {
|
|
61
|
+
toolName,
|
|
62
|
+
serverId,
|
|
63
|
+
sessionId: context.sessionId,
|
|
64
|
+
timestamp: Date.now(),
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
catch (parseError) {
|
|
69
|
+
// If JSON parsing fails, return the text as-is
|
|
70
|
+
return {
|
|
71
|
+
success: !result.isError,
|
|
72
|
+
data: { text: result.content[0].text },
|
|
73
|
+
metadata: {
|
|
74
|
+
toolName,
|
|
75
|
+
serverId,
|
|
76
|
+
sessionId: context.sessionId,
|
|
77
|
+
timestamp: Date.now(),
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// If it has a direct text property
|
|
83
|
+
if (result.text) {
|
|
84
|
+
return {
|
|
85
|
+
success: true,
|
|
86
|
+
data: { text: result.text },
|
|
87
|
+
metadata: {
|
|
88
|
+
toolName,
|
|
89
|
+
serverId,
|
|
90
|
+
sessionId: context.sessionId,
|
|
91
|
+
timestamp: Date.now(),
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
success: false,
|
|
98
|
+
error: "Invalid tool response format",
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
logger.error(`[MCP Client] Tool execution failed: ${toolName}`, error);
|
|
103
|
+
return {
|
|
104
|
+
success: false,
|
|
105
|
+
error: error instanceof Error ? error.message : String(error),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
description,
|
|
110
|
+
inputSchema,
|
|
111
|
+
};
|
|
112
|
+
// Register the tool
|
|
113
|
+
this.tools.set(toolName, registeredTool);
|
|
114
|
+
logger.debug(`[MCP Client] Registered tool: ${toolName}`, {
|
|
115
|
+
serverId,
|
|
116
|
+
originalName,
|
|
117
|
+
description,
|
|
118
|
+
});
|
|
119
|
+
// Emit tool registration event
|
|
120
|
+
this.emit("tool:registered", {
|
|
121
|
+
toolName,
|
|
122
|
+
serverId,
|
|
123
|
+
originalName,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get all registered tools
|
|
128
|
+
*/
|
|
129
|
+
getTools() {
|
|
130
|
+
const tools = {};
|
|
131
|
+
for (const [name, tool] of this.tools) {
|
|
132
|
+
tools[name] = {
|
|
133
|
+
description: tool.description,
|
|
134
|
+
inputSchema: tool.inputSchema,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
return tools;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Execute a tool by name
|
|
141
|
+
*/
|
|
142
|
+
async executeTool(toolName, params, context) {
|
|
143
|
+
const tool = this.tools.get(toolName);
|
|
144
|
+
if (!tool) {
|
|
145
|
+
return {
|
|
146
|
+
success: false,
|
|
147
|
+
error: `Tool not found: ${toolName}`,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
// Create full context
|
|
151
|
+
const fullContext = {
|
|
152
|
+
sessionId: this.config.sessionId,
|
|
153
|
+
userId: this.config.userId,
|
|
154
|
+
aiProvider: this.config.aiProvider,
|
|
155
|
+
modelId: this.config.modelId,
|
|
156
|
+
timestamp: Date.now(),
|
|
157
|
+
...context,
|
|
158
|
+
};
|
|
159
|
+
// Track execution
|
|
160
|
+
this.executionCount++;
|
|
161
|
+
const executionId = `exec-${this.executionCount}`;
|
|
162
|
+
// Emit execution start event
|
|
163
|
+
this.emit("tool:execute:start", {
|
|
164
|
+
executionId,
|
|
165
|
+
toolName,
|
|
166
|
+
serverId: tool.serverId,
|
|
167
|
+
params,
|
|
168
|
+
});
|
|
169
|
+
const startTime = Date.now();
|
|
170
|
+
try {
|
|
171
|
+
// Execute the tool
|
|
172
|
+
const result = await tool.execute(params, fullContext);
|
|
173
|
+
// Add execution metadata
|
|
174
|
+
result.metadata = {
|
|
175
|
+
...result.metadata,
|
|
176
|
+
executionId,
|
|
177
|
+
executionTime: Date.now() - startTime,
|
|
178
|
+
};
|
|
179
|
+
// Emit execution complete event
|
|
180
|
+
this.emit("tool:execute:complete", {
|
|
181
|
+
executionId,
|
|
182
|
+
toolName,
|
|
183
|
+
serverId: tool.serverId,
|
|
184
|
+
success: result.success,
|
|
185
|
+
executionTime: result.metadata.executionTime,
|
|
186
|
+
});
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
const executionTime = Date.now() - startTime;
|
|
191
|
+
// Emit execution error event
|
|
192
|
+
this.emit("tool:execute:error", {
|
|
193
|
+
executionId,
|
|
194
|
+
toolName,
|
|
195
|
+
serverId: tool.serverId,
|
|
196
|
+
error: error instanceof Error ? error.message : String(error),
|
|
197
|
+
executionTime,
|
|
198
|
+
});
|
|
199
|
+
return {
|
|
200
|
+
success: false,
|
|
201
|
+
error: error instanceof Error ? error.message : String(error),
|
|
202
|
+
metadata: {
|
|
203
|
+
executionId,
|
|
204
|
+
toolName,
|
|
205
|
+
serverId: tool.serverId,
|
|
206
|
+
executionTime,
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Check if connected to MCP
|
|
213
|
+
*/
|
|
214
|
+
isConnectedToMCP() {
|
|
215
|
+
return this.isConnected;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Disconnect from MCP
|
|
219
|
+
*/
|
|
220
|
+
async disconnect() {
|
|
221
|
+
this.isConnected = false;
|
|
222
|
+
this.tools.clear();
|
|
223
|
+
this.removeAllListeners();
|
|
224
|
+
logger.info(`[MCP Client] Disconnected for session ${this.config.sessionId}`);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Get client statistics
|
|
228
|
+
*/
|
|
229
|
+
getStats() {
|
|
230
|
+
return {
|
|
231
|
+
sessionId: this.config.sessionId,
|
|
232
|
+
toolCount: this.tools.size,
|
|
233
|
+
executionCount: this.executionCount,
|
|
234
|
+
isConnected: this.isConnected,
|
|
235
|
+
uptime: Date.now() - (this.startTime || Date.now()),
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
startTime = Date.now();
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Create a new MCP client instance
|
|
242
|
+
*/
|
|
243
|
+
export function createMCPClient(config) {
|
|
244
|
+
return new NeuroLinkMCPClient(config);
|
|
245
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NeuroLink MCP Configuration
|
|
3
|
+
* Central registry for all MCP servers following Lighthouse patterns
|
|
4
|
+
* Handles built-in servers only - auto-discovery handled by unified registry
|
|
5
|
+
*/
|
|
6
|
+
import type { NeuroLinkMCPServer } from "./factory.js";
|
|
7
|
+
/**
|
|
8
|
+
* Built-in MCP servers (kept for backward compatibility)
|
|
9
|
+
* Add new servers here as they are created
|
|
10
|
+
*/
|
|
11
|
+
export declare const allServers: NeuroLinkMCPServer[];
|
|
12
|
+
/**
|
|
13
|
+
* MCP Configuration following Lighthouse patterns
|
|
14
|
+
* Handles built-in servers - auto-discovery is handled by unified registry
|
|
15
|
+
*/
|
|
16
|
+
export declare const mcpConfig: {
|
|
17
|
+
/**
|
|
18
|
+
* Get list of active built-in MCP servers with implemented tools
|
|
19
|
+
*/
|
|
20
|
+
getServers: () => Promise<NeuroLinkMCPServer[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Get all available tools across all servers
|
|
23
|
+
*/
|
|
24
|
+
getAllTools: () => Promise<{
|
|
25
|
+
name: string;
|
|
26
|
+
description: string;
|
|
27
|
+
serverId: string;
|
|
28
|
+
serverTitle: string;
|
|
29
|
+
category?: string;
|
|
30
|
+
}[]>;
|
|
31
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NeuroLink MCP Configuration
|
|
3
|
+
* Central registry for all MCP servers following Lighthouse patterns
|
|
4
|
+
* Handles built-in servers only - auto-discovery handled by unified registry
|
|
5
|
+
*/
|
|
6
|
+
import { aiCoreServer } from "./servers/ai-providers/ai-core-server.js";
|
|
7
|
+
import { utilityServer } from "./servers/utilities/utility-server.js";
|
|
8
|
+
import { logger } from "../utils/logger.js";
|
|
9
|
+
/**
|
|
10
|
+
* Built-in MCP servers (kept for backward compatibility)
|
|
11
|
+
* Add new servers here as they are created
|
|
12
|
+
*/
|
|
13
|
+
export const allServers = [
|
|
14
|
+
aiCoreServer,
|
|
15
|
+
utilityServer,
|
|
16
|
+
// Add more servers as they are created
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* MCP Configuration following Lighthouse patterns
|
|
20
|
+
* Handles built-in servers - auto-discovery is handled by unified registry
|
|
21
|
+
*/
|
|
22
|
+
export const mcpConfig = {
|
|
23
|
+
/**
|
|
24
|
+
* Get list of active built-in MCP servers with implemented tools
|
|
25
|
+
*/
|
|
26
|
+
getServers: async () => {
|
|
27
|
+
const activeServers = [];
|
|
28
|
+
// Include built-in servers with filtering
|
|
29
|
+
for (const server of allServers) {
|
|
30
|
+
const implementedTools = {};
|
|
31
|
+
let hasImplementedTools = false;
|
|
32
|
+
for (const toolName in server.tools) {
|
|
33
|
+
const tool = server.tools[toolName];
|
|
34
|
+
// Only include tools that are implemented (default to true if not specified)
|
|
35
|
+
if (tool.isImplemented !== false) {
|
|
36
|
+
implementedTools[toolName] = tool;
|
|
37
|
+
hasImplementedTools = true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Only include servers that have at least one implemented tool
|
|
41
|
+
if (hasImplementedTools) {
|
|
42
|
+
activeServers.push({
|
|
43
|
+
...server,
|
|
44
|
+
tools: implementedTools,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
logger.debug("[MCP Config] Built-in servers:", {
|
|
49
|
+
total: activeServers.length,
|
|
50
|
+
serverIds: activeServers.map((s) => s.id),
|
|
51
|
+
});
|
|
52
|
+
return activeServers;
|
|
53
|
+
},
|
|
54
|
+
/**
|
|
55
|
+
* Get all available tools across all servers
|
|
56
|
+
*/
|
|
57
|
+
getAllTools: async () => {
|
|
58
|
+
const servers = await mcpConfig.getServers();
|
|
59
|
+
const allTools = [];
|
|
60
|
+
for (const server of servers) {
|
|
61
|
+
for (const toolName in server.tools) {
|
|
62
|
+
const tool = server.tools[toolName];
|
|
63
|
+
allTools.push({
|
|
64
|
+
name: toolName,
|
|
65
|
+
description: tool.description,
|
|
66
|
+
serverId: server.id,
|
|
67
|
+
serverTitle: server.title,
|
|
68
|
+
category: tool.category,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return allTools;
|
|
73
|
+
},
|
|
74
|
+
};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Unified context creation and management for all tool executions
|
|
4
4
|
* Ensures rich context flows through tool chain with session tracking
|
|
5
5
|
*/
|
|
6
|
-
import type { NeuroLinkExecutionContext } from
|
|
6
|
+
import type { NeuroLinkExecutionContext } from "./factory.js";
|
|
7
7
|
/**
|
|
8
8
|
* Context creation request interface
|
|
9
9
|
*/
|
|
@@ -16,10 +16,10 @@ export interface ContextRequest {
|
|
|
16
16
|
maxTokens?: number;
|
|
17
17
|
organizationId?: string;
|
|
18
18
|
projectId?: string;
|
|
19
|
-
environmentType?:
|
|
20
|
-
frameworkType?:
|
|
19
|
+
environmentType?: "development" | "staging" | "production";
|
|
20
|
+
frameworkType?: "react" | "vue" | "svelte" | "next" | "nuxt" | "sveltekit";
|
|
21
21
|
permissions?: string[];
|
|
22
|
-
securityLevel?:
|
|
22
|
+
securityLevel?: "public" | "private" | "organization";
|
|
23
23
|
[key: string]: any;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
@@ -32,7 +32,7 @@ export class ContextManager {
|
|
|
32
32
|
// Business Context (new for MCP)
|
|
33
33
|
organizationId: request.organizationId,
|
|
34
34
|
projectId: request.projectId,
|
|
35
|
-
environmentType: request.environmentType ||
|
|
35
|
+
environmentType: request.environmentType || "development",
|
|
36
36
|
// Framework Context (new for MCP)
|
|
37
37
|
frameworkType: request.frameworkType,
|
|
38
38
|
// Tool Execution Context (initialized empty)
|
|
@@ -40,9 +40,9 @@ export class ContextManager {
|
|
|
40
40
|
parentToolId: undefined,
|
|
41
41
|
// Security & Permissions
|
|
42
42
|
permissions: request.permissions || [],
|
|
43
|
-
securityLevel: request.securityLevel ||
|
|
43
|
+
securityLevel: request.securityLevel || "private",
|
|
44
44
|
// Copy any additional custom fields
|
|
45
|
-
...this.extractCustomFields(request)
|
|
45
|
+
...this.extractCustomFields(request),
|
|
46
46
|
};
|
|
47
47
|
// Store context for session management
|
|
48
48
|
this.activeContexts.set(sessionId, context);
|
|
@@ -97,7 +97,7 @@ export class ContextManager {
|
|
|
97
97
|
// Set parent tool reference
|
|
98
98
|
parentToolId: parentContext.toolChain?.[parentContext.toolChain.length - 1],
|
|
99
99
|
// Reset tool chain for child (will be populated as child executes tools)
|
|
100
|
-
toolChain: []
|
|
100
|
+
toolChain: [],
|
|
101
101
|
};
|
|
102
102
|
// Store child context
|
|
103
103
|
this.activeContexts.set(childContext.sessionId, childContext);
|
|
@@ -159,9 +159,7 @@ export class ContextManager {
|
|
|
159
159
|
return {
|
|
160
160
|
activeContexts: contexts.length,
|
|
161
161
|
totalSessionsCreated: this.sessionCounter,
|
|
162
|
-
averageToolChainLength: contexts.length > 0
|
|
163
|
-
? totalToolChainLength / contexts.length
|
|
164
|
-
: 0
|
|
162
|
+
averageToolChainLength: contexts.length > 0 ? totalToolChainLength / contexts.length : 0,
|
|
165
163
|
};
|
|
166
164
|
}
|
|
167
165
|
/**
|
|
@@ -183,9 +181,18 @@ export class ContextManager {
|
|
|
183
181
|
*/
|
|
184
182
|
extractCustomFields(request) {
|
|
185
183
|
const knownFields = new Set([
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
184
|
+
"sessionId",
|
|
185
|
+
"userId",
|
|
186
|
+
"aiProvider",
|
|
187
|
+
"modelId",
|
|
188
|
+
"temperature",
|
|
189
|
+
"maxTokens",
|
|
190
|
+
"organizationId",
|
|
191
|
+
"projectId",
|
|
192
|
+
"environmentType",
|
|
193
|
+
"frameworkType",
|
|
194
|
+
"permissions",
|
|
195
|
+
"securityLevel",
|
|
189
196
|
]);
|
|
190
197
|
const customFields = {};
|
|
191
198
|
for (const [key, value] of Object.entries(request)) {
|
|
@@ -234,23 +241,23 @@ export class ContextValidator {
|
|
|
234
241
|
const warnings = [];
|
|
235
242
|
// Required field validation
|
|
236
243
|
if (!context.sessionId) {
|
|
237
|
-
errors.push(
|
|
244
|
+
errors.push("sessionId is required");
|
|
238
245
|
}
|
|
239
246
|
// Optional field validation with warnings
|
|
240
247
|
if (!context.environmentType) {
|
|
241
|
-
warnings.push(
|
|
248
|
+
warnings.push("environmentType not specified, defaulting to development");
|
|
242
249
|
}
|
|
243
250
|
if (!context.securityLevel) {
|
|
244
|
-
warnings.push(
|
|
251
|
+
warnings.push("securityLevel not specified, defaulting to private");
|
|
245
252
|
}
|
|
246
253
|
// Tool chain validation
|
|
247
254
|
if (context.toolChain && context.toolChain.length > 10) {
|
|
248
|
-
warnings.push(
|
|
255
|
+
warnings.push("Tool chain is getting long (>10 tools), consider breaking into smaller workflows");
|
|
249
256
|
}
|
|
250
257
|
return {
|
|
251
258
|
isValid: errors.length === 0,
|
|
252
259
|
errors,
|
|
253
|
-
warnings
|
|
260
|
+
warnings,
|
|
254
261
|
};
|
|
255
262
|
}
|
|
256
263
|
/**
|
|
@@ -266,8 +273,7 @@ export class ContextValidator {
|
|
|
266
273
|
}
|
|
267
274
|
const contextPermissions = context.permissions || [];
|
|
268
275
|
// Check if context has all required permissions
|
|
269
|
-
return requiredPermissions.every(permission => contextPermissions.includes(permission) ||
|
|
270
|
-
contextPermissions.includes(
|
|
271
|
-
);
|
|
276
|
+
return requiredPermissions.every((permission) => contextPermissions.includes(permission) ||
|
|
277
|
+
contextPermissions.includes("*"));
|
|
272
278
|
}
|
|
273
279
|
}
|
package/dist/mcp/factory.d.ts
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
* Factory-First Architecture: MCP servers create tools for internal orchestration
|
|
4
4
|
* Compatible with Lighthouse MCP patterns for seamless migration
|
|
5
5
|
*/
|
|
6
|
-
import { z } from
|
|
6
|
+
import { z } from "zod";
|
|
7
7
|
/**
|
|
8
8
|
* MCP Server Categories for organization and discovery
|
|
9
9
|
*/
|
|
10
|
-
export type MCPServerCategory =
|
|
10
|
+
export type MCPServerCategory = "ai-providers" | "frameworks" | "development" | "business" | "content" | "data" | "integrations" | "automation" | "analysis" | "custom";
|
|
11
11
|
/**
|
|
12
12
|
* Tool execution context - Rich context passed to every tool execution
|
|
13
|
-
*
|
|
13
|
+
* Following Lighthouse's pattern for rich tool context
|
|
14
14
|
*/
|
|
15
15
|
export interface NeuroLinkExecutionContext {
|
|
16
16
|
sessionId: string;
|
|
@@ -19,14 +19,30 @@ export interface NeuroLinkExecutionContext {
|
|
|
19
19
|
modelId?: string;
|
|
20
20
|
temperature?: number;
|
|
21
21
|
maxTokens?: number;
|
|
22
|
+
appId?: string;
|
|
23
|
+
clientId?: string;
|
|
24
|
+
clientVersion?: string;
|
|
22
25
|
organizationId?: string;
|
|
23
26
|
projectId?: string;
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
environment?: string;
|
|
28
|
+
environmentType?: "development" | "staging" | "production";
|
|
29
|
+
platform?: string;
|
|
30
|
+
device?: string;
|
|
31
|
+
browser?: string;
|
|
32
|
+
userAgent?: string;
|
|
33
|
+
frameworkType?: "react" | "vue" | "svelte" | "next" | "nuxt" | "sveltekit";
|
|
26
34
|
toolChain?: string[];
|
|
27
35
|
parentToolId?: string;
|
|
36
|
+
locale?: string;
|
|
37
|
+
timezone?: string;
|
|
38
|
+
ipAddress?: string;
|
|
39
|
+
requestId?: string;
|
|
40
|
+
timestamp?: number;
|
|
28
41
|
permissions?: string[];
|
|
29
|
-
|
|
42
|
+
features?: string[];
|
|
43
|
+
enableDemoMode?: boolean;
|
|
44
|
+
securityLevel?: "public" | "private" | "organization";
|
|
45
|
+
metadata?: Record<string, any>;
|
|
30
46
|
[key: string]: any;
|
|
31
47
|
}
|
|
32
48
|
/**
|
|
@@ -50,6 +66,8 @@ export interface ToolResult {
|
|
|
50
66
|
sessionId?: string;
|
|
51
67
|
timestamp?: number;
|
|
52
68
|
executionTime?: number;
|
|
69
|
+
executionId?: string;
|
|
70
|
+
[key: string]: any;
|
|
53
71
|
};
|
|
54
72
|
}
|
|
55
73
|
/**
|
|
@@ -68,8 +86,7 @@ export interface NeuroLinkMCPTool {
|
|
|
68
86
|
metadata?: Record<string, any>;
|
|
69
87
|
}
|
|
70
88
|
/**
|
|
71
|
-
* MCP Server Interface -
|
|
72
|
-
* Minimal required fields for easy adoption
|
|
89
|
+
* MCP Server Interface - Lighthouse compatible
|
|
73
90
|
*/
|
|
74
91
|
export interface NeuroLinkMCPServer {
|
|
75
92
|
id: string;
|
|
@@ -77,9 +94,9 @@ export interface NeuroLinkMCPServer {
|
|
|
77
94
|
description?: string;
|
|
78
95
|
version?: string;
|
|
79
96
|
category?: MCPServerCategory;
|
|
80
|
-
visibility?:
|
|
97
|
+
visibility?: "public" | "private" | "organization";
|
|
81
98
|
tools: Record<string, NeuroLinkMCPTool>;
|
|
82
|
-
registerTool
|
|
99
|
+
registerTool(tool: NeuroLinkMCPTool): NeuroLinkMCPServer;
|
|
83
100
|
metadata?: Record<string, any>;
|
|
84
101
|
dependencies?: string[];
|
|
85
102
|
capabilities?: string[];
|
|
@@ -93,7 +110,7 @@ export interface MCPServerConfig {
|
|
|
93
110
|
description?: string;
|
|
94
111
|
version?: string;
|
|
95
112
|
category?: MCPServerCategory;
|
|
96
|
-
visibility?:
|
|
113
|
+
visibility?: "public" | "private" | "organization";
|
|
97
114
|
metadata?: Record<string, any>;
|
|
98
115
|
dependencies?: string[];
|
|
99
116
|
capabilities?: string[];
|