Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

project: Include user MCP servers before the first worktree loads (#64612)

Phil Winder99cda17e0587
diff --git a/crates/agent_ui/src/context_server_configuration.rs b/crates/agent_ui/src/context_server_configuration.rs
index 3614aef3696..24a1c1d23b8 100644
--- a/crates/agent_ui/src/context_server_configuration.rs
+++ b/crates/agent_ui/src/context_server_configuration.rs
@@ -126,7 +126,9 @@ mod tests {
settings.context_servers.insert(
"slack".into(),
ContextServerSettings::Stdio {
- enabled: true,
+ // The modal only reads these settings; an enabled server would be
+ // spawned as a real process by the worktree-less test projects.
+ enabled: false,
remote: false,
command: ContextServerCommand {
path: "slack-mcp-server".into(),
diff --git a/crates/project/src/context_server_store.rs b/crates/project/src/context_server_store.rs
index eacdbcfb822..d5d2aa66ed9 100644
--- a/crates/project/src/context_server_store.rs
+++ b/crates/project/src/context_server_store.rs
@@ -1167,13 +1167,29 @@ impl ContextServerStore {
}
/// Merges context server settings from all visible worktrees so that servers defined
- /// in any project folder in a multi-root workspace are picked up.
+ /// in any project folder in a multi-root workspace are picked up. With no visible
+ /// worktrees, falls back to user settings.
fn resolve_all_context_server_settings(
worktree_store: &Entity<WorktreeStore>,
cx: &App,
) -> HashMap<Arc<str>, ContextServerSettingsEntry> {
let mut merged = HashMap::default();
- for worktree in worktree_store.read(cx).visible_worktrees(cx) {
+ let mut visible_worktrees = worktree_store.read(cx).visible_worktrees(cx).peekable();
+ if visible_worktrees.peek().is_none() {
+ // Without this, user servers are missing until the first worktree is added,
+ // and never appear in a window that has no folder.
+ for (id, settings) in &ProjectSettings::get(None, cx).context_servers {
+ merged.insert(
+ id.clone(),
+ ContextServerSettingsEntry {
+ worktree_id: None,
+ settings: settings.clone(),
+ },
+ );
+ }
+ return merged;
+ }
+ for worktree in visible_worktrees {
let worktree_id = worktree.read(cx).id();
let location = settings::SettingsLocation {
worktree_id,
diff --git a/crates/project/tests/integration/context_server_store.rs b/crates/project/tests/integration/context_server_store.rs
index 3a1c1684f99..9a8c085464f 100644
--- a/crates/project/tests/integration/context_server_store.rs
+++ b/crates/project/tests/integration/context_server_store.rs
@@ -816,6 +816,54 @@ async fn test_stdio_server_restarts_when_project_root_becomes_available(cx: &mut
});
}
+#[gpui::test]
+async fn test_global_context_servers_start_without_worktrees(cx: &mut TestAppContext) {
+ let server_id = ContextServerId("my-server".into());
+
+ cx.update(|cx| {
+ let settings_store = SettingsStore::test(cx);
+ cx.set_global(settings_store);
+ });
+ let fs = FakeFs::new(cx.executor());
+ let project = Project::test(fs, [], cx).await;
+ let store = project.read_with(cx, |project, _| project.context_server_store());
+ let executor = cx.executor();
+ store.update(cx, |store, _| {
+ store.set_context_server_factory(Box::new(move |id, _| {
+ Arc::new(ContextServer::new(
+ id.clone(),
+ Arc::new(create_fake_transport(id.0.to_string(), executor.clone())),
+ ))
+ }));
+ });
+
+ set_context_server_configuration(
+ vec![(
+ server_id.0.clone(),
+ settings::ContextServerSettingsContent::Stdio {
+ enabled: true,
+ remote: false,
+ command: ContextServerCommand {
+ path: "somebinary".into(),
+ args: vec!["arg".to_string()],
+ env: None,
+ timeout: None,
+ },
+ },
+ )],
+ cx,
+ );
+ cx.run_until_parked();
+
+ cx.update(|cx| {
+ assert_eq!(
+ store.read(cx).status_for_server(&server_id),
+ Some(ContextServerStatus::Running),
+ "user-level context servers must start before any worktree exists"
+ );
+ });
+}
+
#[gpui::test]
async fn test_server_ids_includes_disabled_servers(cx: &mut TestAppContext) {
const ENABLED_SERVER_ID: &str = "enabled-server";