From 2904bb22aba3e084b8ec71420084438933766153 Mon Sep 17 00:00:00 2001 From: Fazle Elahee Date: Tue, 12 May 2026 19:19:06 +0100 Subject: [PATCH] feat: gitignore .mcp.json on cce init MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit .mcp.json carries an absolute path to the cce binary and a project_dir argument — both differ on every contributor's machine. Committing it forces everyone to share one path layout, which never holds in practice (homedir paths, pipx vs uv vs pip installs, etc.). `cce init` regenerates .mcp.json on every machine, so the right default is to keep it out of version control alongside the other per-machine entries (.cce/, .claude/settings.local.json). Behaviour: - Newly-init'd projects get .mcp.json in the managed CCE block of .gitignore. - Existing projects pick up the new entry on the next `cce init` (ensure_gitignore is idempotent and only appends missing entries — it never rewrites unrelated content). - Projects that already explicitly listed .mcp.json don't get a duplicate. - Existing tracked .mcp.json files are not auto-untracked; that's a manual `git rm --cached` decision the user makes. Tests added: - test_ignores_mcp_json: ensure_gitignore writes .mcp.json into a fresh .gitignore. - test_mcp_json_not_duplicated_if_user_already_ignored: pre-existing entry is preserved without duplication. --- src/context_engine/project_commands.py | 6 ++++++ tests/test_project_commands.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/context_engine/project_commands.py b/src/context_engine/project_commands.py index caf5d94..1ccb397 100644 --- a/src/context_engine/project_commands.py +++ b/src/context_engine/project_commands.py @@ -232,6 +232,12 @@ def remove_preference(project_dir: str, key: str) -> bool: # CCE local cache and per-machine files (".cce/", "CCE local cache (per-machine, not for version control)"), (".claude/settings.local.json", "Claude Code local settings written by cce init"), + # `.mcp.json` carries an absolute path to the `cce` binary (different + # on each contributor's machine) and a project_dir argument that's + # also absolute. Committing it would force every contributor to + # share one path layout, which never holds. `cce init` regenerates + # it on each machine, so gitignoring it is the correct default. + (".mcp.json", ".mcp.json contains absolute paths regenerated by `cce init`"), ] diff --git a/tests/test_project_commands.py b/tests/test_project_commands.py index 55f958f..5752697 100644 --- a/tests/test_project_commands.py +++ b/tests/test_project_commands.py @@ -387,6 +387,21 @@ def test_doesnt_duplicate_if_present(self, tmp_path): content = (tmp_path / ".gitignore").read_text() assert content.count(".cce/") == 1 + def test_ignores_mcp_json(self, tmp_path): + """`.mcp.json` contains absolute paths and is regenerated by + `cce init` on each machine — must be in the managed + gitignore block so contributors don't accidentally commit + each other's path layouts.""" + ensure_gitignore(str(tmp_path)) + content = (tmp_path / ".gitignore").read_text() + assert ".mcp.json" in content + + def test_mcp_json_not_duplicated_if_user_already_ignored(self, tmp_path): + (tmp_path / ".gitignore").write_text(".mcp.json\nnode_modules/\n") + ensure_gitignore(str(tmp_path)) + content = (tmp_path / ".gitignore").read_text() + assert content.count(".mcp.json") == 1 + # ── Edge cases ─────────────────────────────────────────────────────────