@mindstone/mcp-server-xero 0.1.4 → 0.2.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 (43) hide show
  1. package/README.md +7 -6
  2. package/dist/handlers/list-xero-accounts.handler.js +5 -5
  3. package/dist/handlers/list-xero-bank-transactions.handler.js +16 -9
  4. package/dist/handlers/list-xero-credit-notes.handler.js +14 -9
  5. package/dist/handlers/list-xero-invoices.handler.js +11 -18
  6. package/dist/handlers/list-xero-items.handler.js +6 -5
  7. package/dist/handlers/list-xero-manual-journals.handler.js +1 -1
  8. package/dist/handlers/list-xero-payments.handler.js +1 -1
  9. package/dist/handlers/list-xero-profit-and-loss.handler.js +8 -12
  10. package/dist/handlers/summarise-xero-totals.handler.js +195 -0
  11. package/dist/helpers/contact-totals-tool.js +107 -0
  12. package/dist/helpers/format-line-item.js +20 -13
  13. package/dist/helpers/format-report.js +28 -0
  14. package/dist/helpers/page-note.js +6 -0
  15. package/dist/helpers/xero-date-where.js +27 -0
  16. package/dist/tools/list/index.js +5 -1
  17. package/dist/tools/list/list-accounts.tool.js +9 -2
  18. package/dist/tools/list/list-aged-payables-by-contact.tool.js +5 -18
  19. package/dist/tools/list/list-aged-receivables-by-contact.tool.js +5 -18
  20. package/dist/tools/list/list-bank-summary.tool.js +2 -8
  21. package/dist/tools/list/list-bank-transactions.tool.js +60 -16
  22. package/dist/tools/list/list-budget-summary.tool.js +2 -8
  23. package/dist/tools/list/list-credit-notes.tool.js +47 -12
  24. package/dist/tools/list/list-executive-summary.tool.js +2 -8
  25. package/dist/tools/list/list-invoices.tool.js +20 -20
  26. package/dist/tools/list/list-items.tool.js +3 -6
  27. package/dist/tools/list/list-manual-journals.tool.js +1 -3
  28. package/dist/tools/list/list-organisation-details.tool.js +15 -15
  29. package/dist/tools/list/list-payments.tool.js +1 -2
  30. package/dist/tools/list/list-payroll-employees.tool.js +1 -1
  31. package/dist/tools/list/list-profit-and-loss.tool.js +23 -24
  32. package/dist/tools/list/list-quotes.tool.js +2 -3
  33. package/dist/tools/list/list-report-balance-sheet.tool.js +2 -8
  34. package/dist/tools/list/list-trial-balance.tool.js +2 -16
  35. package/dist/tools/list/summarise-sales-by-customer.tool.js +9 -0
  36. package/dist/tools/list/summarise-spend-by-supplier.tool.js +10 -0
  37. package/node_modules/cross-spawn/README.md +19 -3
  38. package/node_modules/cross-spawn/lib/parse.js +38 -10
  39. package/node_modules/cross-spawn/lib/util/escape.js +84 -25
  40. package/node_modules/cross-spawn/lib/util/readShebang.js +8 -2
  41. package/node_modules/cross-spawn/lib/util/resolveCommand.js +8 -1
  42. package/node_modules/cross-spawn/package.json +21 -24
  43. package/package.json +1 -1
@@ -0,0 +1,6 @@
1
+ /** The first line of a page of results: how many, and whether to ask for the next page. */
2
+ export function pageNote(count, pageSize, noun) {
3
+ return count === pageSize
4
+ ? `Found ${count} ${noun}. That fills the page (${pageSize}), so there may be more: call again with the next page and the same filters.`
5
+ : `Found ${count} ${noun}:`;
6
+ }
@@ -0,0 +1,27 @@
1
+ import { z } from "zod";
2
+ /** A YYYY-MM-DD date, as every Xero list tool takes it. */
3
+ export const xeroDateParam = z
4
+ .string()
5
+ .regex(/^\d{4}-\d{2}-\d{2}$/, "Must be YYYY-MM-DD format");
6
+ /** A YYYY-MM-DD date as a Xero `where` DateTime, rebuilt from its numbers. */
7
+ export function xeroDateTime(date) {
8
+ const [year, month, day] = date.split("-").map(Number);
9
+ return `DateTime(${year},${month},${day})`;
10
+ }
11
+ /**
12
+ * Xero `where` clauses for a date range, inclusive at both ends. Each date is
13
+ * rebuilt from its numbers, so nothing but digits reaches the clause.
14
+ */
15
+ export function xeroDateRangeWhere(dateFrom, dateTo) {
16
+ const clauses = [];
17
+ if (dateFrom)
18
+ clauses.push(`Date>=${xeroDateTime(dateFrom)}`);
19
+ if (dateTo)
20
+ clauses.push(`Date<=${xeroDateTime(dateTo)}`);
21
+ return clauses;
22
+ }
23
+ /** Join `where` clauses with AND; undefined when there are none. */
24
+ export function joinWhere(clauses) {
25
+ const present = clauses.filter((clause) => !!clause);
26
+ return present.length > 0 ? present.join("&&") : undefined;
27
+ }
@@ -29,6 +29,8 @@ import ListTrialBalanceTool from "./list-trial-balance.tool.js";
29
29
  import ListContactGroupsTool from "./list-contact-groups.tool.js";
