[WIP] Add aggregate_records DML tool to MCP server#3180
Closed
Conversation
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.
Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.
Original prompt
This section details on the original issue you should resolve
<issue_title>[Enh]: add
aggregate_recordsDML tool to MCP server</issue_title><issue_description>## What?
Allow models to answer: "How many products are there?" and "What is our most expensive product?"
Why?
These are among the most common information discovery questions, a primary model use case.
How?
Introduce a new tool:
aggregate_recordsthat reuses native GraphQL aggregation capabilities in DAB.Schema
{ "type": "object", "properties": { "entity": { "type": "string", "description": "Entity name with READ permission.", "required": true }, "function": { "type": "string", "enum": ["count", "avg", "sum", "min", "max"], "description": "Aggregation function to apply.", "required": true }, "field": { "type": "string", "description": "Field to aggregate. Use '*' for count.", "required": true }, "distinct": { "type": "boolean", "description": "Apply DISTINCT before aggregating.", "default": false }, "filter": { "type": "string", "description": "OData filter applied before aggregating (WHERE). Example: 'unitPrice lt 10'", "default": "" }, "groupby": { "type": "array", "items": { "type": "string" }, "description": "Fields to group by, e.g., ['category', 'region']. Grouped field values are included in the response.", "default": [] }, "orderby": { "type": "string", "enum": ["asc", "desc"], "description": "Sort aggregated results by the computed value. Only applies with groupby.", "default": "desc" }, "having": { "type": "object", "description": "Filter applied after aggregating on the result (HAVING). Operators are AND-ed together.", "properties": { "eq": { "type": "number", "description": "Aggregated value equals." }, "neq": { "type": "number", "description": "Aggregated value not equals." }, "gt": { "type": "number", "description": "Aggregated value greater than." }, "gte": { "type": "number", "description": "Aggregated value greater than or equal." }, "lt": { "type": "number", "description": "Aggregated value less than." }, "lte": { "type": "number", "description": "Aggregated value less than or equal." }, "in": { "type": "array", "items": { "type": "number" }, "description": "Aggregated value is in the given list." } } } }, "required": ["entity", "function", "field"] }Response Alias Convention
The aggregated value in the response is always aliased as
{function}_{field}. Forcountwith"*", the alias iscount.Examples
Q1: "How many products are there?"
{ "entity": "Product", "function": "count", "field": "*" }Example output:
Q2: "What is the average price of products under $10?"
{ "entity": "Product", "function": "avg", "field": "unitPrice", "filter": "unitPrice lt 10" }Example output:
Q3: "Which categories have more than 20 products?"
{ "entity": "Product", "function": "count", "field": "*", "groupby": ["categoryName"], "having": { "gt": 20 } }Example output:
Q4: "For discontinued products, which categories have a total revenue between $500 and $10,000?"
{ "entity": "Product", "function": "sum", "field": "unitPrice", "filter": "discontinued eq true", "groupby": ["categoryName"], "having": { "gte": 500, "lte": 10000 } }Example output:
Q5: "How many distinct suppliers do we have?"
{ "entity": "Product", "function": "count", "field": "supplierId", "distinct": true }Example output:
Q6: "Which categories have exactly 5 or 10 products?"
{ "entity": "Product", "function": "count", "field": "*", "groupby": ["categoryName"], "having": { "in": [5, 10] } }