@mindstone/mcp-server-xero 0.0.17 → 0.1.1

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 (80) hide show
  1. package/README.md +46 -0
  2. package/dist/clients/xero-client.js +2 -3
  3. package/dist/handlers/create-xero-purchase-order.handler.js +50 -0
  4. package/dist/handlers/email-xero-invoice.handler.js +27 -0
  5. package/dist/handlers/list-xero-bank-summary.handler.js +38 -0
  6. package/dist/handlers/list-xero-budget-summary.handler.js +45 -0
  7. package/dist/handlers/list-xero-executive-summary.handler.js +37 -0
  8. package/dist/handlers/list-xero-purchase-orders.handler.js +29 -0
  9. package/dist/helpers/create-xero-tool.js +32 -1
  10. package/dist/helpers/get-deeplink.js +15 -4
  11. package/dist/helpers/xero-currencies.js +1 -1
  12. package/dist/server/xero-mcp-server.js +2 -1
  13. package/dist/tools/create/create-bank-transaction.tool.js +2 -1
  14. package/dist/tools/create/create-contact.tool.js +4 -3
  15. package/dist/tools/create/create-credit-note.tool.js +1 -0
  16. package/dist/tools/create/create-invoice.tool.js +1 -0
  17. package/dist/tools/create/create-item.tool.js +1 -0
  18. package/dist/tools/create/create-manual-journal.tool.js +4 -3
  19. package/dist/tools/create/create-payment.tool.js +1 -0
  20. package/dist/tools/create/create-payroll-timesheet.tool.js +1 -0
  21. package/dist/tools/create/create-purchase-order.tool.js +67 -0
  22. package/dist/tools/create/create-quote.tool.js +1 -0
  23. package/dist/tools/create/create-tracking-category.tool.js +2 -1
  24. package/dist/tools/create/create-tracking-options.tool.js +2 -1
  25. package/dist/tools/create/index.js +3 -1
  26. package/dist/tools/delete/delete-payroll-timesheet.tool.js +1 -0
  27. package/dist/tools/get/get-invoice-attachment.tool.js +1 -0
  28. package/dist/tools/get/get-payroll-timesheet.tool.js +1 -0
  29. package/dist/tools/history/index.js +2 -0
  30. package/dist/tools/list/index.js +9 -1
  31. package/dist/tools/list/list-accounts.tool.js +1 -0
  32. package/dist/tools/list/list-aged-payables-by-contact.tool.js +1 -0
  33. package/dist/tools/list/list-aged-receivables-by-contact.tool.js +1 -0
  34. package/dist/tools/list/list-bank-summary.tool.js +42 -0
  35. package/dist/tools/list/list-bank-transactions.tool.js +2 -1
  36. package/dist/tools/list/list-budget-summary.tool.js +48 -0
  37. package/dist/tools/list/list-contact-groups.tool.js +1 -0
  38. package/dist/tools/list/list-contacts.tool.js +1 -0
  39. package/dist/tools/list/list-credit-notes.tool.js +1 -0
  40. package/dist/tools/list/list-currencies.tool.js +1 -0
  41. package/dist/tools/list/list-executive-summary.tool.js +37 -0
  42. package/dist/tools/list/list-invoice-attachments.tool.js +1 -0
  43. package/dist/tools/list/list-invoices.tool.js +1 -0
  44. package/dist/tools/list/list-items.tool.js +1 -0
  45. package/dist/tools/list/list-manual-journals.tool.js +1 -0
  46. package/dist/tools/list/list-organisation-details.tool.js +1 -0
  47. package/dist/tools/list/list-payments.tool.js +1 -0
  48. package/dist/tools/list/list-payroll-employee-leave-balances.tool.js +1 -0
  49. package/dist/tools/list/list-payroll-employee-leave-types.tool.js +1 -0
  50. package/dist/tools/list/list-payroll-employee-leave.tool.js +1 -0
  51. package/dist/tools/list/list-payroll-employees.tool.js +1 -0
  52. package/dist/tools/list/list-payroll-leave-periods.tool.js +1 -0
  53. package/dist/tools/list/list-payroll-leave-types.tool.js +1 -0
  54. package/dist/tools/list/list-payroll-timesheets.tool.js +1 -0
  55. package/dist/tools/list/list-profit-and-loss.tool.js +1 -0
  56. package/dist/tools/list/list-purchase-orders.tool.js +98 -0
  57. package/dist/tools/list/list-quotes.tool.js +1 -0
  58. package/dist/tools/list/list-report-balance-sheet.tool.js +1 -0
  59. package/dist/tools/list/list-tax-rates.tool.js +1 -0
  60. package/dist/tools/list/list-tracking-categories.tool.js +2 -1
  61. package/dist/tools/list/list-trial-balance.tool.js +1 -0
  62. package/dist/tools/tool-factory.js +4 -1
  63. package/dist/tools/update/approve-payroll-timesheet.tool.js +1 -0
  64. package/dist/tools/update/email-invoice.tool.js +30 -0
  65. package/dist/tools/update/index.js +3 -1
  66. package/dist/tools/update/revert-payroll-timesheet.tool.js +1 -0
  67. package/dist/tools/update/update-bank-transaction.tool.js +1 -0
  68. package/dist/tools/update/update-contact.tool.js +4 -3
  69. package/dist/tools/update/update-credit-note.tool.js +1 -0
  70. package/dist/tools/update/update-invoice.tool.js +1 -0
  71. package/dist/tools/update/update-item.tool.js +1 -0
  72. package/dist/tools/update/update-manual-journal-tool.js +4 -3
  73. package/dist/tools/update/update-payroll-timesheet-add-line.tool.js +1 -0
  74. package/dist/tools/update/update-payroll-timesheet-update-line.tool.js +1 -0
  75. package/dist/tools/update/update-quote.tool.js +1 -0
  76. package/dist/tools/update/update-tracking-category.tool.js +2 -1
  77. package/dist/tools/update/update-tracking-options.tool.js +2 -1
  78. package/dist/untrusted-content.js +130 -0
  79. package/package.json +2 -2
  80. package/dist/helpers/ensure-error.js +0 -13
