{"record":{"id":"c09134f2b29b51f6","repo":"zed-industries/zed","slug":"expected-exactly-one-context-server-configuration","errorCode":null,"errorMessage":"Expected exactly one context server configuration","messagePattern":"Expected exactly one context server configuration","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/agent_ui/src/agent_configuration/configure_context_server_modal.rs","lineNumber":357,"sourceCode":"fn parse_http_input(\n    text: &str,\n) -> Result<(\n    ContextServerId,\n    String,\n    HashMap<String, String>,\n    Option<OAuthClientSettings>,\n)> {\n    #[derive(Deserialize)]\n    struct Temp {\n        url: String,\n        #[serde(default)]\n        headers: HashMap<String, String>,\n        #[serde(default)]\n        oauth: Option<OAuthClientSettings>,\n    }\n    let value: HashMap<String, Temp> = serde_json_lenient::from_str(text)?;\n    if value.len() != 1 {\n        anyhow::bail!(\"Expected exactly one context server configuration\");\n    }\n\n    let (key, value) = value.into_iter().next().unwrap();\n\n    Ok((\n        ContextServerId(key.into()),\n        value.url,\n        value.headers,\n        value.oauth,\n    ))\n}\n\nfn resolve_context_server_extension(\n    id: ContextServerId,\n    worktree_store: Entity<WorktreeStore>,\n    cx: &mut App,\n) -> Task<Option<ConfigurationTarget>> {\n    let registry = ContextServerDescriptorRegistry::default_global(cx).read(cx);","sourceCodeStart":339,"sourceCodeEnd":375,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/agent_ui/src/agent_configuration/configure_context_server_modal.rs#L339-L375","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Paste exactly one entry: `{ \"my-server\": { \"url\": \"...\" } }`.","Add additional servers one at a time, one paste per server.","Remove outer `\"context_servers\":` wrappers and sibling server entries before pasting.","Keep optional `headers` and `oauth` inside the inner object, not beside the server key."],"exampleFix":"// before — pasted block with two servers\n{\n  \"a\": { \"url\": \"https://a.example/sse\" },\n  \"b\": { \"url\": \"https://b.example/sse\" }\n}\n\n// after — one server per paste\n{ \"a\": { \"url\": \"https://a.example/sse\" } }","handlingStrategy":"validation","validationCode":"let value: serde_json::Value = serde_json::from_str(text)?;\nif let serde_json::Value::Object(map) = &value {\n    if map.len() != 1 { /* reject before parse: paste exactly one named server */ }\n}","typeGuard":"fn is_single_server_config(text: &str) -> bool {\n    serde_json::from_str::<serde_json::Value>(text)\n        .ok()\n        .and_then(|v| v.as_object().map(|m| m.len() == 1))\n        .unwrap_or(false)\n}","tryCatchPattern":"match parse_context_server_config(text) {\n    Err(e) if e.to_string().contains(\"exactly one context server\") => {\n        // prompt the user to paste one `{ \"name\": { \"url\": ... } }` entry at a time\n    }\n    rest => rest,\n}","preventionTips":["Paste one server object per operation, keyed by server name.","Strip wrapper keys like `context_servers` and sibling entries before pasting.","Validate the pasted JSON shape with `jq 'length == 1'` when scripting."],"tags":["rust","zed","context-server","mcp","json","configuration","paste"],"backgroundTag":"invalid-config-shape","analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}