[MCP] Bug-fix- aggregate_records always requires groupby#3294
[MCP] Bug-fix- aggregate_records always requires groupby#3294souvikghosh04 wants to merge 3 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes aggregate_records MCP tool behavior so simple aggregations (e.g., count(*)) don’t get blocked by an auto-populated orderby that previously forced groupby, addressing issue #3279.
Changes:
- Removed the
orderbyschema default so models/clients are less likely to sendorderbyunnecessarily. - Updated groupby dependency validation to ignore
orderbywhengroupbyis absent (instead of erroring). - Added/updated tests to cover the “orderby without groupby” scenario and to assert the schema no longer includes an
orderbydefault.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/Azure.DataApiBuilder.Mcp/BuiltInTools/AggregateRecordsTool.cs | Removes orderby default from tool schema and changes validation to clear/ignore orderby when groupby is not present. |
| src/Service.Tests/Mcp/AggregateRecordsToolTests.cs | Replaces the previous “orderby without groupby” rejection test with new coverage asserting the new behavior and schema shape. |
You can also share your feedback on Copilot code review. Take the survey.
| [DataRow("{\"entity\": \"Book\", \"function\": \"count\", \"field\": \"*\", \"orderby\": \"asc\"}", | ||
| DisplayName = "count(*) with orderby asc, no groupby")] | ||
| [DataRow("{\"entity\": \"Book\", \"function\": \"avg\", \"field\": \"price\", \"orderby\": \"desc\"}", | ||
| DisplayName = "avg(price) with orderby desc, no groupby")] |
There was a problem hiding this comment.
no need to change the aggregation function - avg, sum to test the same input validation as done for count
Essentially, avg and sum tests are redundant, can be removed
| { | ||
| bool userProvidedOrderby = true; | ||
| CallToolResult? result = AggregateRecordsTool.ValidateGroupByDependencies( | ||
| groupbyCount: 0, |
There was a problem hiding this comment.
The tests above regarding validation already cover this.
Aniruddh25
left a comment
There was a problem hiding this comment.
Remove some redundant tests
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
Why make this change?
aggregate_recordsALWAYS requiresgroupby#3279The aggregate_records MCP tool always rejects requests without groupby because the orderby schema has "default": "desc", causing LLMs to always include it, which then triggers a validation error requiring groupby. Simple aggregations like SELECT COUNT(*) FROM table had to go through this kind of behaviour and complexity.
What is this change?
Removed "default": "desc" from the orderby input schema so LLMs no longer auto-populate it.
Updated ValidateGroupByDependencies to silently ignore orderby when groupby is absent instead of returning an error. Ordering is meaningless without grouping, so the parameter is harmlessly cleared via a ref flag.
How was this tested?