Skip to main content
Glama
XeroAPI

Xero MCP Server

Official

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
NameRequiredDescriptionDefault
fromDateNoOptional start date in YYYY-MM-DD format
toDateNoOptional end date in YYYY-MM-DD format
periodsNoOptional number of periods to compare
timeframeNoOptional timeframe for the report (MONTH, QUARTER, YEAR)
standardLayoutNoOptional flag to use standard layout
paymentsOnlyNoOptional 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), }; } }
  • 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), );
  • Includes ListProfitAndLossTool in the ListTools export array for batch registration.
    ListProfitAndLossTool,

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/XeroAPI/xero-mcp-server'

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