Skip to content

fix(mcp): drop -p shorthand on --port to avoid collision with global --profile - #9

Open
Millon15 wants to merge 1 commit into
zach-snell:mainfrom
Millon15:mcp-port-shorthand-collision
Open

fix(mcp): drop -p shorthand on --port to avoid collision with global --profile#9
Millon15 wants to merge 1 commit into
zach-snell:mainfrom
Millon15:mcp-port-shorthand-collision

Conversation

@Millon15

Copy link
Copy Markdown
Contributor

Problem

bbkt mcp panics immediately on startup and never serves:

panic: unable to redefine 'p' shorthand in "mcp" flagset: it's already used for "port" flag

goroutine 1 [running]:
github.com/spf13/pflag.(*FlagSet).AddFlag(...)
...
github.com/spf13/cobra.(*Command).mergePersistentFlags(...)
github.com/spf13/cobra.(*Command).InitDefaultHelpFlag(...)
github.com/spf13/cobra.(*Command).execute(...)

The persistent --profile flag and the mcp-local --port flag both claim the -p shorthand:

  • cmd/cli/root.goRootCmd.PersistentFlags().StringP("profile", "p", "", ...)
  • cmd/cli/mcp.gomcpCmd.Flags().IntVarP(&port, "port", "p", 0, ...)

When cobra runs mergePersistentFlags (via InitDefaultHelpFlag at execute time), pflag panics because two flags in the mcp flagset want -p. Only mcp is affected — it's the sole subcommand defining its own -p — which is why the rest of the CLI works while bbkt mcp always crashes.

Net effect: MCP clients (Claude Code/Desktop, Cursor, etc.) can never connect over stdio — the server process dies before the handshake, surfacing as a generic transport failure on the client side.

Fix

Drop the -p shorthand from --port:

mcpCmd.Flags().IntVar(&port, "port", 0, "Port to listen on for HTTP Streamable transport")
  • --profile -p (global, documented in --help examples) is unchanged.
  • --port keeps its long form; stdio MCP clients don't use a port at all, and the HTTP-transport example already uses --port 8080 (long form), so docs stay accurate.

Verification

# before: panic on startup
$ bbkt mcp
panic: unable to redefine 'p' shorthand in "mcp" flagset: it's already used for "port" flag

# after: clean stdio startup, responds to initialize
$ bbkt mcp        # serves over stdio, no panic

go build ./cmd/bbkt passes.


🤖 Generated with Claude Code

…--profile

`bbkt mcp` panicked at startup:

    panic: unable to redefine 'p' shorthand in "mcp" flagset: it's already used for "port" flag

The persistent `--profile` flag (cmd/cli/root.go) and the mcp-local `--port`
flag (cmd/cli/mcp.go) both registered the `-p` shorthand. cobra's
mergePersistentFlags panics when it merges the global `-p` into the mcp
flagset, so every `bbkt mcp` invocation crashed before serving — MCP clients
(Claude Code/Desktop, Cursor) could never connect over stdio.

Drop the rarely-used `-p` shorthand from `--port`; the long `--port` still
works and stdio clients don't use it at all. `--profile -p` is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant