From 2db01c4a98b3484153e5438fb12fbcde3c0b54a5 Mon Sep 17 00:00:00 2001 From: le-dawg <3172733+le-dawg@users.noreply.github.com> Date: Tue, 19 May 2026 15:29:24 +0200 Subject: [PATCH 1/2] fix: setup-claude config filename/key, remove stale tools, bundle schema in package - setup-claude now writes .mcp.json (not .claude-mcp-config.json) - top-level key changed from 'servers' to 'mcpServers' (Claude Code standard) - removed hardcoded stale tools array and description field from generated config - moved schemas/adr.schema.json into adr_kit/schemas/ for pip distribution - fixed validate.py _get_default_schema_path() to use package-relative path - added [tool.setuptools.package-data] to pyproject.toml - updated tests/unit/test_adr_schema.py path after schema move - added tests/integration/test_setup_commands.py (4 tests, all passing) Fixes: kschlt/adr-kit#23, kschlt/adr-kit#24 --- adr_kit/cli.py | 16 +------ adr_kit/core/validate.py | 12 ++--- {schemas => adr_kit/schemas}/adr.schema.json | 0 pyproject.toml | 3 ++ tests/integration/test_setup_commands.py | 47 ++++++++++++++++++++ tests/unit/test_adr_schema.py | 2 +- 6 files changed, 59 insertions(+), 21 deletions(-) rename {schemas => adr_kit/schemas}/adr.schema.json (100%) create mode 100644 tests/integration/test_setup_commands.py diff --git a/adr_kit/cli.py b/adr_kit/cli.py index f40d9bd..f3ba4f8 100644 --- a/adr_kit/cli.py +++ b/adr_kit/cli.py @@ -831,27 +831,15 @@ def _setup_claude_impl() -> None: # Create Claude Code config claude_config = { - "servers": { + "mcpServers": { "adr-kit": { "command": adr_kit_command, "args": ["mcp-server"], - "description": "AI-first Architectural Decision Records management", - "tools": [ - "adr_init", - "adr_query_related", - "adr_create", - "adr_approve", - "adr_supersede", - "adr_validate", - "adr_index", - "adr_export_lint_config", - "adr_render_site", - ], } } } - claude_config_file = Path(".claude-mcp-config.json") + claude_config_file = Path(".mcp.json") with open(claude_config_file, "w") as f: json.dump(claude_config, f, indent=2) diff --git a/adr_kit/core/validate.py b/adr_kit/core/validate.py index a8a5747..7f42487 100644 --- a/adr_kit/core/validate.py +++ b/adr_kit/core/validate.py @@ -86,13 +86,13 @@ def __init__( def _get_default_schema_path(self) -> Path: """Get path to the bundled ADR schema.""" - # Assume schema is in the schemas/ directory relative to project root - # __file__ = .../adr-kit/adr_kit/core/validate.py - # current_dir = .../adr-kit/adr_kit/core - # project_root = .../adr-kit + # Schema lives inside the package at adr_kit/schemas/adr.schema.json + # This resolves correctly after pip install (site-packages/adr_kit/schemas/) + # __file__ = .../adr_kit/core/validate.py + # current_dir = .../adr_kit/core + # package_root = .../adr_kit current_dir = Path(__file__).parent - project_root = current_dir.parent.parent - return project_root / "schemas" / "adr.schema.json" + return current_dir.parent / "schemas" / "adr.schema.json" def _load_schema(self) -> dict[str, Any]: """Load and parse the JSON schema.""" diff --git a/schemas/adr.schema.json b/adr_kit/schemas/adr.schema.json similarity index 100% rename from schemas/adr.schema.json rename to adr_kit/schemas/adr.schema.json diff --git a/pyproject.toml b/pyproject.toml index ac247b2..02ad8af 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,6 +64,9 @@ where = ["."] include = ["adr_kit*"] exclude = ["tests*", "scripts*", ".agent*"] +[tool.setuptools.package-data] +adr_kit = ["schemas/*"] + [tool.black] line-length = 88 target-version = ['py310'] diff --git a/tests/integration/test_setup_commands.py b/tests/integration/test_setup_commands.py new file mode 100644 index 0000000..74fa306 --- /dev/null +++ b/tests/integration/test_setup_commands.py @@ -0,0 +1,47 @@ +"""Integration tests for setup-claude config output and schema packaging fix.""" + +import json +from pathlib import Path + +from typer.testing import CliRunner + +from adr_kit.cli import app + +runner = CliRunner() + + +def test_setup_claude_creates_mcp_json(tmp_path): + with runner.isolated_filesystem(temp_dir=tmp_path): + result = runner.invoke(app, ["setup-claude"]) + assert Path(".mcp.json").exists(), ".mcp.json must be created by setup-claude" + assert not Path( + ".claude-mcp-config.json" + ).exists(), ".claude-mcp-config.json must not be created (wrong filename)" + + +def test_setup_claude_uses_mcp_servers_key(tmp_path): + with runner.isolated_filesystem(temp_dir=tmp_path): + runner.invoke(app, ["setup-claude"]) + config = json.loads(Path(".mcp.json").read_text()) + assert "mcpServers" in config, "top-level key must be 'mcpServers'" + assert "servers" not in config, "'servers' key must not be present" + + +def test_setup_claude_no_stale_tools_array(tmp_path): + with runner.isolated_filesystem(temp_dir=tmp_path): + runner.invoke(app, ["setup-claude"]) + config = json.loads(Path(".mcp.json").read_text()) + server = config["mcpServers"]["adr-kit"] + assert "tools" not in server, "stale tools array must be removed from config" + assert "description" not in server, "description field must be removed" + + +def test_schema_file_bundled_in_package(): + from adr_kit.core.validate import ADRValidator + + validator = ADRValidator.__new__(ADRValidator) + schema_path = validator._get_default_schema_path() + assert schema_path.exists(), ( + f"Schema must exist at {schema_path} — " + "schemas/adr.schema.json must be bundled inside adr_kit/schemas/" + ) diff --git a/tests/unit/test_adr_schema.py b/tests/unit/test_adr_schema.py index 4ab7bc3..aa24cf6 100644 --- a/tests/unit/test_adr_schema.py +++ b/tests/unit/test_adr_schema.py @@ -6,7 +6,7 @@ import jsonschema import pytest -SCHEMA_PATH = Path(__file__).parents[2] / "schemas" / "adr.schema.json" +SCHEMA_PATH = Path(__file__).parents[2] / "adr_kit" / "schemas" / "adr.schema.json" SCHEMA = json.loads(SCHEMA_PATH.read_text()) From 9bcc336d21a391fcfa78ca02c948261e953cec22 Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Tue, 19 May 2026 13:41:49 +0000 Subject: [PATCH 2/2] fix: apply CodeRabbit auto-fixes Fixed 1 file(s) based on 1 unresolved review comment. Co-authored-by: CodeRabbit --- adr_kit/cli.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/adr_kit/cli.py b/adr_kit/cli.py index f3ba4f8..097d9d7 100644 --- a/adr_kit/cli.py +++ b/adr_kit/cli.py @@ -840,8 +840,25 @@ def _setup_claude_impl() -> None: } claude_config_file = Path(".mcp.json") + + # Load existing config if present to avoid clobbering other entries + existing_config = {} + if claude_config_file.exists(): + try: + with open(claude_config_file) as f: + existing_config = json.load(f) + except json.JSONDecodeError: + # Treat invalid JSON as empty config + pass + + # Merge configs: preserve existing keys, update mcpServers + if "mcpServers" in existing_config: + existing_config["mcpServers"].update(claude_config["mcpServers"]) + else: + existing_config.update(claude_config) + with open(claude_config_file, "w") as f: - json.dump(claude_config, f, indent=2) + json.dump(existing_config, f, indent=2) console.print(f"✅ Created {claude_config_file}")