/** * MCP Tool Registry System * Provides centralized registration and management of MCP tools * * @module @wundr/mcp-server/tools/registry */ import type { ToolName } from './schemas'; import type { z } from 'zod'; /** * MCP Tool definition interface */ export interface McpTool { /** Unique tool name */ name: string; /** Human-readable description */ description: string; /** JSON Schema for input validation */ inputSchema: Record; /** Tool category for organization (optional for backward compatibility) */ category?: string; /** Tool handler function (optional for static tool definitions) */ handler?: (input: TInput) => Promise>; /** Optional Zod schema for runtime validation */ zodSchema?: z.ZodType; } /** * Result returned by MCP tool handlers */ export interface McpToolResult { /** Whether the operation succeeded */ success: boolean; /** Result data if successful */ data?: T; /** Human-readable message describing the result */ message?: string; /** Error message if failed */ error?: string; /** Detailed error information */ errorDetails?: { code: string; message: string; stack?: string; context?: Record; }; /** Warnings that don't prevent success */ warnings?: string[]; /** Metadata about the operation */ metadata?: { duration?: number; timestamp?: string; toolVersion?: string; }; } /** * Tool registration options */ export interface ToolRegistrationOptions { /** Override existing tool with same name */ override?: boolean; /** Enable debug logging for this tool */ debug?: boolean; /** Tool version */ version?: string; } /** * Tool execution context */ export interface ToolExecutionContext { /** Working directory */ cwd?: string; /** Environment variables */ env?: Record; /** Timeout in milliseconds */ timeout?: number; /** Enable verbose output */ verbose?: boolean; } /** * Central registry for MCP tools * Provides registration, lookup, and execution of tools */ export declare class ToolRegistry { private tools; private categories; private version; constructor(); /** * Register a new MCP tool * * @param tool - Tool definition to register * @param options - Registration options * @throws Error if tool already exists and override is false * * @example * ```typescript * registry.register({ * name: 'my-tool', * description: 'My custom tool', * inputSchema: { type: 'object', properties: {} }, * category: 'custom', * handler: async (input) => ({ success: true, data: input }), * }); * ``` */ register(tool: McpTool, options?: ToolRegistrationOptions): void; /** * Unregister a tool by name * * @param name - Tool name to unregister * @returns true if tool was removed, false if not found */ unregister(name: string): boolean; /** * Get a registered tool by name * * @param name - Tool name * @returns Tool definition or undefined */ get(name: string): McpTool | undefined; /** * Check if a tool is registered * * @param name - Tool name * @returns true if tool exists */ has(name: string): boolean; /** * Get all registered tools * * @returns Array of all tool definitions */ getAll(): McpTool[]; /** * Get tools by category * * @param category - Category name * @returns Array of tools in category */ getByCategory(category: string): McpTool[]; /** * Get all category names * * @returns Array of category names */ getCategories(): string[]; /** * Execute a tool by name * * @param name - Tool name * @param input - Tool input * @param context - Execution context * @returns Tool result * * @example * ```typescript * const result = await registry.execute('computer-setup', { * profile: 'fullstack', * dryRun: true, * }); * ``` */ execute(name: string, input: TInput, context?: ToolExecutionContext): Promise>; /** * Get MCP-compatible tool definitions for all registered tools * Used for MCP server tool listing * * @returns Array of MCP tool definitions */ getMcpToolDefinitions(): Array<{ name: string; description: string; inputSchema: Record; }>; /** * Export registry state for debugging/logging * * @returns Registry state object */ exportState(): { version: string; toolCount: number; tools: Array<{ name: string; category: string; description: string; }>; categories: Record; }; } /** * Create a new tool registry with default Wundr tools * * @returns Configured ToolRegistry instance */ export declare function createToolRegistry(): ToolRegistry; /** * Create an MCP tool definition from a schema entry * * @param name - Tool name (must be a key in ToolSchemas) * @param handler - Tool handler function * @returns McpTool definition */ export declare function createToolFromSchema(name: ToolName, handler: (input: TInput) => Promise>): McpTool; /** * Global tool registry instance * Use this for most cases unless you need isolated registries */ export declare const globalRegistry: ToolRegistry; /** * Create a successful tool result * * @param data - Result data * @param warnings - Optional warnings * @returns McpToolResult with success: true */ export declare function successResult(data: T, warnings?: string[]): McpToolResult; /** * Create an error tool result * * @param error - Error message * @param code - Error code * @param context - Additional error context * @returns McpToolResult with success: false */ export declare function errorResult(error: string, code?: string, context?: Record): McpToolResult; /** * Wrap an async function with error handling for tool handlers * * @param fn - Async function to wrap * @returns Wrapped function that returns McpToolResult */ export declare function wrapHandler(fn: (input: TInput) => Promise): (input: TInput) => Promise>; //# sourceMappingURL=registry.d.ts.map