fix(mcp): configure mcp_client on project load and switch
- Add _configure_mcp_for_project() helper method - Call it at end of _load_active_project() to configure mcp_client on startup - _switch_project() calls it after _refresh_from_project() - This ensures mcp_client._base_dirs is populated before GUI buttons try to read files
This commit is contained in:
+29
-16
@@ -1521,24 +1521,30 @@ class AppController:
|
||||
if self.active_project_path and Path(self.active_project_path).exists():
|
||||
try:
|
||||
self.project = project_manager.load_project(self.active_project_path)
|
||||
return
|
||||
except Exception as e:
|
||||
print(f"Failed to load project {self.active_project_path}: {e}")
|
||||
for pp in self.project_paths:
|
||||
if Path(pp).exists():
|
||||
try:
|
||||
self.project = project_manager.load_project(pp)
|
||||
self.active_project_path = pp
|
||||
return
|
||||
except Exception:
|
||||
continue
|
||||
self.project = project_manager.migrate_from_legacy_config(self.config)
|
||||
name = self.project.get("project", {}).get("name", "project")
|
||||
fallback_path = f"{name}.toml"
|
||||
project_manager.save_project(self.project, fallback_path)
|
||||
self.active_project_path = fallback_path
|
||||
if fallback_path not in self.project_paths:
|
||||
self.project_paths.append(fallback_path)
|
||||
self.project = project_manager.migrate_from_legacy_config(self.config)
|
||||
self.active_project_path = ""
|
||||
else:
|
||||
self.project = project_manager.migrate_from_legacy_config(self.config)
|
||||
self.active_project_path = ""
|
||||
if not self.active_project_path:
|
||||
for pp in self.project_paths:
|
||||
if Path(pp).exists():
|
||||
try:
|
||||
self.project = project_manager.load_project(pp)
|
||||
self.active_project_path = pp
|
||||
break
|
||||
except Exception:
|
||||
continue
|
||||
if not self.active_project_path:
|
||||
name = self.project.get("project", {}).get("name", "project")
|
||||
fallback_path = f"{name}.toml"
|
||||
project_manager.save_project(self.project, fallback_path)
|
||||
self.active_project_path = fallback_path
|
||||
if fallback_path not in self.project_paths:
|
||||
self.project_paths.append(fallback_path)
|
||||
self._configure_mcp_for_project()
|
||||
|
||||
def _prune_old_logs(self) -> None:
|
||||
"""Asynchronously prunes old insignificant logs on startup."""
|
||||
@@ -2327,6 +2333,13 @@ class AppController:
|
||||
self._create_discussion(nm)
|
||||
self.ui_disc_new_name_input = ""
|
||||
|
||||
def _configure_mcp_for_project(self) -> None:
|
||||
if not self.active_project_path:
|
||||
return
|
||||
project_root = Path(self.active_project_path).parent
|
||||
file_items_as_dicts = [{"path": f.path if hasattr(f, "path") else str(f)} for f in self.files]
|
||||
mcp_client.configure(file_items_as_dicts, [str(project_root)])
|
||||
|
||||
def _switch_project(self, path: str) -> None:
|
||||
"""
|
||||
[C: src/gui_2.py:App._render_projects_panel]
|
||||
|
||||
Reference in New Issue
Block a user