fix(cli): skip reserved flag names in canonical MCP command generator#444
Open
typefield wants to merge 1 commit into
Open
fix(cli): skip reserved flag names in canonical MCP command generator#444typefield wants to merge 1 commit into
typefield wants to merge 1 commit into
Conversation
MCP tools whose inputSchema contains properties named "params", "json",
"format", "timeout", "yes", or any other name that collides with built-in
or inherited persistent flags cause a pflag panic ("flag redefined") when
the canonical command tree is constructed.
The compat/overlay path already filters "json" and "params", but the
canonical path in applyFlagSpecs did not. This adds a dynamic collision
check using cmd.Flags().Lookup so any future persistent flag additions
are automatically covered. Colliding alias names are also skipped.
Users can still pass these values via --json '{"params":"..."}'.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Author
测试验证报告1. 单元测试2. cli_to_mcp E2E 全量测试(17 个产品)使用 dws-wukong develop 分支构建的二进制(含本次 fix),逐产品运行 pytest:
3. 关键验证点
4. dws-wukong Go 测试
|
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
panic: flag redefined: paramswhen MCP tool inputSchema contains properties namedparams,json, or any name colliding with built-in/inherited CLI flagsapplyFlagSpecsusingcmd.Flags().Lookup/cmd.InheritedFlags().LookupRoot Cause
The canonical MCP command path (
internal/cli/canonical.go) auto-generates CLI flags fromtools/listinputSchema. When a tool (e.g.chat_permission_grant) declares a property namedparams, the generator tries to register--paramswhich conflicts with the built-in--paramsflag.pflagpanics on duplicate registration.The compat/overlay path already filters reserved names, but the canonical path did not.
Fix
applyFlagSpecsnow checks if the flag name (or alias) already exists before registering. This covers all built-in and inherited persistent flags dynamically. Users can still pass colliding values via--json '{"params":"..."}'.Test plan
TestApplyFlagSpecsSkipsReservedAndInheritedFlags,TestApplyFlagSpecsSkipsCollidingAliasgo test ./internal/cli/— all pass🤖 Generated with Claude Code