@teamnetwork-nz/xero-mcp-server 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +282 -0
  3. package/dist/clients/xero-client.js +141 -0
  4. package/dist/consts/deeplinks.js +24 -0
  5. package/dist/handlers/approve-xero-payroll-timesheet.handler.js +28 -0
  6. package/dist/handlers/archive-xero-contact.handler.js +28 -0
  7. package/dist/handlers/authorise-xero-invoice.handler.js +34 -0
  8. package/dist/handlers/convert-xero-quote-to-invoice.handler.js +50 -0
  9. package/dist/handlers/create-xero-bank-transaction.handler.js +51 -0
  10. package/dist/handlers/create-xero-contact.handler.js +49 -0
  11. package/dist/handlers/create-xero-credit-note.handler.js +50 -0
  12. package/dist/handlers/create-xero-invoice.handler.js +53 -0
  13. package/dist/handlers/create-xero-item.handler.js +59 -0
  14. package/dist/handlers/create-xero-manual-journal.handler.js +57 -0
  15. package/dist/handlers/create-xero-payment.handler.js +50 -0
  16. package/dist/handlers/create-xero-payroll-timesheet.handler.js +28 -0
  17. package/dist/handlers/create-xero-quote.handler.js +53 -0
  18. package/dist/handlers/create-xero-tracking-category.handler.js +35 -0
  19. package/dist/handlers/create-xero-tracking-option.handler.js +31 -0
  20. package/dist/handlers/delete-xero-invoice-attachment.handler.js +30 -0
  21. package/dist/handlers/delete-xero-payroll-timesheet.handler.js +28 -0
  22. package/dist/handlers/download-xero-invoice-attachment.handler.js +23 -0
  23. package/dist/handlers/download-xero-invoice-pdf.handler.js +25 -0
  24. package/dist/handlers/get-xero-invoice.handler.js +19 -0
  25. package/dist/handlers/get-xero-payroll-timesheet.handler.js +28 -0
  26. package/dist/handlers/list-aged-payables-by-contact.handler.js +37 -0
  27. package/dist/handlers/list-aged-receivables-by-contact.handler.js +37 -0
  28. package/dist/handlers/list-xero-accounts.handler.js +32 -0
  29. package/dist/handlers/list-xero-bank-transactions.handler.js +39 -0
  30. package/dist/handlers/list-xero-contact-groups.handler.js +34 -0
  31. package/dist/handlers/list-xero-contacts.handler.js +47 -0
  32. package/dist/handlers/list-xero-credit-notes.handler.js +42 -0
  33. package/dist/handlers/list-xero-invoice-attachments.handler.js +20 -0
  34. package/dist/handlers/list-xero-invoices.handler.js +54 -0
  35. package/dist/handlers/list-xero-items.handler.js +32 -0
  36. package/dist/handlers/list-xero-manual-journals.handler.js +33 -0
  37. package/dist/handlers/list-xero-organisation-details.handler.js +32 -0
  38. package/dist/handlers/list-xero-payments.handler.js +52 -0
  39. package/dist/handlers/list-xero-payroll-employee-leave-balances.handler.js +42 -0
  40. package/dist/handlers/list-xero-payroll-employee-leave-types.handler.js +42 -0
  41. package/dist/handlers/list-xero-payroll-employee-leave.handler.js +44 -0
  42. package/dist/handlers/list-xero-payroll-employees.handler.js +31 -0
  43. package/dist/handlers/list-xero-payroll-leave-periods.handler.js +44 -0
  44. package/dist/handlers/list-xero-payroll-leave-types.handler.js +40 -0
  45. package/dist/handlers/list-xero-profit-and-loss.handler.js +52 -0
  46. package/dist/handlers/list-xero-quotes.handler.js +36 -0
  47. package/dist/handlers/list-xero-report-balance-sheet.handler.js +34 -0
  48. package/dist/handlers/list-xero-tax-rates.handler.js +30 -0
  49. package/dist/handlers/list-xero-timesheets.handler.js +29 -0
  50. package/dist/handlers/list-xero-tracking-categories.handler.js +29 -0
  51. package/dist/handlers/list-xero-trial-balance.handler.js +42 -0
  52. package/dist/handlers/revert-xero-payroll-timesheet.handler.js +28 -0
  53. package/dist/handlers/update-xero-bank-transaction.handler.js +56 -0
  54. package/dist/handlers/update-xero-contact.handler.js +66 -0
  55. package/dist/handlers/update-xero-credit-note.handler.js +61 -0
  56. package/dist/handlers/update-xero-invoice.handler.js +62 -0
  57. package/dist/handlers/update-xero-item.handler.js +46 -0
  58. package/dist/handlers/update-xero-manual-journal.handler.js +46 -0
  59. package/dist/handlers/update-xero-payroll-timesheet-add-line.handler.js +28 -0
  60. package/dist/handlers/update-xero-payroll-timesheet-update-line.handler.js +28 -0
  61. package/dist/handlers/update-xero-quote.handler.js +78 -0
  62. package/dist/handlers/update-xero-tracking-category.handler.js +43 -0
  63. package/dist/handlers/update-xero-tracking-options.handler.js +51 -0
  64. package/dist/handlers/upload-xero-invoice-attachment.handler.js +36 -0
  65. package/dist/handlers/void-xero-invoice.handler.js +52 -0
  66. package/dist/helpers/build-where-clause.js +29 -0
  67. package/dist/helpers/create-xero-tool.js +6 -0
  68. package/dist/helpers/datetime.js +91 -0
  69. package/dist/helpers/ensure-error.js +13 -0
  70. package/dist/helpers/format-aged-report-filter.js +8 -0
  71. package/dist/helpers/format-error.js +25 -0
  72. package/dist/helpers/format-line-item.js +13 -0
  73. package/dist/helpers/format-tracking-option.js +7 -0
  74. package/dist/helpers/get-client-headers.js +8 -0
  75. package/dist/helpers/get-deeplink.js +41 -0
  76. package/dist/helpers/get-download-path.js +16 -0
  77. package/dist/helpers/get-external-link.js +8 -0
  78. package/dist/helpers/get-package-version.js +20 -0
  79. package/dist/index.js +18 -0
  80. package/dist/resources/register-resources.js +27 -0
  81. package/dist/server/xero-mcp-server.js +43 -0
  82. package/dist/tools/create/convert-quote-to-invoice.tool.js +46 -0
  83. package/dist/tools/create/create-bank-transaction.tool.js +57 -0
  84. package/dist/tools/create/create-contact.tool.js +56 -0
  85. package/dist/tools/create/create-credit-note.tool.js +53 -0
  86. package/dist/tools/create/create-invoice.tool.js +78 -0
  87. package/dist/tools/create/create-item.tool.js +61 -0
  88. package/dist/tools/create/create-manual-journal.tool.js +116 -0
  89. package/dist/tools/create/create-payment.tool.js +71 -0
  90. package/dist/tools/create/create-payroll-timesheet.tool.js +40 -0
  91. package/dist/tools/create/create-quote.tool.js +57 -0
  92. package/dist/tools/create/create-tracking-category.tool.js +28 -0
  93. package/dist/tools/create/create-tracking-options.tool.js +30 -0
  94. package/dist/tools/create/index.js +35 -0
  95. package/dist/tools/create/upload-invoice-attachment.tool.js +49 -0
  96. package/dist/tools/delete/archive-contact.tool.js +30 -0
  97. package/dist/tools/delete/delete-invoice-attachment.tool.js +28 -0
  98. package/dist/tools/delete/delete-payroll-timesheet.tool.js +28 -0
  99. package/dist/tools/delete/index.js +15 -0
  100. package/dist/tools/get/get-invoice-attachment.tool.js +33 -0
  101. package/dist/tools/get/get-invoice-pdf.tool.js +33 -0
  102. package/dist/tools/get/get-invoice.tool.js +72 -0
  103. package/dist/tools/get/get-payroll-timesheet.tool.js +50 -0
  104. package/dist/tools/get/index.js +17 -0
  105. package/dist/tools/list/index.js +64 -0
  106. package/dist/tools/list/list-accounts.tool.js +39 -0
  107. package/dist/tools/list/list-aged-payables-by-contact.tool.js +51 -0
  108. package/dist/tools/list/list-aged-receivables-by-contact.tool.js +51 -0
  109. package/dist/tools/list/list-bank-transactions.tool.js +66 -0
  110. package/dist/tools/list/list-contact-groups.tool.js +48 -0
  111. package/dist/tools/list/list-contacts.tool.js +80 -0
  112. package/dist/tools/list/list-credit-notes.tool.js +72 -0
  113. package/dist/tools/list/list-invoice-attachments.tool.js +42 -0
  114. package/dist/tools/list/list-invoices.tool.js +98 -0
  115. package/dist/tools/list/list-items.tool.js +50 -0
  116. package/dist/tools/list/list-manual-journals.tool.js +80 -0
  117. package/dist/tools/list/list-organisation-details.tool.js +91 -0
  118. package/dist/tools/list/list-payments.tool.js +91 -0
  119. package/dist/tools/list/list-payroll-employee-leave-balances.tool.js +39 -0
  120. package/dist/tools/list/list-payroll-employee-leave-types.tool.js +57 -0
  121. package/dist/tools/list/list-payroll-employee-leave.tool.js +43 -0
  122. package/dist/tools/list/list-payroll-employees.tool.js +49 -0
  123. package/dist/tools/list/list-payroll-leave-periods.tool.js +45 -0
  124. package/dist/tools/list/list-payroll-leave-types.tool.js +40 -0
  125. package/dist/tools/list/list-payroll-timesheets.tool.js +40 -0
  126. package/dist/tools/list/list-profit-and-loss.tool.js +46 -0
  127. package/dist/tools/list/list-quotes.tool.js +69 -0
  128. package/dist/tools/list/list-report-balance-sheet.tool.js +39 -0
  129. package/dist/tools/list/list-tax-rates.tool.js +49 -0
  130. package/dist/tools/list/list-tracking-categories.tool.js +39 -0
  131. package/dist/tools/list/list-trial-balance.tool.js +42 -0
  132. package/dist/tools/tool-factory.js +24 -0
  133. package/dist/tools/update/approve-payroll-timesheet.tool.js +29 -0
  134. package/dist/tools/update/authorise-invoice.tool.js +42 -0
  135. package/dist/tools/update/index.js +39 -0
  136. package/dist/tools/update/revert-payroll-timesheet.tool.js +29 -0
  137. package/dist/tools/update/update-bank-transaction.tool.js +56 -0
  138. package/dist/tools/update/update-contact.tool.js +69 -0
  139. package/dist/tools/update/update-credit-note.tool.js +56 -0
  140. package/dist/tools/update/update-invoice.tool.js +76 -0
  141. package/dist/tools/update/update-item.tool.js +62 -0
  142. package/dist/tools/update/update-manual-journal-tool.js +89 -0
  143. package/dist/tools/update/update-payroll-timesheet-add-line.tool.js +34 -0
  144. package/dist/tools/update/update-payroll-timesheet-update-line.tool.js +35 -0
  145. package/dist/tools/update/update-quote.tool.js +61 -0
  146. package/dist/tools/update/update-tracking-category.tool.js +30 -0
  147. package/dist/tools/update/update-tracking-options.tool.js +35 -0
  148. package/dist/tools/update/void-invoice.tool.js +33 -0
  149. package/dist/types/list-report-balance-sheet-params.js +1 -0
  150. package/dist/types/timeframeType.js +1 -0
  151. package/dist/types/tool-definition.js +1 -0
  152. package/dist/types/tool-list.js +1 -0
  153. package/dist/types/tool-response.js +1 -0
  154. package/package.json +38 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Xero Limited
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,282 @@
1
+ # TEAMnetwork Xero MCP Server
2
+
3
+ A [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server for Xero, maintained by [TEAMnetwork](https://teamnetwork.co.nz). Forked and extended from the [official Xero MCP Server](https://github.com/XeroAPI/xero-mcp-server).
4
+
5
+ Provides AI agents and MCP-compatible clients (e.g. Claude Desktop) with tools to read and write Xero accounting data, manage invoice attachments, and download invoice PDFs.
6
+
7
+ ## Features
8
+
9
+ - **Invoices** — create, list (with status/date filters), update, authorise, void, get full detail, download as PDF
10
+ - **Contacts** — create, list, update, archive
11
+ - **Quotes** — create, list, update, convert to invoice
12
+ - **Payments & Credit Notes** — create, list, update
13
+ - **Bank Transactions & Manual Journals** — create, list, update
14
+ - **Accounts, Items, Tax Rates, Tracking** — list, create, update
15
+ - **Financial Reports** — Trial Balance, Profit & Loss, Balance Sheet, Aged Payables/Receivables
16
+ - **Invoice Attachments** — list, upload (e.g. Crystal Reports PDFs), download, delete
17
+ - **Payroll** — employees, leave, timesheets *(optional, off by default)*
18
+ - **Modular scopes** — only request the Xero API permissions your use case needs
19
+
20
+ ## Prerequisites
21
+
22
+ - Node.js v18 or higher
23
+ - A Xero developer account with API credentials
24
+
25
+ ## Docs and Links
26
+
27
+ - [Xero Public API Documentation](https://developer.xero.com/documentation/api/)
28
+ - [Xero API Explorer](https://api-explorer.xero.com/)
29
+ - [Xero-Node SDK Docs](https://xeroapi.github.io/xero-node/accounting)
30
+ - [MCP Protocol Specification](https://modelcontextprotocol.io/)
31
+
32
+ ---
33
+
34
+ ## Setup
35
+
36
+ ### 1. Create a Xero Developer App
37
+
38
+ Set up a **Custom Connection** following Xero's guide:
39
+ https://developer.xero.com/documentation/guides/oauth2/custom-connections/
40
+
41
+ When configuring scopes in your Xero app, include the scopes for the feature groups you plan to use (see [Feature Groups](#feature-groups) below). At minimum you need:
42
+
43
+ ```
44
+ accounting.transactions
45
+ accounting.contacts
46
+ accounting.settings
47
+ accounting.attachments
48
+ ```
49
+
50
+ ### 2. Authentication
51
+
52
+ There are two authentication modes:
53
+
54
+ #### Custom Connections (recommended)
55
+
56
+ Uses a Client ID and Secret tied to a specific Xero organisation. Best for Claude Desktop and single-org setups.
57
+
58
+ ```json
59
+ {
60
+ "mcpServers": {
61
+ "xero": {
62
+ "command": "npx",
63
+ "args": ["-y", "tn-xero-mcp-server@latest"],
64
+ "env": {
65
+ "XERO_CLIENT_ID": "your_client_id_here",
66
+ "XERO_CLIENT_SECRET": "your_client_secret_here"
67
+ }
68
+ }
69
+ }
70
+ }
71
+ ```
72
+
73
+ #### Bearer Token
74
+
75
+ Use when your MCP client handles the OAuth flow (e.g. PKCE). The bearer token takes precedence over Client ID/Secret if both are set.
76
+
77
+ ```json
78
+ {
79
+ "mcpServers": {
80
+ "xero": {
81
+ "command": "npx",
82
+ "args": ["-y", "tn-xero-mcp-server@latest"],
83
+ "env": {
84
+ "XERO_CLIENT_BEARER_TOKEN": "your_bearer_token"
85
+ }
86
+ }
87
+ }
88
+ }
89
+ ```
90
+
91
+ When obtaining a bearer token, request the scopes matching your enabled feature groups. See [Feature Groups](#feature-groups) for the full scope list.
92
+
93
+ ---
94
+
95
+ ## Feature Groups
96
+
97
+ Scopes and tools are controlled by environment variables. This means you only provision the Xero API permissions your setup actually needs.
98
+
99
+ | Variable | Default | Scopes requested | Tools enabled |
100
+ |---|---|---|---|
101
+ | *(core — always on)* | — | `accounting.transactions` `accounting.contacts` `accounting.settings` `accounting.attachments` | All invoicing, contact, payment, attachment & PDF tools |
102
+ | `XERO_ENABLE_REPORTS` | `true` | `accounting.reports.read` | Trial Balance, P&L, Balance Sheet, Aged Payables/Receivables |
103
+ | `XERO_ENABLE_PAYROLL` | `false` | `payroll.settings` `payroll.employees` `payroll.timesheets` | All payroll tools |
104
+
105
+ > **Note:** To use payroll tools, your Xero region must be **NZ** or **UK**, and your Xero app must have the payroll scopes provisioned.
106
+
107
+ ### Full configuration example
108
+
109
+ ```json
110
+ {
111
+ "mcpServers": {
112
+ "xero": {
113
+ "command": "npx",
114
+ "args": ["-y", "tn-xero-mcp-server@latest"],
115
+ "env": {
116
+ "XERO_CLIENT_ID": "your_client_id_here",
117
+ "XERO_CLIENT_SECRET": "your_client_secret_here",
118
+ "XERO_ENABLE_REPORTS": "true",
119
+ "XERO_ENABLE_PAYROLL": "false",
120
+ "XERO_DOWNLOAD_PATH": "C:/Users/you/Downloads/Xero"
121
+ }
122
+ }
123
+ }
124
+ }
125
+ ```
126
+
127
+ ### `XERO_DOWNLOAD_PATH`
128
+
129
+ The local directory where downloaded invoice PDFs and attachments are saved.
130
+ Defaults to `~/Downloads` if not set.
131
+
132
+ ---
133
+
134
+ ## Available Tools
135
+
136
+ ### Invoices
137
+ | Tool | Description |
138
+ |---|---|
139
+ | `list-invoices` | List invoices with optional filters: status, contact, invoice number, date range |
140
+ | `get-invoice` | Get full details of a single invoice including all line items |
141
+ | `create-invoice` | Create a new draft invoice (AR or AP) |
142
+ | `update-invoice` | Update a draft invoice |
143
+ | `authorise-invoice` | Promote a DRAFT or SUBMITTED invoice to AUTHORISED |
144
+ | `void-invoice` | Void an AUTHORISED invoice, or delete a DRAFT invoice |
145
+ | `get-invoice-pdf` | Download the Xero-generated invoice PDF to local disk |
146
+ | `list-invoice-attachments` | List all file attachments on an invoice |
147
+ | `upload-invoice-attachment` | Upload a local file (e.g. Crystal Reports PDF) as an invoice attachment |
148
+ | `get-invoice-attachment` | Download an invoice attachment to local disk |
149
+ | `delete-invoice-attachment` | Delete an attachment from an invoice |
150
+
151
+ ### Quotes
152
+ | Tool | Description |
153
+ |---|---|
154
+ | `list-quotes` | List quotes |
155
+ | `create-quote` | Create a new quote |
156
+ | `update-quote` | Update an existing quote |
157
+ | `convert-quote-to-invoice` | Convert a quote into a draft invoice, copying all line items |
158
+
159
+ ### Contacts
160
+ | Tool | Description |
161
+ |---|---|
162
+ | `list-contacts` | List contacts with optional search term |
163
+ | `create-contact` | Create a new contact |
164
+ | `update-contact` | Update an existing contact |
165
+ | `archive-contact` | Archive a contact (Xero does not support hard deletion) |
166
+ | `list-contact-groups` | List contact groups |
167
+
168
+ ### Payments & Credit Notes
169
+ | Tool | Description |
170
+ |---|---|
171
+ | `list-payments` | List payments |
172
+ | `create-payment` | Record a payment against an invoice |
173
+ | `list-credit-notes` | List credit notes |
174
+ | `create-credit-note` | Create a credit note |
175
+ | `update-credit-note` | Update a draft credit note |
176
+
177
+ ### Bank & Journals
178
+ | Tool | Description |
179
+ |---|---|
180
+ | `list-bank-transactions` | List bank transactions |
181
+ | `create-bank-transaction` | Create a bank transaction |
182
+ | `update-bank-transaction` | Update a bank transaction |
183
+ | `list-manual-journals` | List manual journals |
184
+ | `create-manual-journal` | Create a manual journal |
185
+ | `update-manual-journal` | Update a manual journal |
186
+
187
+ ### Settings & Configuration
188
+ | Tool | Description |
189
+ |---|---|
190
+ | `list-accounts` | List chart of accounts |
191
+ | `list-tax-rates` | List tax rates |
192
+ | `list-items` | List inventory items |
193
+ | `create-item` | Create an inventory item |
194
+ | `update-item` | Update an inventory item |
195
+ | `list-tracking-categories` | List tracking categories and options |
196
+ | `create-tracking-category` | Create a tracking category |
197
+ | `update-tracking-category` | Update a tracking category |
198
+ | `update-tracking-options` | Update tracking options |
199
+ | `create-tracking-option` | Create a tracking option |
200
+ | `list-organisation-details` | Get organisation details |
201
+
202
+ ### Financial Reports *(requires `XERO_ENABLE_REPORTS=true`)*
203
+ | Tool | Description |
204
+ |---|---|
205
+ | `list-trial-balance` | Trial balance report |
206
+ | `list-profit-and-loss` | Profit and loss report |
207
+ | `list-report-balance-sheet` | Balance sheet report |
208
+ | `list-aged-receivables-by-contact` | Aged receivables for a contact |
209
+ | `list-aged-payables-by-contact` | Aged payables for a contact |
210
+
211
+ ### Payroll *(requires `XERO_ENABLE_PAYROLL=true`)*
212
+ | Tool | Description |
213
+ |---|---|
214
+ | `list-payroll-employees` | List payroll employees |
215
+ | `list-payroll-employee-leave` | List an employee's leave records |
216
+ | `list-payroll-employee-leave-balances` | List an employee's leave balances |
217
+ | `list-payroll-employee-leave-types` | List leave types for an employee |
218
+ | `list-payroll-leave-periods` | List leave periods for an employee |
219
+ | `list-payroll-leave-types` | List all available leave types |
220
+ | `list-timesheets` | List timesheets |
221
+ | `create-payroll-timesheet` | Create a timesheet |
222
+ | `add-payroll-timesheet-line` | Add a line to a timesheet |
223
+ | `update-payroll-timesheet-line` | Update a timesheet line |
224
+ | `approve-payroll-timesheet` | Approve a timesheet |
225
+ | `revert-payroll-timesheet` | Revert an approved timesheet |
226
+ | `delete-timesheet` | Delete a timesheet |
227
+ | `get-payroll-timesheet` | Get a timesheet by ID |
228
+
229
+ ---
230
+
231
+ ## For Developers
232
+
233
+ ### Local development setup
234
+
235
+ ```bash
236
+ git clone https://github.com/your-org/tn-xero-mcp-server.git
237
+ cd tn-xero-mcp-server
238
+ npm install
239
+ cp .env.example .env
240
+ # Edit .env with your credentials
241
+ npm run build
242
+ ```
243
+
244
+ ### Linking to Claude Desktop for development
245
+
246
+ In your `claude_desktop_config.json`, point directly at the built file:
247
+
248
+ ```json
249
+ {
250
+ "mcpServers": {
251
+ "xero": {
252
+ "command": "node",
253
+ "args": ["C:\\Users\\you\\Development\\Xero-MCP\\dist\\index.js"],
254
+ "env": {
255
+ "XERO_CLIENT_ID": "your_client_id_here",
256
+ "XERO_CLIENT_SECRET": "your_client_secret_here",
257
+ "XERO_ENABLE_PAYROLL": "false",
258
+ "XERO_DOWNLOAD_PATH": "C:\\Users\\you\\Downloads\\Xero"
259
+ }
260
+ }
261
+ }
262
+ }
263
+ ```
264
+
265
+ > **Windows note:** Backslashes in `args` paths must be escaped as `\\`.
266
+
267
+ ### Publishing updates
268
+
269
+ ```bash
270
+ npm run build
271
+ npm publish
272
+ ```
273
+
274
+ ---
275
+
276
+ ## License
277
+
278
+ MIT
279
+
280
+ ## Security
281
+
282
+ Do not commit your `.env` file or any credentials to version control. The `.gitignore` excludes `.env` by default.
@@ -0,0 +1,141 @@
1
+ import axios from "axios";
2
+ import dotenv from "dotenv";
3
+ import { XeroClient, } from "xero-node";
4
+ import { ensureError } from "../helpers/ensure-error.js";
5
+ dotenv.config();
6
+ const client_id = process.env.XERO_CLIENT_ID;
7
+ const client_secret = process.env.XERO_CLIENT_SECRET;
8
+ const bearer_token = process.env.XERO_CLIENT_BEARER_TOKEN;
9
+ const grant_type = "client_credentials";
10
+ if (!bearer_token && (!client_id || !client_secret)) {
11
+ throw Error("Environment Variables not set - please check your .env file");
12
+ }
13
+ /**
14
+ * Builds the OAuth2 scope string based on enabled feature groups.
15
+ *
16
+ * Core scopes are always included. Optional groups are controlled by env vars:
17
+ * XERO_ENABLE_REPORTS — default true (accounting.reports.read)
18
+ * XERO_ENABLE_PAYROLL — default false (payroll.settings/employees/timesheets)
19
+ */
20
+ function buildScopes() {
21
+ const scopes = [
22
+ "accounting.transactions",
23
+ "accounting.contacts",
24
+ "accounting.settings",
25
+ "accounting.attachments",
26
+ ];
27
+ if (process.env.XERO_ENABLE_REPORTS !== "false") {
28
+ scopes.push("accounting.reports.read");
29
+ }
30
+ if (process.env.XERO_ENABLE_PAYROLL === "true") {
31
+ scopes.push("payroll.settings", "payroll.employees", "payroll.timesheets");
32
+ }
33
+ return scopes.join(" ");
34
+ }
35
+ class MCPXeroClient extends XeroClient {
36
+ tenantId;
37
+ shortCode;
38
+ constructor(config) {
39
+ super(config);
40
+ this.tenantId = "";
41
+ this.shortCode = "";
42
+ }
43
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
+ async updateTenants(fullOrgDetails) {
45
+ await super.updateTenants(fullOrgDetails);
46
+ if (this.tenants && this.tenants.length > 0) {
47
+ this.tenantId = this.tenants[0].tenantId;
48
+ }
49
+ return this.tenants;
50
+ }
51
+ async getOrganisation() {
52
+ await this.authenticate();
53
+ const organisationResponse = await this.accountingApi.getOrganisations(this.tenantId || "");
54
+ const organisation = organisationResponse.body.organisations?.[0];
55
+ if (!organisation) {
56
+ throw new Error("Failed to retrieve organisation");
57
+ }
58
+ return organisation;
59
+ }
60
+ async getShortCode() {
61
+ if (!this.shortCode) {
62
+ try {
63
+ const organisation = await this.getOrganisation();
64
+ this.shortCode = organisation.shortCode ?? "";
65
+ }
66
+ catch (error) {
67
+ const err = ensureError(error);
68
+ throw new Error(`Failed to get Organisation short code: ${err.message}`);
69
+ }
70
+ }
71
+ return this.shortCode;
72
+ }
73
+ }
74
+ class CustomConnectionsXeroClient extends MCPXeroClient {
75
+ clientId;
76
+ clientSecret;
77
+ constructor(config) {
78
+ super(config);
79
+ this.clientId = config.clientId;
80
+ this.clientSecret = config.clientSecret;
81
+ }
82
+ async getClientCredentialsToken() {
83
+ const scope = buildScopes();
84
+ const credentials = Buffer.from(`${this.clientId}:${this.clientSecret}`).toString("base64");
85
+ try {
86
+ const response = await axios.post("https://identity.xero.com/connect/token", `grant_type=client_credentials&scope=${encodeURIComponent(scope)}`, {
87
+ headers: {
88
+ Authorization: `Basic ${credentials}`,
89
+ "Content-Type": "application/x-www-form-urlencoded",
90
+ Accept: "application/json",
91
+ },
92
+ });
93
+ // Get the tenant ID from the connections endpoint
94
+ const token = response.data.access_token;
95
+ const connectionsResponse = await axios.get("https://api.xero.com/connections", {
96
+ headers: {
97
+ Authorization: `Bearer ${token}`,
98
+ Accept: "application/json",
99
+ },
100
+ });
101
+ if (connectionsResponse.data && connectionsResponse.data.length > 0) {
102
+ this.tenantId = connectionsResponse.data[0].tenantId;
103
+ }
104
+ return response.data;
105
+ }
106
+ catch (error) {
107
+ const axiosError = error;
108
+ throw new Error(`Failed to get Xero token: ${axiosError.response?.data || axiosError.message}`);
109
+ }
110
+ }
111
+ async authenticate() {
112
+ const tokenResponse = await this.getClientCredentialsToken();
113
+ this.setTokenSet({
114
+ access_token: tokenResponse.access_token,
115
+ expires_in: tokenResponse.expires_in,
116
+ token_type: tokenResponse.token_type,
117
+ });
118
+ }
119
+ }
120
+ class BearerTokenXeroClient extends MCPXeroClient {
121
+ bearerToken;
122
+ constructor(config) {
123
+ super();
124
+ this.bearerToken = config.bearerToken;
125
+ }
126
+ async authenticate() {
127
+ this.setTokenSet({
128
+ access_token: this.bearerToken,
129
+ });
130
+ await this.updateTenants();
131
+ }
132
+ }
133
+ export const xeroClient = bearer_token
134
+ ? new BearerTokenXeroClient({
135
+ bearerToken: bearer_token,
136
+ })
137
+ : new CustomConnectionsXeroClient({
138
+ clientId: client_id,
139
+ clientSecret: client_secret,
140
+ grantType: grant_type,
141
+ });
@@ -0,0 +1,24 @@
1
+ export const invoiceDeepLink = (orgShortCode, invoiceId) => {
2
+ return ` https://go.xero.com/app/${orgShortCode}/invoicing/view/${invoiceId}`;
3
+ };
4
+ export const contactDeepLink = (orgShortCode, contactId) => {
5
+ return ` https://go.xero.com/app/${orgShortCode}/contacts/contact/${contactId}`;
6
+ };
7
+ export const creditNoteDeepLink = (orgShortCode, creditNoteId) => {
8
+ return `https://go.xero.com/organisationlogin/default.aspx?shortcode=${orgShortCode}&redirecturl=/AccountsPayable/ViewCreditNote.aspx?creditNoteID=${creditNoteId}`;
9
+ };
10
+ export const quoteDeepLink = (orgShortCode, quoteId) => {
11
+ return `https://go.xero.com/app/${orgShortCode}/quotes/view/${quoteId}`;
12
+ };
13
+ export const paymentDeepLink = (orgShortCode, paymentId) => {
14
+ return `https://go.xero.com/organisationlogin/default.aspx?shortcode=${orgShortCode}&redirecturl=/Bank/ViewTransaction.aspx?bankTransactionID=${paymentId}`;
15
+ };
16
+ export const bankTransactionDeepLink = (accountId, bankTransactionId) => {
17
+ return `https://go.xero.com/Bank/ViewTransaction.aspx?bankTransactionID=${bankTransactionId}&accountID=${accountId}`;
18
+ };
19
+ export const manualJournalDeepLink = (journalId) => {
20
+ return `https://go.xero.com/Journal/View.aspx?invoiceID=${journalId}`;
21
+ };
22
+ export const billDeepLink = (orgShortCode, billId) => {
23
+ return `https://go.xero.com/organisationlogin/default.aspx?shortcode=${orgShortCode}&redirecturl=/AccountsPayable/Edit.aspx?InvoiceID=${billId}`;
24
+ };
@@ -0,0 +1,28 @@
1
+ import { xeroClient } from "../clients/xero-client.js";
2
+ import { formatError } from "../helpers/format-error.js";
3
+ async function approveTimesheet(timesheetID) {
4
+ await xeroClient.authenticate();
5
+ // Call the approveTimesheet endpoint from the PayrollNZApi
6
+ const approvedTimesheet = await xeroClient.payrollNZApi.approveTimesheet(xeroClient.tenantId, timesheetID);
7
+ return approvedTimesheet.body.timesheet ?? null;
8
+ }
9
+ /**
10
+ * Approve a payroll timesheet in Xero
11
+ */
12
+ export async function approveXeroPayrollTimesheet(timesheetID) {
13
+ try {
14
+ const approvedTimesheet = await approveTimesheet(timesheetID);
15
+ return {
16
+ result: approvedTimesheet,
17
+ isError: false,
18
+ error: null,
19
+ };
20
+ }
21
+ catch (error) {
22
+ return {
23
+ result: null,
24
+ isError: true,
25
+ error: formatError(error),
26
+ };
27
+ }
28
+ }
@@ -0,0 +1,28 @@
1
+ import { xeroClient } from "../clients/xero-client.js";
2
+ import { formatError } from "../helpers/format-error.js";
3
+ import { Contact } from "xero-node";
4
+ import { getClientHeaders } from "../helpers/get-client-headers.js";
5
+ /**
6
+ * Archive a contact in Xero. Xero does not support hard-deleting contacts;
7
+ * archiving sets their status to ARCHIVED and hides them from active lists.
8
+ */
9
+ export async function archiveXeroContact(contactId) {
10
+ try {
11
+ await xeroClient.authenticate();
12
+ const response = await xeroClient.accountingApi.updateContact(xeroClient.tenantId, contactId, {
13
+ contacts: [
14
+ {
15
+ contactID: contactId,
16
+ contactStatus: Contact.ContactStatusEnum.ARCHIVED,
17
+ },
18
+ ],
19
+ }, undefined, getClientHeaders());
20
+ const contact = response.body.contacts?.[0];
21
+ if (!contact)
22
+ throw new Error("Failed to archive contact.");
23
+ return { result: contact, isError: false, error: null };
24
+ }
25
+ catch (error) {
26
+ return { result: null, isError: true, error: formatError(error) };
27
+ }
28
+ }
@@ -0,0 +1,34 @@
1
+ import { xeroClient } from "../clients/xero-client.js";
2
+ import { formatError } from "../helpers/format-error.js";
3
+ import { Invoice } from "xero-node";
4
+ import { getClientHeaders } from "../helpers/get-client-headers.js";
5
+ /**
6
+ * Authorise a DRAFT or SUBMITTED invoice in Xero (promotes it to AUTHORISED).
7
+ */
8
+ export async function authoriseXeroInvoice(invoiceId) {
9
+ try {
10
+ await xeroClient.authenticate();
11
+ const existing = await xeroClient.accountingApi.getInvoice(xeroClient.tenantId, invoiceId, undefined, getClientHeaders());
12
+ const invoice = existing.body.invoices?.[0];
13
+ if (!invoice) {
14
+ throw new Error("Invoice not found.");
15
+ }
16
+ const { status } = invoice;
17
+ if (status !== Invoice.StatusEnum.DRAFT &&
18
+ status !== Invoice.StatusEnum.SUBMITTED) {
19
+ return {
20
+ result: null,
21
+ isError: true,
22
+ error: `Cannot authorise invoice with status ${status}. Only DRAFT or SUBMITTED invoices can be authorised.`,
23
+ };
24
+ }
25
+ const response = await xeroClient.accountingApi.updateInvoice(xeroClient.tenantId, invoiceId, { invoices: [{ status: Invoice.StatusEnum.AUTHORISED }] }, undefined, undefined, getClientHeaders());
26
+ const updated = response.body.invoices?.[0];
27
+ if (!updated)
28
+ throw new Error("Failed to authorise invoice.");
29
+ return { result: updated, isError: false, error: null };
30
+ }
31
+ catch (error) {
32
+ return { result: null, isError: true, error: formatError(error) };
33
+ }
34
+ }
@@ -0,0 +1,50 @@
1
+ import { xeroClient } from "../clients/xero-client.js";
2
+ import { formatError } from "../helpers/format-error.js";
3
+ import { Invoice } from "xero-node";
4
+ import { getClientHeaders } from "../helpers/get-client-headers.js";
5
+ /**
6
+ * Convert an ACCEPTED quote into a draft ACCREC invoice in Xero.
7
+ * Line items, contact, and reference are copied from the quote.
8
+ */
9
+ export async function convertXeroQuoteToInvoice(quoteId, dueDate) {
10
+ try {
11
+ await xeroClient.authenticate();
12
+ const quoteResponse = await xeroClient.accountingApi.getQuote(xeroClient.tenantId, quoteId, getClientHeaders());
13
+ const quote = quoteResponse.body.quotes?.[0];
14
+ if (!quote)
15
+ throw new Error("Quote not found.");
16
+ if (!quote.contact?.contactID) {
17
+ throw new Error("Quote has no associated contact.");
18
+ }
19
+ const today = new Date().toISOString().split("T")[0];
20
+ const defaultDueDate = new Date(Date.now() + 30 * 24 * 60 * 60 * 1000)
21
+ .toISOString()
22
+ .split("T")[0];
23
+ const invoice = {
24
+ type: Invoice.TypeEnum.ACCREC,
25
+ contact: { contactID: quote.contact.contactID },
26
+ date: today,
27
+ dueDate: dueDate ?? defaultDueDate,
28
+ reference: quote.quoteNumber,
29
+ lineItems: (quote.lineItems ?? []).map((li) => ({
30
+ description: li.description,
31
+ quantity: li.quantity,
32
+ unitAmount: li.unitAmount,
33
+ accountCode: li.accountCode,
34
+ taxType: li.taxType,
35
+ itemCode: li.itemCode,
36
+ lineItemID: undefined, // let Xero assign a new ID
37
+ })),
38
+ lineAmountTypes: quote.lineAmountTypes,
39
+ status: Invoice.StatusEnum.DRAFT,
40
+ };
41
+ const invoiceResponse = await xeroClient.accountingApi.createInvoices(xeroClient.tenantId, { invoices: [invoice] }, true, undefined, undefined, getClientHeaders());
42
+ const created = invoiceResponse.body.invoices?.[0];
43
+ if (!created)
44
+ throw new Error("Invoice creation from quote failed.");
45
+ return { result: created, isError: false, error: null };
46
+ }
47
+ catch (error) {
48
+ return { result: null, isError: true, error: formatError(error) };
49
+ }
50
+ }
@@ -0,0 +1,51 @@
1
+ import { xeroClient } from "../clients/xero-client.js";
2
+ import { BankTransaction } from "xero-node";
3
+ import { formatError } from "../helpers/format-error.js";
4
+ import { getClientHeaders } from "../helpers/get-client-headers.js";
5
+ import { localDateString } from "../helpers/datetime.js";
6
+ async function createBankTransaction(type, bankAccountId, contactId, lineItems, reference, date) {
7
+ await xeroClient.authenticate();
8
+ const bankTransaction = {
9
+ type: BankTransaction.TypeEnum[type],
10
+ bankAccount: {
11
+ accountID: bankAccountId
12
+ },
13
+ contact: {
14
+ contactID: contactId
15
+ },
16
+ lineItems: lineItems,
17
+ date: date ?? localDateString(),
18
+ reference: reference,
19
+ status: BankTransaction.StatusEnum.AUTHORISED
20
+ };
21
+ const response = await xeroClient.accountingApi.createBankTransactions(xeroClient.tenantId, // xeroTenantId
22
+ {
23
+ bankTransactions: [bankTransaction]
24
+ }, // bankTransactions
25
+ true, // summarizeErrors
26
+ undefined, // unitdp
27
+ undefined, // idempotencyKey
28
+ getClientHeaders());
29
+ const createdBankTransaction = response.body.bankTransactions?.[0];
30
+ return createdBankTransaction;
31
+ }
32
+ export async function createXeroBankTransaction(type, bankAccountId, contactId, lineItems, reference, date) {
33
+ try {
34
+ const createdTransaction = await createBankTransaction(type, bankAccountId, contactId, lineItems, reference, date);
35
+ if (!createdTransaction) {
36
+ throw new Error("Bank transaction creation failed.");
37
+ }
38
+ return {
39
+ result: createdTransaction,
40
+ isError: false,
41
+ error: null
42
+ };
43
+ }
44
+ catch (error) {
45
+ return {
46
+ result: null,
47
+ isError: true,
48
+ error: formatError(error)
49
+ };
50
+ }
51
+ }