30
30
  import ListInvoiceAttachmentsTool from "./list-invoice-attachments.tool.js";
31
31
  import ListExecutiveSummaryTool from "./list-executive-summary.tool.js";
32
+ import SummariseSalesByCustomerTool from "./summarise-sales-by-customer.tool.js";
33
+ import SummariseSpendBySupplierTool from "./summarise-spend-by-supplier.tool.js";
32
34
  export const ListTools = [
33
35
  ListAccountsTool,
34
36
  ListContactsTool,
@@ -60,5 +62,7 @@ export const ListTools = [
60
62
  ListBankSummaryTool,
61
63
  ListBudgetSummaryTool,
62
64
  ListExecutiveSummaryTool,
63
- ListPurchaseOrdersTool
65
+ ListPurchaseOrdersTool,
66
+ SummariseSalesByCustomerTool,
67
+ SummariseSpendBySupplierTool,
64
68
  ];
@@ -1,7 +1,12 @@
1
+ import { z } from "zod";
1
2
  import { listXeroAccounts } from "../../handlers/list-xero-accounts.handler.js";
2
3
  import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
3
- 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 () => {
4
- const response = await listXeroAccounts();
4
+ const ListAccountsTool = CreateXeroTool("list-accounts", `Lists the chart of accounts in Xero: each account's code, name, class and type.
5
+ Use it to find the account codes for a kind of income or cost (e.g. software, travel) before summarising spend, to see which accounts are bank accounts, or to pick account codes for a new invoice.`, {
6
+ accountClass: z.enum(["ASSET", "EQUITY", "EXPENSE", "LIABILITY", "REVENUE"]).optional()
7
+ .describe("Only accounts of this class, e.g. EXPENSE for cost accounts. Leave out for all."),
8
+ }, async ({ accountClass }) => {
9
+ const response = await listXeroAccounts(accountClass);
5
10
  if (response.error !== null) {
6
11
  return {
7
12
  content: [
@@ -26,7 +31,9 @@ const ListAccountsTool = CreateXeroTool("list-accounts", "Lists all accounts in
26
31
  `Account: ${account.name || "Unnamed"}`,
27
32
  `Code: ${account.code || "No code"}`,
28
33
  `ID: ${account.accountID || "No ID"}`,
34
+ `Class: ${account._class || "Unknown class"}`,
29
35
  `Type: ${account.type || "Unknown type"}`,
36
+ account.bankAccountType ? `Bank Account Type: ${account.bankAccountType}` : null,
30
37
  `Status: ${account.status || "Unknown status"}`,
31
38
  account.description ? `Description: ${account.description}` : null,
32
39
  account.taxType ? `Tax Type: ${account.taxType}` : null,
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
3
+ import { formatReport } from "../../helpers/format-report.js";
3
4
  import { formatAgedReportFilter } from "../../helpers/format-aged-report-filter.js";
4
5
  import { listXeroAgedPayablesByContact } from "../../handlers/list-aged-payables-by-contact.handler.js";
5
6
  const ListAgedPayablesByContact = CreateXeroTool("list-aged-payables-by-contact", `Lists the aged payables in Xero.
@@ -8,9 +9,9 @@ const ListAgedPayablesByContact = CreateXeroTool("list-aged-payables-by-contact"
8
9
  reportDate: z.string().optional()
9
10
  .describe("Optional date to retrieve aged payables in YYYY-MM-DD format. If none is provided, defaults to end of the current month."),
10
11
  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
+ .describe("Optional from date in YYYY-MM-DD format. If provided, will only show bills dated on or after this date for the contact."),
12
13
  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
+ .describe("Optional to date in YYYY-MM-DD format. If provided, will only show bills dated on or before this date for the contact."),
14
15
  }, async ({ contactId, reportDate, invoicesFromDate, invoicesToDate }) => {
15
16
  const response = await listXeroAgedPayablesByContact(contactId, reportDate, invoicesFromDate, invoicesToDate);
16
17
  if (response.isError) {
@@ -28,22 +29,8 @@ const ListAgedPayablesByContact = CreateXeroTool("list-aged-payables-by-contact"
28
29
  const filter = formatAgedReportFilter(invoicesFromDate, invoicesToDate);
29
30
  return {
30
31
  content: [
31
- {
32
- type: "text",
33
- text: `Report Name: ${agedPayablesReport.reportName || "Not specified"}`,
34
- },
35
- {
36
- type: "text",
37
- text: `Report Date: ${agedPayablesReport.reportDate || "Not specified"}`
38
- },
39
- {
40
- type: "text",
41
- text: filter ?? "Showing all relevant invoices"
42
- },
43
- {
44
- type: "text",
45
- text: JSON.stringify(agedPayablesReport.rows, null, 2),
46
- }
32
+ { type: "text", text: formatReport(agedPayablesReport) },
33
+ { type: "text", text: filter ?? "Showing all relevant invoices" },
47
34
  ],
48
35
  };
49
36
  });
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { listXeroAgedReceivablesByContact } from "../../handlers/list-aged-receivables-by-contact.handler.js";
3
3
  import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
4
+ import { formatReport } from "../../helpers/format-report.js";
4
5
  import { formatAgedReportFilter } from "../../helpers/format-aged-report-filter.js";
5
6
  const ListAgedReceivablesByContact = CreateXeroTool("list-aged-receivables-by-contact", `Lists the aged receivables in Xero.
6
7
  This shows aged receivables for a certain contact up to a report date.`, {
@@ -8,9 +9,9 @@ const ListAgedReceivablesByContact = CreateXeroTool("list-aged-receivables-by-co
8
9
  reportDate: z.string().optional()
9
10
  .describe("Optional date to retrieve aged receivables in YYYY-MM-DD format. If none is provided, defaults to end of the current month."),
10
11
  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
+ .describe("Optional from date in YYYY-MM-DD format. If provided, will only show invoices dated on or after this date for the contact."),
12
13
  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
+ .describe("Optional to date in YYYY-MM-DD format. If provided, will only show invoices dated on or before this date for the contact."),
14
15
  }, async ({ contactId, reportDate, invoicesFromDate, invoicesToDate }) => {
15
16
  const response = await listXeroAgedReceivablesByContact(contactId, reportDate, invoicesFromDate, invoicesToDate);
16
17
  if (response.isError) {
@@ -28,22 +29,8 @@ const ListAgedReceivablesByContact = CreateXeroTool("list-aged-receivables-by-co
28
29
  const filter = formatAgedReportFilter(invoicesFromDate, invoicesToDate);
29
30
  return {
30
31
  content: [
31
- {
32
- type: "text",
33
- text: `Report Name: ${agedReceivablesReport.reportName || "Not specified"}`,
34
- },
35
- {
36
- type: "text",
37
- text: `Report Date: ${agedReceivablesReport.reportDate || "Not specified"}`
38
- },
39
- {
40
- type: "text",
41
- text: filter ?? "Showing all relevant invoices"
42
- },
43
- {
44
- type: "text",
45
- text: JSON.stringify(agedReceivablesReport.rows, null, 2),
46
- }
32
+ { type: "text", text: formatReport(agedReceivablesReport) },
33
+ { type: "text", text: filter ?? "Showing all relevant invoices" },
47
34
  ],
48
35
  };
49
36
  });
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { listXeroBankSummary } from "../../handlers/list-xero-bank-summary.handler.js";
3
3
  import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
4
+ import { formatReport } from "../../helpers/format-report.js";
4
5
  const ListBankSummaryTool = CreateXeroTool("list-bank-summary", "Get the bank summary report from Xero: opening and closing balances plus total money in/out per bank account over a period. Useful for cash-position questions.", {
5
6
  fromDate: z
6
7
  .string()
@@ -28,14 +29,7 @@ const ListBankSummaryTool = CreateXeroTool("list-bank-summary", "Get the bank su
28
29
  const report = response.result;
29
30
  return {
30
31
  content: [
31
- {
32
- type: "text",
33
- text: `Bank Summary Report: ${report?.reportName ?? "Unnamed"}`,
34
- },
35
- {
36
- type: "text",
37
- text: JSON.stringify(report.rows, null, 2),
38
- },
32
+ { type: "text", text: formatReport(report) },
39
33
  ],
40
34
  };
41
35
  });
@@ -1,22 +1,64 @@
1
1
  import { z } from "zod";
2
2
  import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
3
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.
4
+ import { formatLineItems } from "../../helpers/format-line-item.js";
5
+ import { xeroDateParam } from "../../helpers/xero-date-where.js";
6
+ import { pageNote } from "../../helpers/page-note.js";
7
+ const ListBankTransactionsTool = CreateXeroTool("list-bank-transactions", `List bank transactions in Xero (spend money, receive money, overpayments, prepayments and transfers), newest first, with their line items and account codes.
8
+
9
+ FILTERING: Use dateFrom/dateTo (YYYY-MM-DD) for a period, type for a direction (SPEND = money out, RECEIVE = money in), and bankAccountId for one account (IDs from list-accounts).
10
+ PAGINATION: Up to pageSize results per page (default 100, max 1000). If results equal pageSize, call again with page+1 and the same filters.
11
+ TOTALS: For spend by supplier or by account over a period, use summarise-spend-by-supplier instead of paging this tool.
12
12
 
13
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);
14
+ - Only use the params listed above. There is no "search", "query", "contact", "sortBy", "limit", or "offset" param.
15
+ - Date format is strictly YYYY-MM-DD.`, {
16
+ page: z
17
+ .number()
18
+ .int()
19
+ .min(1)
20
+ .optional()
21
+ .describe("Page number (1-based, default 1)"),
22
+ pageSize: z
23
+ .number()
24
+ .int()
25
+ .min(1)
26
+ .max(1000)
27
+ .optional()
28
+ .describe("Results per page (default 100, max 1000)"),
29
+ bankAccountId: z
30
+ .string()
31
+ .uuid()
32
+ .optional()
33
+ .describe("Only this bank account's transactions (its account ID)"),
34
+ type: z
35
+ .enum([
36
+ "SPEND",
37
+ "RECEIVE",
38
+ "SPEND-OVERPAYMENT",
39
+ "RECEIVE-OVERPAYMENT",
40
+ "SPEND-PREPAYMENT",
41
+ "RECEIVE-PREPAYMENT",
42
+ "SPEND-TRANSFER",
43
+ "RECEIVE-TRANSFER",
44
+ ])
45
+ .optional()
46
+ .describe("SPEND = money out, RECEIVE = money in"),
47
+ dateFrom: xeroDateParam
48
+ .optional()
49
+ .describe("Only transactions on or after this date (YYYY-MM-DD)"),
50
+ dateTo: xeroDateParam
51
+ .optional()
52
+ .describe("Only transactions on or before this date (YYYY-MM-DD)"),
53
+ }, async ({ page, pageSize, bankAccountId, type, dateFrom, dateTo }) => {
54
+ const response = await listXeroBankTransactions({
55
+ page,
56
+ pageSize,
57
+ bankAccountId,
58
+ type,
59
+ dateFrom,
60
+ dateTo,
61
+ });
20
62
  if (response.isError) {
21
63
  return {
22
64
  content: [
@@ -33,12 +75,13 @@ COMMON MISTAKES:
33
75
  content: [
34
76
  {
35
77
  type: "text",
36
- text: `Found ${bankTransactions?.length || 0} bank transactions:`
78
+ text: pageNote(bankTransactions?.length ?? 0, pageSize ?? 100, "bank transactions")
37
79
  },
38
80
  ...(bankTransactions?.map((transaction) => ({
39
81
  type: "text",
40
82
  text: [
41
83
  `Bank Transaction ID: ${transaction.bankTransactionID}`,
84
+ transaction.type ? `Type: ${transaction.type}` : null,
42
85
  `Bank Account: ${transaction.bankAccount.name} (${transaction.bankAccount.accountID})`,
43
86
  transaction.contact
44
87
  ? `Contact: ${transaction.contact.name} (${transaction.contact.contactID})`
@@ -50,12 +93,13 @@ COMMON MISTAKES:
50
93
  transaction.total ? `Total: ${transaction.total}` : null,
51
94
  transaction.isReconciled !== undefined ? (`${transaction.isReconciled ? "Reconciled" : "Unreconciled"}`) : null,
52
95
  transaction.currencyCode ? `Currency Code: ${transaction.currencyCode}` : null,
96
+ transaction.currencyRate ? `Currency Rate: ${transaction.currencyRate}` : null,
53
97
  `${transaction.status || "Unknown"}`,
54
98
  transaction.lineAmountTypes ? `Line Amount Types: ${transaction.lineAmountTypes}` : undefined,
55
99
  transaction.hasAttachments !== undefined
56
100
  ? (transaction.hasAttachments ? "Has attachments" : "Does not have attachments")
57
101
  : null,
58
- `Line Items: ${transaction.lineItems?.map(formatLineItem)}`,
102
+ formatLineItems(transaction.lineItems),
59
103
  ].filter(Boolean).join("\n")
60
104
  })) || [])
61
105
  ]
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { listXeroBudgetSummary } from "../../handlers/list-xero-budget-summary.handler.js";
3
3
  import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
4
+ import { formatReport } from "../../helpers/format-report.js";
4
5
  const ListBudgetSummaryTool = CreateXeroTool("list-budget-summary", "Get the budget summary report from Xero: budgeted vs actual figures per account. Useful for 'are we tracking to budget?' questions. Requires budgets to be set up in the Xero organisation.", {
5
6
  date: z
6
7
  .string()
@@ -34,14 +35,7 @@ const ListBudgetSummaryTool = CreateXeroTool("list-budget-summary", "Get the bud
34
35
  const report = response.result;
35
36
  return {
36
37
  content: [
37
- {
38
- type: "text",
39
- text: `Budget Summary Report: ${report?.reportName ?? "Unnamed"}`,
40
- },
41
- {
42
- type: "text",
43
- text: JSON.stringify(report.rows, null, 2),
44
- },
38
+ { type: "text", text: formatReport(report) },
45
39
  ],
46
40
  };
47
41
  });
@@ -1,21 +1,55 @@
1
1
  import { z } from "zod";
2
2
  import { listXeroCreditNotes } from "../../handlers/list-xero-credit-notes.handler.js";
3
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.
4
+ import { formatLineItems } from "../../helpers/format-line-item.js";
5
+ import { pageNote } from "../../helpers/page-note.js";
6
+ import { xeroDateParam } from "../../helpers/xero-date-where.js";
7
+ const ListCreditNotesTool = CreateXeroTool("list-credit-notes", `List credit notes in Xero, newest first, with their line items and account codes.
8
+
9
+ FILTERING: Use type for a direction (ACCPAYCREDIT = credit from a supplier, ACCRECCREDIT = credit given to a customer), dateFrom/dateTo (YYYY-MM-DD) for a period, and contactId for one contact.
10
+ PAGINATION: Up to pageSize results per page (default 100, max 1000). If results equal pageSize, call again with page+1 and the same filters.
11
+ TOTALS: For spend by supplier over a period, use summarise-spend-by-supplier, which already subtracts supplier credit notes.
11
12
 
12
13
  COMMON MISTAKES:
13
14
  - Only use the params listed above. Do not invent additional filter or sort params.
14
15
  - 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);
16
+ page: z
17
+ .number()
18
+ .int()
19
+ .min(1)
20
+ .optional()
21
+ .describe("Page number (1-based, default 1)"),
22
+ pageSize: z
23
+ .number()
24
+ .int()
25
+ .min(1)
26
+ .max(1000)
27
+ .optional()
28
+ .describe("Results per page (default 100, max 1000)"),
29
+ contactId: z
30
+ .string()
31
+ .uuid()
32
+ .optional()
33
+ .describe("Only this contact's credit notes (its contact ID)"),
34
+ type: z
35
+ .enum(["ACCPAYCREDIT", "ACCRECCREDIT"])
36
+ .optional()
37
+ .describe("ACCPAYCREDIT = from a supplier, ACCRECCREDIT = to a customer"),
38
+ dateFrom: xeroDateParam
39
+ .optional()
40
+ .describe("Only credit notes dated on or after this date (YYYY-MM-DD)"),
41
+ dateTo: xeroDateParam
42
+ .optional()
43
+ .describe("Only credit notes dated on or before this date (YYYY-MM-DD)"),
44
+ }, async ({ page, pageSize, contactId, type, dateFrom, dateTo }) => {
45
+ const response = await listXeroCreditNotes({
46
+ page,
47
+ pageSize,
48
+ contactId,
49
+ type,
50
+ dateFrom,
51
+ dateTo,
52
+ });
19
53
  if (response.error !== null) {
20
54
  return {
21
55
  content: [
@@ -32,7 +66,7 @@ COMMON MISTAKES:
32
66
  content: [
33
67
  {
34
68
  type: "text",
35
- text: `Found ${creditNotes?.length || 0} credit notes:`,
69
+ text: pageNote(creditNotes?.length ?? 0, pageSize ?? 100, "credit notes"),
36
70
  },
37
71
  ...(creditNotes?.map((creditNote) => ({
38
72
  type: "text",
@@ -61,6 +95,7 @@ COMMON MISTAKES:
61
95
  creditNote.updatedDateUTC
62
96
  ? `Last Updated: ${creditNote.updatedDateUTC}`
63
97
  : null,
98
+ formatLineItems(creditNote.lineItems),
64
99
  ]
65
100
  .filter(Boolean)
66
101
  .join("\n"),
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { listXeroExecutiveSummary } from "../../handlers/list-xero-executive-summary.handler.js";
3
3
  import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
4
+ import { formatReport } from "../../helpers/format-report.js";
4
5
  const ListExecutiveSummaryTool = CreateXeroTool("list-executive-summary", "Get the executive summary report from Xero: a high-level snapshot of key financial metrics (cash, debtors, creditors, revenue, profit) for a date. Useful for 'how is the business doing?' questions.", {
5
6
  date: z
6
7
  .string()
@@ -23,14 +24,7 @@ const ListExecutiveSummaryTool = CreateXeroTool("list-executive-summary", "Get t
23
24
  const report = response.result;
24
25
  return {
25
26
  content: [
26
- {
27
- type: "text",
28
- text: `Executive Summary Report: ${report?.reportName ?? "Unnamed"}`,
29
- },
30
- {
31
- type: "text",
32
- text: JSON.stringify(report.rows, null, 2),
33
- },
27
+ { type: "text", text: formatReport(report) },
34
28
  ],
35
29
  };
36
30
  });
@@ -1,15 +1,21 @@
1
1
  import { z } from "zod";
2
2
  import { listXeroInvoices } from "../../handlers/list-xero-invoices.handler.js";
3
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).
4
+ import { formatLineItems } from "../../helpers/format-line-item.js";
5
+ import { pageNote } from "../../helpers/page-note.js";
6
+ import { xeroDateParam } from "../../helpers/xero-date-where.js";
7
+ const ListInvoicesTool = CreateXeroTool("list-invoices", `List invoices in Xero, with their line items (description, amount, account code). Returns up to pageSize results per page (default 100, max 1000).
6
8
 
7
9
  SORTING: Default sort is UpdatedDateUTC DESC (last-modified first). Use orderBy to sort by DueDate, Date, or InvoiceNumber. Use orderDirection for ASC/DESC.
8
10
 
9
11
  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
12
 
13
+ OVERDUE: status AUTHORISED (approved, not fully paid) with dueBefore today lists everything overdue; Amount Due is what is still owed. Use type ACCREC for what customers owe, ACCPAY for what we owe. pageSize 1000 gets them in one call.
14
+
11
15
  PAGINATION: If results returned equals pageSize, there may be more pages. Call again with page+1.
12
16
 
17
+ TOTALS: For spend by supplier or by account over a period, use summarise-spend-by-supplier instead of paging bills by hand.
18
+
13
19
  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
20
 
15
21
  WORKFLOW:
@@ -31,7 +37,7 @@ COMMON MISTAKES:
31
37
  invoiceNumbers: z
32
38
  .array(z.string())
33
39
  .optional()
34
- .describe("If provided, invoice line items will also be returned"),
40
+ .describe("Only these invoice numbers"),
35
41
  orderBy: z
36
42
  .enum(["UpdatedDateUTC", "DueDate", "Date", "InvoiceNumber"])
37
43
  .optional()
@@ -48,25 +54,24 @@ COMMON MISTAKES:
48
54
  .enum(["ACCREC", "ACCPAY"])
49
55
  .optional()
50
56
  .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")
57
+ dateFrom: xeroDateParam
54
58
  .optional()
55
59
  .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")
60
+ dateTo: xeroDateParam
59
61
  .optional()
60
62
  .describe("Only invoices on or before this date (YYYY-MM-DD)"),
61
63
  pageSize: z
62
64
  .number()
63
65
  .int()
64
66
  .min(1)
65
- .max(100)
67
+ .max(1000)
66
68
  .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);
69
+ .describe("Results per page (default 100, max 1000)"),
70
+ dueBefore: xeroDateParam
71
+ .optional()
72
+ .describe("Only invoices due before this date (YYYY-MM-DD); with status AUTHORISED and today's date, the overdue ones"),
73
+ }, async ({ page, contactIds, invoiceNumbers, orderBy, orderDirection, status, type, dateFrom, dateTo, pageSize, dueBefore, }) => {
74
+ const response = await listXeroInvoices(page, contactIds, invoiceNumbers, orderBy, orderDirection, status, type, dateFrom, dateTo, pageSize, dueBefore);
70
75
  if (response.error !== null) {
71
76
  return {
72
77
  content: [
@@ -79,16 +84,13 @@ COMMON MISTAKES:
79
84
  };
80
85
  }
81
86
  const invoices = response.result;
82
- const returnLineItems = (invoiceNumbers?.length ?? 0) > 0;
83
87
  const effectivePageSize = pageSize ?? 100;
84
88
  const invoiceCount = invoices?.length ?? 0;
85
89
  return {
86
90
  content: [
87
91
  {
88
92
  type: "text",
89
- text: invoiceCount === effectivePageSize
90
- ? `Found ${invoiceCount} invoices. The number of results equals pageSize (${effectivePageSize}), so there may be more pages.`
91
- : `Found ${invoiceCount} invoices:`,
93
+ text: pageNote(invoiceCount, effectivePageSize, "invoices"),
92
94
  },
93
95
  ...(invoices?.map((invoice) => ({
94
96
  type: "text",
@@ -129,9 +131,7 @@ COMMON MISTAKES:
129
131
  : null,
130
132
  invoice.hasErrors ? "Has Errors: Yes" : null,
131
133
  invoice.isDiscounted ? "Is Discounted: Yes" : null,
132
- returnLineItems
133
- ? `Line Items: ${invoice.lineItems?.map(formatLineItem)}`
134
- : null,
134
+ formatLineItems(invoice.lineItems),
135
135
  ]
136
136
  .filter(Boolean)
137
137
  .join("\n"),
@@ -1,14 +1,11 @@
1
- import { z } from "zod";
2
1
  import { listXeroItems } from "../../handlers/list-xero-items.handler.js";
3
2
  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.
3
+ const ListItemsTool = CreateXeroTool("list-items", `Lists all items in Xero, in one response (there are no pages). Use this tool to get the item codes and descriptions to be used when creating invoices in Xero.
5
4
 
6
5
  COMMON MISTAKES:
7
6
  - 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);
7
+ - There is no "search", "query", "filter", "sortBy", "limit", or "offset" param.`, {}, async () => {
8
+ const response = await listXeroItems();
12
9
  if (response.isError) {
13
10
  return {
14
11
  content: [
@@ -2,11 +2,9 @@ import { listXeroManualJournals } from "../../handlers/list-xero-manual-journals
2
2
  import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
3
3
  import { z } from "zod";
4
4
  const ListManualJournalsTool = CreateXeroTool("list-manual-journals", `List all manual journals from Xero.
5
- Ask the user if they want to see a specific manual journal or all manual journals before running.
6
5
  Can optionally pass in manual journal ID to retrieve a specific journal, or a date to filter journals modified after that date.
7
6
  The response presents a complete overview of all manual journals currently registered in your Xero account, with their details.
8
- Ask the user if they want the next page of manual journals after running this tool if 10 manual journals are returned.
9
- 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.
7
+ Returns up to 100 manual journals a page. If 100 come back there may be more: call this tool again with the next page number and the same filters.
10
8
 
11
9
  COMMON MISTAKES:
12
10
  - Only use the params listed above. Do not invent additional filter or sort params.
@@ -46,28 +46,28 @@ const ListOrganisationDetailsTool = CreateXeroTool("list-organisation-details",
46
46
  return `Phone ${index + 1}: ${phone.phoneType || "Unknown type"} - ${phone.phoneNumber || "No number"}`;
47
47
  }).join("\n") || "No phone numbers available.";
48
48
  const organisationDetails = [
49
- `Name: ${organisation.name} || "No name available."`,
50
- `Legal Name: ${organisation.legalName} || "No legal name available."`,
49
+ `Name: ${organisation.name || "No name available."}`,
50
+ `Legal Name: ${organisation.legalName || "No legal name available."}`,
51
51
  `Pays Tax: ${organisation.paysTax ? "Yes" : "No"}`,
52
- `Short Code: ${organisation.shortCode} || "No short code available."`,
53
- `Organisation ID: ${organisation.organisationID} || "No organisation ID available."`,
54
- `Version: ${organisation.version} || "No version available."`,
52
+ `Short Code: ${organisation.shortCode || "No short code available."}`,
53
+ `Organisation ID: ${organisation.organisationID || "No organisation ID available."}`,
54
+ `Version: ${organisation.version || "No version available."}`,
55
55
  organisation.organisationType ? `Organisation Type: ${organisation.organisationType}` : null,
56
- `Base Currency: ${organisation.baseCurrency} || "No base currency available."`,
57
- `Country Code: ${organisation.countryCode} || "No country code available."`,
58
- `Timezone: ${organisation.timezone} || "No timezone available."`,
56
+ `Base Currency: ${organisation.baseCurrency || "No base currency available."}`,
57
+ `Country Code: ${organisation.countryCode || "No country code available."}`,
58
+ `Timezone: ${organisation.timezone || "No timezone available."}`,
59
59
  organisation.registrationNumber ? `Registration Number: ${organisation.registrationNumber}` : null,
60
60
  organisation.taxNumber ? `Tax Number: ${organisation.taxNumber}` : null,
61
61
  organisation.organisationEntityType ? `Organisation Entity Type: ${organisation.organisationEntityType}` : null,
62
- `Financial Year End Day: ${organisation.financialYearEndDay} || "No financial year end day set."`,
63
- `Financial Year End Month: ${organisation.financialYearEndMonth} || "No financial year end month set."`,
64
- `Sales Tax Basis: ${organisation.salesTaxBasis} || "No sales tax basis available."`,
65
- `Sales Tax Period: ${organisation.salesTaxPeriod} || "No sales tax period available."`,
62
+ `Financial Year End Day: ${organisation.financialYearEndDay || "No financial year end day set."}`,
63
+ `Financial Year End Month: ${organisation.financialYearEndMonth || "No financial year end month set."}`,
64
+ `Sales Tax Basis: ${organisation.salesTaxBasis || "No sales tax basis available."}`,
65
+ `Sales Tax Period: ${organisation.salesTaxPeriod || "No sales tax period available."}`,
66
66
  organisation.periodLockDate ? `Period Lock Date: ${organisation.periodLockDate}` : null,
67
67
  organisation.organisationStatus ? `Organisation Status: ${organisation.organisationStatus}` : null,
68
- `Created Date: ${organisation.createdDateUTC} || "No created date available."`,
69
- `Edition: ${organisation.edition} || "No edition available."`,
70
- `Class: ${organisation._class} || "No class available."`,
68
+ `Created Date: ${organisation.createdDateUTC || "No created date available."}`,
69
+ `Edition: ${organisation.edition || "No edition available."}`,
70
+ `Class: ${organisation._class || "No class available."}`,
71
71
  `Is Demo Company: ${organisation.isDemoCompany ? "Yes" : "No"}`,
72
72
  organisation.lineOfBusiness ? `Line of Business: ${organisation.lineOfBusiness}` : null,
73
73
  `Addresses:\n${addresses}`,
@@ -39,8 +39,7 @@ function paymentFormatter(payment) {
39
39
  const ListPaymentsTool = CreateXeroTool("list-payments", `List payments in Xero.
40
40
  This tool shows all payments made against invoices, including payment date, amount, and payment method.
41
41
  You can filter payments by invoice number, invoice ID, payment ID, or invoice reference.
42
- Ask the user if they want to see payments for a specific invoice, contact, payment or reference before running.
43
- If many payments are returned, ask the user if they want to see the next page.
42
+ Returns up to 100 payments a page. If 100 come back there may be more: call this tool again with the next page number and the same filters.
44
43
 
45
44
  COMMON MISTAKES:
46
45
  - Only use the params listed above. Do not invent additional filter or sort params.