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

133 lines (132 loc) 4.11 kB
/** * NeuroLink SDK Tool Registration API * Simple interface for developers to register custom tools */ import { z } from "zod"; import { logger } from "../utils/logger.js"; import type { MCPServerInfo, MCPServerCategory } from "../types/mcpTypes.js"; import type { ToolArgs, ToolContext as CoreToolContext, ToolResult, SimpleTool as CoreSimpleTool, ZodUnknownSchema } from "../types/tools.js"; import type { JsonValue } from "../types/common.js"; /** * Enhanced validation configuration */ declare const VALIDATION_CONFIG: { readonly NAME_MIN_LENGTH: 2; readonly NAME_MAX_LENGTH: number; readonly DESCRIPTION_MIN_LENGTH: 10; readonly DESCRIPTION_MAX_LENGTH: number; readonly RESERVED_NAMES: Set<string>; readonly RECOMMENDED_PATTERNS: readonly ["get_data", "fetch_info", "calculate_value", "send_message", "create_item", "update_record", "delete_file", "validate_input"]; readonly COMPILED_PATTERN_REGEXES: RegExp[]; }; /** * Context provided to tools during execution * Extends the core ToolContext with SDK-specific features */ export interface ToolContext extends CoreToolContext { /** * Current session ID */ sessionId: string; /** * AI provider being used */ provider?: string; /** * Model being used */ model?: string; /** * Call another tool */ callTool?: (name: string, params: ToolArgs) => Promise<ToolResult>; /** * Logger instance */ logger: typeof logger; } /** * Simple tool interface for SDK users * Extends the core SimpleTool with specific types */ export interface SimpleTool<TArgs = ToolArgs, TResult = JsonValue> extends Omit<CoreSimpleTool<TArgs, TResult>, "execute"> { /** * Tool description that helps AI understand when to use it */ description: string; /** * Parameters schema using Zod (optional) */ parameters?: ZodUnknownSchema; /** * Tool execution function */ execute: (params: TArgs, context?: ToolContext) => Promise<TResult>; /** * Optional metadata */ metadata?: { category?: string; version?: string; author?: string; tags?: string[]; documentation?: string; [key: string]: JsonValue | undefined; }; } /** * Creates a MCPServerInfo from a set of tools */ export declare function createMCPServerFromTools(serverId: string, tools: Record<string, SimpleTool>, metadata?: { title?: string; description?: string; category?: MCPServerCategory; version?: string; author?: string; [key: string]: JsonValue | undefined; }): MCPServerInfo; /** * Helper to create a tool with type safety */ export declare function createTool<TParams = ToolArgs>(config: SimpleTool): SimpleTool; /** * Helper to create a validated tool with suggested improvements */ export declare function createValidatedTool(name: string, config: SimpleTool, options?: { strict?: boolean; suggestions?: boolean; }): SimpleTool; /** * Helper to create a tool with typed parameters */ export declare function createTypedTool<TParams extends ZodUnknownSchema>(config: Omit<SimpleTool, "execute"> & { parameters: TParams; execute: (params: z.infer<TParams>, context?: ToolContext) => Promise<JsonValue> | JsonValue; }): SimpleTool; /** * Validate tool configuration with detailed error messages */ export declare function validateTool(name: string, tool: SimpleTool): void; /** * Utility to validate multiple tools at once */ export declare function validateTools(tools: Record<string, SimpleTool>): { valid: string[]; invalid: Array<{ name: string; error: string; }>; }; /** * Get validation configuration for external inspection */ export declare function getValidationConfig(): typeof VALIDATION_CONFIG; /** * Check if a tool name is available (not reserved) */ export declare function isToolNameAvailable(name: string): boolean; /** * Suggest alternative tool names if the provided name is invalid */ export declare function suggestToolNames(baseName: string): string[]; export {};