Hmbown/CodeWhale · error · anyhow::Error

required MCP server failed to initialize

Error message

required MCP server failed to initialize

What it means

After a connect pass completes, the pool checks servers marked required and reports this error for any that never reached the ready state and have no other recorded error. It ensures a required server's absence is loud even when the individual handshake produced no diagnostic.

Solutions

  1. Check the server's command/URL in the MCP config and verify it starts manually (e.g. run the listed command directly)
  2. Ensure the required server is enabled in config (is_enabled)
  3. Check server logs/stderr for why the handshake did not complete; if it is simply slow, retry the connect
Defensive patterns

Strategy: validation

Validate before calling

// before startup, verify each required server is configured and enabled
for name in required_servers {
    let cfg = config.server_config(&name).ok_or_else(|| anyhow!("required server '{name}' missing"))?;
    anyhow::ensure!(cfg.is_enabled(), "required server '{name}' disabled");
}

Prevention

When it happens

Trigger: A server listed as required in MCP config failed to become ready (is_ready() false) after the concurrent handshake pass, and it is absent from the errors list.

Common situations: Required server binary missing or failing silently at spawn; required server disabled in config; slow server that did not finish handshake within the pass.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/d5fe2f0c42495543. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/mcp.rs:3763

    pub(crate) fn push_required_server_errors(&self, errors: &mut Vec<McpConnectError>) {
        for (name, server_cfg) in &self.config.servers {
            // Only stand in for a missing diagnosis. When the connect attempt
            // above already reported why this server failed, appending a
            // second, contentless entry for the same name buries it: callers
            // fold these pairs into a `HashMap<name, message>`, so the later
            // generic string silently replaced the real cause.
            if self.server_allowed(name)
                && server_cfg.required
                && server_cfg.is_enabled()
                && !self
                    .connections
                    .get(name)
                    .is_some_and(McpConnection::is_ready)
                && !errors.iter().any(|(failed, _)| failed == name)
            {
                errors.push((
                    name.clone(),
                    anyhow::anyhow!("required MCP server failed to initialize"),
                ));
            }
        }
    }

    /// Handshake the pending servers concurrently without holding the pool
    /// lock. Callers insert results under a short lock so a live turn can
    /// snapshot ready tools while optional servers are still connecting.
    pub(crate) fn spawn_pending_connects(
        pending: Vec<McpPendingConnect>,
        timeouts: McpTimeouts,
        network_policy: Option<NetworkPolicyDecider>,
        catalog_generation: u64,
    ) -> tokio::task::JoinSet<(String, Result<McpConnection, anyhow::Error>)> {
        let semaphore = std::sync::Arc::new(tokio::sync::Semaphore::new(Self::CONNECT_CONCURRENCY));
        let mut joins: tokio::task::JoinSet<(String, Result<McpConnection, anyhow::Error>)> =
            tokio::task::JoinSet::new();
        for (name, config) in pending {

View on GitHub (pinned to 73e0f67d83)