@juspay/neurolink 1.2.3 → 1.3.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 +108 -0
- package/README.md +213 -1138
- package/dist/cli/commands/config.d.ts +373 -0
- package/dist/cli/commands/config.js +532 -0
- package/dist/cli/commands/mcp.d.ts +7 -0
- package/dist/cli/commands/mcp.js +434 -0
- package/dist/cli/index.d.ts +9 -0
- package/dist/cli/index.js +451 -169
- package/dist/core/factory.js +10 -2
- package/dist/core/types.d.ts +3 -1
- package/dist/core/types.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mcp/context-manager.d.ts +164 -0
- package/dist/mcp/context-manager.js +273 -0
- package/dist/mcp/factory.d.ts +144 -0
- package/dist/mcp/factory.js +141 -0
- package/dist/mcp/orchestrator.d.ts +170 -0
- package/dist/mcp/orchestrator.js +372 -0
- package/dist/mcp/registry.d.ts +188 -0
- package/dist/mcp/registry.js +373 -0
- package/dist/mcp/servers/ai-providers/ai-core-server.d.ts +10 -0
- package/dist/mcp/servers/ai-providers/ai-core-server.js +280 -0
- package/dist/neurolink.d.ts +2 -2
- package/dist/neurolink.js +1 -1
- package/dist/providers/anthropic.d.ts +34 -0
- package/dist/providers/anthropic.js +307 -0
- package/dist/providers/azureOpenAI.d.ts +37 -0
- package/dist/providers/azureOpenAI.js +338 -0
- package/dist/providers/index.d.ts +4 -0
- package/dist/providers/index.js +5 -1
- package/dist/utils/providerUtils.js +8 -2
- package/package.json +163 -97
package/dist/core/factory.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GoogleVertexAI, AmazonBedrock, OpenAI } from '../providers/index.js';
|
|
1
|
+
import { GoogleVertexAI, AmazonBedrock, OpenAI, AnthropicProvider, AzureOpenAIProvider } from '../providers/index.js';
|
|
2
2
|
import { getBestProvider } from '../utils/providerUtils.js';
|
|
3
3
|
const componentIdentifier = 'aiProviderFactory';
|
|
4
4
|
/**
|
|
@@ -34,8 +34,16 @@ export class AIProviderFactory {
|
|
|
34
34
|
case 'gpt':
|
|
35
35
|
provider = new OpenAI(modelName);
|
|
36
36
|
break;
|
|
37
|
+
case 'anthropic':
|
|
38
|
+
case 'claude':
|
|
39
|
+
provider = new AnthropicProvider();
|
|
40
|
+
break;
|
|
41
|
+
case 'azure':
|
|
42
|
+
case 'azure-openai':
|
|
43
|
+
provider = new AzureOpenAIProvider();
|
|
44
|
+
break;
|
|
37
45
|
default:
|
|
38
|
-
throw new Error(`Unknown provider: ${providerName}. Supported providers: vertex, bedrock, openai`);
|
|
46
|
+
throw new Error(`Unknown provider: ${providerName}. Supported providers: vertex, bedrock, openai, anthropic, azure`);
|
|
39
47
|
}
|
|
40
48
|
console.log(`[${functionTag}] Provider creation succeeded`, {
|
|
41
49
|
providerName,
|
package/dist/core/types.d.ts
CHANGED
|
@@ -6,7 +6,9 @@ import type { StreamTextResult, ToolSet, Schema, GenerateTextResult } from 'ai';
|
|
|
6
6
|
export declare enum AIProviderName {
|
|
7
7
|
BEDROCK = "bedrock",
|
|
8
8
|
OPENAI = "openai",
|
|
9
|
-
VERTEX = "vertex"
|
|
9
|
+
VERTEX = "vertex",
|
|
10
|
+
ANTHROPIC = "anthropic",
|
|
11
|
+
AZURE = "azure"
|
|
10
12
|
}
|
|
11
13
|
/**
|
|
12
14
|
* Supported Models for Amazon Bedrock
|
package/dist/core/types.js
CHANGED
|
@@ -6,6 +6,8 @@ export var AIProviderName;
|
|
|
6
6
|
AIProviderName["BEDROCK"] = "bedrock";
|
|
7
7
|
AIProviderName["OPENAI"] = "openai";
|
|
8
8
|
AIProviderName["VERTEX"] = "vertex";
|
|
9
|
+
AIProviderName["ANTHROPIC"] = "anthropic";
|
|
10
|
+
AIProviderName["AZURE"] = "azure";
|
|
9
11
|
})(AIProviderName || (AIProviderName = {}));
|
|
10
12
|
/**
|
|
11
13
|
* Supported Models for Amazon Bedrock
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { AIProviderFactory } from './core/factory.js';
|
|
|
10
10
|
export { AIProviderFactory };
|
|
11
11
|
export type { AIProvider, AIProviderName, ProviderConfig, StreamingOptions, ProviderAttempt, SupportedModelName } from './core/types.js';
|
|
12
12
|
export { BedrockModels, OpenAIModels, VertexModels, DEFAULT_PROVIDER_CONFIGS } from './core/types.js';
|
|
13
|
-
export { GoogleVertexAI, AmazonBedrock, OpenAI } from './providers/index.js';
|
|
13
|
+
export { GoogleVertexAI, AmazonBedrock, OpenAI, AnthropicProvider, AzureOpenAIProvider } from './providers/index.js';
|
|
14
14
|
export type { ProviderName } from './providers/index.js';
|
|
15
15
|
export { PROVIDERS, AVAILABLE_PROVIDERS } from './providers/index.js';
|
|
16
16
|
export { getBestProvider, getAvailableProviders, isValidProvider } from './utils/providerUtils.js';
|
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@ export { AIProviderFactory };
|
|
|
12
12
|
// Model enums
|
|
13
13
|
export { BedrockModels, OpenAIModels, VertexModels, DEFAULT_PROVIDER_CONFIGS } from './core/types.js';
|
|
14
14
|
// Provider exports
|
|
15
|
-
export { GoogleVertexAI, AmazonBedrock, OpenAI } from './providers/index.js';
|
|
15
|
+
export { GoogleVertexAI, AmazonBedrock, OpenAI, AnthropicProvider, AzureOpenAIProvider } from './providers/index.js';
|
|
16
16
|
export { PROVIDERS, AVAILABLE_PROVIDERS } from './providers/index.js';
|
|
17
17
|
// Utility exports
|
|
18
18
|
export { getBestProvider, getAvailableProviders, isValidProvider } from './utils/providerUtils.js';
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NeuroLink MCP Context Management System
|
|
3
|
+
* Unified context creation and management for all tool executions
|
|
4
|
+
* Ensures rich context flows through tool chain with session tracking
|
|
5
|
+
*/
|
|
6
|
+
import type { NeuroLinkExecutionContext } from './factory.js';
|
|
7
|
+
/**
|
|
8
|
+
* Context creation request interface
|
|
9
|
+
*/
|
|
10
|
+
export interface ContextRequest {
|
|
11
|
+
sessionId?: string;
|
|
12
|
+
userId?: string;
|
|
13
|
+
aiProvider?: string;
|
|
14
|
+
modelId?: string;
|
|
15
|
+
temperature?: number;
|
|
16
|
+
maxTokens?: number;
|
|
17
|
+
organizationId?: string;
|
|
18
|
+
projectId?: string;
|
|
19
|
+
environmentType?: 'development' | 'staging' | 'production';
|
|
20
|
+
frameworkType?: 'react' | 'vue' | 'svelte' | 'next' | 'nuxt' | 'sveltekit';
|
|
21
|
+
permissions?: string[];
|
|
22
|
+
securityLevel?: 'public' | 'private' | 'organization';
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Context manager for creating and managing execution contexts
|
|
27
|
+
* Provides rich context for all tool executions with session tracking
|
|
28
|
+
*/
|
|
29
|
+
export declare class ContextManager {
|
|
30
|
+
private sessionCounter;
|
|
31
|
+
private activeContexts;
|
|
32
|
+
/**
|
|
33
|
+
* Create a new execution context with rich information
|
|
34
|
+
*
|
|
35
|
+
* @param request Context creation request with optional fields
|
|
36
|
+
* @returns Complete execution context ready for tool chain
|
|
37
|
+
*/
|
|
38
|
+
createContext(request?: ContextRequest): NeuroLinkExecutionContext;
|
|
39
|
+
/**
|
|
40
|
+
* Add a tool to the execution chain
|
|
41
|
+
*
|
|
42
|
+
* @param context Execution context to modify
|
|
43
|
+
* @param toolName Name of the tool being executed
|
|
44
|
+
*/
|
|
45
|
+
addToToolChain(context: NeuroLinkExecutionContext, toolName: string): void;
|
|
46
|
+
/**
|
|
47
|
+
* Get the current tool chain for a context
|
|
48
|
+
*
|
|
49
|
+
* @param context Execution context
|
|
50
|
+
* @returns Array of tool names in execution order
|
|
51
|
+
*/
|
|
52
|
+
getToolChain(context: NeuroLinkExecutionContext): string[];
|
|
53
|
+
/**
|
|
54
|
+
* Set parent tool for nested tool execution
|
|
55
|
+
*
|
|
56
|
+
* @param context Execution context to modify
|
|
57
|
+
* @param parentToolId ID of the parent tool
|
|
58
|
+
*/
|
|
59
|
+
setParentTool(context: NeuroLinkExecutionContext, parentToolId: string): void;
|
|
60
|
+
/**
|
|
61
|
+
* Create child context for nested tool execution
|
|
62
|
+
*
|
|
63
|
+
* @param parentContext Parent execution context
|
|
64
|
+
* @param childToolName Name of the child tool
|
|
65
|
+
* @returns New child context with inherited properties
|
|
66
|
+
*/
|
|
67
|
+
createChildContext(parentContext: NeuroLinkExecutionContext, childToolName: string): NeuroLinkExecutionContext;
|
|
68
|
+
/**
|
|
69
|
+
* Get context by session ID
|
|
70
|
+
*
|
|
71
|
+
* @param sessionId Session identifier
|
|
72
|
+
* @returns Execution context or undefined if not found
|
|
73
|
+
*/
|
|
74
|
+
getContext(sessionId: string): NeuroLinkExecutionContext | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Update context with new information
|
|
77
|
+
*
|
|
78
|
+
* @param sessionId Session identifier
|
|
79
|
+
* @param updates Partial context updates
|
|
80
|
+
*/
|
|
81
|
+
updateContext(sessionId: string, updates: Partial<NeuroLinkExecutionContext>): void;
|
|
82
|
+
/**
|
|
83
|
+
* Remove context from active tracking
|
|
84
|
+
*
|
|
85
|
+
* @param sessionId Session identifier
|
|
86
|
+
*/
|
|
87
|
+
removeContext(sessionId: string): void;
|
|
88
|
+
/**
|
|
89
|
+
* Get all active contexts (for debugging/monitoring)
|
|
90
|
+
*
|
|
91
|
+
* @returns Array of all active contexts
|
|
92
|
+
*/
|
|
93
|
+
getActiveContexts(): NeuroLinkExecutionContext[];
|
|
94
|
+
/**
|
|
95
|
+
* Clear all active contexts
|
|
96
|
+
*/
|
|
97
|
+
clearAllContexts(): void;
|
|
98
|
+
/**
|
|
99
|
+
* Get context statistics
|
|
100
|
+
*
|
|
101
|
+
* @returns Context usage statistics
|
|
102
|
+
*/
|
|
103
|
+
getStats(): {
|
|
104
|
+
activeContexts: number;
|
|
105
|
+
totalSessionsCreated: number;
|
|
106
|
+
averageToolChainLength: number;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Generate unique session ID
|
|
110
|
+
*
|
|
111
|
+
* @returns Unique session identifier
|
|
112
|
+
*/
|
|
113
|
+
private generateSessionId;
|
|
114
|
+
/**
|
|
115
|
+
* Extract custom fields from request (excluding known fields)
|
|
116
|
+
*
|
|
117
|
+
* @param request Context creation request
|
|
118
|
+
* @returns Custom fields object
|
|
119
|
+
*/
|
|
120
|
+
private extractCustomFields;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Default context manager instance
|
|
124
|
+
* Can be used across the application for consistent context management
|
|
125
|
+
*/
|
|
126
|
+
export declare const defaultContextManager: ContextManager;
|
|
127
|
+
/**
|
|
128
|
+
* Utility function to create context with defaults
|
|
129
|
+
*
|
|
130
|
+
* @param request Optional context request
|
|
131
|
+
* @returns Execution context with sensible defaults
|
|
132
|
+
*/
|
|
133
|
+
export declare function createExecutionContext(request?: ContextRequest): NeuroLinkExecutionContext;
|
|
134
|
+
/**
|
|
135
|
+
* Utility function to add tool to default context manager
|
|
136
|
+
*
|
|
137
|
+
* @param context Execution context
|
|
138
|
+
* @param toolName Tool name to add
|
|
139
|
+
*/
|
|
140
|
+
export declare function addToolToChain(context: NeuroLinkExecutionContext, toolName: string): void;
|
|
141
|
+
/**
|
|
142
|
+
* Context validation utilities
|
|
143
|
+
*/
|
|
144
|
+
export declare class ContextValidator {
|
|
145
|
+
/**
|
|
146
|
+
* Validate context has required fields for tool execution
|
|
147
|
+
*
|
|
148
|
+
* @param context Execution context to validate
|
|
149
|
+
* @returns Validation result with details
|
|
150
|
+
*/
|
|
151
|
+
static validateContext(context: NeuroLinkExecutionContext): {
|
|
152
|
+
isValid: boolean;
|
|
153
|
+
errors: string[];
|
|
154
|
+
warnings: string[];
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Validate context permissions for tool execution
|
|
158
|
+
*
|
|
159
|
+
* @param context Execution context
|
|
160
|
+
* @param requiredPermissions Permissions required by tool
|
|
161
|
+
* @returns Whether context has required permissions
|
|
162
|
+
*/
|
|
163
|
+
static hasPermissions(context: NeuroLinkExecutionContext, requiredPermissions: string[]): boolean;
|
|
164
|
+
}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NeuroLink MCP Context Management System
|
|
3
|
+
* Unified context creation and management for all tool executions
|
|
4
|
+
* Ensures rich context flows through tool chain with session tracking
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Context manager for creating and managing execution contexts
|
|
8
|
+
* Provides rich context for all tool executions with session tracking
|
|
9
|
+
*/
|
|
10
|
+
export class ContextManager {
|
|
11
|
+
sessionCounter = 0;
|
|
12
|
+
activeContexts = new Map();
|
|
13
|
+
/**
|
|
14
|
+
* Create a new execution context with rich information
|
|
15
|
+
*
|
|
16
|
+
* @param request Context creation request with optional fields
|
|
17
|
+
* @returns Complete execution context ready for tool chain
|
|
18
|
+
*/
|
|
19
|
+
createContext(request = {}) {
|
|
20
|
+
// Generate session ID if not provided
|
|
21
|
+
const sessionId = request.sessionId || this.generateSessionId();
|
|
22
|
+
// Create comprehensive context
|
|
23
|
+
const context = {
|
|
24
|
+
// Session Management
|
|
25
|
+
sessionId,
|
|
26
|
+
userId: request.userId,
|
|
27
|
+
// AI Provider Context (from existing NeuroLink)
|
|
28
|
+
aiProvider: request.aiProvider,
|
|
29
|
+
modelId: request.modelId,
|
|
30
|
+
temperature: request.temperature,
|
|
31
|
+
maxTokens: request.maxTokens,
|
|
32
|
+
// Business Context (new for MCP)
|
|
33
|
+
organizationId: request.organizationId,
|
|
34
|
+
projectId: request.projectId,
|
|
35
|
+
environmentType: request.environmentType || 'development',
|
|
36
|
+
// Framework Context (new for MCP)
|
|
37
|
+
frameworkType: request.frameworkType,
|
|
38
|
+
// Tool Execution Context (initialized empty)
|
|
39
|
+
toolChain: [],
|
|
40
|
+
parentToolId: undefined,
|
|
41
|
+
// Security & Permissions
|
|
42
|
+
permissions: request.permissions || [],
|
|
43
|
+
securityLevel: request.securityLevel || 'private',
|
|
44
|
+
// Copy any additional custom fields
|
|
45
|
+
...this.extractCustomFields(request)
|
|
46
|
+
};
|
|
47
|
+
// Store context for session management
|
|
48
|
+
this.activeContexts.set(sessionId, context);
|
|
49
|
+
return context;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Add a tool to the execution chain
|
|
53
|
+
*
|
|
54
|
+
* @param context Execution context to modify
|
|
55
|
+
* @param toolName Name of the tool being executed
|
|
56
|
+
*/
|
|
57
|
+
addToToolChain(context, toolName) {
|
|
58
|
+
if (!context.toolChain) {
|
|
59
|
+
context.toolChain = [];
|
|
60
|
+
}
|
|
61
|
+
context.toolChain.push(toolName);
|
|
62
|
+
// Update the active context
|
|
63
|
+
this.activeContexts.set(context.sessionId, context);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get the current tool chain for a context
|
|
67
|
+
*
|
|
68
|
+
* @param context Execution context
|
|
69
|
+
* @returns Array of tool names in execution order
|
|
70
|
+
*/
|
|
71
|
+
getToolChain(context) {
|
|
72
|
+
return context.toolChain || [];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Set parent tool for nested tool execution
|
|
76
|
+
*
|
|
77
|
+
* @param context Execution context to modify
|
|
78
|
+
* @param parentToolId ID of the parent tool
|
|
79
|
+
*/
|
|
80
|
+
setParentTool(context, parentToolId) {
|
|
81
|
+
context.parentToolId = parentToolId;
|
|
82
|
+
this.activeContexts.set(context.sessionId, context);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Create child context for nested tool execution
|
|
86
|
+
*
|
|
87
|
+
* @param parentContext Parent execution context
|
|
88
|
+
* @param childToolName Name of the child tool
|
|
89
|
+
* @returns New child context with inherited properties
|
|
90
|
+
*/
|
|
91
|
+
createChildContext(parentContext, childToolName) {
|
|
92
|
+
const childContext = {
|
|
93
|
+
// Inherit all parent context
|
|
94
|
+
...parentContext,
|
|
95
|
+
// Create new session ID for child
|
|
96
|
+
sessionId: this.generateSessionId(),
|
|
97
|
+
// Set parent tool reference
|
|
98
|
+
parentToolId: parentContext.toolChain?.[parentContext.toolChain.length - 1],
|
|
99
|
+
// Reset tool chain for child (will be populated as child executes tools)
|
|
100
|
+
toolChain: []
|
|
101
|
+
};
|
|
102
|
+
// Store child context
|
|
103
|
+
this.activeContexts.set(childContext.sessionId, childContext);
|
|
104
|
+
return childContext;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get context by session ID
|
|
108
|
+
*
|
|
109
|
+
* @param sessionId Session identifier
|
|
110
|
+
* @returns Execution context or undefined if not found
|
|
111
|
+
*/
|
|
112
|
+
getContext(sessionId) {
|
|
113
|
+
return this.activeContexts.get(sessionId);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Update context with new information
|
|
117
|
+
*
|
|
118
|
+
* @param sessionId Session identifier
|
|
119
|
+
* @param updates Partial context updates
|
|
120
|
+
*/
|
|
121
|
+
updateContext(sessionId, updates) {
|
|
122
|
+
const context = this.activeContexts.get(sessionId);
|
|
123
|
+
if (context) {
|
|
124
|
+
const updatedContext = { ...context, ...updates };
|
|
125
|
+
this.activeContexts.set(sessionId, updatedContext);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Remove context from active tracking
|
|
130
|
+
*
|
|
131
|
+
* @param sessionId Session identifier
|
|
132
|
+
*/
|
|
133
|
+
removeContext(sessionId) {
|
|
134
|
+
this.activeContexts.delete(sessionId);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get all active contexts (for debugging/monitoring)
|
|
138
|
+
*
|
|
139
|
+
* @returns Array of all active contexts
|
|
140
|
+
*/
|
|
141
|
+
getActiveContexts() {
|
|
142
|
+
return Array.from(this.activeContexts.values());
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Clear all active contexts
|
|
146
|
+
*/
|
|
147
|
+
clearAllContexts() {
|
|
148
|
+
this.activeContexts.clear();
|
|
149
|
+
this.sessionCounter = 0;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get context statistics
|
|
153
|
+
*
|
|
154
|
+
* @returns Context usage statistics
|
|
155
|
+
*/
|
|
156
|
+
getStats() {
|
|
157
|
+
const contexts = Array.from(this.activeContexts.values());
|
|
158
|
+
const totalToolChainLength = contexts.reduce((sum, ctx) => sum + (ctx.toolChain?.length || 0), 0);
|
|
159
|
+
return {
|
|
160
|
+
activeContexts: contexts.length,
|
|
161
|
+
totalSessionsCreated: this.sessionCounter,
|
|
162
|
+
averageToolChainLength: contexts.length > 0
|
|
163
|
+
? totalToolChainLength / contexts.length
|
|
164
|
+
: 0
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Generate unique session ID
|
|
169
|
+
*
|
|
170
|
+
* @returns Unique session identifier
|
|
171
|
+
*/
|
|
172
|
+
generateSessionId() {
|
|
173
|
+
this.sessionCounter++;
|
|
174
|
+
const timestamp = Date.now();
|
|
175
|
+
const random = Math.random().toString(36).substring(2, 8);
|
|
176
|
+
return `nlmcp-${timestamp}-${this.sessionCounter}-${random}`;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Extract custom fields from request (excluding known fields)
|
|
180
|
+
*
|
|
181
|
+
* @param request Context creation request
|
|
182
|
+
* @returns Custom fields object
|
|
183
|
+
*/
|
|
184
|
+
extractCustomFields(request) {
|
|
185
|
+
const knownFields = new Set([
|
|
186
|
+
'sessionId', 'userId', 'aiProvider', 'modelId', 'temperature', 'maxTokens',
|
|
187
|
+
'organizationId', 'projectId', 'environmentType', 'frameworkType',
|
|
188
|
+
'permissions', 'securityLevel'
|
|
189
|
+
]);
|
|
190
|
+
const customFields = {};
|
|
191
|
+
for (const [key, value] of Object.entries(request)) {
|
|
192
|
+
if (!knownFields.has(key)) {
|
|
193
|
+
customFields[key] = value;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return customFields;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Default context manager instance
|
|
201
|
+
* Can be used across the application for consistent context management
|
|
202
|
+
*/
|
|
203
|
+
export const defaultContextManager = new ContextManager();
|
|
204
|
+
/**
|
|
205
|
+
* Utility function to create context with defaults
|
|
206
|
+
*
|
|
207
|
+
* @param request Optional context request
|
|
208
|
+
* @returns Execution context with sensible defaults
|
|
209
|
+
*/
|
|
210
|
+
export function createExecutionContext(request = {}) {
|
|
211
|
+
return defaultContextManager.createContext(request);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Utility function to add tool to default context manager
|
|
215
|
+
*
|
|
216
|
+
* @param context Execution context
|
|
217
|
+
* @param toolName Tool name to add
|
|
218
|
+
*/
|
|
219
|
+
export function addToolToChain(context, toolName) {
|
|
220
|
+
defaultContextManager.addToToolChain(context, toolName);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Context validation utilities
|
|
224
|
+
*/
|
|
225
|
+
export class ContextValidator {
|
|
226
|
+
/**
|
|
227
|
+
* Validate context has required fields for tool execution
|
|
228
|
+
*
|
|
229
|
+
* @param context Execution context to validate
|
|
230
|
+
* @returns Validation result with details
|
|
231
|
+
*/
|
|
232
|
+
static validateContext(context) {
|
|
233
|
+
const errors = [];
|
|
234
|
+
const warnings = [];
|
|
235
|
+
// Required field validation
|
|
236
|
+
if (!context.sessionId) {
|
|
237
|
+
errors.push('sessionId is required');
|
|
238
|
+
}
|
|
239
|
+
// Optional field validation with warnings
|
|
240
|
+
if (!context.environmentType) {
|
|
241
|
+
warnings.push('environmentType not specified, defaulting to development');
|
|
242
|
+
}
|
|
243
|
+
if (!context.securityLevel) {
|
|
244
|
+
warnings.push('securityLevel not specified, defaulting to private');
|
|
245
|
+
}
|
|
246
|
+
// Tool chain validation
|
|
247
|
+
if (context.toolChain && context.toolChain.length > 10) {
|
|
248
|
+
warnings.push('Tool chain is getting long (>10 tools), consider breaking into smaller workflows');
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
isValid: errors.length === 0,
|
|
252
|
+
errors,
|
|
253
|
+
warnings
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Validate context permissions for tool execution
|
|
258
|
+
*
|
|
259
|
+
* @param context Execution context
|
|
260
|
+
* @param requiredPermissions Permissions required by tool
|
|
261
|
+
* @returns Whether context has required permissions
|
|
262
|
+
*/
|
|
263
|
+
static hasPermissions(context, requiredPermissions) {
|
|
264
|
+
if (!requiredPermissions || requiredPermissions.length === 0) {
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
const contextPermissions = context.permissions || [];
|
|
268
|
+
// Check if context has all required permissions
|
|
269
|
+
return requiredPermissions.every(permission => contextPermissions.includes(permission) ||
|
|
270
|
+
contextPermissions.includes('*') // Wildcard permission
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NeuroLink MCP Server Factory
|
|
3
|
+
* Factory-First Architecture: MCP servers create tools for internal orchestration
|
|
4
|
+
* Compatible with Lighthouse MCP patterns for seamless migration
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
/**
|
|
8
|
+
* MCP Server Categories for organization and discovery
|
|
9
|
+
*/
|
|
10
|
+
export type MCPServerCategory = 'ai-providers' | 'frameworks' | 'development' | 'business' | 'content' | 'data' | 'integrations' | 'automation' | 'analysis' | 'custom';
|
|
11
|
+
/**
|
|
12
|
+
* Tool execution context - Rich context passed to every tool execution
|
|
13
|
+
* Based on Lighthouse patterns with NeuroLink enhancements
|
|
14
|
+
*/
|
|
15
|
+
export interface NeuroLinkExecutionContext {
|
|
16
|
+
sessionId: string;
|
|
17
|
+
userId?: string;
|
|
18
|
+
aiProvider?: string;
|
|
19
|
+
modelId?: string;
|
|
20
|
+
temperature?: number;
|
|
21
|
+
maxTokens?: number;
|
|
22
|
+
organizationId?: string;
|
|
23
|
+
projectId?: string;
|
|
24
|
+
environmentType?: 'development' | 'staging' | 'production';
|
|
25
|
+
frameworkType?: 'react' | 'vue' | 'svelte' | 'next' | 'nuxt' | 'sveltekit';
|
|
26
|
+
toolChain?: string[];
|
|
27
|
+
parentToolId?: string;
|
|
28
|
+
permissions?: string[];
|
|
29
|
+
securityLevel?: 'public' | 'private' | 'organization';
|
|
30
|
+
[key: string]: any;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Tool execution result - Standardized result format
|
|
34
|
+
*/
|
|
35
|
+
export interface ToolResult {
|
|
36
|
+
success: boolean;
|
|
37
|
+
data?: any;
|
|
38
|
+
error?: string;
|
|
39
|
+
usage?: {
|
|
40
|
+
tokens?: number;
|
|
41
|
+
cost?: number;
|
|
42
|
+
provider?: string;
|
|
43
|
+
model?: string;
|
|
44
|
+
executionTime?: number;
|
|
45
|
+
};
|
|
46
|
+
metadata?: {
|
|
47
|
+
toolName?: string;
|
|
48
|
+
serverId?: string;
|
|
49
|
+
serverTitle?: string;
|
|
50
|
+
sessionId?: string;
|
|
51
|
+
timestamp?: number;
|
|
52
|
+
executionTime?: number;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* MCP Tool Interface - Lighthouse compatible with NeuroLink enhancements
|
|
57
|
+
*/
|
|
58
|
+
export interface NeuroLinkMCPTool {
|
|
59
|
+
name: string;
|
|
60
|
+
description: string;
|
|
61
|
+
execute: (params: unknown, context: NeuroLinkExecutionContext) => Promise<ToolResult>;
|
|
62
|
+
inputSchema?: z.ZodSchema;
|
|
63
|
+
outputSchema?: z.ZodSchema;
|
|
64
|
+
isImplemented?: boolean;
|
|
65
|
+
category?: string;
|
|
66
|
+
permissions?: string[];
|
|
67
|
+
version?: string;
|
|
68
|
+
metadata?: Record<string, any>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* MCP Server Interface - 99% Lighthouse compatible
|
|
72
|
+
* Minimal required fields for easy adoption
|
|
73
|
+
*/
|
|
74
|
+
export interface NeuroLinkMCPServer {
|
|
75
|
+
id: string;
|
|
76
|
+
title: string;
|
|
77
|
+
description?: string;
|
|
78
|
+
version?: string;
|
|
79
|
+
category?: MCPServerCategory;
|
|
80
|
+
visibility?: 'public' | 'private' | 'organization';
|
|
81
|
+
tools: Record<string, NeuroLinkMCPTool>;
|
|
82
|
+
registerTool: (tool: NeuroLinkMCPTool) => NeuroLinkMCPServer;
|
|
83
|
+
metadata?: Record<string, any>;
|
|
84
|
+
dependencies?: string[];
|
|
85
|
+
capabilities?: string[];
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* MCP Server Configuration for creation
|
|
89
|
+
*/
|
|
90
|
+
export interface MCPServerConfig {
|
|
91
|
+
id: string;
|
|
92
|
+
title: string;
|
|
93
|
+
description?: string;
|
|
94
|
+
version?: string;
|
|
95
|
+
category?: MCPServerCategory;
|
|
96
|
+
visibility?: 'public' | 'private' | 'organization';
|
|
97
|
+
metadata?: Record<string, any>;
|
|
98
|
+
dependencies?: string[];
|
|
99
|
+
capabilities?: string[];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Create MCP Server Factory Function
|
|
103
|
+
*
|
|
104
|
+
* Core factory function for creating Lighthouse-compatible MCP servers.
|
|
105
|
+
* Follows Factory-First architecture where tools are internal implementation.
|
|
106
|
+
*
|
|
107
|
+
* @param config Server configuration with minimal required fields
|
|
108
|
+
* @returns Fully configured MCP server ready for tool registration
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const aiCoreServer = createMCPServer({
|
|
113
|
+
* id: 'neurolink-ai-core',
|
|
114
|
+
* title: 'NeuroLink AI Core',
|
|
115
|
+
* description: 'Core AI provider tools',
|
|
116
|
+
* category: 'ai-providers'
|
|
117
|
+
* });
|
|
118
|
+
*
|
|
119
|
+
* aiCoreServer.registerTool({
|
|
120
|
+
* name: 'generate-text',
|
|
121
|
+
* description: 'Generate text using AI providers',
|
|
122
|
+
* execute: async (params, context) => {
|
|
123
|
+
* // Tool implementation
|
|
124
|
+
* return { success: true, data: result };
|
|
125
|
+
* }
|
|
126
|
+
* });
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export declare function createMCPServer(config: MCPServerConfig): NeuroLinkMCPServer;
|
|
130
|
+
/**
|
|
131
|
+
* Utility function to validate tool interface
|
|
132
|
+
*/
|
|
133
|
+
export declare function validateTool(tool: NeuroLinkMCPTool): boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Utility function to get server info
|
|
136
|
+
*/
|
|
137
|
+
export declare function getServerInfo(server: NeuroLinkMCPServer): {
|
|
138
|
+
id: string;
|
|
139
|
+
title: string;
|
|
140
|
+
description?: string;
|
|
141
|
+
category?: MCPServerCategory;
|
|
142
|
+
toolCount: number;
|
|
143
|
+
capabilities: string[];
|
|
144
|
+
};
|