import { type RagContentBlock } from './error-utils.js'; import type { DeleteFileInput, IngestDataInput, IngestFileInput, QueryDocumentsInput, RAGServerConfig, ReadChunkNeighborsInput } from './types.js'; /** RAG server compliant with MCP Protocol */ export declare class RAGServer { private readonly server; private readonly vectorStore; private readonly embedder; private readonly chunker; private readonly parser; private readonly dbPath; /** * One or more allowed document base directories — REALPATH-normalized * (the validation/security domain). Passed to `DocumentParser` as the * security boundary. NOT used for `list_files` scanning/display; that uses * the NORMAL-path `rawBaseDirs` below. Normalized from either the legacy * `{ baseDir }` config shape or the new `{ baseDirs }` shape so downstream * readers do not need to branch on shape. */ private readonly baseDirs; /** * Normal-path (resolve()) roots, index-aligned with `baseDirs`, for * user-facing `list_files` scan/display. Falls back to `baseDirs` for legacy * `{ baseDir }` callers. See {@link BaseDirsConfig} for the path policy. */ private readonly rawBaseDirs; /** Legacy single-root accessor for `rawBaseDirs`. Derived from `rawBaseDirs[0]`. */ private readonly rawBaseDir; private readonly cacheDir; private readonly excludePaths; private readonly configWarnings; /** * Structured base-dirs resolution error. When non-null, the server is in * degraded mode: `status` remains callable so the user can diagnose the * problem via MCP, while root-dependent tools should surface this error * before doing DB or filesystem work. See `resolveBaseDirs` for the error * semantics. */ private readonly configError; private readonly minChunkLength; private readonly device; constructor(config: RAGServerConfig); /** * Fail-fast guard for root-dependent tools. When a {@link BaseDirsConfigError} * is stored on the instance the server is in degraded mode (invalid * `BASE_DIRS` — see `resolveBaseDirs`) and every root-dependent tool MUST * reject BEFORE any DB / embedder / parser access so the user sees the * configuration problem unambiguously. Throws the stored * {@link BaseDirsConfigError} (kind `config`) so the central dispatcher * mapper renders it as `McpError(InvalidParams)` — error→code ownership * stays in exactly one place instead of being hand-built here. * * `status` deliberately does NOT call this helper; it remains callable in * degraded mode and exposes the error via a diagnostic content block so * the user can recover via MCP without inspecting stderr. */ private assertConfigOk; /** * Append the centralized config-warning blocks to a handler response. * Every tool handler funnels through this method so the warning shape * stays in exactly one place (design-doc-mandated countermeasure for the * "warning shape changes touch many handlers" risk). */ private withWarnings; /** * Set up MCP handlers */ private setupHandlers; /** * Initialization */ initialize(): Promise; /** * query_documents tool handler */ handleQueryDocuments(args: QueryDocumentsInput): Promise<{ content: RagContentBlock[]; }>; /** * ingest_file tool handler (re-ingestion support, transaction processing, rollback capability) */ handleIngestFile(args: IngestFileInput): Promise<{ content: RagContentBlock[]; }>; /** * ingest_data tool handler * Saves raw content to raw-data directory and calls handleIngestFile internally * * For HTML content: * - Parses HTML and extracts main content using Readability * - Converts to Markdown for better chunking * - Saves as .md file */ handleIngestData(args: IngestDataInput): Promise<{ content: RagContentBlock[]; }>; /** * list_files tool handler * * Scans the normal-path roots (`this.rawBaseDirs`) so scanned paths match the * resolve()-stored DB keys (see {@link BaseDirsConfig} for the path policy). * * Scans every effective base directory (`this.rawBaseDirs`) for supported * files and cross-references with ingested documents. Multi-root contract: * - Returns top-level `baseDirs` (all effective roots in normal-path space, * nested-root-pruned by `resolveBaseDirs`). * - Preserves legacy top-level `baseDir = rawBaseDirs[0]` for clients written * against the single-root shape. * - Annotates each file entry with the producing `baseDir`. * - De-duplicates exact duplicate file paths across roots (first occurrence * wins, preserving root iteration order). * - Preserves raw-data / orphaned DB entries under `sources` with no * producing-root annotation. * - Excludes `dbPath` and `cacheDir` uniformly across every root. */ handleListFiles(): Promise<{ content: RagContentBlock[]; }>; /** * status tool handler */ handleStatus(): Promise<{ content: RagContentBlock[]; }>; /** * delete_file tool handler * Deletes chunks from VectorDB and physical raw-data files * Supports both filePath (for ingest_file) and source (for ingest_data) */ handleDeleteFile(args: DeleteFileInput): Promise<{ content: RagContentBlock[]; }>; /** * read_chunk_neighbors tool handler * Returns chunks around a target chunkIndex within a single ingested document. * Context-expansion utility — not a search tool. Mirrors handleDeleteFile's * dual-input (filePath XOR source) resolution pattern. */ handleReadChunkNeighbors(args: ReadChunkNeighborsInput): Promise<{ content: RagContentBlock[]; }>; /** * Start the server */ run(): Promise; /** * Stop the server and release resources */ close(): Promise; } //# sourceMappingURL=index.d.ts.map