Skip to main content
Glama

run_report

Execute ERPNext reports to extract business data with optional filters for analysis and decision-making.

Instructions

Run an ERPNext report

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
report_nameYesName of the report
filtersNoReport filters (optional)

Implementation Reference

  • MCP tool call handler for 'run_report': checks authentication, extracts report_name and optional filters from arguments, calls erpnext.runReport, returns JSON result or error message.
    case "run_report": {
      if (!erpnext.isAuthenticated()) {
        return {
          content: [{
            type: "text",
            text: "Not authenticated with ERPNext. Please configure API key authentication."
          }],
          isError: true
        };
      }
      
      const reportName = String(request.params.arguments?.report_name);
      const filters = request.params.arguments?.filters as Record<string, any> | undefined;
      
      if (!reportName) {
        throw new McpError(
          ErrorCode.InvalidParams,
          "Report name is required"
        );
      }
      
      try {
        const result = await erpnext.runReport(reportName, filters);
        return {
          content: [{
            type: "text",
            text: JSON.stringify(result, null, 2)
          }]
        };
      } catch (error: any) {
        return {
          content: [{
            type: "text",
            text: `Failed to run report ${reportName}: ${error?.message || 'Unknown error'}`
          }],
          isError: true
        };
      }
    }
  • Input schema for the 'run_report' tool, defining report_name as required string and optional filters object.
    {
      name: "run_report",
      description: "Run an ERPNext report",
      inputSchema: {
        type: "object",
        properties: {
          report_name: {
            type: "string",
            description: "Name of the report"
          },
          filters: {
            type: "object",
            additionalProperties: true,
            description: "Report filters (optional)"
          }
        },
        required: ["report_name"]
      }
    }
  • src/index.ts:324-442 (registration)
    Registration of the 'run_report' tool via the ListToolsRequest handler, which includes its name, description, and input schema.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          {
            name: "get_doctypes",
            description: "Get a list of all available DocTypes",
            inputSchema: {
              type: "object",
              properties: {}
            }
          },
          {
            name: "get_doctype_fields",
            description: "Get fields list for a specific DocType",
            inputSchema: {
              type: "object",
              properties: {
                doctype: {
                  type: "string",
                  description: "ERPNext DocType (e.g., Customer, Item)"
                }
              },
                required: ["doctype"]
            }
          },
          {
            name: "get_documents",
            description: "Get a list of documents for a specific doctype",
            inputSchema: {
              type: "object",
              properties: {
                doctype: {
                  type: "string",
                  description: "ERPNext DocType (e.g., Customer, Item)"
                },
                fields: {
                  type: "array",
                  items: {
                    type: "string"
                  },
                  description: "Fields to include (optional)"
                },
                filters: {
                  type: "object",
                  additionalProperties: true,
                  description: "Filters in the format {field: value} (optional)"
                },
                limit: {
                  type: "number",
                  description: "Maximum number of documents to return (optional)"
                }
              },
              required: ["doctype"]
            }
          },
          {
            name: "create_document",
            description: "Create a new document in ERPNext",
            inputSchema: {
              type: "object",
              properties: {
                doctype: {
                  type: "string",
                  description: "ERPNext DocType (e.g., Customer, Item)"
                },
                data: {
                  type: "object",
                  additionalProperties: true,
                  description: "Document data"
                }
              },
              required: ["doctype", "data"]
            }
          },
          {
            name: "update_document",
            description: "Update an existing document in ERPNext",
            inputSchema: {
              type: "object",
              properties: {
                doctype: {
                  type: "string",
                  description: "ERPNext DocType (e.g., Customer, Item)"
                },
                name: {
                  type: "string",
                  description: "Document name/ID"
                },
                data: {
                  type: "object",
                  additionalProperties: true,
                  description: "Document data to update"
                }
              },
              required: ["doctype", "name", "data"]
            }
          },
          {
            name: "run_report",
            description: "Run an ERPNext report",
            inputSchema: {
              type: "object",
              properties: {
                report_name: {
                  type: "string",
                  description: "Name of the report"
                },
                filters: {
                  type: "object",
                  additionalProperties: true,
                  description: "Report filters (optional)"
                }
              },
              required: ["report_name"]
            }
          }
        ]
      };
    });
  • ERPNextClient.runReport helper method that performs the actual API call to ERPNext's frappe.desk.query_report.run endpoint with report_name and filters.
    // Run a report
    async runReport(reportName: string, filters?: Record<string, any>): Promise<any> {
      try {
        const response = await this.axiosInstance.get(`/api/method/frappe.desk.query_report.run`, {
          params: {
            report_name: reportName,
            filters: filters ? JSON.stringify(filters) : undefined
          }
        });
        return response.data.message;
      } catch (error: any) {
        throw new Error(`Failed to run report ${reportName}: ${error?.message || 'Unknown error'}`);
      }
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

C2.7/5.0
Behavior1/5

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

With no annotations provided, the description carries full responsibility for behavioral disclosure. It only says 'Run an ERPNext report,' offering no information about side effects, read-only nature, required permissions, or output characteristics. The lack of any behavioral context makes it nearly useless for understanding tool behavior.

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 a single, front-loaded sentence with no wasted words. It is efficient, though arguably under-specified. Given the minimal detail required for a two-parameter tool, this level of conciseness is acceptable, but it could be expanded slightly without losing clarity.

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

Completeness2/5

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

The tool has no output schema and no annotations, and the description is too brief to convey essential context such as what the report returns, how filters are used, or any constraints. The parameter schema covers the 'what' but not the 'how' or expected behavior, making the description insufficient for an agent to use it correctly.

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

Parameters3/5

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

The input schema has descriptions for both parameters ('Report filters (optional)' and 'Name of the report'), achieving 100% coverage. The description itself adds no additional parameter information, so it neither helps nor hurts. The baseline of 3 is appropriate since the schema does the heavy lifting.

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 uses a specific verb 'Run' and a resource 'ERPNext report', which distinguishes it from sibling tools that deal with doctypes and documents. However, it lacks detail on what 'run' entails (e.g., returning data), making it clear but slightly under-specified.

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

Usage Guidelines2/5

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

There is no guidance on when to use this tool versus alternatives. The sibling tools are about document operations, so it is implied this is for reports, but no explicit context, prerequisites, or exclusions are provided. The description simply states what it does, not when to use it.

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