Skip to content

aggregate_records should default fields to *#3529

Open
souvikghosh04 wants to merge 2 commits intomainfrom
Usr/sogh/aggrecdef
Open

aggregate_records should default fields to *#3529
souvikghosh04 wants to merge 2 commits intomainfrom
Usr/sogh/aggrecdef

Conversation

@souvikghosh04
Copy link
Copy Markdown
Contributor

@souvikghosh04 souvikghosh04 commented May 7, 2026

Why make this change?

  • Closes [Enh]: aggregate_records should default fields to * #3280
  • The aggregate_records MCP tool requires callers to explicitly pass a field argument, even for the most common case (function: count) where * is the only sensible value. The issue requests defaulting field to "*" in the JSON Schema so LLM clients (and other MCP callers) can omit the argument for count-all scenarios, aligning the tool with the conventional COUNT(*) shape.

What is this change?

  • Updated the aggregate_records tool's input schema in AggregateRecordsTool.cs:
    • Added "default": "*" to the field property and clarified its description.
    • Removed "field" from the schema's required array (now only entity and function are required).
  • Updated argument parsing in TryParseAndValidateArguments so that when field is omitted:
    • function: countfield defaults to "*" (existing count(*) validation/path is preserved).
    • function: avg | sum | min | max ⇒ returns an InvalidArguments error explaining a specific numeric field is required, since "*" is invalid for those aggregations.
  • Existing behavior is preserved when field is explicitly supplied (including the field='*' + non-count rejection and the distinct + count(*) rejection).

How was this tested?

  • Integration Tests
  • Unit Tests
    • Updated GetToolMetadata_HasRequiredSchemaProperties to assert:
      • field is no longer in the required array.
      • The field property declares "default": "*".
    • Updated AggregateRecords_MissingOrInvalidRequiredArgs_ReturnsInvalidArguments data rows to:
      • Remove the now-invalid "missing field with count" failure case.
      • Add new rows asserting avg / sum without field return an InvalidArguments error mentioning field.
    • All 60 tests in AggregateRecordsToolTests pass locally.

Sample Request(s)

Before this change (required):

{
  "tool": "aggregate_records",
  "arguments": {
    "entity": "Book",
    "function": "count",
    "field": "*"
  }
}

After this change (field may be omitted for count):

{
  "tool": "aggregate_records",
  "arguments": {
    "entity": "Book",
    "function": "count"
  }
}

Non-count functions still require an explicit field:

// Returns InvalidArguments: "Missing required argument 'field'. The default value '*'
// is only valid with function 'count'; for function 'avg', provide a specific numeric field name."
{
  "tool": "aggregate_records",
  "arguments": {
    "entity": "Book",
    "function": "avg"
  }
}

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the aggregate_records built-in MCP tool to make field optional for the common count(*) scenario by declaring a JSON Schema default ("*"), removing field from the required list, and adding runtime validation to only apply that default for function=count.

Changes:

  • Updated aggregate_records input schema: field is no longer required and declares "default": "*".
  • Updated argument parsing to default field to "*" only when function=count; non-count functions now error if field is omitted.
  • Updated unit tests to validate the schema’s required list and field default, and to adjust missing-field validation cases.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Azure.DataApiBuilder.Mcp/BuiltInTools/AggregateRecordsTool.cs Makes field optional in the schema and implements defaulting/validation behavior in argument parsing.
src/Service.Tests/Mcp/AggregateRecordsToolTests.cs Updates schema assertions and missing-argument test cases to reflect the new optional field behavior.

Comment thread src/Azure.DataApiBuilder.Mcp/BuiltInTools/AggregateRecordsTool.cs
Comment thread src/Service.Tests/Mcp/AggregateRecordsToolTests.cs
@souvikghosh04 souvikghosh04 moved this from In Progress to Review In Progress in Data API builder May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Review In Progress

Development

Successfully merging this pull request may close these issues.

[Enh]: aggregate_records should default fields to *

4 participants