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
| Name | Required | Description | Default |
|---|---|---|---|
| report_name | Yes | Name of the report | |
| filters | No | Report filters (optional) |
Implementation Reference
- src/index.ts:570-608 (handler)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 }; } }
- src/index.ts:419-437 (schema)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"] } }
- src/index.ts:127-140 (helper)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'}`); } }