xai-org/grok-build · error

Server name cannot be empty.

Error message

Server name cannot be empty.

What it means

This error is thrown by the MCP CLI command `run_set_enabled` when a user attempts to enable or disable an MCP server without providing a server name (empty string). The function deliberately avoids `validate_server_name` (which only allows [A-Za-z0-9_-]) because toggling must also work for compat/plugin names containing dots and other characters, so only the empty-string case is checked. It is a cheap sanity guard before any registry/config lookup happens.

Source

Thrown at crates/codegen/xai-grok-pager/src/mcp_cmd.rs:582

}

fn is_gateway_cli_toggle_name(name: &str) -> bool {
    name.starts_with("managed_gateway:") || name.contains(':')
}

fn available_mcp_server_names(cwd: &Path) -> Vec<String> {
    let mut names: Vec<String> = xai_grok_shell::util::config::cli_known_mcp_server_names(cwd)
        .into_iter()
        .collect();
    names.sort();
    names
}

async fn run_set_enabled(name: &str, enabled: bool) -> Result<()> {
    // Do not use validate_server_name (add-only: [A-Za-z0-9_-])
    // Enable/disable also targets compat/plugin names that may contain dots or other keys
    if name.is_empty() {
        bail!("Server name cannot be empty.");
    }
    if is_gateway_cli_toggle_name(name) {
        eprintln!(
            "Gateway connectors (e.g. managed_gateway:…) cannot be toggled via CLI; use Space in /mcps."
        );
        std::process::exit(1);
    }
    let cwd = current_dir_or_exit();

    if !mcp_server_is_known(name, &cwd) {
        eprintln!("No MCP server named '{name}'.");
        let available = available_mcp_server_names(&cwd);
        if !available.is_empty() {
            eprintln!("Available servers: {}", available.join(", "));
        } else {
            eprintln!("No MCP servers configured. Run `grok mcp add --help` to get started.");
        }
        std::process::exit(1);

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Provide the MCP server name as the first argument: grok mcp set-enabled my-server on
  2. Check the shell/config value feeding the name is non-empty (echo "$NAME" before running the command)
  3. Use `grok mcp list` (or /mcps in the TUI) to find the exact server name
  4. If a name contains dots or unusual characters, it is still accepted here — only emptiness is rejected

Example fix

// before (empty variable)
grok mcp set-enabled "$SERVER" on   # SERVER=""

// after (guard in script)
[ -n "$SERVER" ] || { echo "SERVER is unset"; exit 2; }
grok mcp set-enabled "$SERVER" on
Defensive patterns

Strategy: validation

Validate before calling

fn validate_toggle_name(name: &str) -> Result<(), String> {
    if name.is_empty() {
        return Err("MCP server name must be a non-empty string".into());
    }
    Ok(())
}
// call validate_toggle_name(name)? before running the CLI command

Type guard

fn is_non_empty(s: &str) -> bool { !s.trim().is_empty() }

Try / catch

match result {
    Err(e) if e.to_string().contains("Server name cannot be empty") => {
        eprintln!("Fix: pass a non-empty server name; see `grok mcp list`.");
    }
    other => other?,
}

Prevention

When it happens

Trigger: Calling `grok mcp set-enabled "" <on|off>` (or the underlying run_set_enabled with name=""), e.g. because a shell variable holding the server name is unset/empty, or a positional argument was dropped in a script.

Common situations: Shell scripts using ${SERVER_NAME} where the variable is unset; copy-pasted commands where the name field was accidentally deleted; automation pipelines passing empty config values from environment variables or YAML/JSON config files.

Related errors


AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31). Data as JSON: /api/errors/a4484b8c5b20d2b5. Report an issue: GitHub.