Surface Cosmos request charge (RUs) in MCP structured results#171
Open
mkrueger wants to merge 4 commits into
Open
Surface Cosmos request charge (RUs) in MCP structured results#171mkrueger wants to merge 4 commits into
mkrueger wants to merge 4 commits into
Conversation
Code Coverage OverviewLanguages: C# C# / code-coverage/dotnetThe overall coverage in the branch remains at 61%, unchanged from the branch. Show a code coverage summary of the most impacted files.
Updated |
7d8462a to
298a962
Compare
MCP tool results now populate CallToolResult.StructuredContent with the same JSON payload (result/outputText/error + currentLocation) already emitted as a text block, kept byte-for-byte equivalent. Text-only clients are unaffected. Documents the response contract in docs/mcp.md and adds parity tests.
298a962 to
ae7fc14
Compare
Add a uniform RequestCharge property to CommandState and emit it as a top-level 'requestCharge' field in the MCP tool result payload. Retrofit data-plane commands (query, print, mkitem, replace, patch, rm, import, export, and sproc exec) to record the request units consumed so agents can track RU cost consistently across calls. The document result shape is unchanged; requestCharge is a sibling metadata field. Addresses part (a) of #162.
3cdc2f2 to
044df91
Compare
…charge-surfacing # Conflicts: # CHANGELOG.md # CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/RmCommand.cs
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a consistent way for data-plane commands to report Cosmos DB request charge (RUs) by storing it on CommandState and emitting it as a top-level requestCharge field in MCP tool-result payloads (both structuredContent and the legacy JSON text block).
Changes:
- Add
CommandState.RequestChargeand include it asrequestChargein MCP success payloads when set. - Retrofit multiple data-plane commands (
query,print,mkitem,replace,patch,rm,import,export,sproc exec) to capture RU charge. - Document the MCP payload shape and add/extend tests validating
structuredContentparity andrequestChargebehavior.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/mcp.md | Documents tool-result payload shape and the new requestCharge metadata field. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Mcp/McpResponseFactory.cs | Emits StructuredContent and adds requestCharge to the MCP success payload when available. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/CommandState.cs | Introduces the nullable RequestCharge field for commands to populate. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/QueryCommand.cs | Attempts to aggregate query RU charges and store them on CommandState. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/PrintCommand.cs | Captures point-read RU charge from response headers. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/MakeItemCommand.cs | Accumulates RU charges across single/bulk writes and propagates to returned state. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/ReplaceCommand.cs | Returns total replace charge (single/bulk) and sets it on the returned state. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/PatchCommand.cs | Sets request charge from patch response. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/RmCommand.cs | Tracks delete RU charges and sets them on the command state. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/ImportCommand.cs | Sets aggregated RU charge on success. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/ExportCommand.cs | Sets aggregated RU charge on success. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/SprocCommand.cs | Captures RU charge from stored procedure execution. |
| CosmosDBShell.Tests/McpResponseFactoryTests.cs | Adds tests for StructuredContent population/parity and requestCharge presence/omission. |
| CosmosDBShell.Tests/CommandTests/SprocCommandExecutionTests.cs | Extends sproc exec test to assert RequestCharge is captured. |
| CHANGELOG.md | Adds entries describing structured MCP results and RU surfacing. |
…ent, include scan pages)
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.
Relates to #162 (implements part (a); does not close the issue).
Summary
Surfaces the Cosmos DB request charge (RUs) consumed by data-plane commands as a uniform, machine-readable field on MCP tool results. This addresses part (a) of #162 (RU-cost surfacing) -- consistent RU reporting in structured output. It does not include the budget/
--max-ruguardrails (part b), which are proposed as a separate follow-up.Today RU is reported ad-hoc and inconsistently:
queryincludes it in structured output only in one code path, most write commands print it to the console as a formatted string, and reads/deletes don't report it at all. This change makes RU a first-class, consistent part of the MCP structured contract.What changed
CommandState.RequestCharge-- a new nullabledoublethat data-plane commands set with the RUs consumed.McpResponseFactoryemits a top-levelrequestChargenumber in the structured tool result (and the equivalent text block) whenever it is set. Theresultdocument shape is unchanged;requestChargeis a sibling metadata field, so existing result parsers and CSV/table rendering are unaffected.query-- accumulatesTotalRequestChargeacross pagesprint-- point-read charge from the response headersmkitem,replace,patch-- single and bulk write chargesrm-- accumulates delete charges (previously untracked)import/export-- bulk aggregate chargesproc exec-- stored-procedure execution chargeDesign notes
resultdocument, to avoid changing the document contract that clients parse.Docs
requestChargefield indocs/mcp.md(payload shape table + notes).Testing
McpResponseFactorytests:requestChargepresent when set, omitted when unset.sproc exectest to assert the captured charge.Stacking
Based on
dev/mkrueger/mcp-structured-content(#168) because therequestChargefield extends the MCPstructuredContentpayload introduced there. GitHub will retarget the base tomainonce #168 merges.Part of the Agentic & Automation roadmap, item G2.
Fixes #162