package/README.md CHANGED
@@ -2,6 +2,44 @@
2
2
 
3
3
  This is a Model Context Protocol (MCP) server implementation for Xero. It provides a bridge between the MCP protocol and Xero's API, allowing for standardized access to Xero's accounting and business features.
4
4
 
5
+ ## Provenance
6
+
7
+ This package is Mindstone's maintained build of Xero's community Xero MCP server, announced on the [Xero Developer Blog](https://devblog.xero.com/xero-introduces-new-model-context-protocol-server-for-smarter-accounting-data-integration) and developed upstream at [XeroAPI/xero-mcp-server](https://github.com/XeroAPI/xero-mcp-server). It adds improvements and hardening by Mindstone on top of the upstream project.
8
+
9
+ <!-- BEGIN INSTALL_LINKS: do not edit by hand; regenerated by scripts/gen-install-links.mjs -->
10
+ ## One-click install
11
+
12
+ [![Add to Cursor](https://img.shields.io/badge/Add_to_Cursor-black?style=for-the-badge&logo=cursor&logoColor=white)](cursor://anysphere.cursor-deeplink/mcp/install?name=Xero&config=eyJ0eXBlIjoic3RkaW8iLCJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBtaW5kc3RvbmUvbWNwLXNlcnZlci14ZXJvIl0sImVudiI6eyJYRVJPX0NMSUVOVF9JRCI6IiIsIlhFUk9fQ0xJRU5UX1NFQ1JFVCI6IiIsIlhFUk9fQ0xJRU5UX0JFQVJFUl9UT0tFTiI6IiJ9fQ)
13
+ [![Add to VS Code](https://img.shields.io/badge/Add_to_VS_Code-007ACC?style=for-the-badge&logo=visual-studio-code&logoColor=white)](vscode:mcp/install?%7B%22name%22%3A%22Xero%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40mindstone%2Fmcp-server-xero%22%5D%2C%22env%22%3A%7B%22XERO_CLIENT_ID%22%3A%22%22%2C%22XERO_CLIENT_SECRET%22%3A%22%22%2C%22XERO_CLIENT_BEARER_TOKEN%22%3A%22%22%7D%7D)
14
+ [![Add to VS Code Insiders](https://img.shields.io/badge/Add_to_VS_Code_Insiders-24bfa5?style=for-the-badge&logo=visual-studio-code&logoColor=white)](vscode-insiders:mcp/install?%7B%22name%22%3A%22Xero%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40mindstone%2Fmcp-server-xero%22%5D%2C%22env%22%3A%7B%22XERO_CLIENT_ID%22%3A%22%22%2C%22XERO_CLIENT_SECRET%22%3A%22%22%2C%22XERO_CLIENT_BEARER_TOKEN%22%3A%22%22%7D%7D)
15
+
16
+ After clicking the button, your host will prompt you to fill: `XERO_CLIENT_ID`, `XERO_CLIENT_SECRET`, `XERO_CLIENT_BEARER_TOKEN`.
17
+
18
+ <details>
19
+ <summary>Manual config for Claude Desktop / Claude Code / Goose / Continue.dev (Xero)</summary>
20
+
21
+ ```json
22
+ {
23
+ "mcpServers": {
24
+ "Xero": {
25
+ "command": "npx",
26
+ "args": [
27
+ "-y",
28
+ "@mindstone/mcp-server-xero"
29
+ ],
30
+ "env": {
31
+ "XERO_CLIENT_ID": "",
32
+ "XERO_CLIENT_SECRET": "",
33
+ "XERO_CLIENT_BEARER_TOKEN": ""
34
+ }
35
+ }
36
+ }
37
+ }
38
+ ```
39
+
40
+ </details>
41
+ <!-- END INSTALL_LINKS -->
42
+
5
43
  ## Features
6
44
 
7
45
  - Xero OAuth2 authentication with custom connections
@@ -93,6 +131,8 @@ NOTE: The `XERO_CLIENT_BEARER_TOKEN` will take precedence over the `XERO_CLIENT_
93
131
 
94
132
  ### Available MCP Commands
95
133
 
134
+ > **Tool naming:** this connector's tools use unprefixed dash-case names (e.g. `list-invoices`, `create-contact`), inherited from its fork lineage. Sibling connectors use prefixed snake_case names (e.g. `list_quickbooks_invoices`). In multi-server hosts, unprefixed generic names can collide with other servers' tools. Renaming would be a breaking change for existing configurations, so the names are kept as-is; if your host supports namespacing/aliasing, prefer enabling it for this server.
135
+
96
136
  - `list-accounts`: Retrieve a list of accounts
97
137
  - `list-contacts`: Retrieve a list of contacts from Xero
98
138
  - `list-credit-notes`: Retrieve a list of credit notes
@@ -100,6 +140,9 @@ NOTE: The `XERO_CLIENT_BEARER_TOKEN` will take precedence over the `XERO_CLIENT_
100
140
  - `list-items`: Retrieve a list of items
101
141
  - `list-organisation-details`: Retrieve details about an organisation
102
142
  - `list-profit-and-loss`: Retrieve a profit and loss report
143
+ - `list-bank-summary`: Retrieve the bank summary report (per-account balances and movements)
144
+ - `list-budget-summary`: Retrieve the budget summary report (budget vs actuals)
145
+ - `list-executive-summary`: Retrieve the executive summary report (key financial metrics snapshot)
103
146
  - `list-quotes`: Retrieve a list of quotes
104
147
  - `list-tax-rates`: Retrieve a list of tax rates
105
148
  - `list-payments`: Retrieve a list of payments
@@ -118,11 +161,13 @@ NOTE: The `XERO_CLIENT_BEARER_TOKEN` will take precedence over the `XERO_CLIENT_
118
161
  - `list-contact-groups`: Retrieve a list of contact groups
119
162
  - `list-currencies`: Retrieve currencies enabled in the connected Xero organisation
120
163
  - `list-invoice-attachments`: Retrieve files attached to a Xero invoice
164
+ - `list-purchase-orders`: Retrieve a list of purchase orders
121
165
  - `create-contact`: Create a new contact
122
166
  - `create-credit-note`: Create a new credit note
123
167
  - `create-invoice`: Create a new invoice. Supports optional `currencyCode`, such as `USD`, when that currency is enabled in the connected Xero organisation.
124
168
  - `create-payment`: Create a new payment
125
169
  - `create-quote`: Create a new quote
170
+ - `create-purchase-order`: Create a new purchase order
126
171
  - `create-credit-note`: Create a new credit note
127
172
  - `create-payroll-timesheet`: Create a new Payroll Timesheet
128
173
  - `update-contact`: Update an existing contact
@@ -145,6 +190,7 @@ NOTE: The `XERO_CLIENT_BEARER_TOKEN` will take precedence over the `XERO_CLIENT_
145
190
  - `add-payroll-timesheet-line`: Add new line on an existing Payroll Timesheet
146
191
  - `delete-payroll-timesheet`: Delete an existing Payroll Timesheet
147
192
  - `get-payroll-timesheet`: Retrieve an existing Payroll Timesheet
193
+ - `email-invoice`: Email a copy of an AUTHORISED invoice to its related contact
148
194
 
149
195
  For detailed API documentation, please refer to the [MCP Protocol Specification](https://modelcontextprotocol.io/).
150
196
 
@@ -1,7 +1,7 @@
1
1
  import axios from "axios";
2
2
  import dotenv from "dotenv";
3
3
  import { XeroClient, } from "xero-node";
4
- import { ensureError } from "../helpers/ensure-error.js";
4
+ import { formatError } from "../helpers/format-error.js";
5
5
  import { formatTokenRequestError } from "../helpers/format-token-error.js";
6
6
  import { XERO_CUSTOM_CONNECTION_SCOPE } from "./xero-scopes.js";
7
7
  dotenv.config();
@@ -44,8 +44,7 @@ class MCPXeroClient extends XeroClient {
44
44
  this.shortCode = organisation.shortCode ?? "";
45
45
  }
46
46
  catch (error) {
47
- const err = ensureError(error);
48
- throw new Error(`Failed to get Organisation short code: ${err.message}`);
47
+ throw new Error(`Failed to get Organisation short code: ${formatError(error)}`);
49
48
  }
50
49
  }
51
50
  return this.shortCode;
@@ -0,0 +1,50 @@
1
+ import { xeroClient } from "../clients/xero-client.js";
2
+ import { formatError } from "../helpers/format-error.js";
3
+ import { getClientHeaders } from "../helpers/get-client-headers.js";
4
+ import { assertXeroCurrencyEnabled } from "../helpers/xero-currencies.js";
5
+ import { PurchaseOrder } from "xero-node";
6
+ async function createPurchaseOrder(contactId, lineItems, reference, date, deliveryDate, purchaseOrderNumber, currencyCode, status) {
7
+ await xeroClient.authenticate();
8
+ await assertXeroCurrencyEnabled(currencyCode);
9
+ const purchaseOrder = {
10
+ contact: {
11
+ contactID: contactId,
12
+ },
13
+ lineItems: lineItems,
14
+ ...(date ? { date } : {}),
15
+ ...(deliveryDate ? { deliveryDate } : {}),
16
+ ...(reference ? { reference } : {}),
17
+ ...(purchaseOrderNumber ? { purchaseOrderNumber } : {}),
18
+ ...(currencyCode ? { currencyCode } : {}),
19
+ status: status ?? PurchaseOrder.StatusEnum.DRAFT,
20
+ };
21
+ const response = await xeroClient.accountingApi.createPurchaseOrders(xeroClient.tenantId, {
22
+ purchaseOrders: [purchaseOrder],
23
+ }, true, // summarizeErrors
24
+ undefined, // idempotencyKey
25
+ getClientHeaders());
26
+ return response.body.purchaseOrders?.[0];
27
+ }
28
+ /**
29
+ * Create a new purchase order in Xero
30
+ */
31
+ export async function createXeroPurchaseOrder(contactId, lineItems, reference, date, deliveryDate, purchaseOrderNumber, currencyCode, status) {
32
+ try {
33
+ const createdPurchaseOrder = await createPurchaseOrder(contactId, lineItems, reference, date, deliveryDate, purchaseOrderNumber, currencyCode, status);
34
+ if (!createdPurchaseOrder) {
35
+ throw new Error("Purchase order creation failed.");
36
+ }
37
+ return {
38
+ result: createdPurchaseOrder,
39
+ isError: false,
40
+ error: null,
41
+ };
42
+ }
43
+ catch (error) {
44
+ return {
45
+ result: null,
46
+ isError: true,
47
+ error: formatError(error),
48
+ };
49
+ }
50
+ }
@@ -0,0 +1,27 @@
1
+ import { xeroClient } from "../clients/xero-client.js";
2
+ import { formatError } from "../helpers/format-error.js";
3
+ import { getClientHeaders } from "../helpers/get-client-headers.js";
4
+ /**
5
+ * Email a copy of an invoice to its related contact via Xero.
6
+ * The invoice must be AUTHORISED — Xero rejects emails for DRAFT or
7
+ * SUBMITTED invoices.
8
+ */
9
+ export async function emailXeroInvoice(invoiceId) {
10
+ try {
11
+ await xeroClient.authenticate();
12
+ await xeroClient.accountingApi.emailInvoice(xeroClient.tenantId, invoiceId, {}, undefined, // idempotencyKey
13
+ getClientHeaders());
14
+ return {
15
+ result: true,
16
+ isError: false,
17
+ error: null,
18
+ };
19
+ }
20
+ catch (error) {
21
+ return {
22
+ result: null,
23
+ isError: true,
24
+ error: formatError(error),
25
+ };
26
+ }
27
+ }
@@ -0,0 +1,38 @@
1
+ import { xeroClient } from "../clients/xero-client.js";
2
+ import { formatError } from "../helpers/format-error.js";
3
+ import { getClientHeaders } from "../helpers/get-client-headers.js";
4
+ async function fetchBankSummary(fromDate, toDate) {
5
+ await xeroClient.authenticate();
6
+ const response = await xeroClient.accountingApi.getReportBankSummary(xeroClient.tenantId, fromDate, toDate, getClientHeaders());
7
+ return response.body.reports?.[0] ?? null;
8
+ }
9
+ /**
10
+ * Get the bank summary report from Xero (opening/closing balances and
11
+ * movements per bank account over a period).
12
+ * @param fromDate Optional start date for the report (YYYY-MM-DD)
13
+ * @param toDate Optional end date for the report (YYYY-MM-DD)
14
+ */
15
+ export async function listXeroBankSummary(fromDate, toDate) {
16
+ try {
17
+ const report = await fetchBankSummary(fromDate, toDate);
18
+ if (!report) {
19
+ return {
20
+ result: null,
21
+ isError: true,
22
+ error: "Failed to fetch bank summary data from Xero.",
23
+ };
24
+ }
25
+ return {
26
+ result: report,
27
+ isError: false,
28
+ error: null,
29
+ };
30
+ }
31
+ catch (error) {
32
+ return {
33
+ result: null,
34
+ isError: true,
35
+ error: formatError(error),
36
+ };
37
+ }
38
+ }
@@ -0,0 +1,45 @@
1
+ import { xeroClient } from "../clients/xero-client.js";
2
+ import { formatError } from "../helpers/format-error.js";
3
+ import { getClientHeaders } from "../helpers/get-client-headers.js";
4
+ // The SDK takes timeframe as a number of months (1=MONTH, 3=QUARTER, 12=YEAR).
5
+ const TIMEFRAME_MONTHS = {
6
+ MONTH: 1,
7
+ QUARTER: 3,
8
+ YEAR: 12,
9
+ };
10
+ async function fetchBudgetSummary(date, periods, timeframe) {
11
+ await xeroClient.authenticate();
12
+ const response = await xeroClient.accountingApi.getReportBudgetSummary(xeroClient.tenantId, date, periods, timeframe ? TIMEFRAME_MONTHS[timeframe] : undefined, getClientHeaders());
13
+ return response.body.reports?.[0] ?? null;
14
+ }
15
+ /**
16
+ * Get the budget summary report from Xero (budgeted vs actual figures per
17
+ * account).
18
+ * @param date Optional date for the report (YYYY-MM-DD)
19
+ * @param periods Optional number of periods to compare (1-12)
20
+ * @param timeframe Optional period size to compare (MONTH, QUARTER, YEAR)
21
+ */
22
+ export async function listXeroBudgetSummary(date, periods, timeframe) {
23
+ try {
24
+ const report = await fetchBudgetSummary(date, periods, timeframe);
25
+ if (!report) {
26
+ return {
27
+ result: null,
28
+ isError: true,
29
+ error: "Failed to fetch budget summary data from Xero.",
30
+ };
31
+ }
32
+ return {
33
+ result: report,
34
+ isError: false,
35
+ error: null,
36
+ };
37
+ }
38
+ catch (error) {
39
+ return {
40
+ result: null,
41
+ isError: true,
42
+ error: formatError(error),
43
+ };
44
+ }
45
+ }
@@ -0,0 +1,37 @@
1
+ import { xeroClient } from "../clients/xero-client.js";
2
+ import { formatError } from "../helpers/format-error.js";
3
+ import { getClientHeaders } from "../helpers/get-client-headers.js";
4
+ async function fetchExecutiveSummary(date) {
5
+ await xeroClient.authenticate();
6
+ const response = await xeroClient.accountingApi.getReportExecutiveSummary(xeroClient.tenantId, date, getClientHeaders());
7
+ return response.body.reports?.[0] ?? null;
8
+ }
9
+ /**
10
+ * Get the executive summary report from Xero (a high-level snapshot of key
11
+ * financial metrics such as cash, debtors, creditors, and profit).
12
+ * @param date Optional date for the report (YYYY-MM-DD)
13
+ */
14
+ export async function listXeroExecutiveSummary(date) {
15
+ try {
16
+ const report = await fetchExecutiveSummary(date);
17
+ if (!report) {
18
+ return {
19
+ result: null,
20
+ isError: true,
21
+ error: "Failed to fetch executive summary data from Xero.",
22
+ };
23
+ }
24
+ return {
25
+ result: report,
26
+ isError: false,
27
+ error: null,
28
+ };
29
+ }
30
+ catch (error) {
31
+ return {
32
+ result: null,
33
+ isError: true,
34
+ error: formatError(error),
35
+ };
36
+ }
37
+ }
@@ -0,0 +1,29 @@
1
+ import { xeroClient } from "../clients/xero-client.js";
2
+ import { formatError } from "../helpers/format-error.js";
3
+ import { getClientHeaders } from "../helpers/get-client-headers.js";
4
+ async function getPurchaseOrders(status, dateFrom, dateTo, order, page, pageSize) {
5
+ await xeroClient.authenticate();
6
+ const response = await xeroClient.accountingApi.getPurchaseOrders(xeroClient.tenantId, undefined, // ifModifiedSince
7
+ status, dateFrom, dateTo, order, page, pageSize ?? 100, getClientHeaders());
8
+ return response.body.purchaseOrders ?? [];
9
+ }
10
+ /**
11
+ * List purchase orders from Xero
12
+ */
13
+ export async function listXeroPurchaseOrders(page = 1, status, dateFrom, dateTo, order, pageSize) {
14
+ try {
15
+ const purchaseOrders = await getPurchaseOrders(status, dateFrom, dateTo, order, page, pageSize);
16
+ return {
17
+ result: purchaseOrders,
18
+ isError: false,
19
+ error: null,
20
+ };
21
+ }
22
+ catch (error) {
23
+ return {
24
+ result: null,
25
+ isError: true,
26
+ error: formatError(error),
27
+ };
28
+ }
29
+ }
@@ -1,6 +1,37 @@
1
+ import { wrapUntrusted } from "../untrusted-content.js";
2
+ import { formatError } from "./format-error.js";
3
+ /**
4
+ * AGENTS.md security invariant #6: any text block a tool returns can carry
5
+ * Xero-authored (attacker-controllable) text — contact names, line item
6
+ * descriptions, references, history details/changes, validation messages.
7
+ * Envelope every text block here, at the single factory every tool is built
8
+ * with, so individual tools cannot forget to wrap their external text.
9
+ */
10
+ function envelopToolResult(result, source) {
11
+ return {
12
+ ...result,
13
+ content: result.content?.map((block) => block.type === "text"
14
+ ? { ...block, text: wrapUntrusted(block.text, source) ?? block.text }
15
+ : block),
16
+ };
17
+ }
1
18
  export const CreateXeroTool = (name, description, schema, handler) => () => ({
2
19
  name: name,
3
20
  description: description,
4
21
  schema: schema,
5
- handler: handler,
22
+ handler: (async (args, extra) => {
23
+ try {
24
+ return envelopToolResult(await handler(args, extra), `xero.${name}`);
25
+ }
26
+ catch (error) {
27
+ // A rejection would otherwise bypass the envelope: the SDK serialises
28
+ // the raw error message into a plain, unwrapped text block. Format it
29
+ // (whitelisted fields only — SDK rejections can carry bearer tokens)
30
+ // and route it through the same choke point as any other result.
31
+ return envelopToolResult({
32
+ content: [{ type: "text", text: formatError(error) }],
33
+ isError: true,
34
+ }, `xero.${name}`);
35
+ }
36
+ }),
6
37
  });
@@ -1,4 +1,5 @@
1
1
  import { xeroClient } from "../clients/xero-client.js";
2
+ import { formatError } from "./format-error.js";
2
3
  import { contactDeepLink, creditNoteDeepLink, invoiceDeepLink, paymentDeepLink, manualJournalDeepLink, quoteDeepLink, billDeepLink, } from "../consts/deeplinks.js";
3
4
  export var DeepLinkType;
4
5
  (function (DeepLinkType) {
@@ -11,16 +12,26 @@ export var DeepLinkType;
11
12
  DeepLinkType[DeepLinkType["BILL"] = 6] = "BILL";
12
13
  })(DeepLinkType || (DeepLinkType = {}));
13
14
  /**
14
- * Gets a deep link for a specific type and item ID.
15
- * This will also fetch the org short code from the Xero client.
15
+ * Gets a deep link for a specific type and item ID, or `null` when the link
16
+ * cannot be resolved. Best-effort by design: every caller has already
17
+ * committed a successful write in Xero, so a deeplink failure must never
18
+ * surface as a tool error — the model would retry and duplicate the record.
16
19
  * @param type
17
20
  * @param itemId
18
21
  * @returns
19
22
  */
20
23
  export const getDeepLink = async (type, itemId) => {
21
- const orgShortCode = await xeroClient.getShortCode();
24
+ let orgShortCode;
25
+ try {
26
+ orgShortCode = await xeroClient.getShortCode();
27
+ }
28
+ catch (error) {
29
+ console.warn(`Failed to resolve Xero deep link: ${formatError(error)}`);
30
+ return null;
31
+ }
22
32
  if (!orgShortCode) {
23
- throw new Error("Failed to retrieve organisation short code");
33
+ console.warn("Failed to resolve Xero deep link: no organisation short code");
34
+ return null;
24
35
  }
25
36
  switch (type) {
26
37
  case DeepLinkType.CONTACT:
@@ -19,5 +19,5 @@ export async function assertXeroCurrencyEnabled(currencyCode) {
19
19
  const enabledList = enabledCurrencyCodes.length
20
20
  ? enabledCurrencyCodes.join(", ")
21
21
  : "none";
22
- throw new Error(`Currency ${currencyCode} is not enabled in this Xero organisation. Enabled currencies: ${enabledList}. Add ${currencyCode} in Xero before creating or updating invoices in that currency.`);
22
+ throw new Error(`Currency ${currencyCode} is not enabled in this Xero organisation. Enabled currencies: ${enabledList}. Add ${currencyCode} in Xero before creating or updating records in that currency.`);
23
23
  }
@@ -1,4 +1,5 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { getPackageVersion } from "../helpers/get-package-version.js";
2
3
  export class XeroMcpServer {
3
4
  static instance = null;
4
5
  constructor() { }
@@ -6,7 +7,7 @@ export class XeroMcpServer {
6
7
  if (XeroMcpServer.instance === null) {
7
8
  XeroMcpServer.instance = new McpServer({
8
9
  name: "Xero MCP Server",
9
- version: "1.0.0",
10
+ version: getPackageVersion(),
10
11
  });
11
12
  }
12
13
  return XeroMcpServer.instance;
@@ -30,7 +30,8 @@ const CreateBankTransactionTool = CreateXeroTool("create-bank-transaction", `Cre
30
30
  type: "text",
31
31
  text: `Error creating bank transaction: ${result.error}`
32
32
  }
33
- ]
33
+ ],
34
+ isError: true,
34
35
  };
35
36
  }
36
37
  const bankTransaction = result.result;
@@ -1,7 +1,7 @@
1
1
  import { createXeroContact } from "../../handlers/create-xero-contact.handler.js";
2
2
  import { z } from "zod";
3
3
  import { DeepLinkType, getDeepLink } from "../../helpers/get-deeplink.js";
4
- import { ensureError } from "../../helpers/ensure-error.js";
4
+ import { formatError } from "../../helpers/format-error.js";
5
5
  import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
6
6
  const CreateContactTool = CreateXeroTool("create-contact", "Create a contact in Xero.\
7
7
  When a contact is created, a deep link to the contact in Xero is returned. \
@@ -21,6 +21,7 @@ const CreateContactTool = CreateXeroTool("create-contact", "Create a contact in
21
21
  text: `Error creating contact: ${response.error}`,
22
22
  },
23
23
  ],
24
+ isError: true,
24
25
  };
25
26
  }
26
27
  const contact = response.result;
@@ -42,14 +43,14 @@ const CreateContactTool = CreateXeroTool("create-contact", "Create a contact in
42
43
  };
43
44
  }
44
45
  catch (error) {
45
- const err = ensureError(error);
46
46
  return {
47
47
  content: [
48
48
  {
49
49
  type: "text",
50
- text: `Error creating contact: ${err.message}`,
50
+ text: `Error creating contact: ${formatError(error)}`,
51
51
  },
52
52
  ],
53
+ isError: true,
53
54
  };
54
55
  }
55
56
  });
@@ -26,6 +26,7 @@ const CreateCreditNoteTool = CreateXeroTool("create-credit-note", "Create a cred
26
26
  text: `Error creating credit note: ${result.error}`,
27
27
  },
28
28
  ],
29
+ isError: true,
29
30
  };
30
31
  }
31
32
  const creditNote = result.result;
@@ -46,6 +46,7 @@ const CreateInvoiceTool = CreateXeroTool("create-invoice", "Create an invoice in
46
46
  text: `Error creating invoice: ${result.error}`,
47
47
  },
48
48
  ],
49
+ isError: true,
49
50
  };
50
51
  }
51
52
  const invoice = result.result;
@@ -39,6 +39,7 @@ const CreateItemTool = CreateXeroTool("create-item", "Create an item in Xero.",
39
39
  text: `Error creating item: ${result.error}`,
40
40
  },
41
41
  ],
42
+ isError: true,
42
43
  };
43
44
  }
44
45
  const item = result.result;
@@ -2,7 +2,7 @@ import { z } from "zod";
2
2
  import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
3
3
  import { createXeroManualJournal } from "../../handlers/create-xero-manual-journal.handler.js";
4
4
  import { DeepLinkType, getDeepLink } from "../../helpers/get-deeplink.js";
5
- import { ensureError } from "../../helpers/ensure-error.js";
5
+ import { formatError } from "../../helpers/format-error.js";
6
6
  const CreateManualJournalTool = CreateXeroTool("create-manual-journal", "Create a manual journal in Xero.\
7
7
  Retrieve a list of account codes in Xero to use for the journal lines.\
8
8
  Journal lines must contain at least two individual journal lines with account codes, \
@@ -56,6 +56,7 @@ const CreateManualJournalTool = CreateXeroTool("create-manual-journal", "Create
56
56
  text: `Error creating manual journal: ${response.error}`,
57
57
  },
58
58
  ],
59
+ isError: true,
59
60
  };
60
61
  }
61
62
  const manualJournal = response.result;
@@ -102,14 +103,14 @@ const CreateManualJournalTool = CreateXeroTool("create-manual-journal", "Create
102
103
  };
103
104
  }
104
105
  catch (error) {
105
- const err = ensureError(error);
106
106
  return {
107
107
  content: [
108
108
  {
109
109
  type: "text",
110
- text: `Error creating manual journal: ${err.message}`,
110
+ text: `Error creating manual journal: ${formatError(error)}`,
111
111
  },
112
112
  ],
113
+ isError: true,
113
114
  };
114
115
  }
115
116
  });
@@ -43,6 +43,7 @@ const CreatePaymentTool = CreateXeroTool("create-payment", "Create a payment aga
43
43
  text: `Error creating payment: ${result.error}`,
44
44
  },
45
45
  ],
46
+ isError: true,
46
47
  };
47
48
  }
48
49
  const payment = result.result;
@@ -25,6 +25,7 @@ This allows you to specify details such as the employee ID, payroll calendar ID,
25
25
  text: `Error creating timesheet: ${response.error}`,
26
26
  },
27
27
  ],
28
+ isError: true,
28
29
  };
29
30
  }
30
31
  const timesheet = response.result;
@@ -0,0 +1,67 @@
1
+ import { z } from "zod";
2
+ import { createXeroPurchaseOrder } from "../../handlers/create-xero-purchase-order.handler.js";
3
+ import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
4
+ import { CurrencyCode, PurchaseOrder } from "xero-node";
5
+ const lineItemSchema = z.object({
6
+ description: z.string().describe("The description of the line item"),
7
+ quantity: z.number().describe("The quantity of the line item"),
8
+ unitAmount: z.number().describe("The price per unit of the line item"),
9
+ accountCode: z.string().describe("The account code of the line item - can be obtained from the list-accounts tool"),
10
+ taxType: z.string().describe("The tax type of the line item - can be obtained from the list-tax-rates tool"),
11
+ itemCode: z.string().describe("The item code of the line item - can be obtained from the list-items tool").optional(),
12
+ });
13
+ const CreatePurchaseOrderTool = CreateXeroTool("create-purchase-order", "Create a purchase order in Xero for a supplier. The purchase order is created as DRAFT unless a status is specified.", {
14
+ contactId: z.string().describe("The ID of the supplier contact to create the purchase order for. \
15
+ Can be obtained from the list-contacts tool."),
16
+ lineItems: z.array(lineItemSchema),
17
+ reference: z.string().describe("An additional reference for the purchase order.").optional(),
18
+ date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "Must be YYYY-MM-DD format").describe("The date the purchase order was issued (YYYY-MM-DD format). Defaults to today.").optional(),
19
+ deliveryDate: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "Must be YYYY-MM-DD format").describe("The date the goods are to be delivered (YYYY-MM-DD format).").optional(),
20
+ purchaseOrderNumber: z.string().describe("A unique alpha-numeric code for the purchase order. When omitted, Xero auto-generates one from the organisation settings.").optional(),
21
+ currencyCode: z.nativeEnum(CurrencyCode).describe("Optional purchase order currency, such as USD. Only use a currency enabled in the connected Xero organisation.").optional(),
22
+ status: z.enum(["DRAFT", "SUBMITTED", "AUTHORISED"]).describe("The status to create the purchase order with. Defaults to DRAFT.").optional(),
23
+ }, async ({ contactId, lineItems, reference, date, deliveryDate, purchaseOrderNumber, currencyCode, status }) => {
24
+ const statusMap = {
25
+ DRAFT: PurchaseOrder.StatusEnum.DRAFT,
26
+ SUBMITTED: PurchaseOrder.StatusEnum.SUBMITTED,
27
+ AUTHORISED: PurchaseOrder.StatusEnum.AUTHORISED,
28
+ };
29
+ const result = await createXeroPurchaseOrder(contactId, lineItems, reference, date, deliveryDate, purchaseOrderNumber, currencyCode, status ? statusMap[status] : undefined);
30
+ if (result.isError) {
31
+ return {
32
+ content: [
33
+ {
34
+ type: "text",
35
+ text: `Error creating purchase order: ${result.error}`,
36
+ },
37
+ ],
38
+ isError: true,
39
+ };
40
+ }
41
+ const purchaseOrder = result.result;
42
+ return {
43
+ content: [
44
+ {
45
+ type: "text",
46
+ text: [
47
+ "Purchase order created successfully:",
48
+ `ID: ${purchaseOrder?.purchaseOrderID}`,
49
+ `Purchase Order: ${purchaseOrder?.purchaseOrderNumber}`,
50
+ `Contact: ${purchaseOrder?.contact?.name}`,
51
+ purchaseOrder?.date ? `Date: ${purchaseOrder.date}` : null,
52
+ purchaseOrder?.deliveryDate
53
+ ? `Delivery Date: ${purchaseOrder.deliveryDate}`
54
+ : null,
55
+ purchaseOrder?.currencyCode
56
+ ? `Currency: ${purchaseOrder.currencyCode}`
57
+ : null,
58
+ `Total: ${purchaseOrder?.total}`,
59
+ `Status: ${purchaseOrder?.status}`,
60
+ ]
61
+ .filter(Boolean)
62
+ .join("\n"),
63
+ },
64
+ ],
65
+ };
66
+ });
67
+ export default CreatePurchaseOrderTool;
@@ -30,6 +30,7 @@ const CreateQuoteTool = CreateXeroTool("create-quote", "Create a quote in Xero.\
30
30
  text: `Error creating quote: ${result.error}`,
31
31
  },
32
32
  ],
33
+ isError: true,
33
34
  };
34
35
  }
35
36
  const quote = result.result;
@@ -12,7 +12,8 @@ const CreateTrackingCategoryTool = CreateXeroTool("create-tracking-category", `C
12
12
  type: "text",
13
13
  text: `Error while creating tracking category: ${response.error}`
14
14
  }
15
- ]
15
+ ],
16
+ isError: true,
16
17
  };
17
18
  }
18
19
  const trackingCategory = response.result;