@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, and professional CLI. Built-in tools operational, 58+ external MCP servers discoverable. Connect to filesystem, GitHub, database operations, and more. Build, test, and
159 lines (158 loc) • 4.87 kB
JavaScript
/**
* MCP Registry - Industry Standard Interface with camelCase
*/
import { registryLogger } from "../utils/logger.js";
/**
* Simple MCP registry for plugin management
* Maintains backward compatibility with existing code
*/
export class MCPRegistry {
plugins = new Map();
/**
* Register a plugin
*/
register(plugin) {
this.plugins.set(plugin.metadata.name, plugin);
registryLogger.info(`Registered plugin: ${plugin.metadata.name}`);
}
/**
* Unregister a plugin
*/
unregister(name) {
const removed = this.plugins.delete(name);
if (removed) {
registryLogger.info(`Unregistered plugin: ${name}`);
}
return removed;
}
/**
* Get a plugin
*/
get(name) {
return this.plugins.get(name);
}
/**
* List all plugins
*/
list() {
return Array.from(this.plugins.values());
}
/**
* Check if plugin exists
*/
has(name) {
return this.plugins.has(name);
}
/**
* Clear all plugins
*/
clear() {
this.plugins.clear();
registryLogger.info("Registry cleared");
}
/**
* Register a server (compatible with new interface)
*/
async registerServer(serverId, serverConfig, context) {
const plugin = {
metadata: {
name: serverId,
description: typeof serverConfig === "object" && serverConfig
? serverConfig.description ||
"No description"
: "No description",
},
tools: typeof serverConfig === "object" && serverConfig
? serverConfig.tools
: {},
configuration: typeof serverConfig === "object" && serverConfig
? serverConfig
: {},
};
this.register(plugin);
}
/**
* Execute a tool (mock implementation for tests)
*/
async executeTool(toolName, args, context) {
registryLogger.info(`Executing tool: ${toolName}`);
return { result: `Mock execution of ${toolName}`, args };
}
/**
* List all tools (compatible with new interface)
*/
async listTools(context) {
const tools = this.list().map((plugin) => ({
name: plugin.metadata.name,
description: plugin.metadata.description || "No description",
serverId: plugin.metadata.name,
category: "general",
}));
return tools;
}
// Legacy methods for backward compatibility
/**
* Register a server (legacy sync version)
*/
registerServerSync(plugin) {
this.register(plugin);
}
/**
* Execute a tool (legacy sync version)
*/
executeToolSync(toolName, args) {
registryLogger.info(`Executing tool (sync): ${toolName}`);
return { result: `Mock execution of ${toolName}`, args };
}
/**
* List all tools (legacy sync version)
*/
listToolsSync() {
const tools = this.list().map((plugin) => ({
name: plugin.metadata.name,
description: plugin.metadata.description || "No description",
}));
return tools;
}
/**
* List all registered server IDs
*
* Returns an array of server IDs that are currently registered in the MCP registry.
* This complements listTools() by providing server-level information, while listTools()
* provides tool-level information across all servers.
*
* @returns Array of registered server identifier strings
* @see listTools() for getting detailed tool information from all servers
* @see list() for getting complete server metadata objects
*
* @example
* ```typescript
* const serverIds = registry.listServers();
* // ['ai-core', 'external-api', 'database-connector']
*
* // Compare with listTools() for comprehensive overview:
* const servers = registry.listServers(); // ['server1', 'server2']
* const tools = await registry.listTools(); // [{ name: 'tool1', serverId: 'server1' }, ...]
* ```
*/
listServers() {
return Array.from(this.plugins.keys());
}
}
/**
* Enhanced MCP Registry implementation with config integration
* Will be implemented in Phase 3.2
*/
export class McpRegistryImpl {
baseRegistry = new MCPRegistry();
// Additional implementation will be added in Phase 3.2
async registerServer(serverId, serverConfig, context) {
return this.baseRegistry.registerServer(serverId, serverConfig, context);
}
async executeTool(toolName, args, context) {
return this.baseRegistry.executeTool(toolName, args, context);
}
async listTools(context) {
return this.baseRegistry.listTools(context);
}
}