{"record":{"id":"9125d88c9807c9f9","repo":"Kuberwastaken/claurst","slug":"mcp-server-not-found-or-not-connected","errorCode":null,"errorMessage":"MCP server '{}' not found or not connected","messagePattern":"MCP server '(.+?)' not found or not connected","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-rust/crates/mcp/src/lib.rs","lineNumber":1112,"sourceCode":"                }\r\n                Err(e) => {\r\n                    warn!(server = %name, error = %e, \"Failed to list resources\");\r\n                }\r\n            }\r\n        }\r\n        all\r\n    }\r\n\r\n    /// Read a specific resource from a named server.\r\n    pub async fn read_resource(\r\n        &self,\r\n        server_name: &str,\r\n        uri: &str,\r\n    ) -> anyhow::Result<serde_json::Value> {\r\n        let client = self\r\n            .clients\r\n            .get(server_name)\r\n            .ok_or_else(|| anyhow::anyhow!(\"MCP server '{}' not found or not connected\", server_name))?;\r\n\r\n        let contents = client.read_resource(uri).await?;\r\n        Ok(serde_json::to_value(&contents)?)\r\n    }\r\n\r\n    /// List all prompts from all (or a specific) connected server.\r\n    pub async fn list_all_prompts(\r\n        &self,\r\n        server_filter: Option<&str>,\r\n    ) -> Vec<serde_json::Value> {\r\n        let mut all = vec![];\r\n        for (name, client) in &self.clients {\r\n            if let Some(filter) = server_filter {\r\n                if name != filter {\r\n                    continue;\r\n                }\r\n            }\r\n            match client.list_prompts().await {\r","sourceCodeStart":1094,"sourceCodeEnd":1130,"githubUrl":"https://github.com/Kuberwastaken/claurst/blob/b0637c97ec34144387cbf2f74f65df6d16a6cef1/src-rust/crates/mcp/src/lib.rs#L1094-L1130","documentation":"The McpHub manager keeps a map of connected MCP server clients keyed by server name. read_resource() looks up the named server before forwarding the request; if no connected client exists under that name, it throws this error instead of attempting a network call. It is a lookup failure on the connection table, not a resource-access failure.","triggerScenarios":"Calling McpHub::read_resource(server_name, uri) with a server name that is not in self.clients — never connected, connect failed, typo'd name, or the server was removed/disconnected after startup.","commonSituations":"Typo in the server name in settings.json vs the code call; MCP server process failed at startup so connect() never registered a client; referring to a server by its display label instead of its configured key; racing a reconnect that removed the client mid-session.","solutions":["Print the set of connected servers (iterate McpHub clients) and confirm the exact key before calling read_resource","Fix the server name to match the key used in the MCP servers configuration","Ensure the server successfully connected at startup (check connect logs for that server) before issuing resource requests","Reconnect or restart the MCP server if it dropped out of the clients map"],"exampleFix":"// before\nlet res = hub.read_resource(\"filesystem\", \"file:///etc/hosts\").await?;\n// after\nif !hub.is_connected(\"filesystem\") {\n    anyhow::bail!(\"filesystem is not connected; check mcp server config\");\n}\nlet res = hub.read_resource(\"filesystem\", \"file:///etc/hosts\").await?;","handlingStrategy":"try-catch","validationCode":"// Rust\nif !hub.client_names().contains(&server_name.to_string()) {\n    anyhow::bail!(\"MCP server '{}' is not connected\", server_name);\n}","typeGuard":"fn is_connected(hub: &McpHub, name: &str) -> bool {\n    hub.clients().contains_key(name)\n}","tryCatchPattern":"match hub.read_resource(server, uri).await {\n    Ok(v) => v,\n    Err(e) if e.to_string().contains(\"not found or not connected\") => {\n        eprintln!(\"server {server} not connected; reconnect first\");\n        Default::default()\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Keep server names in a shared constant or enum instead of inline strings","Check connection status before MCP calls in long-lived sessions","Log the connected-server list at startup and after reconnects"],"tags":["mcp","lookup-failure","configuration"],"backgroundTag":"entity-not-found","analyzedSha":"b0637c97ec34144387cbf2f74f65df6d16a6cef1","analyzedAt":"2026-09-10T00:24:58.650Z","contentChangedAt":"2026-09-10T00:24:58.650Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}