Fix MCP orderby validation to return actionable argument errors - #3816
Open
aaronburtle wants to merge 2 commits into
Open
aaronburtle wants to merge 2 commits into
aaronburtle wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
Validation changes are covered by unit and HTTP-level regression tests, with no unresolved review issues.
Pull request overview
Improves MCP orderby validation by returning actionable InvalidArguments errors for malformed inputs.
Changes:
- Validates read and aggregate ordering types.
- Preserves existing ordering behavior and defaults.
- Adds unit and HTTP regression coverage.
File summaries
| File | Description |
|---|---|
src/Service.Tests/Mcp/McpServerConfigurationTests.cs |
Adds HTTP-level MCP validation tests. |
src/Service.Tests/Mcp/BuiltInDmlToolValidationTests.cs |
Tests read ordering shapes and messages. |
src/Service.Tests/Mcp/AggregateRecordsToolTests.cs |
Tests aggregate ordering validation and compatibility. |
src/Azure.DataApiBuilder.Mcp/BuiltInTools/ReadRecordsTool.cs |
Validates and materializes orderby arrays. |
src/Azure.DataApiBuilder.Mcp/BuiltInTools/AggregateRecordsTool.cs |
Validates aggregate orderby JSON types. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Why make this change?
Closes #3810
What is this change?
UnexpectedErrorresponses reported in #3810.orderbyJSON types before accessing their values:read_recordsrequires an array of non-empty strings and validates every array member before metadata resolution.aggregate_recordsrequires a direction string, while preserving its existing null/blank handling.InvalidArgumentswith the parameter name, expected format, and an example.How was this tested?
27 new error-validation regression cases failed against the original implementation and passed after the fix.
Sample Request(s)
Invalid scalar ordering for
read_records{ "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "read_records", "arguments": { "entity": "Book", "orderby": "id desc" } } }Previously returned
UnexpectedError. Now returnsInvalidArgumentsexplaining thatorderbymust be an array of non-empty strings.The supported form remains
"orderby": ["id desc"].Invalid array ordering for
aggregate_records{ "jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": { "name": "aggregate_records", "arguments": { "entity": "Book", "function": "count", "groupby": ["title"], "orderby": ["desc"] } } }Previously returned
UnexpectedError. Now returnsInvalidArgumentsexplaining thatorderbymust be a string containingascordesc.