From ff0ce6c3a72e297bfb50d4add4d067b5403288e8 Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Fri, 17 Oct 2025 14:22:17 -0700 Subject: [PATCH] Improve MCP client working directory handling - Use os.getcwd() directly instead of PWD fallback (more reliable) - Add cwd parameter to _run_command for per-command overrides Amp-Thread-ID: https://ampcode.com/threads/T-bf7caacc-f242-4224-b730-1f4442a7ed50 Co-authored-by: Amp --- integrations/beads-mcp/src/beads_mcp/bd_client.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/integrations/beads-mcp/src/beads_mcp/bd_client.py b/integrations/beads-mcp/src/beads_mcp/bd_client.py index ccc0146c..20bec18b 100644 --- a/integrations/beads-mcp/src/beads_mcp/bd_client.py +++ b/integrations/beads-mcp/src/beads_mcp/bd_client.py @@ -114,8 +114,8 @@ class BdClient: """ if self.working_dir: return self.working_dir - # Fall back to PWD environment variable or current directory - return os.environ.get("PWD", os.getcwd()) + # Use process working directory (set by MCP client at spawn time) + return os.getcwd() def _global_flags(self) -> list[str]: """Build list of global flags for bd commands. @@ -134,11 +134,12 @@ class BdClient: flags.append("--no-auto-import") return flags - async def _run_command(self, *args: str) -> object: + async def _run_command(self, *args: str, cwd: str | None = None) -> object: """Run bd command and parse JSON output. Args: *args: Command arguments to pass to bd + cwd: Optional working directory override for this command Returns: Parsed JSON output (dict or list) @@ -148,6 +149,7 @@ class BdClient: BdCommandError: If bd command fails """ cmd = [self.bd_path, *args, *self._global_flags(), "--json"] + working_dir = cwd if cwd is not None else self._get_working_dir() # Log database routing for debugging import sys