Skip to main content
Glama

list_documents

Retrieve documents from Frappe with customizable filters, field selection, and sorting options to locate specific records efficiently.

Instructions

    List documents from Frappe with filters.
    
    Args:
        doctype: DocType name
        filters: Filter string (optional). Uses custom syntax to bypass MCP validation issues.
        fields: Comma-separated field names (optional). E.g. "name,customer,total"
        limit: Maximum number of records to return (optional). E.g. "20"
        order_by: Field to order by (optional, can include 'desc' like 'creation desc')
    
    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:
        - list_documents("Bank Transaction", "status:Unreconciled") -> List unreconciled transactions
        - list_documents("Task", "status:in:Open|Working", "name,subject", "10") -> List open tasks with specific fields
        - list_documents("User", "name:like:%admin%") -> List users with 'admin' in name
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
doctypeYes
filtersNo
fieldsNo
limitNo
order_byNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function for the 'list_documents' MCP tool. It queries the Frappe REST API (/api/resource/{doctype}) with parsed filters, optional fields, limit, and order_by. Formats results as a count and JSON dump of documents.
    @mcp.tool()
    async def list_documents(
        doctype: str,
        filters: Optional[str] = None,
        fields: Optional[str] = None,
        limit: Optional[str] = None,
        order_by: Optional[str] = None
    ) -> str:
        """
        List documents from Frappe with filters.
        
        Args:
            doctype: DocType name
            filters: Filter string (optional). Uses custom syntax to bypass MCP validation issues.
            fields: Comma-separated field names (optional). E.g. "name,customer,total"
            limit: Maximum number of records to return (optional). E.g. "20"
            order_by: Field to order by (optional, can include 'desc' like 'creation desc')
        
        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:
            - list_documents("Bank Transaction", "status:Unreconciled") -> List unreconciled transactions
            - list_documents("Task", "status:in:Open|Working", "name,subject", "10") -> List open tasks with specific fields
            - list_documents("User", "name:like:%admin%") -> List users with 'admin' in name
        """
        try:
            client = get_client()
            
            # Build query parameters
            params = {}
            parsed_filters = format_filters_for_api(filters)
            if parsed_filters:
                params["filters"] = json.dumps(parsed_filters)
            if fields:
                # Convert comma-separated string to list
                field_list = [f.strip() for f in fields.split(',')]
                params["fields"] = json.dumps(field_list)
            if limit:
                # Convert string to integer for API
                params["limit"] = limit
            if order_by:
                params["order_by"] = order_by
            
            # Make API request to list documents
            response = await client.get(f"api/resource/{doctype}", params=params)
            
            if "data" in response:
                documents = response["data"]
                count = len(documents)
                return f"Found {count} {doctype} documents:\n\n" + json.dumps(documents, indent=2)
            else:
                return json.dumps(response, indent=2)
                
        except Exception as error:
            return _format_error_response(error, "list_documents")
  • src/server.py:40-40 (registration)
    Top-level registration call in the MCP server setup that invokes documents.register_tools(mcp), which defines and registers the list_documents tool among other document tools.
    documents.register_tools(mcp)
  • The register_tools function in documents.py that defines all document-related MCP tools using @mcp.tool() decorators, including the list_documents handler. This function is called from src/server.py.
    def register_tools(mcp: Any) -> None:
  • Input schema defined by function parameters with type hints: doctype (required str), optional filters/fields/limit/order_by (str), returns formatted str response. Detailed usage in docstring.
    async def list_documents(
        doctype: str,
        filters: Optional[str] = None,
        fields: Optional[str] = None,
        limit: Optional[str] = None,
        order_by: Optional[str] = None
    ) -> str:
  • Imports format_filters_for_api helper from filter_parser.py, used at line 391 to parse custom filter strings into Frappe API filter JSON.
    from .filter_parser import format_filters_for_api, FILTER_SYNTAX_DOCS
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It effectively discloses behavioral traits: it's a read operation (implied by 'List'), supports filtering with custom syntax, and includes examples of usage. However, it doesn't mention potential side effects like rate limits or authentication needs, though the examples suggest safe querying.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, starting with the tool's purpose. It uses sections like 'Args:' and 'Filter Syntax:' for structure, but includes extensive operator lists and examples that, while helpful, could be streamlined. Every sentence adds value, but it's slightly verbose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (5 parameters, 0% schema coverage, no annotations) and the presence of an output schema (which handles return values), the description is complete. It covers all parameters, provides syntax details, examples, and usage context, making it sufficient for an AI agent to invoke the tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 0%, so the description must compensate. It adds significant meaning beyond the input schema by detailing each parameter's purpose, optionality, and examples (e.g., 'doctype: DocType name', 'filters: Filter string (optional)'). It also explains the custom filter syntax and operators, which are not covered in the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'List documents from Frappe with filters.' It specifies the verb ('List'), resource ('documents from Frappe'), and scope ('with filters'), distinguishing it from siblings like get_document (single document) or count_documents (aggregate).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage through examples (e.g., filtering unreconciled transactions or open tasks) but does not explicitly state when to use this tool versus alternatives like get_document or count_documents. It provides context for filtering but lacks explicit guidance on tool selection among siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/appliedrelevance/frappe-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server