Skip to content

Render MCP command results in the interactive shell - #302

Merged
Mike Krüger (mkrueger) merged 5 commits into
mainfrom
dev/mkrueger/fix/mcp-terminal-output
Nov 24, 2026
Merged

Mike Krüger (mkrueger) merged 5 commits into
mainfrom
dev/mkrueger/fix/mcp-terminal-output

Conversation

@mkrueger

@mkrueger Mike Krüger (mkrueger) commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

MCP-generated commands currently appear in the terminal without their results. Render each completed tool invocation through the normal shell output path, as if the user had typed the command.

  • Display results using the explicit command format (user, json, csv, or table) or the current session default.
  • Display final warnings, returned failures, and thrown command errors while retaining structured MCP responses and paging metadata.
  • Keep command execution and terminal rendering inside the existing serialization gate, refresh the prompt after success or failure, and propagate rendering failures to the MCP client.
  • Document the terminal behavior and add typed-command parity, format, warning, error, and real HTTP transport regression coverage.

Validation

  • Both shell and test projects built successfully with zero warnings and errors, using a separate output directory because a running shell locks the default executable.
  • 254 focused tests passed: tool operations, MCP response formatting, HTTP transport/location subscriptions, destructive confirmation, and command error handling.
  • Real Streamable HTTP and legacy SSE calls verify that the result appears exactly once in the terminal while remaining available to the client.
  • git diff --check passed.

Compatibility

MCP response envelopes, confirmation requirements, and paging semantics remain unchanged. The intended behavior change is visible terminal output after MCP-generated commands. No migration steps are required.

Backport

Backport to rel/1.2: #303. Merge this PR first, then the backport.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

MCP calls still fail to return plain-text results under a CSV session default, and some command failures display duplicate diagnostics.

2 open issues
What changed in this PR

This PR routes completed MCP commands through the shell’s normal output path so terminal users can see results, warnings, and errors alongside echoed commands.

Changes:

  • Render results using explicit or session-default formats while retaining structured MCP responses.
  • Keep rendering inside serialized execution and refresh the prompt after success or failure.
  • Document terminal behavior and add format, error, warning, and HTTP transport regression coverage.
File Description
docs/​mcp.md Documents terminal results and format selection for MCP calls.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Mcp/​ToolOperations.cs Renders completed commands and refreshes the prompt in cleanup.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Core/​ShellInterpreter.cs Adds shared command-result and error rendering.
CosmosDBShell.Tests/​ToolOperationsCallToolTests.cs Adds rendering parity, format, warning, and failure coverage.
CosmosDBShell.Tests/​McpLocationSubscriptionTests.cs Checks terminal output through Streamable HTTP and legacy SSE.

Review effort: Balanced

@github-code-quality

github-code-quality Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: C#

C# / code-coverage/dotnet

main 088cc6e dev/mkrueger/fix/mcp... 21dbe68 +/-
76% 76% 0%
View coverage of the 8 most impacted files.
File main 088cc6e dev/mkrueger/fix/mcp... 21dbe68 +/-
D:\a\CosmosDBSh...ceOperations.cs 51% 51% 0%
D:\a\CosmosDBSh...\HelpCommand.cs 86% 86% 0%
D:\a\CosmosDBSh...osmosCommand.cs 80% 80% 0%
D:\a\CosmosDBSh...olOperations.cs 95% 95% 0%
D:\a\CosmosDBSh...ponseFactory.cs 98% 98% 0%
D:\a\CosmosDBSh...lInterpreter.cs 80% 81% +1%
D:\a\CosmosDBSh...ThemeCommand.cs 72% 73% +1%
D:\a\CosmosDBSh...\ListCommand.cs 18% 36% +18%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 18, 2026 22:39 UTC

Avoid duplicate diagnostics for already-reported command failures and preserve plain-text MCP results under CSV session defaults. Add regression coverage and simplify output assertions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 10:24
@mkrueger

Copy link
Copy Markdown
Collaborator Author

Addressed all eight review threads in d203314: prevented duplicate diagnostics from theme/help failures, preserved plain-text MCP responses with CSV defaults from both --output and COSMOSDB_SHELL_FORMAT, and consolidated the flagged output assertions. Added regression tests and updated the MCP outputText documentation. Validation: 224 focused tests passed; shell and test builds passed with zero warnings/errors; git diff --check passed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unconditional rendered flags suppress structured JSON error output for failed theme commands and unknown help topics, breaking machine-mode diagnostics and stderr redirection.

2 open issues
2 resolved since last review

Review effort: Balanced

Mike Krüger (mkrueger) added a commit that referenced this pull request Nov 18, 2026
Avoid duplicate diagnostics for already-reported command failures and preserve plain-text MCP results under CSV session defaults. Add regression coverage and simplify output assertions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Resolve theme/help conflicts using shared error reporting and extend MCP coverage for user, JSON, CSV, and redirected errors. Align command echo expectations and documentation with the centralized output policy.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 12:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A terminal-rendering failure discards the completed command’s request charge, causing MCP responses to omit the RUs already consumed.

1 open issue
2 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because real-host command failures can produce duplicate terminal diagnostics through overlapping error-rendering and logging paths.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are identified for the MCP terminal-output changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@mkrueger
Mike Krüger (mkrueger) merged commit bcdf254 into main Nov 24, 2026
13 checks passed
@mkrueger
Mike Krüger (mkrueger) deleted the dev/mkrueger/fix/mcp-terminal-output branch November 24, 2026 10:10
Mike Krüger (mkrueger) added a commit that referenced this pull request Nov 24, 2026
* Render MCP command results in the interactive shell

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit 7e8db53)

* Fix MCP result rendering review issues (#302)

Avoid duplicate diagnostics for already-reported command failures and preserve plain-text MCP results under CSV session defaults. Add regression coverage and simplify output assertions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Preserve machine-mode error diagnostics (#303)

Only mark help and theme errors as rendered when their human-facing diagnostics are visible. Cover unknown help topics in machine output and stderr redirection tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants