Skip to main content
Glama
XeroAPI

Xero MCP Server

Official

list-accounts

Retrieve all account codes and names from Xero to accurately populate invoice details during creation.

Instructions

Lists all accounts in Xero. Use this tool to get the account codes and names to be used when creating invoices in Xero

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Defines and implements the 'list-accounts' MCP tool, including schema (empty), description, and the handler function that calls listXeroAccounts and formats the account list as text blocks.
    const ListAccountsTool = CreateXeroTool( "list-accounts", "Lists all accounts in Xero. Use this tool to get the account codes and names to be used when creating invoices in Xero", {}, async () => { const response = await listXeroAccounts(); if (response.error !== null) { return { content: [ { type: "text" as const, text: `Error listing accounts: ${response.error}`, }, ], }; } const accounts = response.result; return { content: [ { type: "text" as const, text: `Found ${accounts?.length || 0} accounts:`, }, ...(accounts?.map((account) => ({ type: "text" as const, text: [ `Account: ${account.name || "Unnamed"}`, `Code: ${account.code || "No code"}`, `ID: ${account.accountID || "No ID"}`, `Type: ${account.type || "Unknown type"}`, `Status: ${account.status || "Unknown status"}`, account.description ? `Description: ${account.description}` : null, account.taxType ? `Tax Type: ${account.taxType}` : null, ] .filter(Boolean) .join("\n"), })) || []), ], }; }, );
  • Helper function that handles the core logic of listing Xero accounts via the Xero API, including authentication, API call, and error handling.
    export async function listXeroAccounts(): Promise< XeroClientResponse<Account[]> > { try { const accounts = await listAccounts(); return { result: accounts, isError: false, error: null, }; } catch (error) { return { result: null, isError: true, error: formatError(error), }; } }
  • Registers ListAccountsTool in the ListTools array, which collects all list-related tools for further 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 the 'list-accounts' tool (via ListTools) to the MCP server by calling server.tool with name, description, schema, and handler.
    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