@mindstone/mcp-server-xero 0.0.15

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 (137) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +199 -0
  3. package/dist/clients/xero-client.js +134 -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/create-xero-bank-transaction.handler.js +50 -0
  7. package/dist/handlers/create-xero-contact.handler.js +49 -0
  8. package/dist/handlers/create-xero-credit-note.handler.js +49 -0
  9. package/dist/handlers/create-xero-invoice.handler.js +55 -0
  10. package/dist/handlers/create-xero-item.handler.js +59 -0
  11. package/dist/handlers/create-xero-manual-journal.handler.js +57 -0
  12. package/dist/handlers/create-xero-payment.handler.js +49 -0
  13. package/dist/handlers/create-xero-payroll-timesheet.handler.js +28 -0
  14. package/dist/handlers/create-xero-quote.handler.js +54 -0
  15. package/dist/handlers/create-xero-tracking-category.handler.js +35 -0
  16. package/dist/handlers/create-xero-tracking-option.handler.js +31 -0
  17. package/dist/handlers/delete-xero-payroll-timesheet.handler.js +28 -0
  18. package/dist/handlers/download-xero-invoice-attachment.handler.js +26 -0
  19. package/dist/handlers/get-xero-payroll-timesheet.handler.js +28 -0
  20. package/dist/handlers/history-handler-factory.js +46 -0
  21. package/dist/handlers/list-aged-payables-by-contact.handler.js +37 -0
  22. package/dist/handlers/list-aged-receivables-by-contact.handler.js +37 -0
  23. package/dist/handlers/list-xero-accounts.handler.js +32 -0
  24. package/dist/handlers/list-xero-bank-transactions.handler.js +31 -0
  25. package/dist/handlers/list-xero-contact-groups.handler.js +34 -0
  26. package/dist/handlers/list-xero-contacts.handler.js +37 -0
  27. package/dist/handlers/list-xero-credit-notes.handler.js +34 -0
  28. package/dist/handlers/list-xero-invoice-attachments.handler.js +20 -0
  29. package/dist/handlers/list-xero-invoices.handler.js +59 -0
  30. package/dist/handlers/list-xero-items.handler.js +32 -0
  31. package/dist/handlers/list-xero-manual-journals.handler.js +33 -0
  32. package/dist/handlers/list-xero-organisation-details.handler.js +32 -0
  33. package/dist/handlers/list-xero-payments.handler.js +53 -0
  34. package/dist/handlers/list-xero-payroll-employee-leave-balances.handler.js +42 -0
  35. package/dist/handlers/list-xero-payroll-employee-leave-types.handler.js +42 -0
  36. package/dist/handlers/list-xero-payroll-employee-leave.handler.js +44 -0
  37. package/dist/handlers/list-xero-payroll-employees.handler.js +31 -0
  38. package/dist/handlers/list-xero-payroll-leave-periods.handler.js +44 -0
  39. package/dist/handlers/list-xero-payroll-leave-types.handler.js +40 -0
  40. package/dist/handlers/list-xero-profit-and-loss.handler.js +52 -0
  41. package/dist/handlers/list-xero-quotes.handler.js +37 -0
  42. package/dist/handlers/list-xero-report-balance-sheet.handler.js +34 -0
  43. package/dist/handlers/list-xero-tax-rates.handler.js +30 -0
  44. package/dist/handlers/list-xero-timesheets.handler.js +29 -0
  45. package/dist/handlers/list-xero-tracking-categories.handler.js +29 -0
  46. package/dist/handlers/list-xero-trial-balance.handler.js +42 -0
  47. package/dist/handlers/revert-xero-payroll-timesheet.handler.js +28 -0
  48. package/dist/handlers/update-xero-bank-transaction.handler.js +56 -0
  49. package/dist/handlers/update-xero-contact.handler.js +66 -0
  50. package/dist/handlers/update-xero-credit-note.handler.js +61 -0
  51. package/dist/handlers/update-xero-invoice.handler.js +63 -0
  52. package/dist/handlers/update-xero-item.handler.js +46 -0
  53. package/dist/handlers/update-xero-manual-journal.handler.js +46 -0
  54. package/dist/handlers/update-xero-payroll-timesheet-add-line.handler.js +28 -0
  55. package/dist/handlers/update-xero-payroll-timesheet-update-line.handler.js +28 -0
  56. package/dist/handlers/update-xero-quote.handler.js +78 -0
  57. package/dist/handlers/update-xero-tracking-category.handler.js +43 -0
  58. package/dist/handlers/update-xero-tracking-options.handler.js +51 -0
  59. package/dist/helpers/create-xero-tool.js +6 -0
  60. package/dist/helpers/ensure-error.js +13 -0
  61. package/dist/helpers/format-aged-report-filter.js +8 -0
  62. package/dist/helpers/format-error.js +57 -0
  63. package/dist/helpers/format-line-item.js +13 -0
  64. package/dist/helpers/format-token-error.js +34 -0
  65. package/dist/helpers/format-tracking-option.js +7 -0
  66. package/dist/helpers/get-client-headers.js +8 -0
  67. package/dist/helpers/get-deeplink.js +41 -0
  68. package/dist/helpers/get-external-link.js +8 -0
  69. package/dist/helpers/get-package-version.js +20 -0
  70. package/dist/index.js +16 -0
  71. package/dist/server/xero-mcp-server.js +14 -0
  72. package/dist/tools/create/create-bank-transaction.tool.js +57 -0
  73. package/dist/tools/create/create-contact.tool.js +56 -0
  74. package/dist/tools/create/create-credit-note.tool.js +53 -0
  75. package/dist/tools/create/create-invoice.tool.js +76 -0
  76. package/dist/tools/create/create-item.tool.js +61 -0
  77. package/dist/tools/create/create-manual-journal.tool.js +116 -0
  78. package/dist/tools/create/create-payment.tool.js +71 -0
  79. package/dist/tools/create/create-payroll-timesheet.tool.js +40 -0
  80. package/dist/tools/create/create-quote.tool.js +57 -0
  81. package/dist/tools/create/create-tracking-category.tool.js +28 -0
  82. package/dist/tools/create/create-tracking-options.tool.js +30 -0
  83. package/dist/tools/create/index.js +24 -0
  84. package/dist/tools/delete/delete-payroll-timesheet.tool.js +28 -0
  85. package/dist/tools/delete/index.js +4 -0
  86. package/dist/tools/get/get-invoice-attachment.tool.js +45 -0
  87. package/dist/tools/get/get-payroll-timesheet.tool.js +49 -0
  88. package/dist/tools/get/index.js +6 -0
  89. package/dist/tools/history/index.js +141 -0
  90. package/dist/tools/list/index.js +54 -0
  91. package/dist/tools/list/list-accounts.tool.js +39 -0
  92. package/dist/tools/list/list-aged-payables-by-contact.tool.js +49 -0
  93. package/dist/tools/list/list-aged-receivables-by-contact.tool.js +49 -0
  94. package/dist/tools/list/list-bank-transactions.tool.js +63 -0
  95. package/dist/tools/list/list-contact-groups.tool.js +48 -0
  96. package/dist/tools/list/list-contacts.tool.js +70 -0
  97. package/dist/tools/list/list-credit-notes.tool.js +70 -0
  98. package/dist/tools/list/list-invoice-attachments.tool.js +42 -0
  99. package/dist/tools/list/list-invoices.tool.js +141 -0
  100. package/dist/tools/list/list-items.tool.js +53 -0
  101. package/dist/tools/list/list-manual-journals.tool.js +83 -0
  102. package/dist/tools/list/list-organisation-details.tool.js +90 -0
  103. package/dist/tools/list/list-payments.tool.js +84 -0
  104. package/dist/tools/list/list-payroll-employee-leave-balances.tool.js +39 -0
  105. package/dist/tools/list/list-payroll-employee-leave-types.tool.js +57 -0
  106. package/dist/tools/list/list-payroll-employee-leave.tool.js +42 -0
  107. package/dist/tools/list/list-payroll-employees.tool.js +48 -0
  108. package/dist/tools/list/list-payroll-leave-periods.tool.js +45 -0
  109. package/dist/tools/list/list-payroll-leave-types.tool.js +39 -0
  110. package/dist/tools/list/list-payroll-timesheets.tool.js +39 -0
  111. package/dist/tools/list/list-profit-and-loss.tool.js +45 -0
  112. package/dist/tools/list/list-quotes.tool.js +72 -0
  113. package/dist/tools/list/list-report-balance-sheet.tool.js +39 -0
  114. package/dist/tools/list/list-tax-rates.tool.js +49 -0
  115. package/dist/tools/list/list-tracking-categories.tool.js +39 -0
  116. package/dist/tools/list/list-trial-balance.tool.js +41 -0
  117. package/dist/tools/tool-factory.js +24 -0
  118. package/dist/tools/update/approve-payroll-timesheet.tool.js +29 -0
  119. package/dist/tools/update/index.js +28 -0
  120. package/dist/tools/update/revert-payroll-timesheet.tool.js +29 -0
  121. package/dist/tools/update/update-bank-transaction.tool.js +56 -0
  122. package/dist/tools/update/update-contact.tool.js +69 -0
  123. package/dist/tools/update/update-credit-note.tool.js +56 -0
  124. package/dist/tools/update/update-invoice.tool.js +74 -0
  125. package/dist/tools/update/update-item.tool.js +62 -0
  126. package/dist/tools/update/update-manual-journal-tool.js +89 -0
  127. package/dist/tools/update/update-payroll-timesheet-add-line.tool.js +34 -0
  128. package/dist/tools/update/update-payroll-timesheet-update-line.tool.js +35 -0
  129. package/dist/tools/update/update-quote.tool.js +61 -0
  130. package/dist/tools/update/update-tracking-category.tool.js +30 -0
  131. package/dist/tools/update/update-tracking-options.tool.js +35 -0
  132. package/dist/types/list-report-balance-sheet-params.js +1 -0
  133. package/dist/types/timeframeType.js +1 -0
  134. package/dist/types/tool-definition.js +1 -0
  135. package/dist/types/tool-list.js +1 -0
  136. package/dist/types/tool-response.js +1 -0
  137. package/package.json +63 -0
