Hmbown/CodeWhale · warning · anyhow::Error

invalid JSON payload at key {MCP_SERVER_DEFINITIONS_KEY}; co

Error message

invalid JSON payload at key {MCP_SERVER_DEFINITIONS_KEY}; contents were omitted

What it means

The config key mcp.server_definitions must hold a JSON array of MCP server definitions (or a JSON string wrapping such an array for legacy double-encoded values). When the raw value is not parseable as JSON at all, parse_mcp_server_definitions raises this error with contents deliberately omitted. The interactive load path downgrades it to a warning and starts the stdio MCP server with an empty list.

Source

Thrown at crates/cli/src/lib.rs:4364

    match parse_mcp_server_definitions(&raw) {
        Ok(definitions) => definitions,
        Err(err) => {
            eprintln!(
                "warning: failed to parse persisted MCP server definitions ({MCP_SERVER_DEFINITIONS_KEY}): {err}"
            );
            Vec::new()
        }
    }
}

fn parse_mcp_server_definitions(raw: &str) -> Result<Vec<McpServerDefinition>> {
    if let Ok(parsed) = serde_json::from_str::<Vec<McpServerDefinition>>(raw) {
        return Ok(parsed);
    }

    let unwrapped: String = serde_json::from_str(raw).map_err(|_| {
        anyhow!("invalid JSON payload at key {MCP_SERVER_DEFINITIONS_KEY}; contents were omitted")
    })?;
    serde_json::from_str::<Vec<McpServerDefinition>>(&unwrapped).map_err(|_| {
        anyhow!(
            "invalid MCP server definition list in key {MCP_SERVER_DEFINITIONS_KEY}; contents were omitted"
        )
    })
}

fn persist_mcp_server_definitions(
    store: &mut ConfigStore,
    definitions: &[McpServerDefinition],
) -> Result<()> {
    let encoded =
        serde_json::to_string(definitions).context("failed to encode MCP server definitions")?;
    store
        .config
        .set_value(MCP_SERVER_DEFINITIONS_KEY, &encoded)?;
    store.save()

View on GitHub (pinned to 8880682c63)

Solutions

  1. Replace the value with a valid JSON array of definitions, matching the current McpServerDefinition schema
  2. Or delete the key and re-register servers via the mcp commands so the CLI re-persists canonical JSON
  3. If servers vanished after the warning, check stderr for the accompanying "failed to parse persisted MCP server definitions" line

Example fix

# before (config, invalid — TOML not JSON)
 [mcp] 
 server_definitions = [{ command = "npx", args = ["-y", "fs"] }] 

# after
 [mcp] 
 server_definitions = '[{"command":"npx","args":["-y","fs"]}]'
Defensive patterns

Strategy: validation

Validate before calling

function assert_mcp_definitions_json(config_path) {
  const raw = readTomlKey(config_path, "mcp.server_definitions");
  if (raw != null) JSON.parse(raw); // throws before launch if not JSON
}

Prevention

When it happens

Trigger: Hand-editing the config and writing a TOML-style value at mcp.server_definitions (e.g. server_definitions = [{ command = "npx" }]) instead of JSON; a truncated config; an external tool rewriting the extras table into a non-JSON form.

Common situations: Migrating configs between CLI versions; editing with the wrong syntax assumption; tooling that re-renders extras entries (the class of bug fixed for #4727 where TOML re-quoting broke JSON payloads).

Understand the failure class

Related errors


AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16). Data as JSON: /api/errors/28439b145c7d7f15. Report an issue: GitHub.