refactor(mcp): parseAddArgs via stdlib flag.FlagSet#40
Merged
Conversation
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Internal refactor of
nib mcp add's flag parsing (cmd/mcpmanage.go'sparseAddArgs). No behavior change.The function grew flag-by-flag across the MCP CLI work and the recent remote-auth work (#39) into ten near-identical
switchcases — two per flag (--url,--transport,--env,--token,--header), one for the space-separated form and one for inline--flag=value— plus a manual pre-scan loop to find a standalone--and split off the stdio command's own argv.Replaced with stdlib
flag.FlagSet, mirroring the existingparseInstallArgspattern already incmd/plugin.go(two-passflag.NewFlagSet(..., flag.ContinueOnError)parse, handling a positional<name>argument that can appear relative to flags). This isn't a new dependency or a foreign idiom —flagis already imported incmd/mcp.go,cmd/plugin.go, andcmd/skill.go.--url/--transport/--tokenbecomefs.StringVarcalls.--env/--header(both repeatableKEY=VALUEflags) share one smallkvFlagtype implementingflag.Value, registered twice.---boundary scan is deleted entirely: stdlibflag.FlagSetalready terminates parsing at a bare--, strips it, and returns everything after it viafs.Args()— exactly the "rest is the stdio command's own argv" behavior the old code hand-rolled.http/sse, exactly one of command/URL) is unchanged.Error message text changes in a few places (stdlib's own wording for missing-value/unknown-flag cases) — no test asserts exact text, only
err == nil/err != nil, and this is a dev CLI with no message-stability contract.Design spec:
docs/superpowers/specs/2026-07-01-mcpmanage-flag-parsing-refactor.md(local-only, gitignored, not part of this diff)Implementation plan:
docs/superpowers/plans/2026-07-01-mcpmanage-flag-parsing-refactor.md(same)Test plan
cmd/mcpmanage_test.gopass unchanged, both before (baseline) and after the refactor — no test file editsgo build ./...,go vet ./...,go test ./...all clean across every package---boundary termination (confirmedfs.Args()correctly excludes--and returns the literal command argv, including a flag-shaped literal like-x), and thekvFlagmap-aliasing (confirmedmap[string]string→kvFlagconversion shares the backing map, soSetcalls correctly populatesrv.Env/srv.Headers)🤖 Generated with Claude Code