Update new option binding handling#2915
Open
alzimmermsft wants to merge 8 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
⚠️ Not ready to approve
The new OptionTypeHandler has critical correctness issues (enum multi-value binding type mismatch and unsafe IEnumerable element-type extraction) and alias support lacks regression tests.
Pull request overview
This PR refactors the core option-binding pipeline used by commands to improve option creation/binding flexibility (notably adding alias support), moving from a type-handler dictionary to descriptor-driven OptionTypeHandler creation with caching.
Changes:
- Introduces
OptionTypeHandlerto createSystem.CommandLine.Optioninstances fromOptionDescriptor(including support forAliases) and bind values via option-instance lookup. - Updates option descriptor and binder behavior to better account for nullability and multi-value arity, and removes the old enum validator helper in favor of in-handler validation.
- Adjusts related extensions/docs and adopts primary constructor usage in one command base class.
File summaries
| File | Description |
|---|---|
| core/Microsoft.Mcp.Core/tests/Microsoft.Mcp.Core.Tests/Options/OptionBinderTests.cs | Updates array arity expectation in unit tests (nullable array now treated as ZeroOrMore). |
| core/Microsoft.Mcp.Core/src/Options/OptionTypeHandler.cs | Adds the new descriptor-driven option creation/binding implementation (including aliases, nullability/multi-value handling, enum validation). |
| core/Microsoft.Mcp.Core/src/Options/OptionNameConvention.cs | Moves the type into the Options namespace and minor formatting. |
| core/Microsoft.Mcp.Core/src/Options/OptionDescriptor.cs | Makes Description required, adds Aliases, and updates descriptor creation from [Option]. |
| core/Microsoft.Mcp.Core/src/Options/OptionBinder.cs | Switches to cached OptionTypeHandler[] per options type for registration and binding. |
| core/Microsoft.Mcp.Core/src/Options/OptionAttribute.cs | Adds Aliases to the attribute contract. |
| core/Microsoft.Mcp.Core/src/Options/EnumOptionValidator.cs | Removes the prior enum option validator helper (logic moved into OptionTypeHandler). |
| core/Microsoft.Mcp.Core/src/Extensions/ParseResultExtensions.cs | Adds an internal option-instance-based getter helper for the new binding approach. |
| core/Microsoft.Mcp.Core/src/Extensions/CommandResultExtensions.cs | Adds a matching internal option-instance-based getter helper for the new binding approach. |
| core/Microsoft.Mcp.Core/src/Commands/BaseCommand`2.cs | Adds XML doc comments for option validation hook. |
| core/Azure.Mcp.Core/src/Commands/Subscription/SubscriptionCommand`2.cs | Converts to a primary constructor and simplifies field initialization. |
Copilot's findings
- Files reviewed: 11/11 changed files
- Comments generated: 11
Note
Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.
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.
What does this PR do?
Updates new option binding handling with the following updates:
Aliaseswhen binding command-line options.DefaultValuewhen binding command-line options.Dictionarylookup for handling with more flexibleOptionTypeHandler.CreateFromDescriptor. This better supportsstring?and arity handling.OptionTypeHandlers for eachTOptionprocessed asOptions are handled in a way where they aren't mutated once created.Optionwith when changing requiredness that existed in the old binding pattern.GitHub issue number?
[Link to the GitHub issue this PR addresses]Pre-merge Checklist
servers/Azure.Mcp.Server/README.mdand/orservers/Fabric.Mcp.Server/README.mddocumentationREADME.mdchanges running the script./eng/scripts/Process-PackageReadMe.ps1. See Package READMEToolDescriptionEvaluatorand obtained a score of0.4or more and a top 3 ranking for all related test promptsconsolidated-tools.jsonbreaking-changelabelservers/Azure.Mcp.Server/docs/azmcp-commands.md./eng/scripts/Update-AzCommandsMetadata.ps1to update tool metadata inazmcp-commands.md(required for CI)servers/Azure.Mcp.Server/docs/e2eTestPrompts.mdcrypto mining, spam, data exfiltration, etc.)/azp run mcp - pullrequest - liveto run Live Test Pipeline