Repository navigation
Add bounded, resumable pagination for MCP query and ls - #204
Conversation
MCP calls to query and container-item ls now return one Cosmos DB page per call, capped at 100 items by default, with the page's continuation token surfaced as a top-level continuationToken in the structured result. A null token signals exhaustion. Agents resume by passing the token back as the continuation argument. The continuation argument is MCP-only: it is injected into the tool schema and bound explicitly rather than declared as a CosmosOption, so it never appears in shell help, parsing, or docs, and the token is kept out of the echoed command line. IPagedCommand is the single source of truth for which commands paginate, driving the schema, the default cap, and binding. Interactive and scripted behavior is unchanged: those paths keep their multi-page aggregation and the SELECT TOP rewrite, which cannot coexist with a continuation token because tokens are only settable through MCP. The shared max help text keeps its whole-result wording for the shell; the single-page clarification is appended only to the MCP schema. Closes #161
Database and container name listings enumerate their complete result sets and do not expose resumable continuation tokens. Only container-item listings are marked as paged, and the MCP payload documentation now states that scope explicitly.
Code Coverage OverviewLanguages: C# C# / code-coverage/dotnetThe overall line coverage in commit 902a466 in the Show a line coverage summary of the most impacted files.
Updated |
There was a problem hiding this comment.
Pull request overview
Adds bounded, resumable pagination semantics specifically for MCP tool calls (query and container-item ls) to prevent unbounded result floods while keeping interactive/scripting shell behavior unchanged (still aggregates pages normally).
Changes:
- Introduces an
IPagedCommandcontract and MCP wiring to (a) apply a safe defaultmaxof 100 for paged MCP tools and (b) accept an MCP-onlycontinuationargument. - Surfaces a top-level
continuationTokenin MCP structured responses for paged results (includingnullat exhaustion). - Documents the MCP paging contract and adds tests covering schema/defaults and continuation token output.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| README.md | Notes MCP paging behavior and links to detailed pagination docs. |
| docs/mcp.md | Documents continuationToken and the MCP resume flow for paged tools. |
| docs/commands.md | Clarifies MCP-only paging semantics for query and container-item ls. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Mcp/ToolOperations.cs | Adds MCP schema/default handling for paging and binds MCP-only continuation. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Mcp/McpResponseFactory.cs | Adds continuationToken to structured MCP success payloads for paged results. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/CommandState.cs | Adds paging metadata fields (IsPage, ContinuationToken) to command results. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/QueryCommand.cs | Implements IPagedCommand, binds continuation into query iterator, and returns single page under MCP. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/ListCommand.cs | Implements IPagedCommand, binds continuation into item listing iterator, and returns single page under MCP. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/IPagedCommand.cs | New interface defining MCP-only paging inputs for eligible commands. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/CommandFactory.cs | Exposes IsPaged discovery for MCP schema generation/binding. |
| CosmosDBShell.Tests/ToolOperationsTests.cs | Adds coverage for paging schema defaults/descriptions and continuation exposure/binding. |
| CosmosDBShell.Tests/McpResponseFactoryTests.cs | Adds coverage for continuationToken being present (including null) for paged results. |
Suppressed comments (1)
CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/ListCommand.cs:270
- For MCP
lsitem listings,result.limitReachedcurrently only becomes true when the returned item count hitsmax. Cosmos DB can return fewer thanMaxItemCountand still provide a non-null continuation token, so callers could seecontinuationTokenbutlimitReached=false, contradicting the documented MCP paging contract.
var reachedLimit = limitReached && effectiveMaxItemCount.HasValue;
returnState.Result = new ShellJson(JsonSerializer.SerializeToElement(new { type = "item", values = list, limitReached = reachedLimit }));
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Return a sanitized MCP error when `continuation` is not a string or null instead of silently restarting pagination. Add direct binder coverage and an end-to-end CallTool test.
Keep the continuation schema and binder consistent by accepting only non-null strings. Clarify that null continuation output means paging is complete, and add direct and end-to-end null-input coverage.
Derive MCP `limitReached` from continuation-token presence so short Cosmos pages correctly signal that more results remain. Preserve existing shell semantics and add focused regression coverage.
Normalize omitted and non-positive MCP max values to the safe 100-item default for query and ls while preserving shell unlimited semantics. Advertise a positive schema minimum and update tests and documentation.
Resolve pagination conflicts with request charge tracking
There was a problem hiding this comment.
🟢 Approval recommended
The paging contract is consistently implemented across schema, binding, command execution, responses, documentation, and has targeted regression coverage for the key edge cases.
Review details
- Files reviewed: 16/16 changed files
- Comments generated: 0 new
- Review effort level: Lite
Summary
queryand container-itemlscallmaxis omittedcontinuationToken, includingnullat exhaustioncontinuationas an MCP-only argument without exposing or echoing it in the interactive shellImplementation notes
IPagedCommandis the single source of truth used for MCP schema generation, default caps, and continuation binding. Interactive and scripted shell behavior remains unchanged and continues to aggregate pages normally.The shared
maxhelp text retains shell semantics; MCP tool schemas add a paging-specific clarification that callers must usecontinuationTokento detect exhaustion.Validation
Closes #161