@juspay/neurolink 1.10.0 → 1.11.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 +36 -33
- package/README.md +16 -0
- package/dist/agent/direct-tools.d.ts +9 -9
- package/dist/cli/commands/agent-generate.d.ts +1 -2
- package/dist/cli/commands/agent-generate.js +5 -8
- package/dist/cli/commands/config.d.ts +2 -2
- package/dist/cli/commands/config.js +1 -1
- package/dist/cli/commands/mcp.js +91 -100
- package/dist/cli/commands/ollama.d.ts +2 -7
- package/dist/cli/commands/ollama.js +5 -8
- package/dist/cli/index.js +185 -276
- package/dist/core/factory.js +9 -10
- package/dist/index.d.ts +23 -0
- package/dist/index.js +35 -0
- package/dist/lib/agent/direct-tools.d.ts +9 -9
- package/dist/lib/core/factory.js +9 -10
- package/dist/lib/index.d.ts +23 -0
- package/dist/lib/index.js +35 -0
- package/dist/lib/mcp/adapters/plugin-bridge.d.ts +39 -0
- package/dist/lib/mcp/adapters/plugin-bridge.js +82 -0
- package/dist/lib/mcp/auto-discovery.d.ts +38 -96
- package/dist/lib/mcp/auto-discovery.js +100 -744
- package/dist/lib/mcp/client.js +4 -4
- package/dist/lib/mcp/context-manager.js +72 -1
- package/dist/lib/mcp/contracts/mcp-contract.d.ts +162 -0
- package/dist/lib/mcp/contracts/mcp-contract.js +58 -0
- package/dist/lib/mcp/core/plugin-manager.d.ts +45 -0
- package/dist/lib/mcp/core/plugin-manager.js +110 -0
- package/dist/lib/mcp/demo/plugin-demo.d.ts +20 -0
- package/dist/lib/mcp/demo/plugin-demo.js +116 -0
- package/dist/lib/mcp/ecosystem.d.ts +75 -0
- package/dist/lib/mcp/ecosystem.js +161 -0
- package/dist/lib/mcp/external-client.d.ts +88 -0
- package/dist/lib/mcp/external-client.js +323 -0
- package/dist/lib/mcp/external-manager.d.ts +112 -0
- package/dist/lib/mcp/external-manager.js +302 -0
- package/dist/lib/mcp/factory.d.ts +4 -4
- package/dist/lib/mcp/function-calling.js +59 -34
- package/dist/lib/mcp/index.d.ts +39 -184
- package/dist/lib/mcp/index.js +72 -150
- package/dist/lib/mcp/initialize.js +5 -5
- package/dist/lib/mcp/logging.d.ts +27 -60
- package/dist/lib/mcp/logging.js +77 -165
- package/dist/lib/mcp/neurolink-mcp-client.js +31 -3
- package/dist/lib/mcp/orchestrator.d.ts +1 -1
- package/dist/lib/mcp/orchestrator.js +13 -12
- package/dist/lib/mcp/plugin-manager.d.ts +98 -0
- package/dist/lib/mcp/plugin-manager.js +294 -0
- package/dist/lib/mcp/plugins/core/filesystem-mcp.d.ts +35 -0
- package/dist/lib/mcp/plugins/core/filesystem-mcp.js +139 -0
- package/dist/lib/mcp/plugins/filesystem-mcp.d.ts +36 -0
- package/dist/lib/mcp/plugins/filesystem-mcp.js +54 -0
- package/dist/lib/mcp/registry.d.ts +27 -176
- package/dist/lib/mcp/registry.js +31 -372
- package/dist/lib/mcp/security-manager.d.ts +85 -0
- package/dist/lib/mcp/security-manager.js +344 -0
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
- package/dist/lib/mcp/tool-integration.d.ts +4 -14
- package/dist/lib/mcp/tool-integration.js +43 -21
- package/dist/lib/mcp/tool-registry.d.ts +66 -0
- package/dist/lib/mcp/tool-registry.js +160 -0
- package/dist/lib/mcp/unified-mcp.d.ts +123 -0
- package/dist/lib/mcp/unified-mcp.js +246 -0
- package/dist/lib/mcp/unified-registry.d.ts +42 -229
- package/dist/lib/mcp/unified-registry.js +96 -1346
- package/dist/lib/neurolink.d.ts +3 -4
- package/dist/lib/neurolink.js +17 -18
- package/dist/lib/providers/agent-enhanced-provider.js +2 -2
- package/dist/lib/providers/amazonBedrock.js +2 -2
- package/dist/lib/providers/anthropic.js +3 -3
- package/dist/lib/providers/azureOpenAI.js +3 -3
- package/dist/lib/providers/function-calling-provider.js +34 -25
- package/dist/lib/providers/googleAIStudio.js +3 -3
- package/dist/lib/providers/googleVertexAI.js +2 -2
- package/dist/lib/providers/huggingFace.js +2 -2
- package/dist/lib/providers/mcp-provider.js +33 -5
- package/dist/lib/providers/mistralAI.js +2 -2
- package/dist/lib/providers/ollama.js +2 -2
- package/dist/lib/providers/openAI.js +2 -2
- package/dist/lib/utils/providerUtils-fixed.js +9 -9
- package/dist/mcp/adapters/plugin-bridge.d.ts +39 -0
- package/dist/mcp/adapters/plugin-bridge.js +82 -0
- package/dist/mcp/auto-discovery.d.ts +38 -96
- package/dist/mcp/auto-discovery.js +100 -745
- package/dist/mcp/client.js +4 -4
- package/dist/mcp/context-manager.js +72 -1
- package/dist/mcp/contracts/mcp-contract.d.ts +162 -0
- package/dist/mcp/contracts/mcp-contract.js +58 -0
- package/dist/mcp/core/plugin-manager.d.ts +45 -0
- package/dist/mcp/core/plugin-manager.js +110 -0
- package/dist/mcp/demo/plugin-demo.d.ts +20 -0
- package/dist/mcp/demo/plugin-demo.js +116 -0
- package/dist/mcp/ecosystem.d.ts +75 -0
- package/dist/mcp/ecosystem.js +162 -0
- package/dist/mcp/external-client.d.ts +88 -0
- package/dist/mcp/external-client.js +323 -0
- package/dist/mcp/external-manager.d.ts +112 -0
- package/dist/mcp/external-manager.js +302 -0
- package/dist/mcp/factory.d.ts +4 -4
- package/dist/mcp/function-calling.js +59 -34
- package/dist/mcp/index.d.ts +39 -184
- package/dist/mcp/index.js +72 -150
- package/dist/mcp/initialize.js +5 -5
- package/dist/mcp/logging.d.ts +27 -60
- package/dist/mcp/logging.js +77 -165
- package/dist/mcp/neurolink-mcp-client.js +31 -3
- package/dist/mcp/orchestrator.d.ts +1 -1
- package/dist/mcp/orchestrator.js +13 -12
- package/dist/mcp/plugin-manager.d.ts +98 -0
- package/dist/mcp/plugin-manager.js +295 -0
- package/dist/mcp/plugins/core/filesystem-mcp.d.ts +35 -0
- package/dist/mcp/plugins/core/filesystem-mcp.js +139 -0
- package/dist/mcp/plugins/core/neurolink-mcp.json +17 -0
- package/dist/mcp/plugins/filesystem-mcp.d.ts +36 -0
- package/dist/mcp/plugins/filesystem-mcp.js +54 -0
- package/dist/mcp/registry.d.ts +27 -176
- package/dist/mcp/registry.js +31 -372
- package/dist/mcp/security-manager.d.ts +85 -0
- package/dist/mcp/security-manager.js +344 -0
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
- package/dist/mcp/tool-integration.d.ts +4 -14
- package/dist/mcp/tool-integration.js +43 -21
- package/dist/mcp/tool-registry.d.ts +66 -0
- package/dist/mcp/tool-registry.js +160 -0
- package/dist/mcp/unified-mcp.d.ts +123 -0
- package/dist/mcp/unified-mcp.js +246 -0
- package/dist/mcp/unified-registry.d.ts +42 -229
- package/dist/mcp/unified-registry.js +96 -1345
- package/dist/neurolink.d.ts +3 -4
- package/dist/neurolink.js +17 -18
- package/dist/providers/agent-enhanced-provider.js +2 -2
- package/dist/providers/amazonBedrock.js +2 -2
- package/dist/providers/anthropic.js +3 -3
- package/dist/providers/azureOpenAI.js +3 -3
- package/dist/providers/function-calling-provider.js +34 -25
- package/dist/providers/googleAIStudio.js +3 -3
- package/dist/providers/googleVertexAI.js +2 -2
- package/dist/providers/huggingFace.js +2 -2
- package/dist/providers/mcp-provider.js +33 -5
- package/dist/providers/mistralAI.js +2 -2
- package/dist/providers/ollama.js +2 -2
- package/dist/providers/openAI.js +2 -2
- package/dist/utils/providerUtils-fixed.js +9 -9
- package/package.json +1 -1
package/dist/lib/mcp/client.js
CHANGED
|
@@ -147,15 +147,15 @@ export class NeuroLinkMCPClient extends EventEmitter {
|
|
|
147
147
|
error: `Tool not found: ${toolName}`,
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
|
-
// Create full context
|
|
151
|
-
const
|
|
150
|
+
// Create full context using createExecutionContext for proper structure
|
|
151
|
+
const { createExecutionContext } = await import("./context-manager.js");
|
|
152
|
+
const fullContext = createExecutionContext({
|
|
152
153
|
sessionId: this.config.sessionId,
|
|
153
154
|
userId: this.config.userId,
|
|
154
155
|
aiProvider: this.config.aiProvider,
|
|
155
156
|
modelId: this.config.modelId,
|
|
156
|
-
timestamp: Date.now(),
|
|
157
157
|
...context,
|
|
158
|
-
};
|
|
158
|
+
});
|
|
159
159
|
// Track execution
|
|
160
160
|
this.executionCount++;
|
|
161
161
|
const executionId = `exec-${this.executionCount}`;
|
|
@@ -23,7 +23,78 @@ export class ContextManager {
|
|
|
23
23
|
const context = {
|
|
24
24
|
// Session Management
|
|
25
25
|
sessionId,
|
|
26
|
-
userId: request.userId,
|
|
26
|
+
userId: request.userId || "unknown-user",
|
|
27
|
+
// Required ExecutionContext properties
|
|
28
|
+
secureFS: {
|
|
29
|
+
readFile: async (path, encoding) => {
|
|
30
|
+
const fs = await import("fs/promises");
|
|
31
|
+
if (encoding) {
|
|
32
|
+
return fs.readFile(path, { encoding: encoding });
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return fs.readFile(path);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
writeFile: async (path, content) => {
|
|
39
|
+
const fs = await import("fs/promises");
|
|
40
|
+
return fs.writeFile(path, content);
|
|
41
|
+
},
|
|
42
|
+
readdir: async (path) => {
|
|
43
|
+
const fs = await import("fs/promises");
|
|
44
|
+
return fs.readdir(path);
|
|
45
|
+
},
|
|
46
|
+
stat: async (path) => {
|
|
47
|
+
const fs = await import("fs/promises");
|
|
48
|
+
return fs.stat(path);
|
|
49
|
+
},
|
|
50
|
+
mkdir: async (path, options) => {
|
|
51
|
+
const fs = await import("fs/promises");
|
|
52
|
+
await fs.mkdir(path, options);
|
|
53
|
+
},
|
|
54
|
+
exists: async (path) => {
|
|
55
|
+
const fs = await import("fs/promises");
|
|
56
|
+
try {
|
|
57
|
+
await fs.access(path);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
path: {
|
|
66
|
+
join: (...paths) => {
|
|
67
|
+
const path = require("path");
|
|
68
|
+
return path.join(...paths);
|
|
69
|
+
},
|
|
70
|
+
resolve: (...paths) => {
|
|
71
|
+
const path = require("path");
|
|
72
|
+
return path.resolve(...paths);
|
|
73
|
+
},
|
|
74
|
+
relative: (from, to) => {
|
|
75
|
+
const path = require("path");
|
|
76
|
+
return path.relative(from, to);
|
|
77
|
+
},
|
|
78
|
+
dirname: (path) => {
|
|
79
|
+
const pathModule = require("path");
|
|
80
|
+
return pathModule.dirname(path);
|
|
81
|
+
},
|
|
82
|
+
basename: (path, ext) => {
|
|
83
|
+
const pathModule = require("path");
|
|
84
|
+
return pathModule.basename(path, ext);
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
grantedPermissions: request.permissions || [],
|
|
88
|
+
log: (level, message, data) => {
|
|
89
|
+
// Use logger if available, otherwise console
|
|
90
|
+
try {
|
|
91
|
+
const { logger } = require("../utils/logger.js");
|
|
92
|
+
logger[level](message, data);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
console[level === "debug" ? "log" : level](message, data);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
27
98
|
// AI Provider Context (from existing NeuroLink)
|
|
28
99
|
aiProvider: request.aiProvider,
|
|
29
100
|
modelId: request.modelId,
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Abstract Contract - The Foundation of NeuroLink's Plugin Ecosystem
|
|
3
|
+
* Based on research blueprint for extensible MCP architecture
|
|
4
|
+
*/
|
|
5
|
+
import type { ZodSchema } from "zod";
|
|
6
|
+
/**
|
|
7
|
+
* Metadata structure for MCP plugins following manifest-based discovery
|
|
8
|
+
*/
|
|
9
|
+
export interface MCPMetadata {
|
|
10
|
+
/** Unique NPM-style package name */
|
|
11
|
+
name: string;
|
|
12
|
+
/** Semantic version */
|
|
13
|
+
version: string;
|
|
14
|
+
/** Entry point path */
|
|
15
|
+
main: string;
|
|
16
|
+
/** Compatible NeuroLink version range */
|
|
17
|
+
engine: {
|
|
18
|
+
neurolink: string;
|
|
19
|
+
};
|
|
20
|
+
/** Human-readable description */
|
|
21
|
+
description: string;
|
|
22
|
+
/** Declarative permissions array for security */
|
|
23
|
+
permissions: string[];
|
|
24
|
+
/** JSON Schema for configuration validation */
|
|
25
|
+
configSchema?: ZodSchema | object;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Execution Context - Security Sandbox for MCP Operations
|
|
29
|
+
* Provides sandboxed access to system resources with permission checking
|
|
30
|
+
*/
|
|
31
|
+
export interface ExecutionContext {
|
|
32
|
+
/** Session identifier for tracking */
|
|
33
|
+
sessionId: string;
|
|
34
|
+
/** User identifier for permissions */
|
|
35
|
+
userId: string;
|
|
36
|
+
/** Sandboxed filesystem operations */
|
|
37
|
+
secureFS: {
|
|
38
|
+
readFile: (path: string, encoding?: string) => Promise<string | Buffer>;
|
|
39
|
+
writeFile: (path: string, content: string | Buffer) => Promise<void>;
|
|
40
|
+
readdir: (path: string) => Promise<string[]>;
|
|
41
|
+
stat: (path: string) => Promise<any>;
|
|
42
|
+
mkdir: (path: string, options?: any) => Promise<void>;
|
|
43
|
+
exists: (path: string) => Promise<boolean>;
|
|
44
|
+
};
|
|
45
|
+
/** Sandboxed path operations */
|
|
46
|
+
path: {
|
|
47
|
+
join: (...paths: string[]) => string;
|
|
48
|
+
resolve: (...paths: string[]) => string;
|
|
49
|
+
relative: (from: string, to: string) => string;
|
|
50
|
+
dirname: (path: string) => string;
|
|
51
|
+
basename: (path: string, ext?: string) => string;
|
|
52
|
+
};
|
|
53
|
+
/** Sandboxed network operations (future) */
|
|
54
|
+
secureNet?: {
|
|
55
|
+
fetch: (url: string, options?: any) => Promise<Response>;
|
|
56
|
+
};
|
|
57
|
+
/** Plugin-specific permissions granted */
|
|
58
|
+
grantedPermissions: string[];
|
|
59
|
+
/** Log function for debugging */
|
|
60
|
+
log: (level: "debug" | "info" | "warn" | "error", message: string, data?: any) => void;
|
|
61
|
+
/** Plugin instance reference (for plugin bridge compatibility) */
|
|
62
|
+
plugin?: any;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* MCP Abstract Class - The Core Contract for All Plugins
|
|
66
|
+
* Uses TypeScript generics for type-safe configuration
|
|
67
|
+
*/
|
|
68
|
+
export declare abstract class MCP<TConfig = any, TArgs = any, TResult = any> {
|
|
69
|
+
/** Static metadata loaded from manifest */
|
|
70
|
+
abstract readonly metadata: MCPMetadata;
|
|
71
|
+
/** Configuration state - accessible to child classes */
|
|
72
|
+
config?: TConfig;
|
|
73
|
+
/** Initialization flag */
|
|
74
|
+
protected initialized: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Initialize the MCP with user-provided configuration
|
|
77
|
+
* @param config - Plugin-specific configuration object
|
|
78
|
+
*/
|
|
79
|
+
abstract initialize(config: TConfig): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Execute the MCP's primary functionality
|
|
82
|
+
* @param context - Sandboxed execution context
|
|
83
|
+
* @param args - Operation-specific arguments
|
|
84
|
+
* @returns Plugin-specific result
|
|
85
|
+
*/
|
|
86
|
+
abstract execute(context: ExecutionContext, args: TArgs): Promise<TResult>;
|
|
87
|
+
/**
|
|
88
|
+
* Graceful shutdown and resource cleanup
|
|
89
|
+
*/
|
|
90
|
+
abstract dispose(): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Get the current configuration
|
|
93
|
+
*/
|
|
94
|
+
getConfig(): TConfig | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Check if the MCP is initialized
|
|
97
|
+
*/
|
|
98
|
+
isInitialized(): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Get plugin metadata
|
|
101
|
+
*/
|
|
102
|
+
getMetadata(): MCPMetadata;
|
|
103
|
+
/**
|
|
104
|
+
* Validate that the MCP is ready for execution
|
|
105
|
+
*/
|
|
106
|
+
protected ensureInitialized(): void;
|
|
107
|
+
/**
|
|
108
|
+
* Helper method for logging with context
|
|
109
|
+
*/
|
|
110
|
+
protected log(context: ExecutionContext, level: "debug" | "info" | "warn" | "error", message: string, data?: any): void;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Type definitions for plugin registry
|
|
114
|
+
*/
|
|
115
|
+
export type MCPConstructor<T extends MCP = MCP> = new () => T;
|
|
116
|
+
export type MCPInstance<T extends MCP = MCP> = T;
|
|
117
|
+
/**
|
|
118
|
+
* Plugin discovery result
|
|
119
|
+
*/
|
|
120
|
+
export interface DiscoveredMCP {
|
|
121
|
+
metadata: MCPMetadata;
|
|
122
|
+
entryPath: string;
|
|
123
|
+
source: "core" | "project" | "installed";
|
|
124
|
+
constructor?: MCPConstructor;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Plugin load result
|
|
128
|
+
*/
|
|
129
|
+
export interface PluginLoadResult {
|
|
130
|
+
success: boolean;
|
|
131
|
+
plugin?: MCP;
|
|
132
|
+
error?: string;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Plugin discovery result
|
|
136
|
+
*/
|
|
137
|
+
export interface PluginDiscoveryResult {
|
|
138
|
+
total: number;
|
|
139
|
+
loaded: number;
|
|
140
|
+
failed: number;
|
|
141
|
+
plugins: DiscoveredMCP[];
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Plugin execution result
|
|
145
|
+
*/
|
|
146
|
+
export interface PluginExecutionResult<T = any> {
|
|
147
|
+
success: boolean;
|
|
148
|
+
result?: T;
|
|
149
|
+
error?: string;
|
|
150
|
+
executionTime?: number;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* MCP Category for organization
|
|
154
|
+
*/
|
|
155
|
+
export declare enum MCPCategory {
|
|
156
|
+
FILESYSTEM = "filesystem",
|
|
157
|
+
NETWORK = "network",
|
|
158
|
+
DATABASE = "database",
|
|
159
|
+
AI = "ai",
|
|
160
|
+
UTILITY = "utility",
|
|
161
|
+
INTEGRATION = "integration"
|
|
162
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Abstract Contract - The Foundation of NeuroLink's Plugin Ecosystem
|
|
3
|
+
* Based on research blueprint for extensible MCP architecture
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* MCP Abstract Class - The Core Contract for All Plugins
|
|
7
|
+
* Uses TypeScript generics for type-safe configuration
|
|
8
|
+
*/
|
|
9
|
+
export class MCP {
|
|
10
|
+
/** Configuration state - accessible to child classes */
|
|
11
|
+
config;
|
|
12
|
+
/** Initialization flag */
|
|
13
|
+
initialized = false;
|
|
14
|
+
/**
|
|
15
|
+
* Get the current configuration
|
|
16
|
+
*/
|
|
17
|
+
getConfig() {
|
|
18
|
+
return this.config;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Check if the MCP is initialized
|
|
22
|
+
*/
|
|
23
|
+
isInitialized() {
|
|
24
|
+
return this.initialized;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get plugin metadata
|
|
28
|
+
*/
|
|
29
|
+
getMetadata() {
|
|
30
|
+
return this.metadata;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Validate that the MCP is ready for execution
|
|
34
|
+
*/
|
|
35
|
+
ensureInitialized() {
|
|
36
|
+
if (!this.initialized) {
|
|
37
|
+
throw new Error(`MCP ${this.metadata.name} is not initialized. Call initialize() first.`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Helper method for logging with context
|
|
42
|
+
*/
|
|
43
|
+
log(context, level, message, data) {
|
|
44
|
+
context.log(level, `[${this.metadata.name}] ${message}`, data);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* MCP Category for organization
|
|
49
|
+
*/
|
|
50
|
+
export var MCPCategory;
|
|
51
|
+
(function (MCPCategory) {
|
|
52
|
+
MCPCategory["FILESYSTEM"] = "filesystem";
|
|
53
|
+
MCPCategory["NETWORK"] = "network";
|
|
54
|
+
MCPCategory["DATABASE"] = "database";
|
|
55
|
+
MCPCategory["AI"] = "ai";
|
|
56
|
+
MCPCategory["UTILITY"] = "utility";
|
|
57
|
+
MCPCategory["INTEGRATION"] = "integration";
|
|
58
|
+
})(MCPCategory || (MCPCategory = {}));
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Plugin Manager
|
|
3
|
+
* Enhanced plugin management with advanced lifecycle control
|
|
4
|
+
*/
|
|
5
|
+
import type { MCP, MCPMetadata, MCPConstructor, PluginLoadResult, PluginExecutionResult, ExecutionContext } from "../contracts/mcp-contract.js";
|
|
6
|
+
/**
|
|
7
|
+
* Enhanced plugin manager with core functionality
|
|
8
|
+
*/
|
|
9
|
+
export declare class CorePluginManager {
|
|
10
|
+
private plugins;
|
|
11
|
+
private constructors;
|
|
12
|
+
private metadata;
|
|
13
|
+
/**
|
|
14
|
+
* Load a plugin from constructor
|
|
15
|
+
*/
|
|
16
|
+
loadPlugin(name: string, Constructor: MCPConstructor, config: any): Promise<PluginLoadResult>;
|
|
17
|
+
/**
|
|
18
|
+
* Execute a plugin operation
|
|
19
|
+
*/
|
|
20
|
+
executePlugin<T = any>(name: string, context: ExecutionContext, args: any): Promise<PluginExecutionResult<T>>;
|
|
21
|
+
/**
|
|
22
|
+
* Get plugin instance
|
|
23
|
+
*/
|
|
24
|
+
getPlugin(name: string): MCP | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Get plugin metadata
|
|
27
|
+
*/
|
|
28
|
+
getPluginMetadata(name: string): MCPMetadata | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* List all loaded plugins
|
|
31
|
+
*/
|
|
32
|
+
listPlugins(): string[];
|
|
33
|
+
/**
|
|
34
|
+
* Unload a plugin
|
|
35
|
+
*/
|
|
36
|
+
unloadPlugin(name: string): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Dispose all plugins
|
|
39
|
+
*/
|
|
40
|
+
dispose(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Default core plugin manager instance
|
|
44
|
+
*/
|
|
45
|
+
export declare const corePluginManager: CorePluginManager;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Plugin Manager
|
|
3
|
+
* Enhanced plugin management with advanced lifecycle control
|
|
4
|
+
*/
|
|
5
|
+
import { mcpLogger } from "../logging.js";
|
|
6
|
+
/**
|
|
7
|
+
* Enhanced plugin manager with core functionality
|
|
8
|
+
*/
|
|
9
|
+
export class CorePluginManager {
|
|
10
|
+
plugins = new Map();
|
|
11
|
+
constructors = new Map();
|
|
12
|
+
metadata = new Map();
|
|
13
|
+
/**
|
|
14
|
+
* Load a plugin from constructor
|
|
15
|
+
*/
|
|
16
|
+
async loadPlugin(name, Constructor, config) {
|
|
17
|
+
try {
|
|
18
|
+
const instance = new Constructor();
|
|
19
|
+
await instance.initialize(config);
|
|
20
|
+
this.plugins.set(name, instance);
|
|
21
|
+
this.constructors.set(name, Constructor);
|
|
22
|
+
this.metadata.set(name, instance.getMetadata());
|
|
23
|
+
mcpLogger.info(`[CorePluginManager] Loaded plugin: ${name}`);
|
|
24
|
+
return {
|
|
25
|
+
success: true,
|
|
26
|
+
plugin: instance,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
mcpLogger.error(`[CorePluginManager] Failed to load plugin ${name}:`, error);
|
|
31
|
+
return {
|
|
32
|
+
success: false,
|
|
33
|
+
error: error instanceof Error ? error.message : String(error),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Execute a plugin operation
|
|
39
|
+
*/
|
|
40
|
+
async executePlugin(name, context, args) {
|
|
41
|
+
const startTime = Date.now();
|
|
42
|
+
try {
|
|
43
|
+
const plugin = this.plugins.get(name);
|
|
44
|
+
if (!plugin) {
|
|
45
|
+
throw new Error(`Plugin ${name} not loaded`);
|
|
46
|
+
}
|
|
47
|
+
const result = await plugin.execute(context, args);
|
|
48
|
+
const executionTime = Date.now() - startTime;
|
|
49
|
+
return {
|
|
50
|
+
success: true,
|
|
51
|
+
result,
|
|
52
|
+
executionTime,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
const executionTime = Date.now() - startTime;
|
|
57
|
+
mcpLogger.error(`[CorePluginManager] Plugin execution failed for ${name}:`, error);
|
|
58
|
+
return {
|
|
59
|
+
success: false,
|
|
60
|
+
error: error instanceof Error ? error.message : String(error),
|
|
61
|
+
executionTime,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get plugin instance
|
|
67
|
+
*/
|
|
68
|
+
getPlugin(name) {
|
|
69
|
+
return this.plugins.get(name);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get plugin metadata
|
|
73
|
+
*/
|
|
74
|
+
getPluginMetadata(name) {
|
|
75
|
+
return this.metadata.get(name);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* List all loaded plugins
|
|
79
|
+
*/
|
|
80
|
+
listPlugins() {
|
|
81
|
+
return Array.from(this.plugins.keys());
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Unload a plugin
|
|
85
|
+
*/
|
|
86
|
+
async unloadPlugin(name) {
|
|
87
|
+
const plugin = this.plugins.get(name);
|
|
88
|
+
if (plugin) {
|
|
89
|
+
await plugin.dispose();
|
|
90
|
+
this.plugins.delete(name);
|
|
91
|
+
this.constructors.delete(name);
|
|
92
|
+
this.metadata.delete(name);
|
|
93
|
+
mcpLogger.info(`[CorePluginManager] Unloaded plugin: ${name}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Dispose all plugins
|
|
98
|
+
*/
|
|
99
|
+
async dispose() {
|
|
100
|
+
const pluginNames = Array.from(this.plugins.keys());
|
|
101
|
+
for (const name of pluginNames) {
|
|
102
|
+
await this.unloadPlugin(name);
|
|
103
|
+
}
|
|
104
|
+
mcpLogger.info("[CorePluginManager] All plugins disposed");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Default core plugin manager instance
|
|
109
|
+
*/
|
|
110
|
+
export const corePluginManager = new CorePluginManager();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin Demo - Example MCP Plugin Usage
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Demo plugin functionality
|
|
6
|
+
*/
|
|
7
|
+
export declare class PluginDemo {
|
|
8
|
+
/**
|
|
9
|
+
* Demonstrate filesystem plugin
|
|
10
|
+
*/
|
|
11
|
+
static demonstrateFileSystem(): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Demonstrate plugin execution via ecosystem
|
|
14
|
+
*/
|
|
15
|
+
static demonstrateEcosystem(): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Demonstrate quick plugin factory
|
|
18
|
+
*/
|
|
19
|
+
static demonstrateQuickFactory(): Promise<void>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin Demo - Example MCP Plugin Usage
|
|
3
|
+
*/
|
|
4
|
+
import { mcpEcosystem } from "../ecosystem.js";
|
|
5
|
+
import { FileSystemMCP } from "../plugins/core/filesystem-mcp.js";
|
|
6
|
+
import { QuickPluginFactory, executePlugin, } from "../adapters/plugin-bridge.js";
|
|
7
|
+
import { mcpLogger } from "../logging.js";
|
|
8
|
+
/**
|
|
9
|
+
* Demo plugin functionality
|
|
10
|
+
*/
|
|
11
|
+
export class PluginDemo {
|
|
12
|
+
/**
|
|
13
|
+
* Demonstrate filesystem plugin
|
|
14
|
+
*/
|
|
15
|
+
static async demonstrateFileSystem() {
|
|
16
|
+
try {
|
|
17
|
+
// Create filesystem plugin instance
|
|
18
|
+
const fsPlugin = new FileSystemMCP();
|
|
19
|
+
await fsPlugin.initialize({ basePath: process.cwd() });
|
|
20
|
+
mcpLogger.info("FileSystem plugin demonstration started");
|
|
21
|
+
// This would normally be done through the ecosystem
|
|
22
|
+
// but we're demonstrating direct usage
|
|
23
|
+
const result = await mcpEcosystem.filesystem({
|
|
24
|
+
action: "listFiles",
|
|
25
|
+
path: ".",
|
|
26
|
+
basePath: process.cwd(),
|
|
27
|
+
});
|
|
28
|
+
mcpLogger.info("File listing result:", result);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
mcpLogger.error("Demo failed:", error);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Demonstrate plugin execution via ecosystem
|
|
36
|
+
*/
|
|
37
|
+
static async demonstrateEcosystem() {
|
|
38
|
+
try {
|
|
39
|
+
await mcpEcosystem.initialize();
|
|
40
|
+
const stats = await mcpEcosystem.getStats();
|
|
41
|
+
mcpLogger.info("MCP Ecosystem stats:", stats);
|
|
42
|
+
// Try to read a file
|
|
43
|
+
const fsPlugin = new FileSystemMCP();
|
|
44
|
+
await fsPlugin.initialize({ basePath: process.cwd() });
|
|
45
|
+
const result = await executePlugin(fsPlugin, createMockContext(), "listFiles", ".");
|
|
46
|
+
mcpLogger.info("Plugin execution result:", result);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
mcpLogger.error("Ecosystem demo failed:", error);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Demonstrate quick plugin factory
|
|
54
|
+
*/
|
|
55
|
+
static async demonstrateQuickFactory() {
|
|
56
|
+
try {
|
|
57
|
+
const fsPlugin = new FileSystemMCP();
|
|
58
|
+
await fsPlugin.initialize({ basePath: process.cwd() });
|
|
59
|
+
const quickPlugin = await QuickPluginFactory.create("demo-plugin", {
|
|
60
|
+
basePath: process.cwd(),
|
|
61
|
+
});
|
|
62
|
+
mcpLogger.info("Quick plugin created:", quickPlugin);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
mcpLogger.error("Quick factory demo failed:", error);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Create a mock execution context for testing
|
|
71
|
+
*/
|
|
72
|
+
function createMockContext() {
|
|
73
|
+
return {
|
|
74
|
+
sessionId: "demo-session",
|
|
75
|
+
userId: "demo-user",
|
|
76
|
+
grantedPermissions: ["fs:read:./**/*", "fs:write:./temp/**/*"],
|
|
77
|
+
secureFS: {
|
|
78
|
+
async readFile(path, encoding) {
|
|
79
|
+
return `Mock content from ${path}`;
|
|
80
|
+
},
|
|
81
|
+
async writeFile(path, content) {
|
|
82
|
+
mcpLogger.info(`Mock write to ${path}`);
|
|
83
|
+
},
|
|
84
|
+
async readdir(path) {
|
|
85
|
+
return ["file1.txt", "file2.json", "subdir"];
|
|
86
|
+
},
|
|
87
|
+
async stat(path) {
|
|
88
|
+
return {
|
|
89
|
+
size: 1024,
|
|
90
|
+
mtime: new Date(),
|
|
91
|
+
isDirectory: () => false,
|
|
92
|
+
isFile: () => true,
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
async mkdir(path, options) {
|
|
96
|
+
mcpLogger.info(`Mock mkdir: ${path}`);
|
|
97
|
+
},
|
|
98
|
+
async exists(path) {
|
|
99
|
+
return true;
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
path: {
|
|
103
|
+
join: (...paths) => paths.join("/"),
|
|
104
|
+
resolve: (...paths) => "/" + paths.join("/"),
|
|
105
|
+
relative: (from, to) => to,
|
|
106
|
+
dirname: (path) => path.split("/").slice(0, -1).join("/"),
|
|
107
|
+
basename: (path, ext) => {
|
|
108
|
+
const name = path.split("/").pop() || "";
|
|
109
|
+
return ext ? name.replace(ext, "") : name;
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
log: (level, message, data) => {
|
|
113
|
+
mcpLogger[level](`[MockContext] ${message}`, data);
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Ecosystem Integration - Bridge Between Research Blueprint and NeuroLink
|
|
3
|
+
* Provides unified interface for plugin management and execution
|
|
4
|
+
*/
|
|
5
|
+
import { MCP } from "./contracts/mcp-contract.js";
|
|
6
|
+
import type { MCPMetadata, ExecutionContext } from "./contracts/mcp-contract.js";
|
|
7
|
+
/**
|
|
8
|
+
* MCP Ecosystem - Main Interface for Plugin Operations
|
|
9
|
+
*/
|
|
10
|
+
export declare class MCPEcosystem {
|
|
11
|
+
private static instance;
|
|
12
|
+
private securityManager;
|
|
13
|
+
private initialized;
|
|
14
|
+
private constructor();
|
|
15
|
+
static getInstance(): MCPEcosystem;
|
|
16
|
+
/**
|
|
17
|
+
* Initialize the MCP ecosystem
|
|
18
|
+
*/
|
|
19
|
+
initialize(): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* List all available MCPs
|
|
22
|
+
*/
|
|
23
|
+
list(): Promise<MCPMetadata[]>;
|
|
24
|
+
/**
|
|
25
|
+
* Get metadata for a specific MCP
|
|
26
|
+
*/
|
|
27
|
+
getMetadata(name: string): Promise<MCPMetadata | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Create and execute an MCP instance
|
|
30
|
+
*/
|
|
31
|
+
execute<T = any>(name: string, config: any, args: any, context?: {
|
|
32
|
+
sessionId?: string;
|
|
33
|
+
userId?: string;
|
|
34
|
+
}): Promise<T>;
|
|
35
|
+
/**
|
|
36
|
+
* Execute filesystem operations using FileSystemMCP
|
|
37
|
+
*/
|
|
38
|
+
filesystem(operation: {
|
|
39
|
+
action: "readFile" | "writeFile" | "listFiles" | "createDir";
|
|
40
|
+
path: string;
|
|
41
|
+
content?: string;
|
|
42
|
+
basePath?: string;
|
|
43
|
+
}): Promise<any>;
|
|
44
|
+
/**
|
|
45
|
+
* Get ecosystem statistics
|
|
46
|
+
*/
|
|
47
|
+
getStats(): Promise<{
|
|
48
|
+
initialized: boolean;
|
|
49
|
+
pluginsDiscovered: number;
|
|
50
|
+
pluginsBySource: Record<string, number>;
|
|
51
|
+
availablePlugins: string[];
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* Create an MCP instance for direct use
|
|
55
|
+
*/
|
|
56
|
+
createInstance<T extends MCP>(name: string, config: any): Promise<T>;
|
|
57
|
+
/**
|
|
58
|
+
* Create execution context for manual MCP usage
|
|
59
|
+
*/
|
|
60
|
+
createExecutionContext(sessionId: string, userId: string, permissions: string[], basePath?: string): ExecutionContext;
|
|
61
|
+
/**
|
|
62
|
+
* Ensure ecosystem is initialized
|
|
63
|
+
*/
|
|
64
|
+
private ensureInitialized;
|
|
65
|
+
/**
|
|
66
|
+
* Get all tools formatted for AI providers
|
|
67
|
+
*/
|
|
68
|
+
getToolsForAI(): Promise<any>;
|
|
69
|
+
/**
|
|
70
|
+
* Dispose of all resources
|
|
71
|
+
*/
|
|
72
|
+
dispose(): Promise<void>;
|
|
73
|
+
}
|
|
74
|
+
export declare const mcpEcosystem: MCPEcosystem;
|
|
75
|
+
export type { MCPMetadata, ExecutionContext, } from "./contracts/mcp-contract.js";
|