/** * RAG File Search Tool * Search files using Retrieval-Augmented Generation with semantic understanding * * This handler provides: * - Semantic file search using RAG technology * - Flexible file type filtering * - Chunking configuration for indexing * - Metadata filtering for refined searches * - Citations and line number references * - AI-generated summaries of findings * * @module @wundr/mcp-server/tools/rag/rag-file-search */ import * as fs from 'fs'; import { z } from 'zod'; import type { McpToolResult } from '../registry.js'; /** * Default maximum results to return */ export declare const DEFAULT_MAX_RESULTS = 10; /** * Default store name prefix */ export declare const DEFAULT_STORE_NAME_PREFIX = "rag-store-"; /** * Default minimum relevance score threshold */ export declare const DEFAULT_MIN_SCORE = 0.3; /** * Maximum files to index in a single operation */ export declare const MAX_FILES_TO_INDEX = 1000; /** * Maximum file size to index (in bytes) */ export declare const MAX_FILE_SIZE: number; /** * Supported file type categories */ export type FileTypeCategory = 'code' | 'documentation' | 'config' | 'data' | 'all'; /** * Mapping of file type categories to extensions */ export declare const FILE_TYPE_EXTENSIONS: Record; /** * Default file patterns to exclude */ export declare const DEFAULT_EXCLUDE_PATTERNS: string[]; /** * Filter files by type category * * @param filePath - Path to the file * @param fileTypes - Array of file type categories to include * @returns True if the file matches any of the specified categories */ export declare function filterByFileType(filePath: string, fileTypes?: FileTypeCategory[]): boolean; /** * Get file extensions for specified file type categories * * @param fileTypes - Array of file type categories * @returns Array of file extensions (with dots) */ export declare function getExtensionsForFileTypes(fileTypes?: FileTypeCategory[]): string[]; /** * Convert file type categories to glob include patterns * * @param fileTypes - Array of file type categories * @returns Array of glob patterns */ export declare function fileTypesToIncludePatterns(fileTypes?: FileTypeCategory[]): string[]; /** * Detect programming language from file extension * * @param filePath - Path to the file * @returns Detected language or undefined */ export declare function detectLanguage(filePath: string): string | undefined; /** * Generate a store name from the target path * * @param targetPath - Target directory path * @returns Generated store name */ export declare function generateStoreName(targetPath: string): string; export declare const RagFileSearchInputSchema: z.ZodObject<{ targetPath: z.ZodString; query: z.ZodString; includePatterns: z.ZodOptional>; excludePatterns: z.ZodOptional>; fileTypes: z.ZodOptional, "many">>; storeName: z.ZodOptional; forceReindex: z.ZodDefault>; chunkingConfig: z.ZodOptional>; chunkSize: z.ZodOptional; chunkOverlap: z.ZodOptional; minChunkSize: z.ZodOptional; maxChunksPerFile: z.ZodOptional; }, "strip", z.ZodTypeAny, { strategy?: "semantic" | "fixed" | "paragraph" | "sentence" | undefined; chunkSize?: number | undefined; chunkOverlap?: number | undefined; minChunkSize?: number | undefined; maxChunksPerFile?: number | undefined; }, { strategy?: "semantic" | "fixed" | "paragraph" | "sentence" | undefined; chunkSize?: number | undefined; chunkOverlap?: number | undefined; minChunkSize?: number | undefined; maxChunksPerFile?: number | undefined; }>>; metadataFilter: z.ZodOptional; extension: z.ZodOptional]>>; modifiedAfter: z.ZodOptional; modifiedBefore: z.ZodOptional; custom: z.ZodOptional>>; }, "strip", z.ZodTypeAny, { custom?: Record | undefined; extension?: string | string[] | undefined; pathContains?: string | undefined; modifiedAfter?: string | undefined; modifiedBefore?: string | undefined; }, { custom?: Record | undefined; extension?: string | string[] | undefined; pathContains?: string | undefined; modifiedAfter?: string | undefined; modifiedBefore?: string | undefined; }>>; maxResults: z.ZodDefault>; }, "strip", z.ZodTypeAny, { query: string; maxResults: number; targetPath: string; forceReindex: boolean; includePatterns?: string[] | undefined; excludePatterns?: string[] | undefined; storeName?: string | undefined; fileTypes?: ("code" | "data" | "config" | "all" | "documentation")[] | undefined; chunkingConfig?: { strategy?: "semantic" | "fixed" | "paragraph" | "sentence" | undefined; chunkSize?: number | undefined; chunkOverlap?: number | undefined; minChunkSize?: number | undefined; maxChunksPerFile?: number | undefined; } | undefined; metadataFilter?: { custom?: Record | undefined; extension?: string | string[] | undefined; pathContains?: string | undefined; modifiedAfter?: string | undefined; modifiedBefore?: string | undefined; } | undefined; }, { query: string; targetPath: string; includePatterns?: string[] | undefined; excludePatterns?: string[] | undefined; maxResults?: number | undefined; storeName?: string | undefined; forceReindex?: boolean | undefined; fileTypes?: ("code" | "data" | "config" | "all" | "documentation")[] | undefined; chunkingConfig?: { strategy?: "semantic" | "fixed" | "paragraph" | "sentence" | undefined; chunkSize?: number | undefined; chunkOverlap?: number | undefined; minChunkSize?: number | undefined; maxChunksPerFile?: number | undefined; } | undefined; metadataFilter?: { custom?: Record | undefined; extension?: string | string[] | undefined; pathContains?: string | undefined; modifiedAfter?: string | undefined; modifiedBefore?: string | undefined; } | undefined; }>; export type RagFileSearchInput = z.infer; /** * Citation information for a search result */ export interface Citation { /** Source file path */ filePath: string; /** Starting line number (1-indexed) */ startLine: number; /** Ending line number (1-indexed) */ endLine: number; /** Column start position */ startColumn?: number; /** Column end position */ endColumn?: number; /** Highlighted snippet */ snippet: string; } /** * A matched chunk from the search */ export interface MatchedChunk { /** Chunk content */ content: string; /** Relevance score (0-1) */ score: number; /** Citation information */ citation: Citation; /** Chunk metadata */ metadata?: Record; } /** * Search result for a single file */ export interface FileSearchResult { /** File path */ filePath: string; /** Relative path from target */ relativePath: string; /** Overall relevance score for this file */ relevanceScore: number; /** Matched chunks within this file */ matchedChunks: MatchedChunk[]; /** File metadata */ metadata: { /** File size in bytes */ size: number; /** Last modified timestamp */ lastModified: string; /** File extension */ extension: string; /** Total chunks in file */ totalChunks: number; /** Language (if detected) */ language?: string; }; } /** * Output from RAG file search */ export interface RagFileSearchOutput { /** Search results sorted by relevance */ results: FileSearchResult[]; /** AI-generated summary of findings */ summary: string; /** Total number of files searched */ totalFilesSearched: number; /** Total number of chunks searched */ totalChunksSearched: number; /** Search duration in milliseconds */ searchDuration: number; /** Index statistics */ indexStats: { /** Whether the index was created fresh */ wasReindexed: boolean; /** Number of files indexed */ filesIndexed: number; /** Number of chunks created */ chunksCreated: number; /** Indexing duration in milliseconds */ indexingDuration?: number; }; /** Store information */ storeInfo: { /** Store name */ name: string; /** Store creation timestamp */ createdAt: string; /** Store last updated timestamp */ lastUpdated: string; }; } /** * Apply metadata filters to a file * * @param filePath - Path to the file * @param stats - File stats * @param filter - Metadata filter to apply * @returns True if the file passes the filter */ export declare function applyMetadataFilter(filePath: string, stats: fs.Stats, filter?: RagFileSearchInput['metadataFilter']): boolean; /** * RAG File Search Handler * * Executes semantic search against files in the specified path. * * @param input - Search input parameters * @returns Search results with relevance scores, citations, and AI summary */ export declare function ragFileSearchHandler(input: RagFileSearchInput): Promise>; /** * Tool definition for MCP registration */ export declare const ragFileSearchTool: { name: string; description: string; inputSchema: { type: string; properties: { targetPath: { type: string; description: string; }; query: { type: string; description: string; }; includePatterns: { type: string; items: { type: string; }; description: string; }; excludePatterns: { type: string; items: { type: string; }; description: string; }; fileTypes: { type: string; items: { type: string; enum: string[]; }; description: string; }; storeName: { type: string; description: string; }; forceReindex: { type: string; description: string; default: boolean; }; chunkingConfig: { type: string; properties: { strategy: { type: string; enum: string[]; description: string; }; chunkSize: { type: string; description: string; }; chunkOverlap: { type: string; description: string; }; minChunkSize: { type: string; description: string; }; maxChunksPerFile: { type: string; description: string; }; }; description: string; }; metadataFilter: { type: string; properties: { pathContains: { type: string; description: string; }; extension: { oneOf: ({ type: string; items?: undefined; } | { type: string; items: { type: string; }; })[]; description: string; }; modifiedAfter: { type: string; description: string; }; modifiedBefore: { type: string; description: string; }; }; description: string; }; maxResults: { type: string; description: string; default: number; }; }; required: string[]; }; category: string; }; //# sourceMappingURL=rag-file-search.d.ts.map