Skip to main content
Glama

run_query_report

Execute Frappe query reports with customizable filters to extract and analyze data from Frappe Framework sites using specific filter syntax.

Instructions

    Execute a Frappe query report with filters.
    
    Args:
        report_name: Name of the report to run
        filters: Filter string (optional). Uses custom syntax to bypass MCP validation issues.
    
    Filter Syntax: Use the same string-based syntax as count_documents and list_documents.
    Examples: "status:Open", "date:>=:2025-01-01", "status:in:Open|Working"
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
report_nameYes
filtersNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main async handler function for executing the 'run_query_report' tool. It calls the Frappe API to run query reports with optional filters, formats the result as JSON, and handles errors.
    async def run_query_report(
        report_name: str,
        filters: Optional[str] = None
    ) -> str:
        """
        Execute a Frappe query report with filters.
        
        Args:
            report_name: Name of the report to run
            filters: Filter string (optional). Uses custom syntax to bypass MCP validation issues.
        
        Filter Syntax: Use the same string-based syntax as count_documents and list_documents.
        Examples: "status:Open", "date:>=:2025-01-01", "status:in:Open|Working"
        """
        try:
            client = get_client()
            
            # Prepare request data
            parsed_filters = format_filters_for_api(filters) or {}
            request_data = {
                "cmd": "frappe.desk.query_report.run",
                "report_name": report_name,
                "filters": json.dumps(parsed_filters),
                "ignore_prepared_report": 1
            }
            
            # Run the report
            response = await client.post("api/method/frappe.desk.query_report.run", json_data=request_data)
            
            if "message" in response:
                result = response["message"]
                
                # Format the response
                columns = result.get("columns", [])
                data = result.get("result", [])
                
                formatted_result = {
                    "report_name": report_name,
                    "columns": columns,
                    "data": data,
                    "row_count": len(data)
                }
                
                return json.dumps(formatted_result, indent=2)
            else:
                return json.dumps(response, indent=2)
                
        except Exception as error:
            return _format_error_response(error, "run_query_report")
  • src/server.py:42-42 (registration)
    Registration of the reports tools module, which includes the run_query_report tool, by calling its register_tools function on the MCP server instance.
    reports.register_tools(mcp)
  • Helper function used by run_query_report to format error responses consistently.
    def _format_error_response(error: Exception, operation: str) -> str:
        """Format error response with detailed information."""
        credentials_check = validate_api_credentials()
        
        # Check for missing credentials first
        if not credentials_check["valid"]:
            error_msg = f"Authentication failed: {credentials_check['message']}. "
            error_msg += "API key/secret is the only supported authentication method."
            return error_msg
        
        # Handle FrappeApiError
        if isinstance(error, FrappeApiError):
            error_msg = f"Frappe API error: {error}"
            if error.status_code in (401, 403):
                error_msg += " Please check your API key and secret."
            return error_msg
        
        # Default error handling
        return f"Error in {operation}: {str(error)}"
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions that filters use a custom syntax to bypass MCP validation issues, adding useful context about potential quirks. However, it doesn't cover other behavioral aspects like error handling, performance implications, or what the output contains, leaving gaps in transparency.

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 core purpose followed by parameter details and examples. Every sentence adds value, such as explaining filter syntax and providing concrete examples. Minor improvements could include briefer phrasing, but overall it's efficient and well-structured.

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

Completeness4/5

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

Given the tool's complexity (2 parameters, no annotations, but with an output schema), the description is reasonably complete. It covers the purpose, parameter usage, and filter syntax, which are crucial for invocation. Since an output schema exists, it doesn't need to explain return values, making the description adequate for the context.

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

Parameters4/5

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

Schema description coverage is 0%, so the description must compensate. It adds significant meaning beyond the schema by explaining that 'filters' uses a custom string-based syntax with examples like 'status:Open', clarifying how to format this optional parameter. This compensates well for the low schema coverage, though it doesn't detail 'report_name' beyond its name.

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

Purpose4/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: 'Execute a Frappe query report with filters.' It specifies the verb 'execute' and the resource 'Frappe query report,' making the action and target explicit. However, it doesn't distinguish this tool from its sibling 'run_doctype_report,' which might serve a similar purpose, preventing a perfect score.

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 by mentioning filters and providing syntax examples, suggesting it's for running reports with optional filtering. However, it lacks explicit guidance on when to use this tool versus alternatives like 'run_doctype_report' or other report-related tools, nor does it mention prerequisites or exclusions, leaving usage context partially unclear.

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