Skip to main content
Glama

run_report

Execute ERPNext reports to extract business data and insights using customizable 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

  • Main handler for the 'run_report' tool call within the CallToolRequestSchema handler. Extracts parameters, validates, calls erpnext.runReport, and returns the result or error.
    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
        };
      }
    }
  • Tool registration and input schema definition for 'run_report' in the ListToolsRequestSchema handler, specifying parameters report_name (required) and optional filters.
    {
      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"]
      }
    }
  • Helper method in ERPNextClient class that performs the actual API call to run the specified ERPNext report with given 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'}`);
      }
    }

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/rakeshgangwar/erpnext-mcp-server'

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