@teamnetwork-nz/xero-mcp-server 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +282 -0
  3. package/dist/clients/xero-client.js +141 -0
  4. package/dist/consts/deeplinks.js +24 -0
  5. package/dist/handlers/approve-xero-payroll-timesheet.handler.js +28 -0
  6. package/dist/handlers/archive-xero-contact.handler.js +28 -0
  7. package/dist/handlers/authorise-xero-invoice.handler.js +34 -0
  8. package/dist/handlers/convert-xero-quote-to-invoice.handler.js +50 -0
  9. package/dist/handlers/create-xero-bank-transaction.handler.js +51 -0
  10. package/dist/handlers/create-xero-contact.handler.js +49 -0
  11. package/dist/handlers/create-xero-credit-note.handler.js +50 -0
  12. package/dist/handlers/create-xero-invoice.handler.js +53 -0
  13. package/dist/handlers/create-xero-item.handler.js +59 -0
  14. package/dist/handlers/create-xero-manual-journal.handler.js +57 -0
  15. package/dist/handlers/create-xero-payment.handler.js +50 -0
  16. package/dist/handlers/create-xero-payroll-timesheet.handler.js +28 -0
  17. package/dist/handlers/create-xero-quote.handler.js +53 -0
  18. package/dist/handlers/create-xero-tracking-category.handler.js +35 -0
  19. package/dist/handlers/create-xero-tracking-option.handler.js +31 -0
  20. package/dist/handlers/delete-xero-invoice-attachment.handler.js +30 -0
  21. package/dist/handlers/delete-xero-payroll-timesheet.handler.js +28 -0
  22. package/dist/handlers/download-xero-invoice-attachment.handler.js +23 -0
  23. package/dist/handlers/download-xero-invoice-pdf.handler.js +25 -0
  24. package/dist/handlers/get-xero-invoice.handler.js +19 -0
  25. package/dist/handlers/get-xero-payroll-timesheet.handler.js +28 -0
  26. package/dist/handlers/list-aged-payables-by-contact.handler.js +37 -0
  27. package/dist/handlers/list-aged-receivables-by-contact.handler.js +37 -0
  28. package/dist/handlers/list-xero-accounts.handler.js +32 -0
  29. package/dist/handlers/list-xero-bank-transactions.handler.js +39 -0
  30. package/dist/handlers/list-xero-contact-groups.handler.js +34 -0
  31. package/dist/handlers/list-xero-contacts.handler.js +47 -0
  32. package/dist/handlers/list-xero-credit-notes.handler.js +42 -0
  33. package/dist/handlers/list-xero-invoice-attachments.handler.js +20 -0
  34. package/dist/handlers/list-xero-invoices.handler.js +54 -0
  35. package/dist/handlers/list-xero-items.handler.js +32 -0
  36. package/dist/handlers/list-xero-manual-journals.handler.js +33 -0
  37. package/dist/handlers/list-xero-organisation-details.handler.js +32 -0
  38. package/dist/handlers/list-xero-payments.handler.js +52 -0
  39. package/dist/handlers/list-xero-payroll-employee-leave-balances.handler.js +42 -0
  40. package/dist/handlers/list-xero-payroll-employee-leave-types.handler.js +42 -0
  41. package/dist/handlers/list-xero-payroll-employee-leave.handler.js +44 -0
  42. package/dist/handlers/list-xero-payroll-employees.handler.js +31 -0
  43. package/dist/handlers/list-xero-payroll-leave-periods.handler.js +44 -0
  44. package/dist/handlers/list-xero-payroll-leave-types.handler.js +40 -0
  45. package/dist/handlers/list-xero-profit-and-loss.handler.js +52 -0
  46. package/dist/handlers/list-xero-quotes.handler.js +36 -0
  47. package/dist/handlers/list-xero-report-balance-sheet.handler.js +34 -0
  48. package/dist/handlers/list-xero-tax-rates.handler.js +30 -0
  49. package/dist/handlers/list-xero-timesheets.handler.js +29 -0
  50. package/dist/handlers/list-xero-tracking-categories.handler.js +29 -0
  51. package/dist/handlers/list-xero-trial-balance.handler.js +42 -0
  52. package/dist/handlers/revert-xero-payroll-timesheet.handler.js +28 -0
  53. package/dist/handlers/update-xero-bank-transaction.handler.js +56 -0
  54. package/dist/handlers/update-xero-contact.handler.js +66 -0
  55. package/dist/handlers/update-xero-credit-note.handler.js +61 -0
  56. package/dist/handlers/update-xero-invoice.handler.js +62 -0
  57. package/dist/handlers/update-xero-item.handler.js +46 -0
  58. package/dist/handlers/update-xero-manual-journal.handler.js +46 -0
  59. package/dist/handlers/update-xero-payroll-timesheet-add-line.handler.js +28 -0
  60. package/dist/handlers/update-xero-payroll-timesheet-update-line.handler.js +28 -0
  61. package/dist/handlers/update-xero-quote.handler.js +78 -0
  62. package/dist/handlers/update-xero-tracking-category.handler.js +43 -0
  63. package/dist/handlers/update-xero-tracking-options.handler.js +51 -0
  64. package/dist/handlers/upload-xero-invoice-attachment.handler.js +36 -0
  65. package/dist/handlers/void-xero-invoice.handler.js +52 -0
  66. package/dist/helpers/build-where-clause.js +29 -0
  67. package/dist/helpers/create-xero-tool.js +6 -0
  68. package/dist/helpers/datetime.js +91 -0
  69. package/dist/helpers/ensure-error.js +13 -0
  70. package/dist/helpers/format-aged-report-filter.js +8 -0
  71. package/dist/helpers/format-error.js +25 -0
  72. package/dist/helpers/format-line-item.js +13 -0
  73. package/dist/helpers/format-tracking-option.js +7 -0
  74. package/dist/helpers/get-client-headers.js +8 -0
  75. package/dist/helpers/get-deeplink.js +41 -0
  76. package/dist/helpers/get-download-path.js +16 -0
  77. package/dist/helpers/get-external-link.js +8 -0
  78. package/dist/helpers/get-package-version.js +20 -0
  79. package/dist/index.js +18 -0
  80. package/dist/resources/register-resources.js +27 -0
  81. package/dist/server/xero-mcp-server.js +43 -0
  82. package/dist/tools/create/convert-quote-to-invoice.tool.js +46 -0
  83. package/dist/tools/create/create-bank-transaction.tool.js +57 -0
  84. package/dist/tools/create/create-contact.tool.js +56 -0
  85. package/dist/tools/create/create-credit-note.tool.js +53 -0
  86. package/dist/tools/create/create-invoice.tool.js +78 -0
  87. package/dist/tools/create/create-item.tool.js +61 -0
  88. package/dist/tools/create/create-manual-journal.tool.js +116 -0
  89. package/dist/tools/create/create-payment.tool.js +71 -0
  90. package/dist/tools/create/create-payroll-timesheet.tool.js +40 -0
  91. package/dist/tools/create/create-quote.tool.js +57 -0
  92. package/dist/tools/create/create-tracking-category.tool.js +28 -0
  93. package/dist/tools/create/create-tracking-options.tool.js +30 -0
  94. package/dist/tools/create/index.js +35 -0
  95. package/dist/tools/create/upload-invoice-attachment.tool.js +49 -0
  96. package/dist/tools/delete/archive-contact.tool.js +30 -0
  97. package/dist/tools/delete/delete-invoice-attachment.tool.js +28 -0
  98. package/dist/tools/delete/delete-payroll-timesheet.tool.js +28 -0
  99. package/dist/tools/delete/index.js +15 -0
  100. package/dist/tools/get/get-invoice-attachment.tool.js +33 -0
  101. package/dist/tools/get/get-invoice-pdf.tool.js +33 -0
  102. package/dist/tools/get/get-invoice.tool.js +72 -0
  103. package/dist/tools/get/get-payroll-timesheet.tool.js +50 -0
  104. package/dist/tools/get/index.js +17 -0
  105. package/dist/tools/list/index.js +64 -0
  106. package/dist/tools/list/list-accounts.tool.js +39 -0
  107. package/dist/tools/list/list-aged-payables-by-contact.tool.js +51 -0
  108. package/dist/tools/list/list-aged-receivables-by-contact.tool.js +51 -0
  109. package/dist/tools/list/list-bank-transactions.tool.js +66 -0
  110. package/dist/tools/list/list-contact-groups.tool.js +48 -0
  111. package/dist/tools/list/list-contacts.tool.js +80 -0
  112. package/dist/tools/list/list-credit-notes.tool.js +72 -0
  113. package/dist/tools/list/list-invoice-attachments.tool.js +42 -0
  114. package/dist/tools/list/list-invoices.tool.js +98 -0
  115. package/dist/tools/list/list-items.tool.js +50 -0
  116. package/dist/tools/list/list-manual-journals.tool.js +80 -0
  117. package/dist/tools/list/list-organisation-details.tool.js +91 -0
  118. package/dist/tools/list/list-payments.tool.js +91 -0
  119. package/dist/tools/list/list-payroll-employee-leave-balances.tool.js +39 -0
  120. package/dist/tools/list/list-payroll-employee-leave-types.tool.js +57 -0
  121. package/dist/tools/list/list-payroll-employee-leave.tool.js +43 -0
  122. package/dist/tools/list/list-payroll-employees.tool.js +49 -0
  123. package/dist/tools/list/list-payroll-leave-periods.tool.js +45 -0
  124. package/dist/tools/list/list-payroll-leave-types.tool.js +40 -0
  125. package/dist/tools/list/list-payroll-timesheets.tool.js +40 -0
  126. package/dist/tools/list/list-profit-and-loss.tool.js +46 -0
  127. package/dist/tools/list/list-quotes.tool.js +69 -0
  128. package/dist/tools/list/list-report-balance-sheet.tool.js +39 -0
  129. package/dist/tools/list/list-tax-rates.tool.js +49 -0
  130. package/dist/tools/list/list-tracking-categories.tool.js +39 -0
  131. package/dist/tools/list/list-trial-balance.tool.js +42 -0
  132. package/dist/tools/tool-factory.js +24 -0
  133. package/dist/tools/update/approve-payroll-timesheet.tool.js +29 -0
  134. package/dist/tools/update/authorise-invoice.tool.js +42 -0
  135. package/dist/tools/update/index.js +39 -0
  136. package/dist/tools/update/revert-payroll-timesheet.tool.js +29 -0
  137. package/dist/tools/update/update-bank-transaction.tool.js +56 -0
  138. package/dist/tools/update/update-contact.tool.js +69 -0
  139. package/dist/tools/update/update-credit-note.tool.js +56 -0
  140. package/dist/tools/update/update-invoice.tool.js +76 -0
  141. package/dist/tools/update/update-item.tool.js +62 -0
  142. package/dist/tools/update/update-manual-journal-tool.js +89 -0
  143. package/dist/tools/update/update-payroll-timesheet-add-line.tool.js +34 -0
  144. package/dist/tools/update/update-payroll-timesheet-update-line.tool.js +35 -0
  145. package/dist/tools/update/update-quote.tool.js +61 -0
  146. package/dist/tools/update/update-tracking-category.tool.js +30 -0
  147. package/dist/tools/update/update-tracking-options.tool.js +35 -0
  148. package/dist/tools/update/void-invoice.tool.js +33 -0
  149. package/dist/types/list-report-balance-sheet-params.js +1 -0
  150. package/dist/types/timeframeType.js +1 -0
  151. package/dist/types/tool-definition.js +1 -0
  152. package/dist/types/tool-list.js +1 -0
  153. package/dist/types/tool-response.js +1 -0
  154. package/package.json +38 -0
