astrid-runtime/astrid · error
MCP attach host is empty
Error message
MCP attach host is empty
What it means
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.
Source
Thrown at crates/astrid-cli/src/commands/mcp/attach.rs:113
let host_session_id = std::env::var("ASTRID_SESSION_ID")
.or_else(|_| std::env::var("AOS_MCP_SESSION_ID"))
.or_else(|_| std::env::var("MCP_SESSION_ID"))
.context("MCP attach requires the host session key in ASTRID_SESSION_ID")?;
if host_session_id.trim().is_empty() {
anyhow::bail!("MCP attach host session key is empty");
}
build_registration_with_context(caller, workspace, ready, &host, &host_session_id)
}
fn build_registration_with_context(
caller: &astrid_core::PrincipalId,
workspace: Option<&Path>,
ready: &super::lifecycle::GatewayReady,
host: &str,
host_session_id: &str,
) -> Result<AttachRegistration> {
if host.trim().is_empty() {
anyhow::bail!("MCP attach host is empty");
}
if host_session_id.trim().is_empty() {
anyhow::bail!("MCP attach host session key is empty");
}
let workspace_abs = absolute_workspace(workspace)?;
Ok(AttachRegistration {
version: ATTACH_REGISTRATION_VERSION,
principal: caller.to_string(),
host: host.to_owned(),
workspace_abs: workspace_abs.to_string_lossy().into_owned(),
host_session_id: host_session_id.to_owned(),
hook_token: ready.hook_token.clone(),
})
}
/// Copy both directions until either side closes.
async fn proxy_stdio(stream: UnixStream) -> Result<()> {
let (mut gateway_read, mut gateway_write) = tokio::io::split(stream);View on GitHub (pinned to affd8760f4)
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
Example fix
// before $ aos mcp attach --host "$HOST" # HOST="" // after $ aos mcp attach --host "localhost:8443"
Defensive patterns
Strategy: validation
Validate before calling
let host = cli_host.or(env_host).unwrap_or_default();
if host.trim().is_empty() { return Err("MCP attach host must be a non-empty value"); } Type guard
fn valid_host(h: &str) -> bool { !h.trim().is_empty() } Try / catch
match build_registration(&caller, &ws, &ready, &host).await {
Err(e) if e.to_string().contains("host is empty") => eprintln!("supply --host"),
other => other,
} Prevention
- Always pass --host explicitly in scripts
- Validate config files for empty host fields
- Default host values should never resolve to empty strings
When it happens
Trigger: `aos mcp attach` where the resolved --host value (or its default, e.g. from env/config) is "" or whitespace.
Common situations: Config file with host=""; a script passing an empty variable as --host; template expansion that dropped the host value.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- invalid value for {capsule_id}.{key}: expected one of {}, go
- signed Distro member '{}' must resolve to a prebuilt .capsul
- MCP attach host session key is empty
- gateway.idle_shutdown_secs must be positive and representabl
- MCP gateway control authority is incomplete
AI-assisted analysis of astrid-runtime/astrid@affd8760f4 (2026-09-09).
Data as JSON: /api/errors/9cc27e0befa3e009.
Report an issue: GitHub.