From ba8fdf1a8c5d2496bbe73466cbea7efb2a01b61d Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Tue, 14 Oct 2025 16:47:29 -0700 Subject: [PATCH] fix: MCP init tool creates .beads in current directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Critical bug: MCP init tool reported success but didn't create .beads directory. It was using --db flag which tells bd to use an existing database elsewhere instead of creating a new one. Root cause: - bd_client.init() was calling _global_flags() which adds --db flag - bd init --db uses existing db instead of creating new one - Result: init appeared to succeed but created nothing Fix: - Remove _global_flags() from init command - Only pass --actor flag (safe for init) - Do NOT pass --db flag to init (defeats the purpose) - Add explicit comment explaining why Testing: - Added test_init_creates_beads_directory() integration test - Verifies .beads directory is created in current working directory - Verifies database file has correct prefix - All 91 tests pass This was causing silent failures where agents thought they initialized bd but the .beads directory was never created. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../beads-mcp/src/beads_mcp/bd_client.py | 6 ++- .../tests/test_bd_client_integration.py | 48 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/integrations/beads-mcp/src/beads_mcp/bd_client.py b/integrations/beads-mcp/src/beads_mcp/bd_client.py index 32947bd7..f4ff5a4b 100644 --- a/integrations/beads-mcp/src/beads_mcp/bd_client.py +++ b/integrations/beads-mcp/src/beads_mcp/bd_client.py @@ -462,7 +462,11 @@ class BdClient: if params.prefix: cmd.extend(["--prefix", params.prefix]) - cmd.extend(self._global_flags()) + # NOTE: Do NOT add --db flag for init! + # init creates a NEW database in the current directory. + # Only add actor-related flags. + if self.actor: + cmd.extend(["--actor", self.actor]) try: process = await asyncio.create_subprocess_exec( diff --git a/integrations/beads-mcp/tests/test_bd_client_integration.py b/integrations/beads-mcp/tests/test_bd_client_integration.py index a09a8d61..88b47c82 100644 --- a/integrations/beads-mcp/tests/test_bd_client_integration.py +++ b/integrations/beads-mcp/tests/test_bd_client_integration.py @@ -349,3 +349,51 @@ async def test_dependency_types(bd_client): show_params = ShowIssueParams(issue_id=issue1.id) shown = await bd_client.show(show_params) assert len(shown.dependencies) > 0 + + +@pytest.mark.asyncio +async def test_init_creates_beads_directory(bd_executable): + """Test that init creates .beads directory in current working directory. + + This is a critical test for the bug where init was using --db flag + and creating the database in the wrong location. + """ + import asyncio + from beads_mcp.bd_client import BdClient + from beads_mcp.models import InitParams + + # Create a temporary directory to test in + with tempfile.TemporaryDirectory(prefix="beads_init_test_", dir="/tmp") as temp_dir: + temp_path = Path(temp_dir) + beads_dir = temp_path / ".beads" + + # Ensure .beads doesn't exist yet + assert not beads_dir.exists() + + # Create client WITHOUT beads_db set (this was the bug!) + client = BdClient(bd_path=bd_executable, beads_db=None) + + # Change to temp directory and run init + original_cwd = os.getcwd() + try: + os.chdir(temp_dir) + + # Initialize with custom prefix + params = InitParams(prefix="test") + result = await client.init(params) + + # Verify .beads directory was created in current directory + assert beads_dir.exists(), f".beads directory not created in {temp_dir}" + assert beads_dir.is_dir(), f".beads exists but is not a directory" + + # Verify database file was created with correct prefix + db_files = list(beads_dir.glob("*.db")) + assert len(db_files) > 0, "No database file created in .beads/" + assert any("test" in str(db.name) for db in db_files), \ + f"Database file doesn't contain prefix 'test': {[db.name for db in db_files]}" + + # Verify success message + assert "initialized" in result.lower() or "created" in result.lower() + + finally: + os.chdir(original_cwd)