@@ -0,0 +1,51 @@
1
+ import { z } from "zod";
2
+ import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
3
+ import { formatAgedReportFilter } from "../../helpers/format-aged-report-filter.js";
4
+ import { listXeroAgedPayablesByContact } from "../../handlers/list-aged-payables-by-contact.handler.js";
5
+ const ListAgedPayablesByContact = CreateXeroTool("list-aged-payables-by-contact", "Show aged payables (outstanding bills/purchase invoices) for a SINGLE contact. " +
6
+ "IMPORTANT: This tool requires a contactId and returns data for ONE contact only — there is no bulk aged payables endpoint in the Xero API. " +
7
+ "Do NOT call this in a loop for all contacts — it is slow and will hit rate limits. " +
8
+ "For org-wide AP aging, use list-invoices with type=ACCPAY, statuses=[AUTHORISED], minAmountDue=0.01 instead.", {
9
+ contactId: z.string(),
10
+ reportDate: z.string().optional()
11
+ .describe("Optional date to retrieve aged payables in YYYY-MM-DD format. If none is provided, defaults to end of the current month."),
12
+ invoicesFromDate: z.string().optional()
13
+ .describe("Optional from date in YYYY-MM-DD format. If provided, will only show payable invoices after this date for the contact."),
14
+ invoicesToDate: z.string().optional()
15
+ .describe("Optional to date in YYYY-MM-DD format. If provided, will only show payable invoices before this date for the contact."),
16
+ }, async ({ contactId, reportDate, invoicesFromDate, invoicesToDate }) => {
17
+ const response = await listXeroAgedPayablesByContact(contactId, reportDate, invoicesFromDate, invoicesToDate);
18
+ if (response.isError) {
19
+ return {
20
+ content: [
21
+ {
22
+ type: "text",
23
+ text: `Error listing aged payables by contact: ${response.error}`,
24
+ },
25
+ ],
26
+ };
27
+ }
28
+ const agedPayablesReport = response.result;
29
+ const filter = formatAgedReportFilter(invoicesFromDate, invoicesToDate);
30
+ return {
31
+ content: [
32
+ {
33
+ type: "text",
34
+ text: `Report Name: ${agedPayablesReport.reportName || "Not specified"}`,
35
+ },
36
+ {
37
+ type: "text",
38
+ text: `Report Date: ${agedPayablesReport.reportDate || "Not specified"}`
39
+ },
40
+ {
41
+ type: "text",
42
+ text: filter ?? "Showing all relevant invoices"
43
+ },
44
+ {
45
+ type: "text",
46
+ text: JSON.stringify(agedPayablesReport.rows, null, 2),
47
+ }
48
+ ],
49
+ };
50
+ });
51
+ export default ListAgedPayablesByContact;
@@ -0,0 +1,51 @@
1
+ import { z } from "zod";
2
+ import { listXeroAgedReceivablesByContact } from "../../handlers/list-aged-receivables-by-contact.handler.js";
3
+ import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
4
+ import { formatAgedReportFilter } from "../../helpers/format-aged-report-filter.js";
5
+ const ListAgedReceivablesByContact = CreateXeroTool("list-aged-receivables-by-contact", "Show aged receivables (outstanding sales invoices) for a SINGLE contact. " +
6
+ "IMPORTANT: This tool requires a contactId and returns data for ONE contact only — there is no bulk aged receivables endpoint in the Xero API. " +
7
+ "Do NOT call this in a loop for all contacts — it is slow and will hit rate limits. " +
8
+ "For org-wide AR aging, use list-invoices with type=ACCREC, statuses=[AUTHORISED], minAmountDue=0.01 instead.", {
9
+ contactId: z.string(),
10
+ reportDate: z.string().optional()
11
+ .describe("Optional date to retrieve aged receivables in YYYY-MM-DD format. If none is provided, defaults to end of the current month."),
12
+ invoicesFromDate: z.string().optional()
13
+ .describe("Optional from date in YYYY-MM-DD format. If provided, will only show payable invoices after this date for the contact."),
14
+ invoicesToDate: z.string().optional()
15
+ .describe("Optional to date in YYYY-MM-DD format. If provided, will only show payable invoices before this date for the contact."),
16
+ }, async ({ contactId, reportDate, invoicesFromDate, invoicesToDate }) => {
17
+ const response = await listXeroAgedReceivablesByContact(contactId, reportDate, invoicesFromDate, invoicesToDate);
18
+ if (response.isError) {
19
+ return {
20
+ content: [
21
+ {
22
+ type: "text",
23
+ text: `Error listing aged receivables by contact: ${response.error}`,
24
+ },
25
+ ],
26
+ };
27
+ }
28
+ const agedReceivablesReport = response.result;
29
+ const filter = formatAgedReportFilter(invoicesFromDate, invoicesToDate);
30
+ return {
31
+ content: [
32
+ {
33
+ type: "text",
34
+ text: `Report Name: ${agedReceivablesReport.reportName || "Not specified"}`,
35
+ },
36
+ {
37
+ type: "text",
38
+ text: `Report Date: ${agedReceivablesReport.reportDate || "Not specified"}`
39
+ },
40
+ {
41
+ type: "text",
42
+ text: filter ?? "Showing all relevant invoices"
43
+ },
44
+ {
45
+ type: "text",
46
+ text: JSON.stringify(agedReceivablesReport.rows, null, 2),
47
+ }
48
+ ],
49
+ };
50
+ });
51
+ export default ListAgedReceivablesByContact;
@@ -0,0 +1,66 @@
1
+ import { z } from "zod";
2
+ import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
3
+ import { listXeroBankTransactions } from "../../handlers/list-xero-bank-transactions.handler.js";
4
+ import { formatLineItem } from "../../helpers/format-line-item.js";
5
+ const ListBankTransactionsTool = CreateXeroTool("list-bank-transactions", "List bank transactions from Xero. " +
6
+ "Always use filters — do NOT page through all transactions to find specific ones. " +
7
+ "Common patterns: " +
8
+ "unreconciled transactions → isReconciled=false (filter is applied server-side); " +
9
+ "money in → transactionType=RECEIVE with date range; " +
10
+ "money out → transactionType=SPEND with date range; " +
11
+ "transfers → transactionType=SPEND-TRANSFER or RECEIVE-TRANSFER. " +
12
+ "Always set a fromDate/toDate or isReconciled filter before paginating.", {
13
+ page: z.number().describe("Page number for pagination (starts at 1)."),
14
+ bankAccountId: z.string().optional().describe("Filter by bank account ID. Get IDs from list-accounts."),
15
+ fromDate: z.string().optional().describe("Transactions on or after this date (YYYY-MM-DD)."),
16
+ toDate: z.string().optional().describe("Transactions on or before this date (YYYY-MM-DD)."),
17
+ status: z.enum(["AUTHORISED", "DELETED", "VOIDED"]).optional().describe("Filter by status. Defaults to AUTHORISED (active transactions only). Pass DELETED or VOIDED only if you explicitly need those records."),
18
+ isReconciled: z.boolean().optional().describe("Filter by reconciliation status. Use isReconciled=false to find unreconciled transactions. Never scan pages to find unreconciled items — use this filter."),
19
+ transactionType: z.enum(["SPEND", "RECEIVE", "SPEND-TRANSFER", "RECEIVE-TRANSFER", "SPEND-PREPAYMENT", "RECEIVE-PREPAYMENT", "SPEND-OVERPAYMENT", "RECEIVE-OVERPAYMENT"]).optional().describe("Filter by transaction type. SPEND = money out, RECEIVE = money in, *-TRANSFER = bank transfers."),
20
+ pageSize: z.number().min(1).max(100).optional().default(50).describe("Results per page (1–100, default 50)."),
21
+ }, async ({ bankAccountId, page, fromDate, toDate, status, isReconciled, transactionType, pageSize }) => {
22
+ const response = await listXeroBankTransactions(page, bankAccountId, fromDate, toDate, status, pageSize, isReconciled, transactionType);
23
+ if (response.isError) {
24
+ return {
25
+ content: [
26
+ {
27
+ type: "text",
28
+ text: `Error listing bank transactions: ${response.error}`
29
+ }
30
+ ]
31
+ };
32
+ }
33
+ const bankTransactions = response.result;
34
+ return {
35
+ content: [
36
+ {
37
+ type: "text",
38
+ text: `Found ${bankTransactions?.length || 0} bank transactions:`
39
+ },
40
+ ...(bankTransactions?.map((transaction) => ({
41
+ type: "text",
42
+ text: [
43
+ `Bank Transaction ID: ${transaction.bankTransactionID}`,
44
+ `Bank Account: ${transaction.bankAccount.name} (${transaction.bankAccount.accountID})`,
45
+ transaction.contact
46
+ ? `Contact: ${transaction.contact.name} (${transaction.contact.contactID})`
47
+ : null,
48
+ transaction.reference ? `Reference: ${transaction.reference}` : null,
49
+ transaction.date ? `Date: ${transaction.date}` : null,
50
+ transaction.subTotal ? `Sub Total: ${transaction.subTotal}` : null,
51
+ transaction.totalTax ? `Total Tax: ${transaction.totalTax}` : null,
52
+ transaction.total ? `Total: ${transaction.total}` : null,
53
+ transaction.isReconciled !== undefined ? (`${transaction.isReconciled ? "Reconciled" : "Unreconciled"}`) : null,
54
+ transaction.currencyCode ? `Currency Code: ${transaction.currencyCode}` : null,
55
+ `${transaction.status || "Unknown"}`,
56
+ transaction.lineAmountTypes ? `Line Amount Types: ${transaction.lineAmountTypes}` : undefined,
57
+ transaction.hasAttachments !== undefined
58
+ ? (transaction.hasAttachments ? "Has attachments" : "Does not have attachments")
59
+ : null,
60
+ `Line Items: ${transaction.lineItems?.map(formatLineItem)}`,
61
+ ].filter(Boolean).join("\n")
62
+ })) || [])
63
+ ]
64
+ };
65
+ });
66
+ export default ListBankTransactionsTool;
@@ -0,0 +1,48 @@
1
+ import { z } from "zod";
2
+ import { listXeroContactGroups } from "../../handlers/list-xero-contact-groups.handler.js";
3
+ import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
4
+ const ListContactGroupsTool = CreateXeroTool("list-contact-groups", `List all contact groups in Xero.
5
+ You can optionally specify a contact group ID to retrieve details for that specific group, including its contacts.`, {
6
+ contactGroupId: z
7
+ .string()
8
+ .optional()
9
+ .describe("Optional ID of the contact group to retrieve"),
10
+ }, async (args) => {
11
+ const response = await listXeroContactGroups(args?.contactGroupId);
12
+ if (response.error !== null) {
13
+ return {
14
+ content: [
15
+ {
16
+ type: "text",
17
+ text: `Error listing contact groups: ${response.error}`,
18
+ },
19
+ ],
20
+ };
21
+ }
22
+ const contactGroups = response.result;
23
+ return {
24
+ content: [
25
+ {
26
+ type: "text",
27
+ text: `Found ${contactGroups?.length || 0} contact groups:`,
28
+ },
29
+ ...(contactGroups?.map((contactGroup) => ({
30
+ type: "text",
31
+ text: [
32
+ `Contact Group ID: ${contactGroup.contactGroupID}`,
33
+ `Name: ${contactGroup.name}`,
34
+ `Status: ${contactGroup.status}`,
35
+ contactGroup.contacts
36
+ ? contactGroup.contacts.map(contact => [
37
+ `Contact ID: ${contact.contactID}`,
38
+ `Name: ${contact.name}`,
39
+ ].join('\n')).join('\n')
40
+ : "No contacts in this contact group.",
41
+ ]
42
+ .filter(Boolean)
43
+ .join("\n"),
44
+ })) || []),
45
+ ],
46
+ };
47
+ });
48
+ export default ListContactGroupsTool;
@@ -0,0 +1,80 @@
1
+ import { listXeroContacts } from "../../handlers/list-xero-contacts.handler.js";
2
+ import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
3
+ import { z } from "zod";
4
+ import { formatUtcDatetime } from "../../helpers/datetime.js";
5
+ const ListContactsTool = CreateXeroTool("list-contacts", "List contacts from Xero. " +
6
+ "Use searchTerm for name/email lookup — do NOT list all contacts and scan them. " +
7
+ "Use contactRole to restrict to customers (AR workflows) or suppliers (AP workflows). " +
8
+ "Common patterns: " +
9
+ "find a customer by name → searchTerm=<name>, contactRole=customer; " +
10
+ "all active suppliers → contactRole=supplier, status=ACTIVE; " +
11
+ "recently updated contacts → fromDate=<date>.", {
12
+ page: z.number().optional().describe("Page number for pagination (starts at 1)."),
13
+ searchTerm: z.string().optional().describe("Case-insensitive search across Name, FirstName, LastName, ContactNumber, EmailAddress. Use this instead of listing all contacts."),
14
+ contactRole: z.enum(["customer", "supplier"]).optional().describe("Filter to customers only (IsCustomer==true) or suppliers only (IsSupplier==true). Use customer for AR work, supplier for AP work."),
15
+ fromDate: z.string().optional().describe("Return contacts updated on or after this date (YYYY-MM-DD)."),
16
+ toDate: z.string().optional().describe("Return contacts updated on or before this date (YYYY-MM-DD)."),
17
+ status: z.enum(["ACTIVE", "ARCHIVED"]).optional().describe("Filter by contact status. Defaults to ACTIVE (excludes archived contacts). Pass ARCHIVED only if you specifically need deactivated contacts."),
18
+ pageSize: z.number().min(1).max(100).optional().default(50).describe("Results per page (1–100, default 50)."),
19
+ }, async (params) => {
20
+ const { page, searchTerm, contactRole, fromDate, toDate, status, pageSize } = params;
21
+ const response = await listXeroContacts(page, searchTerm, fromDate, toDate, status, pageSize, contactRole);
22
+ if (response.isError) {
23
+ return {
24
+ content: [
25
+ {
26
+ type: "text",
27
+ text: `Error listing contacts: ${response.error}`,
28
+ },
29
+ ],
30
+ };
31
+ }
32
+ const contacts = response.result;
33
+ return {
34
+ content: [
35
+ {
36
+ type: "text",
37
+ text: `Found ${contacts?.length || 0} contacts${page ? ` (page ${page})` : ''}:`,
38
+ },
39
+ ...(contacts?.map((contact) => ({
40
+ type: "text",
41
+ text: [
42
+ `Contact: ${contact.name}`,
43
+ `ID: ${contact.contactID}`,
44
+ contact.firstName ? `First Name: ${contact.firstName}` : null,
45
+ contact.lastName ? `Last Name: ${contact.lastName}` : null,
46
+ contact.emailAddress
47
+ ? `Email: ${contact.emailAddress}`
48
+ : "No email",
49
+ contact.accountsReceivableTaxType
50
+ ? `AR Tax Type: ${contact.accountsReceivableTaxType}`
51
+ : null,
52
+ contact.accountsPayableTaxType
53
+ ? `AP Tax Type: ${contact.accountsPayableTaxType}`
54
+ : null,
55
+ `Type: ${[
56
+ contact.isCustomer ? "Customer" : null,
57
+ contact.isSupplier ? "Supplier" : null,
58
+ ]
59
+ .filter(Boolean)
60
+ .join(", ") || "Unknown"}`,
61
+ contact.defaultCurrency
62
+ ? `Default Currency: ${contact.defaultCurrency}`
63
+ : null,
64
+ contact.updatedDateUTC
65
+ ? `Last Updated: ${formatUtcDatetime(contact.updatedDateUTC)}`
66
+ : null,
67
+ `Status: ${contact.contactStatus || "Unknown"}`,
68
+ contact.contactGroups?.length
69
+ ? `Groups: ${contact.contactGroups.map((g) => g.name).join(", ")}`
70
+ : null,
71
+ contact.hasAttachments ? "Has Attachments: Yes" : null,
72
+ contact.hasValidationErrors ? "Has Validation Errors: Yes" : null,
73
+ ]
74
+ .filter(Boolean)
75
+ .join("\n"),
76
+ })) || []),
77
+ ],
78
+ };
79
+ });
80
+ export default ListContactsTool;
@@ -0,0 +1,72 @@
1
+ import { z } from "zod";
2
+ import { listXeroCreditNotes } from "../../handlers/list-xero-credit-notes.handler.js";
3
+ import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
4
+ import { formatUtcDatetime } from "../../helpers/datetime.js";
5
+ const ListCreditNotesTool = CreateXeroTool("list-credit-notes", "List credit notes from Xero. " +
6
+ "ACCREC = sales credit notes (issued to customers). ACCPAY = purchase credit notes (received from suppliers). " +
7
+ "Common patterns: " +
8
+ "unallocated credits to apply → statuses=[AUTHORISED], hasRemainingCredit=true; " +
9
+ "customer credit notes → type=ACCREC, statuses=[AUTHORISED]; " +
10
+ "supplier credits → type=ACCPAY.", {
11
+ page: z.number().describe("Page number for pagination (starts at 1)."),
12
+ type: z.enum(["ACCREC", "ACCPAY"]).optional().describe("ACCREC = sales/customer credit notes. ACCPAY = purchase/supplier credit notes."),
13
+ contactId: z.string().optional().describe("Filter by contact ID."),
14
+ fromDate: z.string().optional().describe("Credit note date on or after this date (YYYY-MM-DD)."),
15
+ toDate: z.string().optional().describe("Credit note date on or before this date (YYYY-MM-DD)."),
16
+ statuses: z.array(z.enum(["DRAFT", "SUBMITTED", "AUTHORISED", "PAID", "VOIDED", "DELETED"])).optional().describe("Filter by status. Defaults to [DRAFT, SUBMITTED, AUTHORISED, PAID] — active records only. Pass VOIDED or DELETED explicitly only if those records are specifically needed."),
17
+ hasRemainingCredit: z.boolean().optional().describe("If true, only returns credit notes with RemainingCredit>0 (i.e. not yet fully allocated). Use to find credits available to apply."),
18
+ pageSize: z.number().min(1).max(100).optional().default(50).describe("Results per page (1–100, default 50)."),
19
+ }, async ({ page, type, contactId, fromDate, toDate, statuses, hasRemainingCredit, pageSize }) => {
20
+ const response = await listXeroCreditNotes(page, contactId, fromDate, toDate, statuses, pageSize, type, hasRemainingCredit);
21
+ if (response.error !== null) {
22
+ return {
23
+ content: [
24
+ {
25
+ type: "text",
26
+ text: `Error listing credit notes: ${response.error}`,
27
+ },
28
+ ],
29
+ };
30
+ }
31
+ const creditNotes = response.result;
32
+ return {
33
+ content: [
34
+ {
35
+ type: "text",
36
+ text: `Found ${creditNotes?.length || 0} credit notes:`,
37
+ },
38
+ ...(creditNotes?.map((creditNote) => ({
39
+ type: "text",
40
+ text: [
41
+ `Credit Note ID: ${creditNote.creditNoteID}`,
42
+ `Credit Note Number: ${creditNote.creditNoteNumber}`,
43
+ creditNote.reference ? `Reference: ${creditNote.reference}` : null,
44
+ `Type: ${creditNote.type || "Unknown"}`,
45
+ `Status: ${creditNote.status || "Unknown"}`,
46
+ creditNote.contact
47
+ ? `Contact: ${creditNote.contact.name} (${creditNote.contact.contactID})`
48
+ : null,
49
+ creditNote.date ? `Date: ${creditNote.date}` : null,
50
+ creditNote.lineAmountTypes
51
+ ? `Line Amount Types: ${creditNote.lineAmountTypes}`
52
+ : null,
53
+ creditNote.subTotal ? `Sub Total: ${creditNote.subTotal}` : null,
54
+ creditNote.totalTax ? `Total Tax: ${creditNote.totalTax}` : null,
55
+ `Total: ${creditNote.total || 0}`,
56
+ creditNote.currencyCode
57
+ ? `Currency: ${creditNote.currencyCode}`
58
+ : null,
59
+ creditNote.currencyRate
60
+ ? `Currency Rate: ${creditNote.currencyRate}`
61
+ : null,
62
+ creditNote.updatedDateUTC
63
+ ? `Last Updated: ${formatUtcDatetime(creditNote.updatedDateUTC)}`
64
+ : null,
65
+ ]
66
+ .filter(Boolean)
67
+ .join("\n"),
68
+ })) || []),
69
+ ],
70
+ };
71
+ });
72
+ export default ListCreditNotesTool;
@@ -0,0 +1,42 @@
1
+ import { z } from "zod";
2
+ import { listXeroInvoiceAttachments } from "../../handlers/list-xero-invoice-attachments.handler.js";
3
+ import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
4
+ const ListInvoiceAttachmentsTool = CreateXeroTool("list-invoice-attachments", "List all file attachments on a Xero invoice (debtor or creditor). \
5
+ Returns attachment IDs, filenames, content types, and file sizes. \
6
+ Use the filename with get-invoice-attachment to download a specific file.", {
7
+ invoiceId: z.string().describe("The Xero ID of the invoice."),
8
+ }, async ({ invoiceId }) => {
9
+ const result = await listXeroInvoiceAttachments(invoiceId);
10
+ if (result.isError) {
11
+ return {
12
+ content: [{ type: "text", text: `Error: ${result.error}` }],
13
+ };
14
+ }
15
+ const attachments = result.result;
16
+ if (!attachments || attachments.length === 0) {
17
+ return {
18
+ content: [{ type: "text", text: "No attachments found on this invoice." }],
19
+ };
20
+ }
21
+ return {
22
+ content: [
23
+ {
24
+ type: "text",
25
+ text: `Found ${attachments.length} attachment(s):`,
26
+ },
27
+ ...attachments.map((a) => ({
28
+ type: "text",
29
+ text: [
30
+ `Filename: ${a.fileName}`,
31
+ `Attachment ID: ${a.attachmentID}`,
32
+ a.mimeType ? `Type: ${a.mimeType}` : null,
33
+ a.contentLength ? `Size: ${Math.round((a.contentLength / 1024) * 10) / 10} KB` : null,
34
+ a.includeOnline ? "Visible in online invoice: Yes" : null,
35
+ ]
36
+ .filter(Boolean)
37
+ .join("\n"),
38
+ })),
39
+ ],
40
+ };
41
+ });
42
+ export default ListInvoiceAttachmentsTool;
@@ -0,0 +1,98 @@
1
+ import { z } from "zod";
2
+ import { listXeroInvoices } from "../../handlers/list-xero-invoices.handler.js";
3
+ import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
4
+ import { formatLineItem } from "../../helpers/format-line-item.js";
5
+ import { formatUtcDatetime } from "../../helpers/datetime.js";
6
+ const ListInvoicesTool = CreateXeroTool("list-invoices", "List invoices from Xero. " +
7
+ "ACCREC = sales invoices (Accounts Receivable, money owed to you). " +
8
+ "ACCPAY = bills/purchase invoices (Accounts Payable, money you owe suppliers). " +
9
+ "Always filter by type and status — do NOT retrieve all invoices and scan them. " +
10
+ "Common patterns: " +
11
+ "unpaid sales invoices → type=ACCREC, statuses=[AUTHORISED], minAmountDue=0.01; " +
12
+ "overdue invoices → type=ACCREC, statuses=[AUTHORISED], overdueOnly=true; " +
13
+ "bills to pay → type=ACCPAY, statuses=[AUTHORISED], minAmountDue=0.01; " +
14
+ "recent drafts → statuses=[DRAFT], fromDate=<date>. " +
15
+ "Set pageSize to the minimum needed. Only paginate if the user asks for more.", {
16
+ page: z.number().describe("Page number for pagination. Starts at 1."),
17
+ type: z.enum(["ACCREC", "ACCPAY"]).optional().describe("ACCREC = sales invoices / accounts receivable. ACCPAY = bills / accounts payable. Always set this unless you genuinely need both."),
18
+ contactIds: z.array(z.string()).optional().describe("Filter by one or more contact IDs."),
19
+ invoiceNumbers: z.array(z.string()).optional().describe("Filter by specific invoice numbers. Line items are included in the response when this is set."),
20
+ statuses: z
21
+ .array(z.enum(["DRAFT", "SUBMITTED", "AUTHORISED", "PAID", "VOIDED", "DELETED"]))
22
+ .optional()
23
+ .describe("Filter by status. Defaults to [DRAFT, SUBMITTED, AUTHORISED, PAID] — active invoices only. Pass VOIDED or DELETED explicitly only if those records are specifically needed."),
24
+ fromDate: z.string().optional().describe("Invoice date on or after this date (YYYY-MM-DD)."),
25
+ toDate: z.string().optional().describe("Invoice date on or before this date (YYYY-MM-DD)."),
26
+ minAmountDue: z.number().optional().describe("Only return invoices with AmountDue greater than this value. Use 0.01 to exclude fully paid invoices without needing to filter by date."),
27
+ overdueOnly: z.boolean().optional().describe("If true, returns only invoices past their due date with an outstanding balance. Equivalent to AmountDue>0 AND DueDate<=today. Use with type=ACCREC and statuses=[AUTHORISED] for AR chasing."),
28
+ pageSize: z.number().min(1).max(1000).optional().default(100).describe("Results per page (1–1000, default 100). Use a smaller value if you only need a few results."),
29
+ }, async ({ page, type, contactIds, invoiceNumbers, statuses, fromDate, toDate, minAmountDue, overdueOnly, pageSize }) => {
30
+ const response = await listXeroInvoices(page, contactIds, invoiceNumbers, statuses, fromDate, toDate, pageSize, type, minAmountDue, overdueOnly);
31
+ if (response.error !== null) {
32
+ return {
33
+ content: [
34
+ {
35
+ type: "text",
36
+ text: `Error listing invoices: ${response.error}`,
37
+ },
38
+ ],
39
+ };
40
+ }
41
+ const invoices = response.result;
42
+ const returnLineItems = (invoiceNumbers?.length ?? 0) > 0;
43
+ return {
44
+ content: [
45
+ {
46
+ type: "text",
47
+ text: `Found ${invoices?.length || 0} invoices:`,
48
+ },
49
+ ...(invoices?.map((invoice) => ({
50
+ type: "text",
51
+ text: [
52
+ `Invoice ID: ${invoice.invoiceID}`,
53
+ `Invoice: ${invoice.invoiceNumber}`,
54
+ invoice.reference ? `Reference: ${invoice.reference}` : null,
55
+ `Type: ${invoice.type || "Unknown"}`,
56
+ `Status: ${invoice.status || "Unknown"}`,
57
+ invoice.contact
58
+ ? `Contact: ${invoice.contact.name} (${invoice.contact.contactID})`
59
+ : null,
60
+ invoice.date ? `Date: ${invoice.date}` : null,
61
+ invoice.dueDate ? `Due Date: ${invoice.dueDate}` : null,
62
+ invoice.lineAmountTypes
63
+ ? `Line Amount Types: ${invoice.lineAmountTypes}`
64
+ : null,
65
+ invoice.subTotal ? `Sub Total: ${invoice.subTotal}` : null,
66
+ invoice.totalTax ? `Total Tax: ${invoice.totalTax}` : null,
67
+ `Total: ${invoice.total || 0}`,
68
+ invoice.totalDiscount
69
+ ? `Total Discount: ${invoice.totalDiscount}`
70
+ : null,
71
+ invoice.currencyCode ? `Currency: ${invoice.currencyCode}` : null,
72
+ invoice.currencyRate
73
+ ? `Currency Rate: ${invoice.currencyRate}`
74
+ : null,
75
+ invoice.updatedDateUTC
76
+ ? `Last Updated: ${formatUtcDatetime(invoice.updatedDateUTC)}`
77
+ : null,
78
+ invoice.fullyPaidOnDate
79
+ ? `Fully Paid On: ${invoice.fullyPaidOnDate}`
80
+ : null,
81
+ invoice.amountDue ? `Amount Due: ${invoice.amountDue}` : null,
82
+ invoice.amountPaid ? `Amount Paid: ${invoice.amountPaid}` : null,
83
+ invoice.amountCredited
84
+ ? `Amount Credited: ${invoice.amountCredited}`
85
+ : null,
86
+ invoice.hasErrors ? "Has Errors: Yes" : null,
87
+ invoice.isDiscounted ? "Is Discounted: Yes" : null,
88
+ returnLineItems
89
+ ? `Line Items: ${invoice.lineItems?.map(formatLineItem)}`
90
+ : null,
91
+ ]
92
+ .filter(Boolean)
93
+ .join("\n"),
94
+ })) || []),
95
+ ],
96
+ };
97
+ });
98
+ export default ListInvoicesTool;
@@ -0,0 +1,50 @@
1
+ import { z } from "zod";
2
+ import { listXeroItems } from "../../handlers/list-xero-items.handler.js";
3
+ import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
4
+ import { formatUtcDatetime } from "../../helpers/datetime.js";
5
+ const ListItemsTool = CreateXeroTool("list-items", "Lists all items in Xero. Use this tool to get the item codes and descriptions to be used when creating invoices in Xero", {
6
+ page: z.number(),
7
+ }, async ({ page }) => {
8
+ const response = await listXeroItems(page);
9
+ if (response.isError) {
10
+ return {
11
+ content: [
12
+ {
13
+ type: "text",
14
+ text: `Error listing items: ${response.error}`,
15
+ },
16
+ ],
17
+ };
18
+ }
19
+ const items = response.result;
20
+ return {
21
+ content: [
22
+ {
23
+ type: "text",
24
+ text: `Found ${items?.length || 0} items:`,
25
+ },
26
+ ...(items?.map((item) => ({
27
+ type: "text",
28
+ text: [
29
+ `Item: ${item.name || "Unnamed"}`,
30
+ `ID: ${item.itemID}`,
31
+ `Code: ${item.code}`,
32
+ item.description ? `Description: ${item.description}` : null,
33
+ item.purchaseDescription ? `Purchase Description: ${item.purchaseDescription}` : null,
34
+ item.salesDetails?.unitPrice !== undefined ? `Sales Price: ${item.salesDetails.unitPrice}` : null,
35
+ item.purchaseDetails?.unitPrice !== undefined ? `Purchase Price: ${item.purchaseDetails.unitPrice}` : null,
36
+ item.salesDetails?.accountCode ? `Sales Account: ${item.salesDetails.accountCode}` : null,
37
+ item.purchaseDetails?.accountCode ? `Purchase Account: ${item.purchaseDetails.accountCode}` : null,
38
+ item.isTrackedAsInventory !== undefined ? `Tracked as Inventory: ${item.isTrackedAsInventory ? 'Yes' : 'No'}` : null,
39
+ item.isSold !== undefined ? `Is Sold: ${item.isSold ? 'Yes' : 'No'}` : null,
40
+ item.isPurchased !== undefined ? `Is Purchased: ${item.isPurchased ? 'Yes' : 'No'}` : null,
41
+ item.updatedDateUTC ? `Last Updated: ${formatUtcDatetime(item.updatedDateUTC)}` : null,
42
+ item.validationErrors?.length ? `Validation Errors: ${item.validationErrors.map(e => e.message).join(", ")}` : null,
43
+ ]
44
+ .filter(Boolean)
45
+ .join("\n"),
46
+ })) || []),
47
+ ],
48
+ };
49
+ });
50
+ export default ListItemsTool;
@@ -0,0 +1,80 @@
1
+ import { listXeroManualJournals } from "../../handlers/list-xero-manual-journals.handler.js";
2
+ import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
3
+ import { z } from "zod";
4
+ import { formatUtcDatetime } from "../../helpers/datetime.js";
5
+ const ListManualJournalsTool = CreateXeroTool("list-manual-journals", `List all manual journals from Xero.
6
+ Ask the user if they want to see a specific manual journal or all manual journals before running.
7
+ Can optionally pass in manual journal ID to retrieve a specific journal, or a date to filter journals modified after that date.
8
+ The response presents a complete overview of all manual journals currently registered in your Xero account, with their details.
9
+ Ask the user if they want the next page of manual journals after running this tool if 10 manual journals are returned.
10
+ If they want the next page, call this tool again with the next page number, modified date, and the manual journal ID if one was provided in the previous call.`, {
11
+ manualJournalId: z
12
+ .string()
13
+ .optional()
14
+ .describe("Optional ID of the manual journal to retrieve"),
15
+ modifiedAfter: z
16
+ .string()
17
+ .optional()
18
+ .describe("Optional date YYYY-MM-DD to filter journals modified after this date"),
19
+ page: z.number().optional().describe("Optional page number for pagination"),
20
+ pageSize: z.number().min(1).max(100).optional().default(50).describe("Number of results per page (1–100, default 50)."),
21
+ }, async (args) => {
22
+ const response = await listXeroManualJournals(args?.page, args?.manualJournalId, args?.modifiedAfter, args?.pageSize);
23
+ if (response.isError) {
24
+ return {
25
+ content: [
26
+ {
27
+ type: "text",
28
+ text: `Error listing manual journals: ${response.error}`,
29
+ },
30
+ ],
31
+ };
32
+ }
33
+ const manualJournals = response.result;
34
+ return {
35
+ content: [
36
+ {
37
+ type: "text",
38
+ text: `Found ${manualJournals?.length || 0} manual journals:`,
39
+ },
40
+ ...(manualJournals?.map((journal) => ({
41
+ type: "text",
42
+ text: [
43
+ `Manual Journal ID: ${journal.manualJournalID}`,
44
+ journal.narration
45
+ ? `Description: ${journal.narration}`
46
+ : "No description",
47
+ journal.date ? `Date: ${journal.date}` : null,
48
+ journal.journalLines
49
+ ? journal.journalLines.map((line) => [
50
+ `Line Amount: ${line.lineAmount}`,
51
+ line.accountCode
52
+ ? `Account Code: ${line.accountCode}`
53
+ : "No account code",
54
+ line.description
55
+ ? `Description: ${line.description}`
56
+ : "No description",
57
+ line.taxType ? `Tax Type: ${line.taxType}` : "No tax type",
58
+ `Tax Amount: ${line.taxAmount}`,
59
+ ]
60
+ .filter(Boolean)
61
+ .join("\n")).join("\n\n")
62
+ : "No journal lines",
63
+ journal.lineAmountTypes
64
+ ? `Line Amount Types: ${journal.lineAmountTypes}`
65
+ : "No line amount types",
66
+ journal.status ? `Status: ${journal.status}` : "No status",
67
+ journal.url ? `URL: ${journal.url}` : "No URL",
68
+ `Show on Cash Basis Reports: ${journal.showOnCashBasisReports}`,
69
+ `Has Attachments: ${journal.hasAttachments}`,
70
+ journal.updatedDateUTC
71
+ ? `Last Updated: ${formatUtcDatetime(journal.updatedDateUTC)}`
72
+ : "No last updated date",
73
+ ]
74
+ .filter(Boolean)
75
+ .join("\n"),
76
+ })) || []),
77
+ ],
78
+ };
79
+ });
80
+ export default ListManualJournalsTool;