@@ -0,0 +1,49 @@
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", `Lists the aged payables in Xero.
6
+ This shows aged payables for a certain contact up to a report date.`, {
7
+ contactId: z.string(),
8
+ reportDate: z.string().optional()
9
+ .describe("Optional date to retrieve aged payables in YYYY-MM-DD format. If none is provided, defaults to end of the current month."),
10
+ invoicesFromDate: z.string().optional()
11
+ .describe("Optional from date in YYYY-MM-DD format. If provided, will only show payable invoices after this date for the contact."),
12
+ invoicesToDate: z.string().optional()
13
+ .describe("Optional to date in YYYY-MM-DD format. If provided, will only show payable invoices before this date for the contact."),
14
+ }, async ({ contactId, reportDate, invoicesFromDate, invoicesToDate }) => {
15
+ const response = await listXeroAgedPayablesByContact(contactId, reportDate, invoicesFromDate, invoicesToDate);
16
+ if (response.isError) {
17
+ return {
18
+ content: [
19
+ {
20
+ type: "text",
21
+ text: `Error listing aged payables by contact: ${response.error}`,
22
+ },
23
+ ],
24
+ };
25
+ }
26
+ const agedPayablesReport = response.result;
27
+ const filter = formatAgedReportFilter(invoicesFromDate, invoicesToDate);
28
+ return {
29
+ content: [
30
+ {
31
+ type: "text",
32
+ text: `Report Name: ${agedPayablesReport.reportName || "Not specified"}`,
33
+ },
34
+ {
35
+ type: "text",
36
+ text: `Report Date: ${agedPayablesReport.reportDate || "Not specified"}`
37
+ },
38
+ {
39
+ type: "text",
40
+ text: filter ?? "Showing all relevant invoices"
41
+ },
42
+ {
43
+ type: "text",
44
+ text: JSON.stringify(agedPayablesReport.rows, null, 2),
45
+ }
46
+ ],
47
+ };
48
+ });
49
+ export default ListAgedPayablesByContact;
@@ -0,0 +1,49 @@
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", `Lists the aged receivables in Xero.
6
+ This shows aged receivables for a certain contact up to a report date.`, {
7
+ contactId: z.string(),
8
+ reportDate: z.string().optional()
9
+ .describe("Optional date to retrieve aged receivables in YYYY-MM-DD format. If none is provided, defaults to end of the current month."),
10
+ invoicesFromDate: z.string().optional()
11
+ .describe("Optional from date in YYYY-MM-DD format. If provided, will only show payable invoices after this date for the contact."),
12
+ invoicesToDate: z.string().optional()
13
+ .describe("Optional to date in YYYY-MM-DD format. If provided, will only show payable invoices before this date for the contact."),
14
+ }, async ({ contactId, reportDate, invoicesFromDate, invoicesToDate }) => {
15
+ const response = await listXeroAgedReceivablesByContact(contactId, reportDate, invoicesFromDate, invoicesToDate);
16
+ if (response.isError) {
17
+ return {
18
+ content: [
19
+ {
20
+ type: "text",
21
+ text: `Error listing aged receivables by contact: ${response.error}`,
22
+ },
23
+ ],
24
+ };
25
+ }
26
+ const agedReceivablesReport = response.result;
27
+ const filter = formatAgedReportFilter(invoicesFromDate, invoicesToDate);
28
+ return {
29
+ content: [
30
+ {
31
+ type: "text",
32
+ text: `Report Name: ${agedReceivablesReport.reportName || "Not specified"}`,
33
+ },
34
+ {
35
+ type: "text",
36
+ text: `Report Date: ${agedReceivablesReport.reportDate || "Not specified"}`
37
+ },
38
+ {
39
+ type: "text",
40
+ text: filter ?? "Showing all relevant invoices"
41
+ },
42
+ {
43
+ type: "text",
44
+ text: JSON.stringify(agedReceivablesReport.rows, null, 2),
45
+ }
46
+ ],
47
+ };
48
+ });
49
+ export default ListAgedReceivablesByContact;
@@ -0,0 +1,63 @@
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 all bank transactions in Xero.
6
+ Ask the user if they want to see bank transactions for a specific bank account,
7
+ or to see all bank transactions before running.
8
+ Ask the user if they want the next page of bank transactions after running this tool if
9
+ 10 bank transactions are returned.
10
+ If they do, call this tool again with the next page number and the bank account
11
+ if one was provided in the provided in the previous call.
12
+
13
+ COMMON MISTAKES:
14
+ - Only use the params listed above. Do not invent additional filter or sort params.
15
+ - There is no "search", "query", "filter", "sortBy", "limit", or "offset" param.`, {
16
+ page: z.number(),
17
+ bankAccountId: z.string().optional()
18
+ }, async ({ bankAccountId, page }) => {
19
+ const response = await listXeroBankTransactions(page, bankAccountId);
20
+ if (response.isError) {
21
+ return {
22
+ content: [
23
+ {
24
+ type: "text",
25
+ text: `Error listing bank transactions: ${response.error}`
26
+ }
27
+ ]
28
+ };
29
+ }
30
+ const bankTransactions = response.result;
31
+ return {
32
+ content: [
33
+ {
34
+ type: "text",
35
+ text: `Found ${bankTransactions?.length || 0} bank transactions:`
36
+ },
37
+ ...(bankTransactions?.map((transaction) => ({
38
+ type: "text",
39
+ text: [
40
+ `Bank Transaction ID: ${transaction.bankTransactionID}`,
41
+ `Bank Account: ${transaction.bankAccount.name} (${transaction.bankAccount.accountID})`,
42
+ transaction.contact
43
+ ? `Contact: ${transaction.contact.name} (${transaction.contact.contactID})`
44
+ : null,
45
+ transaction.reference ? `Reference: ${transaction.reference}` : null,
46
+ transaction.date ? `Date: ${transaction.date}` : null,
47
+ transaction.subTotal ? `Sub Total: ${transaction.subTotal}` : null,
48
+ transaction.totalTax ? `Total Tax: ${transaction.totalTax}` : null,
49
+ transaction.total ? `Total: ${transaction.total}` : null,
50
+ transaction.isReconciled !== undefined ? (`${transaction.isReconciled ? "Reconciled" : "Unreconciled"}`) : null,
51
+ transaction.currencyCode ? `Currency Code: ${transaction.currencyCode}` : null,
52
+ `${transaction.status || "Unknown"}`,
53
+ transaction.lineAmountTypes ? `Line Amount Types: ${transaction.lineAmountTypes}` : undefined,
54
+ transaction.hasAttachments !== undefined
55
+ ? (transaction.hasAttachments ? "Has attachments" : "Does not have attachments")
56
+ : null,
57
+ `Line Items: ${transaction.lineItems?.map(formatLineItem)}`,
58
+ ].filter(Boolean).join("\n")
59
+ })) || [])
60
+ ]
61
+ };
62
+ });
63
+ 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,70 @@
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
+ const ListContactsTool = CreateXeroTool("list-contacts", "List all contacts in Xero. This includes Suppliers and Customers.", {
5
+ page: z.number().optional().describe("Optional page number to retrieve for pagination. \
6
+ If not provided, the first page will be returned. If 100 contacts are returned, \
7
+ call this tool again with the next page number."),
8
+ searchTerm: z.string().optional().describe("Search parameter that performs a case-insensitive text search across the Name, FirstName, LastName, ContactNumber and EmailAddress fields"),
9
+ }, async (params) => {
10
+ const { page, searchTerm } = params;
11
+ const response = await listXeroContacts(page, searchTerm);
12
+ if (response.isError) {
13
+ return {
14
+ content: [
15
+ {
16
+ type: "text",
17
+ text: `Error listing contacts: ${response.error}`,
18
+ },
19
+ ],
20
+ };
21
+ }
22
+ const contacts = response.result;
23
+ return {
24
+ content: [
25
+ {
26
+ type: "text",
27
+ text: `Found ${contacts?.length || 0} contacts${page ? ` (page ${page})` : ''}:`,
28
+ },
29
+ ...(contacts?.map((contact) => ({
30
+ type: "text",
31
+ text: [
32
+ `Contact: ${contact.name}`,
33
+ `ID: ${contact.contactID}`,
34
+ contact.firstName ? `First Name: ${contact.firstName}` : null,
35
+ contact.lastName ? `Last Name: ${contact.lastName}` : null,
36
+ contact.emailAddress
37
+ ? `Email: ${contact.emailAddress}`
38
+ : "No email",
39
+ contact.accountsReceivableTaxType
40
+ ? `AR Tax Type: ${contact.accountsReceivableTaxType}`
41
+ : null,
42
+ contact.accountsPayableTaxType
43
+ ? `AP Tax Type: ${contact.accountsPayableTaxType}`
44
+ : null,
45
+ `Type: ${[
46
+ contact.isCustomer ? "Customer" : null,
47
+ contact.isSupplier ? "Supplier" : null,
48
+ ]
49
+ .filter(Boolean)
50
+ .join(", ") || "Unknown"}`,
51
+ contact.defaultCurrency
52
+ ? `Default Currency: ${contact.defaultCurrency}`
53
+ : null,
54
+ contact.updatedDateUTC
55
+ ? `Last Updated: ${contact.updatedDateUTC}`
56
+ : null,
57
+ `Status: ${contact.contactStatus || "Unknown"}`,
58
+ contact.contactGroups?.length
59
+ ? `Groups: ${contact.contactGroups.map((g) => g.name).join(", ")}`
60
+ : null,
61
+ contact.hasAttachments ? "Has Attachments: Yes" : null,
62
+ contact.hasValidationErrors ? "Has Validation Errors: Yes" : null,
63
+ ]
64
+ .filter(Boolean)
65
+ .join("\n"),
66
+ })) || []),
67
+ ],
68
+ };
69
+ });
70
+ export default ListContactsTool;
@@ -0,0 +1,70 @@
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
+ const ListCreditNotesTool = CreateXeroTool("list-credit-notes", `List credit notes in Xero.
5
+ Ask the user if they want to see credit notes for a specific contact,
6
+ or to see all credit notes before running.
7
+ Ask the user if they want the next page of credit notes after running this tool
8
+ if 10 credit notes are returned.
9
+ If they want the next page, call this tool again with the next page number
10
+ and the contact if one was provided in the previous call.
11
+
12
+ COMMON MISTAKES:
13
+ - Only use the params listed above. Do not invent additional filter or sort params.
14
+ - There is no "search", "query", "filter", "sortBy", "limit", or "offset" param.`, {
15
+ page: z.number(),
16
+ contactId: z.string().optional(),
17
+ }, async ({ page, contactId }) => {
18
+ const response = await listXeroCreditNotes(page, contactId);
19
+ if (response.error !== null) {
20
+ return {
21
+ content: [
22
+ {
23
+ type: "text",
24
+ text: `Error listing credit notes: ${response.error}`,
25
+ },
26
+ ],
27
+ };
28
+ }
29
+ const creditNotes = response.result;
30
+ return {
31
+ content: [
32
+ {
33
+ type: "text",
34
+ text: `Found ${creditNotes?.length || 0} credit notes:`,
35
+ },
36
+ ...(creditNotes?.map((creditNote) => ({
37
+ type: "text",
38
+ text: [
39
+ `Credit Note ID: ${creditNote.creditNoteID}`,
40
+ `Credit Note Number: ${creditNote.creditNoteNumber}`,
41
+ creditNote.reference ? `Reference: ${creditNote.reference}` : null,
42
+ `Type: ${creditNote.type || "Unknown"}`,
43
+ `Status: ${creditNote.status || "Unknown"}`,
44
+ creditNote.contact
45
+ ? `Contact: ${creditNote.contact.name} (${creditNote.contact.contactID})`
46
+ : null,
47
+ creditNote.date ? `Date: ${creditNote.date}` : null,
48
+ creditNote.lineAmountTypes
49
+ ? `Line Amount Types: ${creditNote.lineAmountTypes}`
50
+ : null,
51
+ creditNote.subTotal ? `Sub Total: ${creditNote.subTotal}` : null,
52
+ creditNote.totalTax ? `Total Tax: ${creditNote.totalTax}` : null,
53
+ `Total: ${creditNote.total || 0}`,
54
+ creditNote.currencyCode
55
+ ? `Currency: ${creditNote.currencyCode}`
56
+ : null,
57
+ creditNote.currencyRate
58
+ ? `Currency Rate: ${creditNote.currencyRate}`
59
+ : null,
60
+ creditNote.updatedDateUTC
61
+ ? `Last Updated: ${creditNote.updatedDateUTC}`
62
+ : null,
63
+ ]
64
+ .filter(Boolean)
65
+ .join("\n"),
66
+ })) || []),
67
+ ],
68
+ };
69
+ });
70
+ 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 attachments for a specific invoice in Xero. \
5
+ Returns attachment metadata including filename, MIME type, and file size. \
6
+ Requires the accounting.attachments.read scope on the Xero Custom Connection. \
7
+ Use the FileName from the results with download-invoice-attachment to download content.", {
8
+ invoiceId: z.string().describe("The Xero Invoice ID (UUID)"),
9
+ }, async ({ invoiceId }) => {
10
+ const response = await listXeroInvoiceAttachments(invoiceId);
11
+ if (response.error !== null) {
12
+ return {
13
+ content: [
14
+ {
15
+ type: "text",
16
+ text: `Error listing invoice attachments: ${response.error}`,
17
+ },
18
+ ],
19
+ };
20
+ }
21
+ const attachments = response.result;
22
+ return {
23
+ content: [
24
+ {
25
+ type: "text",
26
+ text: `Found ${attachments?.length || 0} attachments:`,
27
+ },
28
+ ...(attachments?.map((attachment) => ({
29
+ type: "text",
30
+ text: [
31
+ `Attachment ID: ${attachment.attachmentID}`,
32
+ `File Name: ${attachment.fileName}`,
33
+ `MIME Type: ${attachment.mimeType}`,
34
+ `Content Length: ${attachment.contentLength}`,
35
+ ]
36
+ .filter(Boolean)
37
+ .join("\n"),
38
+ })) || []),
39
+ ],
40
+ };
41
+ });
42
+ export default ListInvoiceAttachmentsTool;
@@ -0,0 +1,141 @@
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
+ const ListInvoicesTool = CreateXeroTool("list-invoices", `List invoices in Xero. Returns up to pageSize results per page (default 100, max 100).
6
+
7
+ SORTING: Default sort is UpdatedDateUTC DESC (last-modified first). Use orderBy to sort by DueDate, Date, or InvoiceNumber. Use orderDirection for ASC/DESC.
8
+
9
+ FILTERING: Use status to filter by invoice status. Use type ACCREC for sales invoices or ACCPAY for bills. Use dateFrom/dateTo for date ranges (YYYY-MM-DD).
10
+
11
+ PAGINATION: If results returned equals pageSize, there may be more pages. Call again with page+1.
12
+
13
+ AGGREGATE QUERIES: For "latest invoice", "top N by due date", "total outstanding", "how many overdue" — you MUST either use appropriate orderBy/status/dateFrom filters OR paginate ALL pages before answering. Do NOT answer from partial data.
14
+
15
+ WORKFLOW:
16
+ 1. Use orderBy + status filters to get the exact data you need
17
+ 2. For specific contacts, use contactIds (look up IDs via list-contacts first)
18
+ 3. For specific invoices by number, use invoiceNumbers
19
+
20
+ COMMON MISTAKES:
21
+ - Do NOT pass contactName, search, query, fromDate, toDate, sortBy, limit, or offset — these params do not exist
22
+ - Status values are UPPERCASE: DRAFT, SUBMITTED, AUTHORISED, PAID, VOIDED, DELETED
23
+ - Type values: ACCREC (sales/receivable) or ACCPAY (bills/payable)
24
+ - Date format is strictly YYYY-MM-DD`, {
25
+ page: z
26
+ .number()
27
+ .int()
28
+ .min(1)
29
+ .describe("Page number (1-based). If results equal pageSize, there may be more pages."),
30
+ contactIds: z.array(z.string()).optional(),
31
+ invoiceNumbers: z
32
+ .array(z.string())
33
+ .optional()
34
+ .describe("If provided, invoice line items will also be returned"),
35
+ orderBy: z
36
+ .enum(["UpdatedDateUTC", "DueDate", "Date", "InvoiceNumber"])
37
+ .optional()
38
+ .describe("Sort field. Default: UpdatedDateUTC"),
39
+ orderDirection: z
40
+ .enum(["ASC", "DESC"])
41
+ .optional()
42
+ .describe("Sort direction. Default: DESC"),
43
+ status: z
44
+ .enum(["DRAFT", "SUBMITTED", "AUTHORISED", "PAID", "VOIDED", "DELETED"])
45
+ .optional()
46
+ .describe("Filter by invoice status"),
47
+ type: z
48
+ .enum(["ACCREC", "ACCPAY"])
49
+ .optional()
50
+ .describe("ACCREC = sales invoices (accounts receivable), ACCPAY = bills (accounts payable)"),
51
+ dateFrom: z
52
+ .string()
53
+ .regex(/^\d{4}-\d{2}-\d{2}$/, "Must be YYYY-MM-DD format")
54
+ .optional()
55
+ .describe("Only invoices on or after this date (YYYY-MM-DD)"),
56
+ dateTo: z
57
+ .string()
58
+ .regex(/^\d{4}-\d{2}-\d{2}$/, "Must be YYYY-MM-DD format")
59
+ .optional()
60
+ .describe("Only invoices on or before this date (YYYY-MM-DD)"),
61
+ pageSize: z
62
+ .number()
63
+ .int()
64
+ .min(1)
65
+ .max(100)
66
+ .optional()
67
+ .describe("Results per page (default 100, max 100)"),
68
+ }, async ({ page, contactIds, invoiceNumbers, orderBy, orderDirection, status, type, dateFrom, dateTo, pageSize, }) => {
69
+ const response = await listXeroInvoices(page, contactIds, invoiceNumbers, orderBy, orderDirection, status, type, dateFrom, dateTo, pageSize);
70
+ if (response.error !== null) {
71
+ return {
72
+ content: [
73
+ {
74
+ type: "text",
75
+ text: `Error listing invoices: ${response.error}`,
76
+ },
77
+ ],
78
+ };
79
+ }
80
+ const invoices = response.result;
81
+ const returnLineItems = (invoiceNumbers?.length ?? 0) > 0;
82
+ const effectivePageSize = pageSize ?? 100;
83
+ const invoiceCount = invoices?.length ?? 0;
84
+ return {
85
+ content: [
86
+ {
87
+ type: "text",
88
+ text: invoiceCount === effectivePageSize
89
+ ? `Found ${invoiceCount} invoices. The number of results equals pageSize (${effectivePageSize}), so there may be more pages.`
90
+ : `Found ${invoiceCount} invoices:`,
91
+ },
92
+ ...(invoices?.map((invoice) => ({
93
+ type: "text",
94
+ text: [
95
+ `Invoice ID: ${invoice.invoiceID}`,
96
+ `Invoice: ${invoice.invoiceNumber}`,
97
+ invoice.reference ? `Reference: ${invoice.reference}` : null,
98
+ `Type: ${invoice.type || "Unknown"}`,
99
+ `Status: ${invoice.status || "Unknown"}`,
100
+ invoice.contact
101
+ ? `Contact: ${invoice.contact.name} (${invoice.contact.contactID})`
102
+ : null,
103
+ invoice.date ? `Date: ${invoice.date}` : null,
104
+ invoice.dueDate ? `Due Date: ${invoice.dueDate}` : null,
105
+ invoice.lineAmountTypes
106
+ ? `Line Amount Types: ${invoice.lineAmountTypes}`
107
+ : null,
108
+ invoice.subTotal ? `Sub Total: ${invoice.subTotal}` : null,
109
+ invoice.totalTax ? `Total Tax: ${invoice.totalTax}` : null,
110
+ `Total: ${invoice.total || 0}`,
111
+ invoice.totalDiscount
112
+ ? `Total Discount: ${invoice.totalDiscount}`
113
+ : null,
114
+ invoice.currencyCode ? `Currency: ${invoice.currencyCode}` : null,
115
+ invoice.currencyRate
116
+ ? `Currency Rate: ${invoice.currencyRate}`
117
+ : null,
118
+ invoice.updatedDateUTC
119
+ ? `Last Updated: ${invoice.updatedDateUTC}`
120
+ : null,
121
+ invoice.fullyPaidOnDate
122
+ ? `Fully Paid On: ${invoice.fullyPaidOnDate}`
123
+ : null,
124
+ invoice.amountDue ? `Amount Due: ${invoice.amountDue}` : null,
125
+ invoice.amountPaid ? `Amount Paid: ${invoice.amountPaid}` : null,
126
+ invoice.amountCredited
127
+ ? `Amount Credited: ${invoice.amountCredited}`
128
+ : null,
129
+ invoice.hasErrors ? "Has Errors: Yes" : null,
130
+ invoice.isDiscounted ? "Is Discounted: Yes" : null,
131
+ returnLineItems
132
+ ? `Line Items: ${invoice.lineItems?.map(formatLineItem)}`
133
+ : null,
134
+ ]
135
+ .filter(Boolean)
136
+ .join("\n"),
137
+ })) || []),
138
+ ],
139
+ };
140
+ });
141
+ export default ListInvoicesTool;
@@ -0,0 +1,53 @@
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
+ 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.
5
+
6
+ COMMON MISTAKES:
7
+ - Only use the params listed above. Do not invent additional filter or sort params.
8
+ - There is no "search", "query", "filter", "sortBy", "limit", or "offset" param.`, {
9
+ page: z.number(),
10
+ }, async ({ page }) => {
11
+ const response = await listXeroItems(page);
12
+ if (response.isError) {
13
+ return {
14
+ content: [
15
+ {
16
+ type: "text",
17
+ text: `Error listing items: ${response.error}`,
18
+ },
19
+ ],
20
+ };
21
+ }
22
+ const items = response.result;
23
+ return {
24
+ content: [
25
+ {
26
+ type: "text",
27
+ text: `Found ${items?.length || 0} items:`,
28
+ },
29
+ ...(items?.map((item) => ({
30
+ type: "text",
31
+ text: [
32
+ `Item: ${item.name || "Unnamed"}`,
33
+ `ID: ${item.itemID}`,
34
+ `Code: ${item.code}`,
35
+ item.description ? `Description: ${item.description}` : null,
36
+ item.purchaseDescription ? `Purchase Description: ${item.purchaseDescription}` : null,
37
+ item.salesDetails?.unitPrice !== undefined ? `Sales Price: ${item.salesDetails.unitPrice}` : null,
38
+ item.purchaseDetails?.unitPrice !== undefined ? `Purchase Price: ${item.purchaseDetails.unitPrice}` : null,
39
+ item.salesDetails?.accountCode ? `Sales Account: ${item.salesDetails.accountCode}` : null,
40
+ item.purchaseDetails?.accountCode ? `Purchase Account: ${item.purchaseDetails.accountCode}` : null,
41
+ item.isTrackedAsInventory !== undefined ? `Tracked as Inventory: ${item.isTrackedAsInventory ? 'Yes' : 'No'}` : null,
42
+ item.isSold !== undefined ? `Is Sold: ${item.isSold ? 'Yes' : 'No'}` : null,
43
+ item.isPurchased !== undefined ? `Is Purchased: ${item.isPurchased ? 'Yes' : 'No'}` : null,
44
+ item.updatedDateUTC ? `Last Updated: ${item.updatedDateUTC}` : null,
45
+ item.validationErrors?.length ? `Validation Errors: ${item.validationErrors.map(e => e.message).join(", ")}` : null,
46
+ ]
47
+ .filter(Boolean)
48
+ .join("\n"),
49
+ })) || []),
50
+ ],
51
+ };
52
+ });
53
+ export default ListItemsTool;