Skip to content

mcpx: zsh completion script fails to parse (unquoted _describe entries) #272

Closed

Description

@dezren39

Bug

mcpx completion zsh generates a script that zsh cannot parse.

This is the same defect as dezren39/darwin-nix#365 (fixed there by PR #379), present in this repo's pkgs/mcpx copy: the fix was never ported here. pkgs/mcpx/internal/cli/completion.go (~line 92, zshCompletion) still emits each _describe commands entry unquoted:

fmt.Fprintf(&b, "    %s:%s\n", c.Name, zshEscape(c.Summary))

Summaries carry apostrophes, parentheses and glob brackets — e.g. prompts: list or render a server's prompts (manual.go:414) and search: find tools by name and description (keyword or semantic). zshEscape turns ' into '\'', which is only valid inside single quotes, and leaves parens/brackets bare.

Reproduction (verified on main a29abd3, 2026-10-18)

$ go build -o /tmp/mcpx ./cmd/mcpx   # in pkgs/mcpx
$ /tmp/mcpx completion zsh > comp.zsh
$ zsh -n comp.zsh
comp.zsh:192: parse error near `;;'
$ echo $?
1

Generated array (excerpt):

    prompts:list or render a server'\''s prompts
    resources:list or read a server'\''s resources
    search:find tools by name and description (keyword or semantic)

No existing issue in this repo tracks this (gh search issues --repo developing-today/code zsh → none); there is also no internal/cli/completion_test.go in this copy.

Why it matters

Anyone who installs the zsh completion gets a script their shell rejects at load — the completion feature is simply broken for zsh users, silently. It was already diagnosed and fixed once in the sibling copy; letting the copies drift means users here keep the broken version.

Suggested fix (mirrors dezren39/nix PR #379)

  • Emit each commands entry single-quoted: '%s:%s' with a new zshDescribe helper that only handles _describe's own syntax (backslash-escape : inside the description, '\'' for apostrophes) instead of reusing zshEscape.
  • Keep zshEscape for the flag-description sites, which are already inside single quotes.
  • Port the regression tests from nix (internal/cli/completion_test.go): every commands entry is single-quoted, an apostrophe-bearing entry is present, and zshDescribe escapes colons/quotes.

Acceptance criteria

  • mcpx completion zsh | zsh -n exits 0
  • bash/fish completions still parse (bash -n, fish -n or equivalent)
  • New regression tests in internal/cli fail on the pre-fix code and pass with the fix
  • go test ./internal/cli/ passes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions