Skip to main content

sanitize_cli_name

Function sanitize_cli_name 

Source
pub fn sanitize_cli_name(name: &str) -> String
Expand description

Sanitize an arbitrary string into a safe CLI command / script name.

§Rules (applied in order)

  1. Lowercase the entire string.
  2. Replace every character not in [a-z0-9_-] with -.
  3. Collapse consecutive [-_] sequences into a single -.
  4. Strip leading and trailing - and _.
  5. If the result is empty, use "mcp".
  6. If the result starts with a digit, prepend "mcp-".

§Examples

InputOutput
"My Server!""my-server"
"atlassian-labs""atlassian-labs"
" spaces ""spaces"
"""mcp"
"123abc""mcp-123abc"
"multi spaces""multi-spaces"