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
| Name | Required | Description | Default |
|---|---|---|---|
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), }; } }
- src/tools/list/index.ts:32-58 (registration)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 ];
- src/tools/tool-factory.ts:20-22 (registration)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), );