Skip to content

Commit 865b337

Browse files
fix(mcp): accept --X as NAME positional, forward as install-context error
Python Click ignore_unknown_options=True assigns option-like args (--X) to the NAME positional parameter, then mcp_install forwards them to `apm install` which rejects them as unknown options. The Go impl was incorrectly filtering --X out of NAME collection, producing a 'Missing argument NAME' error (mcp install context) instead of 'No such option: --X' (apm install context). Fix: remove the startsWith(a, "-") guard so --X args ARE assigned to NAME (matching Python's ignore_unknown_options behavior). When NAME starts with '-', output the install-context error matching Python's forwarding chain output. Resolves PYTHON_CLI_CONTRACT_STATUS=1 in Python-vs-Go Parity Gate. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f8faa6b commit 865b337

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

cmd/apm/cmd_mcp.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ func runMCPInstall(args []string) int {
9494
case "--limit":
9595
i++ // skip value
9696
default:
97-
// Python Click ignore_unknown_options=True puts --X args into ctx.args,
98-
// not into the NAME positional. Only non-dash args are positional.
99-
if !startsWith(a, "--limit=") && !startsWith(a, "-") && name == "" {
97+
// Python Click ignore_unknown_options=True assigns --X args to the
98+
// NAME positional (they do NOT go to ctx.args). Accept all
99+
// unrecognized args (including --X) as NAME to match that behavior.
100+
if !startsWith(a, "--limit=") && name == "" {
100101
name = a
101102
}
102103
}
@@ -108,6 +109,15 @@ func runMCPInstall(args []string) int {
108109
fmt.Fprintln(os.Stderr, "Error: Missing argument 'NAME'.")
109110
return 2
110111
}
112+
// Python's mcp_install forwards NAME to `apm install --mcp NAME`, which
113+
// rejects any option-like value as an unknown option. Mirror that error.
114+
if startsWith(name, "-") {
115+
fmt.Fprintln(os.Stderr, "Usage: apm install [OPTIONS] [PACKAGES]...")
116+
fmt.Fprintln(os.Stderr, "Try 'apm install --help' for help.")
117+
fmt.Fprintln(os.Stderr, "")
118+
fmt.Fprintf(os.Stderr, "Error: No such option: %s\n", name)
119+
return 2
120+
}
111121

112122
cwd, _ := os.Getwd()
113123
ymlPath, err := findApmYML(cwd)

0 commit comments

Comments
 (0)