Kuberwastaken/claurst · error · anyhow::Error

MCP server ' ' not found or not connected

Error message

MCP server '{}' not found or not connected

What it means

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.

Solutions

  1. Print the set of connected servers (iterate McpHub clients) and confirm the exact key before calling read_resource
  2. Fix the server name to match the key used in the MCP servers configuration
  3. Ensure the server successfully connected at startup (check connect logs for that server) before issuing resource requests
  4. Reconnect or restart the MCP server if it dropped out of the clients map

Example fix

// before
let res = hub.read_resource("filesystem", "file:///etc/hosts").await?;
// after
if !hub.is_connected("filesystem") {
    anyhow::bail!("filesystem is not connected; check mcp server config");
}
let res = hub.read_resource("filesystem", "file:///etc/hosts").await?;
Defensive patterns

Strategy: try-catch

Validate before calling

// Rust
if !hub.client_names().contains(&server_name.to_string()) {
    anyhow::bail!("MCP server '{}' is not connected", server_name);
}

Type guard

fn is_connected(hub: &McpHub, name: &str) -> bool {
    hub.clients().contains_key(name)
}

Try / catch

match hub.read_resource(server, uri).await {
    Ok(v) => v,
    Err(e) if e.to_string().contains("not found or not connected") => {
        eprintln!("server {server} not connected; reconnect first");
        Default::default()
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of Kuberwastaken/claurst@b0637c97ec (2026-09-10). Data as JSON: /api/errors/9125d88c9807c9f9. Report an issue: GitHub.

Appendix: source

Thrown at src-rust/crates/mcp/src/lib.rs:1112

                }
                Err(e) => {
                    warn!(server = %name, error = %e, "Failed to list resources");
                }
            }
        }
        all
    }

    /// Read a specific resource from a named server.
    pub async fn read_resource(
        &self,
        server_name: &str,
        uri: &str,
    ) -> anyhow::Result<serde_json::Value> {
        let client = self
            .clients
            .get(server_name)
            .ok_or_else(|| anyhow::anyhow!("MCP server '{}' not found or not connected", server_name))?;

        let contents = client.read_resource(uri).await?;
        Ok(serde_json::to_value(&contents)?)
    }

    /// List all prompts from all (or a specific) connected server.
    pub async fn list_all_prompts(
        &self,
        server_filter: Option<&str>,
    ) -> Vec<serde_json::Value> {
        let mut all = vec![];
        for (name, client) in &self.clients {
            if let Some(filter) = server_filter {
                if name != filter {
                    continue;
                }
            }
            match client.list_prompts().await {

View on GitHub (pinned to b0637c97ec)