Fix bd-8zf2: MCP server auto-detects workspace from CWD

- Add _find_beads_db_in_tree() to walk up looking for .beads/*.db
- Update _get_client() to auto-detect when workspace not set
- Matches CLI behavior (no manual set_context needed after restart)
- Add 8 comprehensive tests for auto-detection
- Update existing tests to mock auto-detection in error cases

Fixes silent failures after Amp restart.

Amp-Thread-ID: https://ampcode.com/threads/T-c47f524d-c101-40d5-839a-659f52b9be48
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Steve Yegge
2025-11-07 23:59:57 -08:00
parent e6e458fc40
commit 44179d7326
4 changed files with 228 additions and 11 deletions

View File

@@ -299,5 +299,7 @@ async def test_get_client_no_workspace_error():
tools.current_workspace.set(None)
with patch.dict('os.environ', {}, clear=True):
with pytest.raises(BdError, match="No workspace set"):
await _get_client()
# Mock auto-detection to fail
with patch("beads_mcp.tools._find_beads_db_in_tree", return_value=None):
with pytest.raises(BdError, match="No beads workspace found"):
await _get_client()