Repository navigation
fix(mcp): stop a stray root-owned .cocoindex_code from hijacking project-root discovery - #341
Open
RizkiRachman wants to merge 1 commit into
Open
RizkiRachman wants to merge 1 commit into
RizkiRachman wants to merge 1 commit into
Conversation
…ect-root discovery MCP launchers (editors, agent harnesses) start `ccc mcp` in an unrelated working directory, commonly the filesystem root. `find_project_root` accepted any directory containing `.cocoindex_code/settings.yml`, including ones the current user cannot write to (e.g. a root-owned `/.cocoindex_code` left behind by a system-level install). The daemon then tried to create its SQLite database inside that directory and every request failed with the cryptic `sqlite3.OperationalError: unable to open database file`. - `find_project_root` skips candidates whose `.cocoindex_code` is not writable by the current user, so unusable markers cannot hijack discovery - `ccc mcp` gains `--project-root`; `COCOINDEX_CODE_ROOT_PATH` now acts as the documented override for launcher contexts (checked before the CWD walk) - the legacy `cocoindex-code` entrypoint exits with an actionable message when the resolved root is not serviceable - `Project.create` wraps SQLite open failures with the project root, the DB path and the likely cause instead of surfacing the raw driver error
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ccc mcpdiscovers its project root by walking up from the current working directory looking for.cocoindex_code/settings.yml. MCP clients (editors, agent harnesses like OpenCode) launch the server with an unrelated CWD, in practice/.When a
.cocoindex_codedirectory exists at/but is not writable by the user running the server (in our case a root-owned/.cocoindex_codeleft behind at container setup), discovery accepts it as the project root. The daemon then tries to create its SQLite database inside that directory and every request fails with a raw driver error:Nothing in that message points at the real cause: a stray, unusable marker directory hijacking discovery.
Root cause
settings.find_project_rootreturns any directory containing.cocoindex_code/settings.yml, without checking that the current user can actually use it.COCOINDEX_CODE_ROOT_PATHis only consulted when discovery finds nothing, so it cannot rescue a launcher pinned to a bad CWD.sqlite3.OperationalErrorwith no context.Fix
find_project_rootskips candidates whose.cocoindex_codedirectory is not writable by the current user. The daemon must write the index DB there, so such candidates are unusable by definition and can no longer hijack discovery.ccc mcp --project-root <dir>: explicit flag for launcher configs.COCOINDEX_CODE_ROOT_PATHis now honored as an override forccc mcp(the flag wins over the env var).cocoindex-code serveentrypoint exits with an actionable message when the resolved root is not serviceable.Project.createwraps SQLite open failures with the project root, the DB path and the likely cause instead of the bare driver error.Verification
Reproduced the incident against a real root-owned
/.cocoindex_codeon/:find_project_root(Path("/"))with unwritable marker/(hijacked)Nonefind_project_rootfrom a writable project_mcp_root_override(None)with env setrequire_project_root(override=...)New unit tests cover the skip behavior and override precedence (
tests/test_settings.py,tests/test_cli_helpers.py). I could not run the full suite locally (no pytest in this environment);py_compilepasses on all touched files and CI will run the suite.Launcher config for affected setups, e.g. opencode:
or with this PR: