/** * delete_index Tool * * MCP tool to remove the search index for the current project. Deletes all * index data including the LanceDB database, fingerprints, config, metadata, * and logs. Stops the file watcher if running. Requires user confirmation * (destructive operation). * * Features: * - Safe path validation to prevent accidental deletion of user files * - File watcher stop before deletion * - Complete cleanup of all index files * - Graceful handling of missing index * - Requires user confirmation (irreversible operation) */ import { z } from 'zod'; import type { ToolContext } from './searchCode.js'; import type { StrategyOrchestrator } from '../engines/strategyOrchestrator.js'; /** * Input schema for delete_index tool * * No required inputs - uses current directory context from the MCP client. */ export declare const DeleteIndexInputSchema: z.ZodObject<{}, z.core.$strip>; /** * Inferred input type from schema */ export type DeleteIndexInput = z.infer; /** * Output status for delete_index tool */ export type DeleteIndexStatus = 'success' | 'cancelled' | 'not_found'; /** * Output structure for delete_index tool */ export interface DeleteIndexOutput { /** Result status */ status: DeleteIndexStatus; /** Absolute path to the project root (if successful) */ projectPath?: string; /** Additional message */ message?: string; } /** * Extended tool context with optional watcher stop callback */ export interface DeleteIndexContext extends ToolContext { /** Whether user has confirmed the operation (for MCP confirmation flow) */ confirmed?: boolean; /** Optional callback to stop the file watcher before deletion */ stopWatcher?: () => Promise; /** Optional callback to close LanceDB connection before deletion */ closeLanceDB?: () => Promise; /** Optional strategy orchestrator for stopping strategy before deletion */ orchestrator?: StrategyOrchestrator; } /** * Verify that a path is within the safe indexes directory * * This is a security measure to prevent accidental deletion of arbitrary * directories on the user's system. Only paths within ~/.mcp/search/indexes/ * are considered safe to delete. * * @param targetPath - The path to validate * @returns true if the path is safe to delete * * @example * ```typescript * isPathSafeToDelete('/home/user/.mcp/search/indexes/abc123') // => true * isPathSafeToDelete('/home/user/Documents') // => false * isPathSafeToDelete('/etc/passwd') // => false * ``` */ export declare function isPathSafeToDelete(targetPath: string): boolean; /** * Safely delete an index directory * * Validates the path is within the safe indexes directory before deletion. * Handles partial deletion gracefully - continues deleting remaining files * if some files fail to delete. * * @param indexPath - Absolute path to the index directory * @returns Object with success status and any warnings * @throws MCPError if path validation fails (security error) * * @example * ```typescript * const result = await safeDeleteIndex('/home/user/.mcp/search/indexes/abc123'); * if (result.warnings.length > 0) { * console.warn('Some files could not be deleted:', result.warnings); * } * ``` */ export declare function safeDeleteIndex(indexPath: string): Promise<{ success: boolean; warnings: string[]; }>; /** * Check if an index exists for the project * * @param projectPath - Absolute path to the project root * @returns true if an index exists (has metadata.json) */ export declare function checkIndexExistsForDelete(projectPath: string): Promise; /** * Delete the search index for the current project * * Stops the file watcher, closes LanceDB connection, and removes all index * data including the database, fingerprints, config, metadata, and logs. * * SECURITY FIX (SMCP-057): Uses IndexingLock to prevent race conditions between * concurrent create/delete/reindex operations (TOCTOU vulnerability fix). * * @param input - The input (empty object, uses project context) * @param context - Tool context containing the project path and optional callbacks * @returns Deletion result with status * * @example * ```typescript * const result = await deleteIndex( * {}, * { * projectPath: '/path/to/project', * confirmed: true, * stopWatcher: async () => { watcher.stop(); }, * closeLanceDB: async () => { store.close(); } * } * ); * * console.log(result.status); // 'success' | 'cancelled' | 'not_found' * ``` */ export declare function deleteIndex(input: DeleteIndexInput, context: DeleteIndexContext): Promise; /** * MCP tool definition for delete_index * * This tool removes the search index for the current project. * It REQUIRES confirmation as it is a destructive, irreversible operation. */ export declare const deleteIndexTool: { name: string; description: string; inputSchema: { type: "object"; properties: {}; required: string[]; }; requiresConfirmation: boolean; }; /** * Get confirmation message for the tool * * Returns a user-friendly message asking for confirmation before deletion. * * @param projectPath - The detected project path (optional) * @returns Confirmation message string */ export declare function getDeleteConfirmationMessage(projectPath?: string): string; //# sourceMappingURL=deleteIndex.d.ts.map