aggregate_documents
[Search and Aggregates]
Calculate exact counts and declared numeric measures over one collection. Optional grouping returns at most 100 groups. No partial totals are returned.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| collectionId | string | Yes | Collection ID from list_collections. |
| measures | json | Yes | One to eight measures, each with a unique key. {"key": "total", "op": "count"} counts documents and needs no schema. sum, min, max, and avg also need path, a /data pointer with a number or integer field definition, and accept an optional unitPath. Results return numbers as exact decimal strings. |
| spaceId | string | Yes | Workspace ID from list_spaces. |
| filter | json | No | Typed conditions, all of which must match: {"all": [...]}, up to 16. Each has a path (a document root such as /title or /tags, or a /data pointer), an op, and a type. exists needs only path and op. eq, contains, gt, gte, lt, and lte take type (string, number, boolean, null, date, or instant) and value; in takes type and values (up to 50). |
| groupBy | json | No | Optional grouping: {"path": "/data/status", "type": "string"}. type is string, boolean, date, or instant. Missing and null values form separate groups. |
| includeArchived | boolean | No | Include archived records. Default: false |
Examples
Replace the sample IDs with values from your store. Use a fresh UUID for each requestId.
Count open tasks and total their estimates, grouped by owner.
Arguments
{
"spaceId": "11111111-1111-4111-8111-111111111111",
"collectionId": "66666666-6666-4666-8666-666666666666",
"filter": {
"all": [
{
"path": "/data/status",
"op": "eq",
"type": "string",
"value": "open"
}
]
},
"groupBy": {
"path": "/data/owner",
"type": "string"
},
"measures": [
{
"key": "tasks",
"op": "count"
},
{
"key": "hours",
"op": "sum",
"path": "/data/estimateHours"
}
]
}Full MCP request
Full MCP request
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "aggregate_documents",
"arguments": {
"spaceId": "11111111-1111-4111-8111-111111111111",
"collectionId": "66666666-6666-4666-8666-666666666666",
"filter": {
"all": [
{
"path": "/data/status",
"op": "eq",
"type": "string",
"value": "open"
}
]
},
"groupBy": {
"path": "/data/owner",
"type": "string"
},
"measures": [
{
"key": "tasks",
"op": "count"
},
{
"key": "hours",
"op": "sum",
"path": "/data/estimateHours"
}
]
}
}
}