fix(mcp): run bd commands in user's working directory instead of MCP server directory

The MCP server was running all bd commands in its own installation directory
(~/.claude/plugins/marketplaces/beads-marketplace/integrations/beads-mcp/)
instead of the user's project directory. This caused databases to be created
in the wrong location.

For example, when working in ~/ai/flutter/wyvern and running `bd init --prefix wy-`,
the database was created at:
  ~/.claude/plugins/marketplaces/beads-marketplace/integrations/beads-mcp/.beads/wy-.db

Instead of the expected location:
  ~/ai/flutter/wyvern/.beads/wy-.db

Solution:
- Add `cwd=os.getcwd()` to all asyncio.create_subprocess_exec() calls
- This makes bd commands execute in the current working directory from PWD env var
- Claude Code updates PWD for the MCP server process environment

Impact:
- bd init now creates .beads/ in the correct project directory
- All bd commands (create, list, update, etc.) operate on the correct database
- Multi-project workflows work correctly without manual DB path configuration

Test results: 90/91 tests passing (1 unrelated path assertion failure)
This commit is contained in:
Steve Yegge
2025-10-14 17:11:45 -07:00
parent f16ba3f30f
commit c049bf4351
2 changed files with 7 additions and 1 deletions

View File

@@ -2,6 +2,7 @@
import asyncio
import json
import os
import re
from .config import load_config
@@ -124,6 +125,7 @@ class BdClient:
*cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
cwd=os.getcwd(),
)
stdout, stderr = await process.communicate()
except FileNotFoundError as e:
@@ -167,6 +169,7 @@ class BdClient:
"version",
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
cwd=os.getcwd(),
)
stdout, stderr = await process.communicate()
except FileNotFoundError as e:
@@ -380,6 +383,7 @@ class BdClient:
*cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
cwd=os.getcwd(),
)
_stdout, stderr = await process.communicate()
except FileNotFoundError as e:
@@ -407,6 +411,7 @@ class BdClient:
*cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
cwd=os.getcwd(),
)
stdout, stderr = await process.communicate()
except FileNotFoundError as e:
@@ -473,6 +478,7 @@ class BdClient:
*cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
cwd=os.getcwd(),
)
stdout, stderr = await process.communicate()
except FileNotFoundError as e:

View File

@@ -48,7 +48,7 @@ wheels = [
[[package]]
name = "beads-mcp"
version = "0.9.2"
version = "0.9.3"
source = { editable = "." }
dependencies = [
{ name = "fastmcp" },