zed-industries/zed · error · anyhow::Error

Expected exactly one context server configuration

Error message

Expected exactly one context server configuration

What it means

The context-server settings paste parser deserializes the text as `HashMap<String, Temp>` where each entry is one `{ url, headers?, oauth? }` server config, keyed by server name. It then requires exactly one entry: `value.len() != 1` bails. The modal accepts a single named server configuration object, not a list, not multiple servers, not an empty object.

Solutions

  1. Paste exactly one entry: `{ "my-server": { "url": "..." } }`.
  2. Add additional servers one at a time, one paste per server.
  3. Remove outer `"context_servers":` wrappers and sibling server entries before pasting.
  4. Keep optional `headers` and `oauth` inside the inner object, not beside the server key.

Example fix

// before — pasted block with two servers
{
  "a": { "url": "https://a.example/sse" },
  "b": { "url": "https://b.example/sse" }
}

// after — one server per paste
{ "a": { "url": "https://a.example/sse" } }
Defensive patterns

Strategy: validation

Validate before calling

let value: serde_json::Value = serde_json::from_str(text)?;
if let serde_json::Value::Object(map) = &value {
    if map.len() != 1 { /* reject before parse: paste exactly one named server */ }
}

Type guard

fn is_single_server_config(text: &str) -> bool {
    serde_json::from_str::<serde_json::Value>(text)
        .ok()
        .and_then(|v| v.as_object().map(|m| m.len() == 1))
        .unwrap_or(false)
}

Try / catch

match parse_context_server_config(text) {
    Err(e) if e.to_string().contains("exactly one context server") => {
        // prompt the user to paste one `{ "name": { "url": ... } }` entry at a time
    }
    rest => rest,
}

Prevention

When it happens

Trigger: Pasting `{}` (empty), a config with two server keys, a JSON array `[{...}]`, or wrapping the server in an extra nesting level so the map has more than one key (or zero, when the top level is not an object — which instead fails serde with a different error).

Common situations: Users copy a whole `context_servers` settings block containing several servers, or an MCP server list from another tool's config, and paste it into Zed's single-server modal.

Related errors


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/c09134f2b29b51f6. Report an issue: GitHub.

Appendix: source

Thrown at crates/agent_ui/src/agent_configuration/configure_context_server_modal.rs:357

fn parse_http_input(
    text: &str,
) -> Result<(
    ContextServerId,
    String,
    HashMap<String, String>,
    Option<OAuthClientSettings>,
)> {
    #[derive(Deserialize)]
    struct Temp {
        url: String,
        #[serde(default)]
        headers: HashMap<String, String>,
        #[serde(default)]
        oauth: Option<OAuthClientSettings>,
    }
    let value: HashMap<String, Temp> = serde_json_lenient::from_str(text)?;
    if value.len() != 1 {
        anyhow::bail!("Expected exactly one context server configuration");
    }

    let (key, value) = value.into_iter().next().unwrap();

    Ok((
        ContextServerId(key.into()),
        value.url,
        value.headers,
        value.oauth,
    ))
}

fn resolve_context_server_extension(
    id: ContextServerId,
    worktree_store: Entity<WorktreeStore>,
    cx: &mut App,
) -> Task<Option<ConfigurationTarget>> {
    let registry = ContextServerDescriptorRegistry::default_global(cx).read(cx);

View on GitHub (pinned to f4178619ac)