{"record":{"id":"a4484b8c5b20d2b5","repo":"xai-org/grok-build","slug":"server-name-cannot-be-empty","errorCode":null,"errorMessage":"Server name cannot be empty.","messagePattern":"Server name cannot be empty\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-pager/src/mcp_cmd.rs","lineNumber":582,"sourceCode":"}\n\nfn is_gateway_cli_toggle_name(name: &str) -> bool {\n    name.starts_with(\"managed_gateway:\") || name.contains(':')\n}\n\nfn available_mcp_server_names(cwd: &Path) -> Vec<String> {\n    let mut names: Vec<String> = xai_grok_shell::util::config::cli_known_mcp_server_names(cwd)\n        .into_iter()\n        .collect();\n    names.sort();\n    names\n}\n\nasync fn run_set_enabled(name: &str, enabled: bool) -> Result<()> {\n    // Do not use validate_server_name (add-only: [A-Za-z0-9_-])\n    // Enable/disable also targets compat/plugin names that may contain dots or other keys\n    if name.is_empty() {\n        bail!(\"Server name cannot be empty.\");\n    }\n    if is_gateway_cli_toggle_name(name) {\n        eprintln!(\n            \"Gateway connectors (e.g. managed_gateway:…) cannot be toggled via CLI; use Space in /mcps.\"\n        );\n        std::process::exit(1);\n    }\n    let cwd = current_dir_or_exit();\n\n    if !mcp_server_is_known(name, &cwd) {\n        eprintln!(\"No MCP server named '{name}'.\");\n        let available = available_mcp_server_names(&cwd);\n        if !available.is_empty() {\n            eprintln!(\"Available servers: {}\", available.join(\", \"));\n        } else {\n            eprintln!(\"No MCP servers configured. Run `grok mcp add --help` to get started.\");\n        }\n        std::process::exit(1);","sourceCodeStart":564,"sourceCodeEnd":600,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-pager/src/mcp_cmd.rs#L564-L600","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Provide the MCP server name as the first argument: grok mcp set-enabled my-server on","Check the shell/config value feeding the name is non-empty (echo \"$NAME\" before running the command)","Use `grok mcp list` (or /mcps in the TUI) to find the exact server name","If a name contains dots or unusual characters, it is still accepted here — only emptiness is rejected"],"exampleFix":"// before (empty variable)\ngrok mcp set-enabled \"$SERVER\" on   # SERVER=\"\"\n\n// after (guard in script)\n[ -n \"$SERVER\" ] || { echo \"SERVER is unset\"; exit 2; }\ngrok mcp set-enabled \"$SERVER\" on","handlingStrategy":"validation","validationCode":"fn validate_toggle_name(name: &str) -> Result<(), String> {\n    if name.is_empty() {\n        return Err(\"MCP server name must be a non-empty string\".into());\n    }\n    Ok(())\n}\n// call validate_toggle_name(name)? before running the CLI command","typeGuard":"fn is_non_empty(s: &str) -> bool { !s.trim().is_empty() }","tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"Server name cannot be empty\") => {\n        eprintln!(\"Fix: pass a non-empty server name; see `grok mcp list`.\");\n    }\n    other => other?,\n}","preventionTips":["Always source server names from `grok mcp list` output, not free text","Guard shell variables with ${VAR:?unset} before invoking the CLI","In scripts, validate args non-empty before exec","Prefer the /mcps TUI when unsure of exact names"],"tags":["cli","validation","empty-argument","mcp"],"backgroundTag":"empty-required-argument","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}