import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { EmbedDb } from "./embed-db.js"; import { type loadEmbedder } from "./embeddings.js"; import { FtsIndex } from "./fts5.js"; import { Vault } from "./vault.js"; import { VaultWatcher } from "./watcher.js"; /** * Configuration for {@link startServer} / {@link prepareServerDeps}. * Mirrors the CLI flag surface (`enquire-mcp serve --vault X --enable-write`) * but typed as a plain options object so HTTP transport / tests can call * the same entry points programmatically. * * Strings on numeric fields (e.g. `maxFileBytes`, `cacheSize`) reflect the * fact that callers usually pass CLI args verbatim — parsing happens * inside `prepareServerDeps` via {@link parsePositiveInt}. */ export interface ServeOptions { /** Absolute path to the vault root directory. Required. */ vault: string; /** Allow the gated write tools (`obsidian_create_note`, * `obsidian_append_to_note`, `obsidian_rename_note`, `obsidian_archive_note`, * …). Default false (read-only). */ enableWrite?: boolean; /** Per-file size cap (parsed via {@link parsePositiveInt}). */ maxFileBytes?: string; /** In-memory parsed-note cache capacity. */ cacheSize?: string; /** Persist the parse cache across server restarts. */ persistentCache?: boolean; /** Override the persistent cache file location. */ cacheFile?: string; /** Enable the persistent FTS5 index (requires `better-sqlite3`). */ persistentIndex?: boolean; /** Override the FTS5 index file location. */ indexFile?: string; /** FTS5 tokenizer mode. */ tokenize?: "unicode61" | "trigram"; /** Privacy: glob patterns to exclude from the vault. */ excludeGlob?: string[]; /** Privacy: glob patterns that form a strict allowlist. */ readPaths?: string[]; /** Enable the filesystem watcher (auto-reindex on change). */ watch?: boolean; /** Per-tool gating: deny list. Tools named here won't register. */ disabledTools?: string[]; /** Per-tool gating: allow list. Only listed tools register (deny still applies). */ enabledTools?: string[]; /** Expose diagnostic / debug tools (`obsidian_full_text_search` etc.). */ diagnosticSearchTools?: boolean; /** v2.8.0 — also index PDFs into FTS5 (and embeddings, if a build-embeddings * with --include-pdfs ran). Off by default; opt-in because PDF extraction * is slower than markdown. */ includePdfs?: boolean; /** v3.9.0-rc.1 — also run Tesseract OCR on image-only / scanned PDFs that * pdfjs can't read text from, so the watcher's embed-db sync keeps * OCR'd PDFs in sync with edits during a long serve session. Requires * `--watch` + `--include-pdfs` + the `tesseract.js` / `@napi-rs/canvas` * optional dependencies. Off by default — OCR is slow (~1-2s per page * on M1 CPU; bounded by `--ocr-max-pages`, default 200). */ ocrPdfs?: boolean; /** v3.9.0-rc.1 — Tesseract language pack for OCR-on-watch. Default `"eng"`. * Multi-lang via `+`, e.g. `"eng+rus"`. Languages must be pre-installed * via `enquire-mcp install-ocr-lang ` (no runtime download). */ ocrLangs?: string; /** v3.9.0-rc.1 — page cap for OCR-on-watch runs. Default 200 (matches * `DEFAULT_OCR_MAX_PAGES`). Image-only PDFs exceeding this skip embed-sync * (FTS5 still updates from the pdfjs `extractPdfText` result, which * returns empty pages for image-only PDFs). */ ocrMaxPages?: string; /** v2.9.0 — enable BGE cross-encoder reranking on top of RRF in * obsidian_search. Off by default; adds ~30-50ms per query at top-50. */ enableReranker?: boolean; /** v2.9.0 — reranker model alias (default "rerank-multilingual"). */ rerankerModel?: string; /** v2.9.0 — how many top fused candidates to rerank (default 50). */ rerankerTopN?: string; /** v2.13.0 — build an in-memory HNSW vector index on serve start. * Off by default; rebuild cost ~25s for 50K chunks. Sub-10ms top-K * per query thereafter, vs O(n) brute-force without it. Defers * persistence to v3.0. */ useHnsw?: boolean; /** v2.13.0 — HNSW search-time beam width (default 100; ≥k). */ hnswEf?: string; /** v3.10.0-rc.5 — opt-in recency re-ranking weight in [0,1] for obsidian_search. * Default 0 (OFF — ranking stays purely relevance-driven). When > 0, the fused * order is re-sorted by `(1-w)*relevanceRank + w*recency`. */ recencyWeight?: string; /** v3.10.0-rc.5 — recency half-life in days for --recency-weight (age at which * recency score = 0.5). Default 365. Tunes recency RE-RANKING only; the `stale` * flag on hits always uses the fixed 365-day default (rc.40 #9 — was mis-claimed * as this flag's threshold). */ staleDays?: string; /** v3.11.0 — opt-in closed-loop feedback weight in [0,1]. Default 0 (OFF — * no `obsidian_mark_useful` tool, no rank boost; ranking stays relevance-pure). * When > 0, registers `obsidian_mark_useful` and blends each note's recorded * usefulness (`useful/(useful+notUseful+1)`) into the `obsidian_search` order: * `(1-w)*relevanceRank + w*feedbackScore`. State persists in a per-vault cache * sidecar (`.feedback.json`; paths + counts only). */ feedbackWeight?: string; /** v2.15.0 — late-chunking context windowing for embeddings (default 0 chars). */ lateChunkContext?: string; /** v2.16.0 — persist HNSW index to disk for fast reload on next serve. * Default true (the persistence is a pure optimization; corrupt files * fall back to rebuild gracefully). Pass `--no-hnsw-persist` to opt out. */ hnswPersist?: boolean; /** v2.17.0 — vector storage encoding for the persistent embed db. * - `"f32"` (default) — Float32 BLOB, identical to v2.16- behavior. * - `"int8"` — int8-quantized BLOB + per-vector (vMin, scale) Float32 * tuple. ~4× storage reduction at ~1-2% recall@10 cost. * Mode is per-database; switching modes triggers a full rebuild * (the meta-table contamination guard treats it as a schema change). * Must match the mode used at build-embeddings time — serving with a * different mode would auto-rebuild the index. */ quantizeEmbeddings?: "f32" | "int8"; } /** * Heavyweight resources shared across every MCP-server instance: the vault * (parsed-note cache + privacy filter), the FTS5 index handle, the optional * filesystem watcher. v2.6.0 split this out so the HTTP transport can spin up * a fresh `McpServer` per session over the SAME vault/index — opening the * SQLite handle once and reusing it across thousands of remote-MCP calls. * * `warningTracker` is a single-fire latch for the `--disabled-tools` / * `--enabled-tools` typo warnings: stdio prints them once at boot; HTTP * prints them on the first session build, then never again. */ export interface ServerDeps { vault: Vault; ftsIndex: FtsIndex | null; watcher: VaultWatcher | null; /** * v3.8.0-rc.2 R-7 — embed-db handle owned by the watcher for runtime * incremental sync. Opened in `prepareServerDeps` when `--watch` is * on AND the embed-db file exists, separate from the HNSW init path * (which opens its own short-lived handle for the rebuild scan). * SQLite WAL mode allows concurrent opens to the same file; the two * handles see consistent state via MVCC. Closed by the shutdown * handler in {@link startServer}. */ watcherEmbedDb: EmbedDb | null; /** * v3.11.0 — opt-in closed-loop feedback store, opened once on serve start when * `--feedback-weight > 0`. Shared across every per-session `McpServer` (HTTP) * so a `mark_useful` in one session influences the search boost in all of them. * `null` when feedback is off. Holds an in-memory tally + a per-vault JSON * sidecar; no open file handle to close at shutdown. */ feedbackStore: import("./feedback.js").FeedbackStore | null; disabledTools: Set; enabledTools: Set; warningTracker: { printed: boolean; }; /** * v2.13.0 — opt-in HNSW vector index built in-memory on serve start * from the embed-db rows. Sub-10ms top-K queries vs O(n) brute-force. * `null` when `--use-hnsw` wasn't passed or the embed-db doesn't exist. */ hnswContext: { /** The HNSW index. */ index: import("./hnsw.js").HnswIndex; /** Map from HNSW label (= embeddings.id) to source row metadata. */ rowByLabel: Map; /** Search-time beam width override; falls back to module default if undefined. */ ef?: number; /** * v3.6.2 HN-4 — model alias the HNSW index was built with (from * the embed-db's persisted meta, or the resolved default for fresh * dbs). Propagated to `HnswSearchContext` at search time so the * query embedder model can be verified against the index. CRIT-1 * fixed the build-side destruction; this seals the search side. */ modelAlias: string; } | null; } /** * One-time bootstrap of the heavy deps (vault open + FTS5 sync + watcher). * Idempotent on a per-call basis but NOT designed to be called multiple * times in one process — the FTS5 sync would double-index. Stdio + HTTP * each call this exactly once at startup. */ export declare function prepareServerDeps(opts: ServeOptions): Promise; /** * Build a fresh `McpServer` over already-prepared deps. Cheap (just * registers tool handlers — no I/O, no SQLite open). Stdio calls this once; * HTTP calls it per session. */ export declare function buildMcpServer(deps: ServerDeps, opts: ServeOptions): McpServer; export declare function startServer(opts: ServeOptions): Promise; /** * Shared "ready" banner used by stdio + HTTP startup paths so the runtime * configuration summary is identical regardless of transport. Transport * suffix is appended by the caller. */ export declare function formatReadyBanner(deps: ServerDeps): string; export { buildEmbedText } from "./embed-pipeline.js"; export declare function syncEmbedDb(vault: Vault, db: EmbedDb, embedder: Awaited>, opts?: { lateChunkContext?: number; }): Promise<{ added: number; updated: number; deleted: number; unchanged: number; total_chunks: number; }>; export declare function syncFtsIndex(vault: Vault, idx: FtsIndex): Promise<{ added: number; updated: number; deleted: number; unchanged: number; total_chunks: number; }>; /** * v2.8.0 — sync PDF chunks into the FTS5 index. Same incremental-mtime * pattern as syncFtsIndex but for PDFs: list .pdf files, diff against * source_state rows where kind="pdf", reindex the changed ones via * `extractPdfText` + `reindexPdfFile`. * * pdfjs-dist is an optionalDependency — extraction failures (missing dep * / corrupt PDF / encrypted without password) are caught per-file and * surfaced via stderr so one bad PDF doesn't poison the whole index. */ export declare function syncPdfFtsIndex(vault: Vault, idx: FtsIndex): Promise<{ added: number; updated: number; deleted: number; unchanged: number; total_chunks: number; }>; /** * v2.8.0 — sync PDF chunks into the embedding index. Mirrors syncEmbedDb * but for PDFs. Page boundaries are preserved as `[page: N]` markers * before chunking so embeddings carry page-citation context. */ export declare function syncPdfEmbedDb(vault: Vault, db: EmbedDb, embedder: Awaited>, opts?: { lateChunkContext?: number; }): Promise<{ added: number; updated: number; deleted: number; unchanged: number; total_chunks: number; }>; //# sourceMappingURL=server.d.ts.map