Skip to main content
Glama
XeroAPI

Xero MCP Server

Official

list-trial-balance

Retrieve a snapshot of Xero's general ledger showing debit and credit balances for each account to verify accounting accuracy and prepare financial statements.

Instructions

Lists trial balance in Xero. This provides a snapshot of the general ledger, showing debit and credit balances for each account.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dateNoOptional date in YYYY-MM-DD format
paymentsOnlyNoOptional flag to include only accounts with payments

Implementation Reference

  • Defines the MCP tool 'list-trial-balance' including Zod input schema, handler logic that calls core handler, and formats response as MCP content blocks.
    const ListTrialBalanceTool = CreateXeroTool(
      "list-trial-balance",
      "Lists trial balance in Xero. This provides a snapshot of the general ledger, showing debit and credit balances for each account.",
      {
        date: z.string().optional().describe("Optional date in YYYY-MM-DD format"),
        paymentsOnly: z.boolean().optional().describe("Optional flag to include only accounts with payments"),
      },
      async (args) => {
        const response = await listXeroTrialBalance(args?.date, args?.paymentsOnly);
        if (response.error !== null) {
          return {
            content: [
              {
                type: "text" as const,
                text: `Error listing trial balance: ${response.error}`,
              },
            ],
          };
        }
    
       const trialBalanceReport = response.result;
    
        return {
          content: [
            {
              type: "text" as const,
              text: `Trial Balance Report: ${trialBalanceReport?.reportName || "Unnamed"}`,
            },
            {
              type: "text" as const,
              text: `Date: ${trialBalanceReport?.reportDate || "Not specified"}`,
            },
            {
              type: "text" as const,
              text: `Updated At: ${trialBalanceReport?.updatedDateUTC ? trialBalanceReport.updatedDateUTC.toISOString() : "Unknown"}`,
            },
            {
              type: "text" as const,
              text: JSON.stringify(trialBalanceReport.rows, null, 2),
            },
          ],
        };
      },
    );
  • Core handler that fetches trial balance report from Xero API using xeroClient.accountingApi.getReportTrialBalance (via internal fetchTrialBalance).
    export async function listXeroTrialBalance(
      date?: string,
      paymentsOnly?: boolean,
    ): Promise<XeroClientResponse<ReportWithRow>> {
      try {
        const trialBalance = await fetchTrialBalance(date, paymentsOnly);
    
        if (!trialBalance) {
          return {
            result: null,
            isError: true,
            error: "Failed to fetch trial balance data from Xero.",
          };
        }
    
        return {
          result: trialBalance,
          isError: false,
          error: null,
        };
      } catch (error) {
        return {
          result: null,
          isError: true,
          error: formatError(error),
        };
      }
    } 
  • Registers the ListTrialBalanceTool in the ListTools array exported for higher-level registration.
    export const ListTools = [
      ListAccountsTool,
      ListContactsTool,
      ListCreditNotesTool,
      ListInvoicesTool,
      ListItemsTool,
      ListManualJournalsTool,
      ListQuotesTool,
      ListTaxRatesTool,
      ListTrialBalanceTool,
      ListPaymentsTool,
      ListProfitAndLossTool,
      ListBankTransactionsTool,
      ListPayrollEmployeesTool,
      ListReportBalanceSheetTool,
      ListOrganisationDetailsTool,
      ListPayrollEmployeeLeaveTool,
      ListPayrollLeavePeriodsToolTool,
      ListPayrollEmployeeLeaveTypesTool,
      ListPayrollEmployeeLeaveBalancesTool,
      ListPayrollLeaveTypesTool,
      ListAgedReceivablesByContact,
      ListAgedPayablesByContact,
      ListPayrollTimesheetsTool,
      ListContactGroupsTool,
      ListTrackingCategoriesTool
    ];
  • Final registration of all ListTools (including list-trial-balance) to the MCP server via server.tool() calls.
    ListTools.map((tool) => tool()).forEach((tool) =>
      server.tool(tool.name, tool.description, tool.schema, tool.handler),
    );

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