list-accounts
Retrieve all Xero accounts with codes and names, enabling accurate invoice creation and account management within the Xero MCP Server.
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
- Creates and defines the 'list-accounts' tool, including its handler function that calls listXeroAccounts and formats the response as MCP content.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"), })) || []), ], }; }, );
- src/tools/tool-factory.ts:6-21 (registration)Registers all ListTools, including 'list-accounts', with the MCP server using server.tool().import { ListTools } from "./list/index.js"; import { UpdateTools } from "./update/index.js"; export function ToolFactory(server: McpServer) { DeleteTools.map((tool) => tool()).forEach((tool) => server.tool(tool.name, tool.description, tool.schema, tool.handler), ); GetTools.map((tool) => tool()).forEach((tool) => server.tool(tool.name, tool.description, tool.schema, tool.handler), ); CreateTools.map((tool) => tool()).forEach((tool) => server.tool(tool.name, tool.description, tool.schema, tool.handler), ); ListTools.map((tool) => tool()).forEach((tool) => server.tool(tool.name, tool.description, tool.schema, tool.handler),
- src/tools/list/index.ts:32-58 (registration)Includes ListAccountsTool in the ListTools array for batch 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 ];
- Helper function that fetches and returns accounts from the Xero API, used by the list-accounts tool handler.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), }; } }
- Empty input schema for the list-accounts tool.{},