count_documents
Count documents in Frappe Framework using flexible filtering with equality, comparison, pattern matching, list, null, and range operators to analyze data efficiently.
Instructions
Count documents in Frappe with optional filters.
This tool addresses the filtering limitation that existed in previous implementations
by using Frappe's native count functionality via the REST API with a custom filter language.
Args:
doctype: DocType name
filters: Filter string (optional). Uses custom syntax to bypass MCP validation issues.
Filter Syntax:
- Simple equality: "field:value" -> {"field": "value"}
- Operators: "field:operator:value" -> {"field": ["operator", value]}
- Multiple filters: "field1:value1,field2:operator:value2"
Supported Operators:
- Equality: = (default), !=
- Comparison: <, >, <=, >=
- Pattern: like, not_like (use % for wildcards)
- Lists: in, not_in (separate values with |)
- Null checks: is:null, is:not_null, is_not:null
- Ranges: between (separate values with |)
Examples:
- "status:Unreconciled" -> Status equals Unreconciled
- "amount:>:100" -> Amount greater than 100
- "name:like:%admin%" -> Name contains 'admin'
- "status:in:Open|Working|Pending" -> Status in list
- "date:between:2025-01-01|2025-12-31" -> Date in range
- "phone:is:not_null" -> Phone is not null
Tool Examples:
- count_documents("User") -> Count all users
- count_documents("Bank Transaction", "status:Unreconciled") -> Count unreconciled transactions
- count_documents("Bank Transaction", "unallocated_amount:>:0") -> Count with unallocated amount
- count_documents("Task", "status:in:Open|Working|Pending") -> Count tasks with multiple statuses
- count_documents("User", "name:like:%admin%") -> Count users with 'admin' in name
- count_documents("Payment Entry", "posting_date:between:2025-01-01|2025-12-31") -> Count in date range
- count_documents("Contact", "phone:is:not_null") -> Count contacts with phone numbers
Input Schema
Name | Required | Description | Default |
---|---|---|---|
doctype | Yes | ||
filters | No |
Input Schema (JSON Schema)
{
"properties": {
"doctype": {
"title": "Doctype",
"type": "string"
},
"filters": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Filters"
}
},
"required": [
"doctype"
],
"title": "count_documentsArguments",
"type": "object"
}