Route CLI parse-error help to stderr - #3177
Open
Pybsama wants to merge 2 commits into
Open
Conversation
Pybsama
requested review from
KarishmaGhiya,
RickWinter,
chidozieononiwu,
g2vinay,
msalaman,
sandeep-sen and
vukelich
July 29, 2026 07:16
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Thank you for your contribution @Pybsama! We will review the pull request and get back to you soon. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Azure MCP CLI stdio stream hygiene by ensuring command-line parse failures (e.g., missing subcommand) emit generated help/usage and diagnostics to stderr, keeping stdout reserved for MCP JSON-RPC messages. It updates the shared help action to honor the System.CommandLine-selected output writer and adds process-level tests to lock in stdout/stderr behavior for both bare invocation and explicit --help.
Changes:
- Route parse-error invocations through a custom
InvocationConfigurationthat sets bothOutputandErrortoConsole.Error. - Update
CustomHelpActionto write viaparseResult.InvocationConfiguration.Output(instead of writing directly toConsole). - Add CLI process tests and a bug-fix changelog entry documenting the user-visible behavior change.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| servers/Azure.Mcp.Server/tests/Azure.Mcp.Server.Tests/Infrastructure/CliOutputTests.cs | Adds process-level assertions for stdout/stderr routing on bare invocation vs explicit --help. |
| servers/Azure.Mcp.Server/src/Program.cs | Introduces parse-error-only invocation configuration to route help/diagnostics to stderr. |
| servers/Azure.Mcp.Server/changelog-entries/pybsama-missing-command-stderr.yml | Records the bug fix in changelog-entry YAML format. |
| core/Microsoft.Mcp.Core/src/Commands/CustomHelpAction.cs | Ensures help/version output uses System.CommandLine’s configured output writer (supports stderr routing on parse errors). |
Author
|
@microsoft-github-policy-service agree |
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?
Routes Azure MCP command-line parse failures to stderr so stdout stays reserved for MCP JSON-RPC messages.
The root cause had two parts:
CustomHelpActionwrote directly toConsole, bypassing the output writer selected by System.CommandLine.This PR makes the shared custom help action honor
InvocationConfiguration.Outputand configures both the output and error writers as stderr only when parsing fails. Successful invocations keep the default stream routing, so explicit--helpcontinues to exit successfully with help on stdout and validserver startJSON-RPC framing is unchanged.Process-level tests cover both bare invocation and explicit help, and a bug-fix changelog entry records the user-visible correction.
GitHub issue number?
Fixes #3098
Validation
dotnet build servers/Azure.Mcp.Server/src/Azure.Mcp.Server.csproj— passed with zero errors.dotnet test servers/Azure.Mcp.Server/tests/Azure.Mcp.Server.Tests/Azure.Mcp.Server.Tests.csproj --filter "FullyQualifiedName~CliOutputTests"— passed 2/2.dotnet test servers/Azure.Mcp.Server/tests/Azure.Mcp.Server.Tests/Azure.Mcp.Server.Tests.csproj --filter "FullyQualifiedName~ServerModeCoverageTests.SingleMode_Should_List_Tools_Without_Initialize"— passed 1/1 and retained JSON-RPC output on stdout.dotnet format --verify-no-changeschecks for all modified C# files — passed.Compile-Changelog.ps1 -DryRun— passed without changing the generated changelog.Invoke-Cspell.ps1andgit diff --check— passed.--help: exit 0, stdout 298 lines, stderr 0 lines.Local restore note: the configured Azure Artifacts feed returned 401 for packages that were not already cached, and the repository's currently pinned dependency graph reports NU1903. The targeted local restore/build/test pass therefore used NuGet.org as a command-line package source with
NuGetAudit=false. No dependencies ornuget.configfiles were changed.Pre-merge Checklist