astrid-runtime/astrid · error
MCP attach registration has an empty host
Error message
MCP attach registration has an empty host
What it means
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.
Source
Thrown at crates/astrid-cli/src/commands/mcp/gateway.rs:928
if control.pid == 0 || control.hook_token.trim().is_empty() {
anyhow::bail!("MCP gateway control authority is incomplete");
}
},
GatewayRequest::Attach(registration) => validate_registration(registration)?,
}
Ok(request)
}
fn validate_registration(registration: &AttachRegistration) -> Result<()> {
if registration.version != ATTACH_REGISTRATION_VERSION {
anyhow::bail!(
"unsupported MCP attach registration version {}",
registration.version
);
}
super::lifecycle::resolve_principal(Some(®istration.principal))?;
if registration.host.trim().is_empty() {
anyhow::bail!("MCP attach registration has an empty host");
}
if registration.host_session_id.trim().is_empty() {
anyhow::bail!("MCP attach registration has an empty host_session_id");
}
if registration.hook_token.trim().is_empty() {
anyhow::bail!("MCP attach registration is missing hook_token");
}
validate_workspace(®istration.workspace_abs)?;
Ok(())
}
fn authenticate_registration(
registration: &AttachRegistration,
state: &GatewayState,
) -> Result<astrid_core::PrincipalId> {
let principal = super::lifecycle::resolve_principal(Some(®istration.principal))?;
if principal != state.principal {
anyhow::bail!(View on GitHub (pinned to affd8760f4)
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.
Example fix
// before
let host = std::env::var("ASTRID_HOST").unwrap_or_default();
// after
let host = std::env::var("ASTRID_HOST")
.ok()
.filter(|h| !h.trim().is_empty())
.or_else(|| hostname::get().ok().map(|h| h.to_string_lossy().into_owned()))
.context("host is required")?; Defensive patterns
Strategy: validation
Validate before calling
fn host_ok(host: &str) -> bool { !host.trim().is_empty() } Type guard
fn non_blank(s: &str) -> Option<&str> {
let t = s.trim();
if t.is_empty() { None } else { Some(t) }
} Try / catch
match result {
Err(e) if e.to_string().contains("empty host") => eprintln!("registration.host must be a non-empty hostname/project identifier"),
other => other?,
} Prevention
- 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.
When it happens
Trigger: An attach registration whose host field is "" or whitespace-only, checked in validate_registration right after resolve_principal.
Common situations: 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.
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
- MCP gateway control authority is incomplete
- MCP attach host session key is empty
- MCP attach host is empty
- MCP gateway attach limit reached for principal '{principal}'
- gateway.idle_shutdown_secs must be positive and representabl
AI-assisted analysis of astrid-runtime/astrid@affd8760f4 (2026-09-09).
Data as JSON: /api/errors/a01aa11c886e72bd.
Report an issue: GitHub.