{"record":{"id":"a01aa11c886e72bd","repo":"astrid-runtime/astrid","slug":"mcp-attach-registration-has-an-empty-host","errorCode":null,"errorMessage":"MCP attach registration has an empty host","messagePattern":"MCP attach registration has an empty host","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-cli/src/commands/mcp/gateway.rs","lineNumber":928,"sourceCode":"            if control.pid == 0 || control.hook_token.trim().is_empty() {\n                anyhow::bail!(\"MCP gateway control authority is incomplete\");\n            }\n        },\n        GatewayRequest::Attach(registration) => validate_registration(registration)?,\n    }\n    Ok(request)\n}\n\nfn validate_registration(registration: &AttachRegistration) -> Result<()> {\n    if registration.version != ATTACH_REGISTRATION_VERSION {\n        anyhow::bail!(\n            \"unsupported MCP attach registration version {}\",\n            registration.version\n        );\n    }\n    super::lifecycle::resolve_principal(Some(&registration.principal))?;\n    if registration.host.trim().is_empty() {\n        anyhow::bail!(\"MCP attach registration has an empty host\");\n    }\n    if registration.host_session_id.trim().is_empty() {\n        anyhow::bail!(\"MCP attach registration has an empty host_session_id\");\n    }\n    if registration.hook_token.trim().is_empty() {\n        anyhow::bail!(\"MCP attach registration is missing hook_token\");\n    }\n    validate_workspace(&registration.workspace_abs)?;\n    Ok(())\n}\n\nfn authenticate_registration(\n    registration: &AttachRegistration,\n    state: &GatewayState,\n) -> Result<astrid_core::PrincipalId> {\n    let principal = super::lifecycle::resolve_principal(Some(&registration.principal))?;\n    if principal != state.principal {\n        anyhow::bail!(","sourceCodeStart":910,"sourceCodeEnd":946,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-cli/src/commands/mcp/gateway.rs#L910-L946","documentation":"validate_registration requires registration.host to be a non-empty, non-blank string. The gateway routes attach bytes per host/project, so an empty host makes the registration unusable and it is rejected before any slot is reserved.","triggerScenarios":"An attach registration whose host field is \"\" or whitespace-only, checked in validate_registration right after resolve_principal.","commonSituations":"An integration layer that fails to detect the current project/host and passes an empty string; environment variables like hostname/project context missing when the client built the registration; CLI invocations run outside a recognized workspace so host resolves to empty.","solutions":["Ensure the attaching client sets host from a valid source (hostname / project root) before serializing the registration; trim it and check non-empty first.","Run `mcp attach` inside a recognized workspace/project directory so host context is detected.","Check that environment variables or config supplying the host value are present and non-blank in the attach client's environment.","If host should default to the machine hostname, fix the client to fall back to hostname::get() instead of an empty literal."],"exampleFix":"// before\nlet host = std::env::var(\"ASTRID_HOST\").unwrap_or_default();\n// after\nlet host = std::env::var(\"ASTRID_HOST\")\n    .ok()\n    .filter(|h| !h.trim().is_empty())\n    .or_else(|| hostname::get().ok().map(|h| h.to_string_lossy().into_owned()))\n    .context(\"host is required\")?;","handlingStrategy":"validation","validationCode":"fn host_ok(host: &str) -> bool { !host.trim().is_empty() }","typeGuard":"fn non_blank(s: &str) -> Option<&str> {\n    let t = s.trim();\n    if t.is_empty() { None } else { Some(t) }\n}","tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"empty host\") => eprintln!(\"registration.host must be a non-empty hostname/project identifier\"),\n    other => other?,\n}","preventionTips":["Resolve host from a reliable source (hostname crate or project root) with a fallback.","Validate all registration fields non-blank before connecting.","Run attach from a recognized workspace so host context exists.","Fail fast client-side with a clear message when host cannot be determined."],"tags":["mcp","validation","gateway","empty-field"],"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"}