{"record":{"id":"aefcc13ab318294a","repo":"zed-industries/zed","slug":"context-server-not-initialized","errorCode":null,"errorMessage":"Context server not initialized","messagePattern":"Context server not initialized","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/agent/src/tools/context_server_registry.rs","lineNumber":365,"sourceCode":"        let tool_name = self.tool.name.clone();\n        let tool_id = mcp_tool_id(&self.server_id.0, &self.tool.name);\n        let display_name = self.tool.name.clone();\n        let initial_title = self.initial_title(serde_json::Value::Null, cx);\n        let authorize =\n            event_stream.authorize_third_party_tool(initial_title, tool_id, display_name, cx);\n\n        cx.spawn(async move |cx| {\n            let input = input\n                .recv()\n                .await\n                .map_err(|e| anyhow::anyhow!(e.to_string()))?;\n\n            authorize\n                .await\n                .map_err(|e| anyhow::anyhow!(e.to_string()))?;\n\n            let Some(protocol) = server.client() else {\n                return Err(anyhow::anyhow!(\"Context server not initialized\").into());\n            };\n\n            let arguments = if let serde_json::Value::Object(map) = input {\n                Some(map.into_iter().collect())\n            } else {\n                None\n            };\n\n            log::trace!(\n                \"Running tool: {} with arguments: {:?}\",\n                tool_name,\n                arguments\n            );\n\n            let request = protocol.request::<context_server::types::requests::CallTool>(\n                context_server::types::CallToolParams {\n                    name: tool_name,\n                    arguments,","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/zed-industries/zed/blob/bc538def4545534201bbfcac4e95ac34ea6501b6/crates/agent/src/tools/context_server_registry.rs#L347-L383","documentation":"The context-server entry exists in the store, but `server.client()` returned None — no JSON-RPC client is currently established for the MCP connection. The server is registered but not initialized: it is still starting up, or it has shut down and its client was cleared. The tool call fails before any request is sent.","triggerScenarios":"Invoking the tool in the window between server registration and connection handshake; after the server process exited or was stopped; races at agent startup when tools are listed before the server is live.","commonSituations":"Slow-starting servers (npx downloading packages) called immediately after activation; servers that crash instantly leaving stale entries; stale tool caches after a server restart.","solutions":["Gate tool invocation on the server reaching a connected state (await the store's running/initialized status).","Check server logs for handshake failures or instant exits and fix the launch command.","Restart the server or extension, then retry the tool once the connection is up.","For slow servers, surface a 'still starting' state instead of failing outright."],"exampleFix":"// before\nlet Some(protocol) = server.client() else {\n    return Err(anyhow::anyhow!(\"Context server not initialized\").into());\n};\n// after\nlet Some(protocol) = server.client() else {\n    return Err(anyhow::anyhow!(\"server {} is still connecting — retry once it is initialized\", self.server_id.0).into());\n};","handlingStrategy":"validation","validationCode":"let Some(server) = store.read(cx).get_running_server(&server_id) else {\n    anyhow::bail!(\"server '{server_id}' not running\");\n};\nif server.client().is_none() {\n    anyhow::bail!(\"server '{server_id}' still connecting — retry after initialization\");\n}","typeGuard":"fn is_context_server_connected(\n    store: &Entity<ContextServerStore>,\n    server_id: &ContextServerId,\n    cx: &App,\n) -> bool {\n    store\n        .read(cx)\n        .get_running_server(server_id)\n        .map(|server| server.client().is_some())\n        .unwrap_or(false)\n}","tryCatchPattern":null,"preventionTips":["Gate tool and prompt invocation on the server reaching a connected state.","Fix fast-exiting server commands; inspect their startup logs.","Restart servers after crashes and refresh cached tool lists before retrying."],"tags":["mcp","context-server","initialization","race-condition","agent"],"backgroundTag":null,"analyzedSha":"bc538def4545534201bbfcac4e95ac34ea6501b6","analyzedAt":"2026-08-16T07:30:46.435Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}