UNPKG

@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

149 lines (148 loc) 4.7 kB
/** * NeuroLink MCP Server Factory * Factory-First Architecture: MCP servers create tools for internal orchestration * Compatible with Lighthouse MCP patterns for seamless migration */ import { z } from "zod"; /** * Input validation schemas */ const ServerConfigSchema = z.object({ id: z.string().min(1, "Server ID is required"), title: z.string().min(1, "Server title is required"), description: z.string().optional(), version: z.string().optional(), category: z .enum([ "aiProviders", "frameworks", "development", "business", "content", "data", "integrations", "automation", "analysis", "custom", ]) .optional(), visibility: z.enum(["public", "private", "organization"]).optional(), metadata: z.record(z.any()).optional(), dependencies: z.array(z.string()).optional(), capabilities: z.array(z.string()).optional(), }); /** * Create MCP Server Factory Function * * Core factory function for creating Lighthouse-compatible MCP servers. * Follows Factory-First architecture where tools are internal implementation. * * @param config Server configuration with minimal required fields * @returns Fully configured MCP server ready for tool registration * * @example * ```typescript * const aiCoreServer = createMCPServer({ * id: 'neurolink-ai-core', * title: 'NeuroLink AI Core', * description: 'Core AI provider tools', * category: 'aiProviders' * }); * * aiCoreServer.registerTool({ * name: 'generate', * description: 'Generate text using AI providers', * execute: async (params, context) => { * // Tool implementation * return { success: true, data: result }; * } * }); * ``` */ export function createMCPServer(config) { // Validate configuration const validatedConfig = ServerConfigSchema.parse(config); // Create server with sensible defaults const server = { // Required fields id: validatedConfig.id, title: validatedConfig.title, // Optional fields with defaults description: validatedConfig.description, version: validatedConfig.version || "1.0.0", category: validatedConfig.category || "custom", visibility: validatedConfig.visibility || "private", // Tool management tools: {}, // Tool registration method registerTool(tool) { // Validate tool has required fields if (!tool.name || !tool.description || !tool.execute) { throw new Error(`Invalid tool: name, description, and execute are required`); } // Check for duplicate tool names if (this.tools[tool.name]) { throw new Error(`Tool '${tool.name}' already exists in server '${this.id}'`); } // Register the tool this.tools[tool.name] = { ...tool, // Add server metadata to tool metadata: { ...tool.metadata, serverId: this.id, serverCategory: this.category, registeredAt: Date.now(), }, }; return this; }, // Extension points metadata: validatedConfig.metadata || {}, dependencies: validatedConfig.dependencies || [], capabilities: validatedConfig.capabilities || [], }; return server; } /** * Utility function to validate tool interface */ export function validateTool(tool) { try { // Check required fields if (!tool.name || typeof tool.name !== "string") { return false; } if (!tool.description || typeof tool.description !== "string") { return false; } if (!tool.execute || typeof tool.execute !== "function") { return false; } // Validate optional schemas if present if (tool.inputSchema && !(tool.inputSchema instanceof z.ZodSchema)) { return false; } if (tool.outputSchema && !(tool.outputSchema instanceof z.ZodSchema)) { return false; } return true; } catch (error) { return false; } } /** * Utility function to get server info */ export function getServerInfo(server) { return { id: server.id, title: server.title, description: server.description, category: server.category, toolCount: Object.keys(server.tools).length, capabilities: server.capabilities || [], }; } // Types are already exported above via export interface declarations