Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(mcp): don't create a stray .repowise/ when the store is missing (#3166)

inchang-ing453c6d4ee24e
diff --git a/packages/server/src/repowise/server/mcp_server/_server.py b/packages/server/src/repowise/server/mcp_server/_server.py
index 04580fb20..fc0bb2dab 100644
--- a/packages/server/src/repowise/server/mcp_server/_server.py
+++ b/packages/server/src/repowise/server/mcp_server/_server.py
@@ -648,13 +648,19 @@ async def _lifespan(server: FastMCP):
db_path = get_repo_db_path(_state._repo_path)
repowise_dir = db_path.parent
store_location = str(repowise_dir)
- if not repowise_dir.exists():
- _log.warning(
- "No .repowise directory at %s — run 'repowise init' first",
+ if not repowise_dir.is_dir():
+ # Creating the store directory here made whatever directory an
+ # MCP host spawned the server from look initialised: it left a
+ # stray .repowise/ behind, silenced the CLI's "run 'repowise
+ # init'" warning for every later start, and seeded an empty
+ # wiki.db. Fail the way an unopenable store does instead (#3163).
+ await _abort_startup(_release_task, _warm_task)
+ raise _store_unavailable(
+ store_location,
_state._repo_path,
+ FileNotFoundError(f"no {repowise_dir.name} directory"),
)
- repowise_dir.mkdir(parents=True, exist_ok=True)
- elif not db_path.exists():
+ if not db_path.exists():
_log.warning(
"No wiki.db in %s — run 'repowise init' to generate the wiki",
repowise_dir,
diff --git a/tests/unit/server/mcp/test_startup_guards.py b/tests/unit/server/mcp/test_startup_guards.py
index a799ed0f7..3e6ed63ea 100644
--- a/tests/unit/server/mcp/test_startup_guards.py
+++ b/tests/unit/server/mcp/test_startup_guards.py
@@ -49,6 +49,36 @@ async def test_lifespan_names_the_path_when_the_store_cannot_be_opened(
assert _state._lancedb_ready is None
+async def test_missing_store_directory_is_not_created(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """An uninitialised repo fails startup instead of getting a stray .repowise/.
+
+ Creating the directory made any directory an MCP host spawned the server
+ from look initialised, and the empty wiki.db it seeded masked the state the
+ CLI's own warning is meant to report (#3163).
+ """
+ for name in ("REPOWISE_DB_URL", "REPOWISE_DATABASE_URL"):
+ monkeypatch.delenv(name, raising=False)
+ monkeypatch.setattr(_state, "_repo_path", str(tmp_path))
+
+ async def _no_warm() -> None:
+ return None
+
+ monkeypatch.setattr(_server, "_warm_lancedb", _no_warm)
+ monkeypatch.setattr(_server, "_detect_workspace", lambda _p: (None, None, None))
+
+ with pytest.raises(StoreUnavailableError) as raised:
+ async with _server._lifespan(_server.mcp):
+ pass
+ message = str(raised.value)
+ assert str(tmp_path / ".repowise") in message
+ assert "repowise init" in message
+ assert not (tmp_path / ".repowise").exists()
+ assert _state._lancedb_ready is None
+
+
def test_missing_tool_dependency_skips_that_tool_and_keeps_the_rest(
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
) -> None: