{"record":{"id":"9cc27e0befa3e009","repo":"astrid-runtime/astrid","slug":"mcp-attach-host-is-empty","errorCode":null,"errorMessage":"MCP attach host is empty","messagePattern":"MCP attach host is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-cli/src/commands/mcp/attach.rs","lineNumber":113,"sourceCode":"    let host_session_id = std::env::var(\"ASTRID_SESSION_ID\")\n        .or_else(|_| std::env::var(\"AOS_MCP_SESSION_ID\"))\n        .or_else(|_| std::env::var(\"MCP_SESSION_ID\"))\n        .context(\"MCP attach requires the host session key in ASTRID_SESSION_ID\")?;\n    if host_session_id.trim().is_empty() {\n        anyhow::bail!(\"MCP attach host session key is empty\");\n    }\n    build_registration_with_context(caller, workspace, ready, &host, &host_session_id)\n}\n\nfn build_registration_with_context(\n    caller: &astrid_core::PrincipalId,\n    workspace: Option<&Path>,\n    ready: &super::lifecycle::GatewayReady,\n    host: &str,\n    host_session_id: &str,\n) -> Result<AttachRegistration> {\n    if host.trim().is_empty() {\n        anyhow::bail!(\"MCP attach host is empty\");\n    }\n    if host_session_id.trim().is_empty() {\n        anyhow::bail!(\"MCP attach host session key is empty\");\n    }\n    let workspace_abs = absolute_workspace(workspace)?;\n    Ok(AttachRegistration {\n        version: ATTACH_REGISTRATION_VERSION,\n        principal: caller.to_string(),\n        host: host.to_owned(),\n        workspace_abs: workspace_abs.to_string_lossy().into_owned(),\n        host_session_id: host_session_id.to_owned(),\n        hook_token: ready.hook_token.clone(),\n    })\n}\n\n/// Copy both directions until either side closes.\nasync fn proxy_stdio(stream: UnixStream) -> Result<()> {\n    let (mut gateway_read, mut gateway_write) = tokio::io::split(stream);","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-cli/src/commands/mcp/attach.rs#L95-L131","documentation":"build_registration_with_context validates the host string before constructing the AttachRegistration. An all-whitespace or empty host would yield a registration the gateway cannot route, so it is rejected with this error.","triggerScenarios":"`aos mcp attach` where the resolved --host value (or its default, e.g. from env/config) is \"\" or whitespace.","commonSituations":"Config file with host=\"\"; a script passing an empty variable as --host; template expansion that dropped the host value.","solutions":["Pass an explicit host: `aos mcp attach --host <host>`","Fix the config/env that supplies an empty host default","Trim whitespace from the value before invoking"],"exampleFix":"// before\n$ aos mcp attach --host \"$HOST\"   # HOST=\"\"\n// after\n$ aos mcp attach --host \"localhost:8443\"","handlingStrategy":"validation","validationCode":"let host = cli_host.or(env_host).unwrap_or_default();\nif host.trim().is_empty() { return Err(\"MCP attach host must be a non-empty value\"); }","typeGuard":"fn valid_host(h: &str) -> bool { !h.trim().is_empty() }","tryCatchPattern":"match build_registration(&caller, &ws, &ready, &host).await {\n    Err(e) if e.to_string().contains(\"host is empty\") => eprintln!(\"supply --host\"),\n    other => other,\n}","preventionTips":["Always pass --host explicitly in scripts","Validate config files for empty host fields","Default host values should never resolve to empty strings"],"tags":["mcp","validation","config"],"backgroundTag":"empty-required-field","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}