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

216 lines (215 loc) 7.16 kB
/** * NeuroLink MCP Server Factory * Factory-First Architecture: MCP servers create tools for internal orchestration * Compatible with MCP patterns for seamless integration */ import type { ExecutionContext } from "./contracts/mcpContract.js"; /** * MCP Server Categories for organization and discovery */ export type MCPServerCategory = "aiProviders" | "frameworks" | "development" | "business" | "content" | "data" | "integrations" | "automation" | "analysis" | "custom"; /** * Tool execution context - Rich context passed to every tool execution * Following standard patterns for rich tool context * Extends ExecutionContext for compatibility */ export interface NeuroLinkExecutionContext extends ExecutionContext { aiProvider?: string; modelId?: string; temperature?: number; maxTokens?: number; appId?: string; clientId?: string; clientVersion?: string; organizationId?: string; projectId?: string; environment?: string; environmentType?: "development" | "staging" | "production"; platform?: string; device?: string; browser?: string; userAgent?: string; frameworkType?: "react" | "vue" | "svelte" | "next" | "nuxt" | "sveltekit"; toolChain?: string[]; parentToolId?: string; locale?: string; timezone?: string; ipAddress?: string; requestId?: string; timestamp?: number; permissions?: string[]; features?: string[]; enableDemoMode?: boolean; securityLevel?: "public" | "private" | "organization"; metadata?: Record<string, unknown>; [key: string]: unknown; } /** * Tool execution result - Standardized result format */ export interface ToolResult { success: boolean; data?: unknown; error?: string | Error; usage?: { tokens?: number; cost?: number; provider?: string; model?: string; executionTime?: number; }; metadata?: { toolName?: string; serverId?: string; serverTitle?: string; sessionId?: string; timestamp?: number; executionTime?: number; executionId?: string; [key: string]: unknown; }; } /** * MCP Tool Interface - Standalone definition to avoid confusion with ToolDefinition execute signature */ /** * NeuroLink MCP Tool Interface - Standardized tool definition for MCP integration * * This interface defines the contract for all tools in the NeuroLink ecosystem, * ensuring consistent execution patterns and metadata handling across different * MCP servers and tool implementations. * * Key features: * - Promise-based execution with ToolResult return type * - Rich context support for session management and permissions * - Optional schema validation for input/output * - Comprehensive metadata support for tool discovery * * @example * ```typescript * const calculatorTool: NeuroLinkMCPTool = { * name: "calculator", * description: "Performs basic arithmetic operations", * category: "math", * inputSchema: z.object({ a: z.number(), b: z.number(), op: z.string() }), * async execute(params, context) { * const { a, b, op } = params as { a: number; b: number; op: string }; * const result = op === "add" ? a + b : a - b; * return { success: true, data: result }; * } * }; * ``` */ export interface NeuroLinkMCPTool { /** Unique tool identifier for MCP registration and execution */ name: string; /** Human-readable description of tool functionality */ description: string; /** Optional category for tool organization and discovery */ category?: string; /** Optional input schema for parameter validation (Zod or JSON Schema) */ inputSchema?: unknown; /** Optional output schema for result validation */ outputSchema?: unknown; /** Implementation status flag for development tracking */ isImplemented?: boolean; /** Required permissions for tool execution in secured environments */ permissions?: string[]; /** Tool version for compatibility and update management */ version?: string; /** Additional metadata for tool information and capabilities */ metadata?: Record<string, unknown>; /** * Tool execution function with standardized signature * * @param params - Input parameters for the tool (validated against inputSchema if provided) * @param context - Execution context with session, user, and environment information * @returns Promise resolving to ToolResult with success status, data, and metadata * @throws ValidationError if parameters fail validation */ execute: (params: unknown, context: NeuroLinkExecutionContext) => Promise<ToolResult>; } /** * MCP Server Interface - Standard compatible */ export interface NeuroLinkMCPServer { id: string; title: string; description?: string; version?: string; category?: MCPServerCategory; visibility?: "public" | "private" | "organization"; tools: Record<string, NeuroLinkMCPTool>; registerTool(tool: NeuroLinkMCPTool): NeuroLinkMCPServer; metadata?: Record<string, unknown>; dependencies?: string[]; capabilities?: string[]; } /** * MCP Server Configuration for creation */ export interface MCPServerConfig { id: string; title: string; description?: string; version?: string; category?: MCPServerCategory; visibility?: "public" | "private" | "organization"; metadata?: Record<string, unknown>; dependencies?: string[]; capabilities?: string[]; } /** * Create MCP Server Factory Function * * Core factory function for creating 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 declare function createMCPServer(config: MCPServerConfig): NeuroLinkMCPServer; /** * Utility function to validate tool interface using centralized validation * Ensures proper async patterns and type safety */ export declare function validateTool(tool: NeuroLinkMCPTool): boolean; /** * Utility function to get server info */ export declare function getServerInfo(server: NeuroLinkMCPServer): { id: string; title: string; description?: string; category?: MCPServerCategory; toolCount: number; capabilities: string[]; }; /** * Async utility function to validate all tools in a server * Ensures all registered tools follow proper async patterns */ export declare function validateServerTools(server: NeuroLinkMCPServer): Promise<{ isValid: boolean; invalidTools: string[]; errors: string[]; }>;