list-profit-and-loss
Generate a profit and loss report in Xero to analyze revenue, expenses, and profitability for a specified time period.
Instructions
Lists profit and loss report in Xero. This provides a summary of revenue, expenses, and profit or loss over a specified period of time.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fromDate | No | Optional start date in YYYY-MM-DD format | |
| toDate | No | Optional end date in YYYY-MM-DD format | |
| periods | No | Optional number of periods to compare | |
| timeframe | No | Optional timeframe for the report (MONTH, QUARTER, YEAR) | |
| standardLayout | No | Optional flag to use standard layout | |
| paymentsOnly | No | Optional flag to include only accounts with payments |
Implementation Reference
- Executes the tool logic: calls the Xero handler and formats the profit and loss report as MCP text content blocks.async (args) => { const response = await listXeroProfitAndLoss( args?.fromDate, args?.toDate, args?.periods, args?.timeframe, args?.standardLayout, args?.paymentsOnly, ); if (response.error !== null) { return { content: [ { type: "text" as const, text: `Error listing profit and loss report: ${response.error}`, }, ], }; } const profitAndLossReport = response.result; return { content: [ { type: "text" as const, text: `Profit and Loss Report: ${profitAndLossReport?.reportName ?? "Unnamed"}`, }, { type: "text" as const, text: `Date Range: ${profitAndLossReport?.reportDate ?? "Not specified"}`, }, { type: "text" as const, text: `Updated At: ${profitAndLossReport?.updatedDateUTC ? profitAndLossReport.updatedDateUTC.toISOString() : "Unknown"}`, }, { type: "text" as const, text: JSON.stringify(profitAndLossReport.rows, null, 2), }, ], }; },
- Zod input schema defining optional parameters for date range, periods, timeframe, and layout options.fromDate: z.string().optional().describe("Optional start date in YYYY-MM-DD format"), toDate: z.string().optional().describe("Optional end date in YYYY-MM-DD format"), periods: z.number().optional().describe("Optional number of periods to compare"), timeframe: z.enum(["MONTH", "QUARTER", "YEAR"]).optional().describe("Optional timeframe for the report (MONTH, QUARTER, YEAR)"), standardLayout: z.boolean().optional().describe("Optional flag to use standard layout"), paymentsOnly: z.boolean().optional().describe("Optional flag to include only accounts with payments"), },
- Core helper that fetches the profit and loss report from Xero API, handles errors, and returns structured response.export async function listXeroProfitAndLoss( fromDate?: string, toDate?: string, periods?: number, timeframe?: TimeframeType, standardLayout?: boolean, paymentsOnly?: boolean, ): Promise<XeroClientResponse<ReportWithRow>> { try { const profitAndLoss = await fetchProfitAndLoss( fromDate, toDate, periods, timeframe, paymentsOnly, ); if (!profitAndLoss) { return { result: null, isError: true, error: "Failed to fetch profit and loss data from Xero.", }; } return { result: profitAndLoss, isError: false, error: null, }; } catch (error) { return { result: null, isError: true, error: formatError(error), }; } }
- src/tools/tool-factory.ts:20-22 (registration)Registers the 'list-profit-and-loss' tool (via ListTools) with the MCP server by calling server.tool().ListTools.map((tool) => tool()).forEach((tool) => server.tool(tool.name, tool.description, tool.schema, tool.handler), );
- src/tools/list/index.ts:43-43 (registration)Includes ListProfitAndLossTool in the ListTools export array for batch registration.ListProfitAndLossTool,