Repository navigation
feat(mcp): add --read-only flag for DuckDB MCP access - #329
Conversation
Opens the DuckDB database read-only for the duration of the MCP session and disables every write path that would otherwise run alongside a query server.
…it forces single-process stdio
ofriw
left a comment
There was a problem hiding this comment.
Note: This review was generated by an AI agent. If you'd like to talk with other humans, drop by our Discord!
Nice direction overall, but I think this still needs a couple of fixes before we can merge it. The biggest issue is that --read-only does not fully uphold its contract yet: startup still has write-capable paths in places that run before the read-only guards really take effect. Concretely, DatabaseConfig.get_db_path() still creates directories, MCP init still unconditionally creates the DB parent directory, and the connection manager's _load_extensions() runs INSTALL vss unconditionally after connection (distinct from _preemptive_wal_cleanup, which the PR correctly skips). The executor thread's _create_connection() in duckdb_provider.py also runs INSTALL vss. If the extension cache is empty, either path can write to the filesystem or fail on an immutable mount, contradicting the feature's promise.
There is also a user-visible status problem: in read-only mode you skip realtime startup and the initial scan, but daemon_status still derives readiness exclusively from scan_completed_at. In practice that means a pre-indexed read-only session can serve queries while still reporting query_ready=false / initializing, which is misleading for clients. Finally, the config surface and tests need one more pass: database.read_only was added to the model but not wired through env loading, and the new tests do not cover the highest-risk behavior changes yet (forced stdio/no-daemon, skipped scan/watcher startup, and the explicit read-only WAL failure path).
Attached is an agent optimized description of the changes in this PR - AGENT_REVIEW.md
…tchman fallback tests Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Brings in the read-only mode feature from PR #329 and resolves conflicts with the compaction subsystem: - database_config.py: kept both read_only and fragmentation_threshold_pct fields - connection_manager.py: compaction recovery first, then read_only guard on WAL cleanup - duckdb_provider.py: read-only DDL skip + elaborated checkpoint skip reasons
* feat(mcp): add --read-only flag for safe DuckDB MCP access Opens the DuckDB database read-only for the duration of the MCP session and disables every write path that would otherwise run alongside a query server. * docs(changelog): document `chunkhound mcp --read-only` and warn when it forces single-process stdio * feat(mcp): finish --read-only wiring and rename scan_completed_at → query_ready_at * test(mcp): cover stale-WAL hint, query_ready_at, and forced-stdio for --read-only * test: stabilize chrome headless flags and stub deferred connect in watchman fallback tests Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
…CP read-only, and fixes Merge main into matryoshka-fix-6-26. main changes incorporated: - DuckDB compaction with atomic swap (#339) - PowerShell (#350) and Metal (#351) language parsers - MCP --read-only flag (#329) - Research per-step timing (#355) - Various fixes: websearch late-completion guard, quickresearch orphan cleanup, token literal counting, claude-cli auto-updater - openai_compatible in factory's supported_providers() Conflict resolution: chunkhound/services/realtime_indexing_service.py was deleted on main (dead code, no production callers). The branch's ModuleType __class__ hack + its test were removed to match.
Note: This PR was generated by an AI agent. If you'd like to talk with other humans, drop by our Discord!
Add
--read-onlyflag for safe DuckDB MCP accessAdds a
--read-onlyflag tochunkhound mcpthat opens the DuckDB file read-only for the MCP session and turns off every write path that would otherwise run alongside the query server (initial scan, realtime watcher, WAL cleanup, checkpoint-on-close). The flag is DuckDB-only andConfig.validate_for_commandrejectsread_only=Truefor any non-mcpsubcommand or non-DuckDB provider, so a stray JSON/env value can't silently break writers.Read-only also forces single-process stdio (
no_daemon = True). The daemon exists to coordinate multi-client writers against a single DuckDB lock — when nothing writes, the coordination layer is just overhead and an extra failure surface, so we skip it. A few defensive details worth highlighting: we drop the flag for:memory:DBs (nothing to read), we never run WAL recovery under read-only (recovery rewrites files), and a pending WAL produces an explicit error pointing the user at the fix rather than a cryptic DuckDB message.The value here is letting you point an MCP client at a pre-indexed DB — shared, mounted read-only, or otherwise untouchable — without risking writes from the indexer or daemon. Tests cover the three user-visible contracts: read-only open serves regex search, writes through the provider's public API raise, and the config validator rejects the flag for non-MCP commands.
AGENT_REVIEW.md