@teamnetwork-nz/xero-mcp-server 1.15.0 → 1.15.2

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.
package/README.md CHANGED
@@ -106,9 +106,12 @@ Scopes and tools are controlled by environment variables. This means you only pr
106
106
  | *(core — always on)* | — | `accounting.transactions` `accounting.contacts` `accounting.settings` `accounting.attachments` `accounting.journals.read` | All invoicing, contact, payment, attachment, PDF & journal tools |
107
107
  | `XERO_ENABLE_REPORTS` | `true` | `accounting.reports.read` | Trial Balance, P&L, Balance Sheet, Aged Payables/Receivables |
108
108
  | `XERO_ENABLE_PAYROLL` | `false` | `payroll.settings` `payroll.employees` `payroll.timesheets` | All payroll tools |
109
+ | `XERO_READWRITE` | `false` | No additional scopes | Create, update, and delete tools |
109
110
 
110
111
  > **Note:** To use payroll tools, your Xero region must be **NZ** or **UK**, and your Xero app must have the payroll scopes provisioned.
111
112
 
113
+ `XERO_ENABLE_READWRITE=true` remains a deprecated compatibility alias for one release. `XERO_READWRITE` takes precedence when both are set.
114
+
112
115
  ### Full configuration example
113
116
 
114
117
  ```json
@@ -122,6 +125,7 @@ Scopes and tools are controlled by environment variables. This means you only pr
122
125
  "XERO_CLIENT_SECRET": "your_client_secret_here",
123
126
  "XERO_ENABLE_REPORTS": "true",
124
127
  "XERO_ENABLE_PAYROLL": "false",
128
+ "XERO_READWRITE": "false",
125
129
  "XERO_DOWNLOAD_PATH": "C:/Users/you/Downloads/Xero"
126
130
  }
127
131
  }
@@ -152,8 +156,8 @@ Date inputs to the Xero API (invoice dates, fromDate, toDate, etc.) are `YYYY-MM
152
156
  ### Invoices
153
157
  | Tool | Description |
154
158
  |---|---|
155
- | `list-invoices` | List invoices with optional filters: status, contact, invoice number, date range |
156
- | `xero_search_transactions` | Structured search by invoice number, reference, supplier/contact, date, amount, status and type |
159
+ | `list-invoices` | List invoices and filter direction with `type=ACCREC` (AR sales invoices) or `type=ACCPAY` (AP purchase bills) |
160
+ | `xero_search_transactions` | Structured invoice/bill search; set `type=ACCREC` for AR or `type=ACCPAY` for AP, because contact filters do not infer direction |
157
161
  | `xero_batch_invoice_lookup` | Native exact lookup for up to 100 invoice numbers with per-input duplicate/unmatched results |
158
162
  | `xero_lookup_invoice` | Scalar exact invoice-number lookup for clients affected by Hermes array coercion |
159
163
  | `get-invoice` | Get full details of a single invoice including all line items |
@@ -182,8 +186,8 @@ Date inputs to the Xero API (invoice dates, fromDate, toDate, etc.) are `YYYY-MM
182
186
  ### Contacts
183
187
  | Tool | Description |
184
188
  |---|---|
185
- | `list-contacts` | List contacts with optional search term |
186
- | `xero_find_contact` | Resolve a contact by ID, name, contact/account number, email or tax number without silently choosing ambiguous matches |
189
+ | `list-contacts` | List contacts; `contactRole=customer` filters AR customers and `contactRole=supplier` filters AP suppliers; omit it to include unclassified contacts |
190
+ | `xero_find_contact` | Resolve a contact without silently choosing ambiguous matches; `role` is optional because contacts may be customer, supplier, both, or `Unknown` |
187
191
  | `create-contact` | Create a new contact |
188
192
  | `update-contact` | Update an existing contact |
189
193
  | `archive-contact` | Archive a contact (Xero does not support hard deletion) |
@@ -256,6 +260,24 @@ Attachment filenames are non-authoritative and may contain amounts that differ f
256
260
  bill's gross total. Use Xero invoice `SubTotal`, `TotalTax`, and `Total` fields for financial
257
261
  reconciliation, and retrieve binary attachment content only when explicitly needed.
258
262
 
263
+ ### AP and AR filtering
264
+
265
+ Invoice direction is explicit. `ACCREC` means Accounts Receivable sales invoices (money owed
266
+ to you by customers); `ACCPAY` means Accounts Payable purchase bills (money you owe suppliers).
267
+ Use the `type` filter on `list-invoices`, `xero_search_transactions`, and exact invoice lookup
268
+ tools whenever direction matters. Omitting `type` searches both. A `supplier` or `contactId`
269
+ filter identifies the contact on the transaction but does not automatically select `ACCPAY`.
270
+
271
+ Contact role is related but separate. `customer` means Xero's `IsCustomer` flag is true and
272
+ `supplier` means `IsSupplier` is true. A contact can be a customer, supplier, both, or neither
273
+ (`Type: Unknown`). Omit `role`/`contactRole` when unclassified contacts must remain searchable.
274
+ These role filters do not filter invoice direction; combine contact resolution with an explicit
275
+ invoice `type` for an AP- or AR-specific workflow.
276
+
277
+ `xero_search_transactions` searches invoices and bills. Bank transactions are a separate Xero
278
+ resource accessed with `list-bank-transactions`, using `RECEIVE` and `SPEND` transaction types
279
+ rather than `ACCREC` and `ACCPAY`.
280
+
259
281
  ### Payroll *(requires `XERO_ENABLE_PAYROLL=true`)*
260
282
  | Tool | Description |
261
283
  |---|---|
@@ -2,14 +2,14 @@ import axios from "axios";
2
2
  import dotenv from "dotenv";
3
3
  import { XeroClient, } from "xero-node";
4
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;
5
+ import { loadXeroCredentials } from "../helpers/xero-config.js";
6
+ import { readWriteEnabled } from "../helpers/write-gate.js";
7
+ dotenv.config({ quiet: true });
8
+ const credentials = loadXeroCredentials();
9
+ const client_id = credentials.clientId;
10
+ const client_secret = credentials.clientSecret;
11
+ const bearer_token = credentials.bearerToken;
9
12
  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
13
  /**
14
14
  * Builds the OAuth2 scope string based on enabled feature groups.
15
15
  *
@@ -131,6 +131,24 @@ class BearerTokenXeroClient extends MCPXeroClient {
131
131
  await this.updateTenants();
132
132
  }
133
133
  }
134
+ const writeEnabled = readWriteEnabled("XERO_READWRITE", { name: "XERO_ENABLE_READWRITE" });
135
+ export function assertXeroWritable() {
136
+ if (!writeEnabled)
137
+ throw new Error("Write operations are disabled. Set XERO_READWRITE=true to enable them.");
138
+ }
139
+ function writeProtectedApi(api) {
140
+ if (writeEnabled)
141
+ return api;
142
+ return new Proxy(api, {
143
+ get(target, property, receiver) {
144
+ const value = Reflect.get(target, property, receiver);
145
+ if (typeof property === "string" && typeof value === "function" && /^(create|update|delete|archive|void|approve|revert)/i.test(property)) {
146
+ return () => Promise.reject(new Error("Write operations are disabled. Set XERO_READWRITE=true to enable them."));
147
+ }
148
+ return typeof value === "function" ? value.bind(target) : value;
149
+ },
150
+ });
151
+ }
134
152
  export const xeroClient = bearer_token
135
153
  ? new BearerTokenXeroClient({
136
154
  bearerToken: bearer_token,
@@ -140,3 +158,8 @@ export const xeroClient = bearer_token
140
158
  clientSecret: client_secret,
141
159
  grantType: grant_type,
142
160
  });
161
+ if (!writeEnabled) {
162
+ const mutable = xeroClient;
163
+ mutable.accountingApi = writeProtectedApi(mutable.accountingApi);
164
+ mutable.payrollNZApi = writeProtectedApi(mutable.payrollNZApi);
165
+ }
package/dist/env.js ADDED
@@ -0,0 +1,12 @@
1
+ export function parsePositiveInt(name, raw, fallback, maximum) {
2
+ if (raw === undefined || raw.trim() === '')
3
+ return fallback;
4
+ if (!/^\d+$/.test(raw.trim())) {
5
+ throw new Error(`${name} must be an integer from 1 to ${maximum}`);
6
+ }
7
+ const value = Number(raw);
8
+ if (!Number.isSafeInteger(value) || value < 1 || value > maximum) {
9
+ throw new Error(`${name} must be an integer from 1 to ${maximum}`);
10
+ }
11
+ return value;
12
+ }
@@ -1,5 +1,5 @@
1
1
  import axios from "axios";
2
- import { xeroClient } from "../clients/xero-client.js";
2
+ import { assertXeroWritable, xeroClient } from "../clients/xero-client.js";
3
3
  import { formatError } from "../helpers/format-error.js";
4
4
  /**
5
5
  * Delete an attachment from an invoice by its attachment ID.
@@ -9,6 +9,7 @@ import { formatError } from "../helpers/format-error.js";
9
9
  */
10
10
  export async function deleteXeroInvoiceAttachment(invoiceId, attachmentId) {
11
11
  try {
12
+ assertXeroWritable();
12
13
  await xeroClient.authenticate();
13
14
  const tokenSet = xeroClient.readTokenSet();
14
15
  const accessToken = tokenSet.access_token;
@@ -18,7 +18,9 @@ export function filterContactMatches(contacts, params) {
18
18
  (!params.email || matches(contact.emailAddress, params.email, exact)) &&
19
19
  (!params.taxNumber || matches(contact.taxNumber, params.taxNumber, exact)));
20
20
  }
21
- function compactContact(contact) {
21
+ export function compactContact(contact) {
22
+ const isCustomer = contact.isCustomer ?? false;
23
+ const isSupplier = contact.isSupplier ?? false;
22
24
  return {
23
25
  contactId: contact.contactID ?? "",
24
26
  name: contact.name ?? null,
@@ -27,8 +29,15 @@ function compactContact(contact) {
27
29
  email: contact.emailAddress ?? null,
28
30
  taxNumber: contact.taxNumber ?? null,
29
31
  status: contact.contactStatus ? String(contact.contactStatus) : null,
30
- isCustomer: contact.isCustomer ?? false,
31
- isSupplier: contact.isSupplier ?? false,
32
+ isCustomer,
33
+ isSupplier,
34
+ type: isCustomer && isSupplier
35
+ ? "Customer, Supplier"
36
+ : isCustomer
37
+ ? "Customer"
38
+ : isSupplier
39
+ ? "Supplier"
40
+ : "Unknown",
32
41
  };
33
42
  }
34
43
  export async function findXeroContact(params) {
@@ -48,7 +57,7 @@ export async function findXeroContact(params) {
48
57
  const filtered = filterContactMatches(raw, params);
49
58
  const truncated = raw.length > params.pageSize || filtered.length > params.pageSize;
50
59
  const matchesFound = filtered.slice(0, params.pageSize).map(compactContact);
51
- return successfulLookup(matchesFound, params.matchMode === "exact", {
60
+ const result = successfulLookup(matchesFound, params.matchMode === "exact", {
52
61
  page: params.page,
53
62
  pageSize: params.pageSize,
54
63
  returned: matchesFound.length,
@@ -56,8 +65,20 @@ export async function findXeroContact(params) {
56
65
  nextPage: truncated ? params.page + 1 : null,
57
66
  complete: !truncated,
58
67
  });
68
+ const notFound = result.matchStatus === "NOT_FOUND";
69
+ return {
70
+ ...result,
71
+ notFoundReason: notFound ? "NO_IDENTIFIER_MATCH" : null,
72
+ hint: notFound
73
+ ? "No contact matched the supplied identifier(s). This does not prove the contact does not exist: the searched field may be blank or stored differently in Xero. Try a known name with matchMode=contains and omit role to search all contact types."
74
+ : null,
75
+ };
59
76
  }
60
77
  catch (error) {
61
- return failedLookup(formatError(error));
78
+ return {
79
+ ...failedLookup(formatError(error)),
80
+ notFoundReason: null,
81
+ hint: null,
82
+ };
62
83
  }
63
84
  }
@@ -18,3 +18,17 @@ export function getPackageVersion() {
18
18
  return '0.0.0'; // Fallback version
19
19
  }
20
20
  }
21
+ /** Gets the published package name from package.json. */
22
+ export function getPackageName() {
23
+ const __filename = fileURLToPath(import.meta.url);
24
+ const __dirname = dirname(__filename);
25
+ const packagePath = join(__dirname, '../../package.json');
26
+ try {
27
+ const packageJson = JSON.parse(readFileSync(packagePath, 'utf-8'));
28
+ return packageJson.name ?? 'xero-mcp-server';
29
+ }
30
+ catch (error) {
31
+ console.warn('Failed to read package name:', error);
32
+ return 'xero-mcp-server';
33
+ }
34
+ }
@@ -0,0 +1,10 @@
1
+ export function readWriteEnabled(canonicalName, legacy, env = process.env) {
2
+ const canonical = env[canonicalName];
3
+ if (canonical !== undefined)
4
+ return canonical.toLowerCase() === 'true';
5
+ if (!legacy || env[legacy.name] === undefined)
6
+ return false;
7
+ process.stderr.write(`[deprecated] ${legacy.name} is deprecated; use ${canonicalName}=true to enable writes.\n`);
8
+ const value = env[legacy.name].toLowerCase();
9
+ return legacy.readonlySemantics ? value === 'false' : value === 'true';
10
+ }
@@ -0,0 +1,21 @@
1
+ import { z } from 'zod';
2
+ export const XeroCredentialSchema = z.object({
3
+ clientId: z.string().min(1).optional(),
4
+ clientSecret: z.string().min(1).optional(),
5
+ bearerToken: z.string().min(1).optional(),
6
+ }).strict().superRefine((value, ctx) => {
7
+ const hasPair = Boolean(value.clientId && value.clientSecret);
8
+ if (!value.bearerToken && !hasPair) {
9
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Set XERO_CLIENT_BEARER_TOKEN, or set both XERO_CLIENT_ID and XERO_CLIENT_SECRET' });
10
+ }
11
+ if ((value.clientId && !value.clientSecret) || (!value.clientId && value.clientSecret)) {
12
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'XERO_CLIENT_ID and XERO_CLIENT_SECRET must be set together' });
13
+ }
14
+ });
15
+ export function loadXeroCredentials() {
16
+ return XeroCredentialSchema.parse({
17
+ clientId: process.env.XERO_CLIENT_ID?.trim() || undefined,
18
+ clientSecret: process.env.XERO_CLIENT_SECRET || undefined,
19
+ bearerToken: process.env.XERO_CLIENT_BEARER_TOKEN || undefined,
20
+ });
21
+ }
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import { XeroMcpServer } from "./server/xero-mcp-server.js";
4
4
  import { ToolFactory } from "./tools/tool-factory.js";
5
5
  import { registerResources } from "./resources/register-resources.js";
6
6
  import { createHttpServer } from "./http-server.js";
7
+ import { parsePositiveInt } from "./env.js";
7
8
  const main = async () => {
8
9
  const createConfiguredServer = () => {
9
10
  const server = XeroMcpServer.GetServer(true);
@@ -14,8 +15,8 @@ const main = async () => {
14
15
  // Start receiving messages on stdin and sending messages on stdout
15
16
  if ((process.env["XERO_TRANSPORT"] ?? "stdio") === "http") {
16
17
  const host = process.env["XERO_HTTP_HOST"] ?? "127.0.0.1";
17
- const port = Number.parseInt(process.env["XERO_HTTP_PORT"] ?? "3000", 10);
18
- createHttpServer(createConfiguredServer, { host, port, serverName: "@teamnetwork-nz/xero-mcp-server", bearerToken: process.env["XERO_HTTP_BEARER_TOKEN"], allowedHosts: process.env["XERO_HTTP_ALLOWED_HOSTS"]?.split(",").map(v => v.trim()).filter(Boolean), allowedOrigins: process.env["XERO_HTTP_ALLOWED_ORIGINS"]?.split(",").map(v => v.trim()).filter(Boolean), maxBodyBytes: Number.parseInt(process.env["XERO_HTTP_MAX_BODY_BYTES"] ?? "1048576", 10) }).listen(port, host, () => console.error(`[xero-mcp] HTTP listening on ${host}:${port}/mcp`));
18
+ const port = parsePositiveInt("XERO_HTTP_PORT", process.env["XERO_HTTP_PORT"], 3000, 65535);
19
+ createHttpServer(createConfiguredServer, { host, port, serverName: "@teamnetwork-nz/xero-mcp-server", bearerToken: process.env["XERO_HTTP_BEARER_TOKEN"], allowedHosts: process.env["XERO_HTTP_ALLOWED_HOSTS"]?.split(",").map(v => v.trim()).filter(Boolean), allowedOrigins: process.env["XERO_HTTP_ALLOWED_ORIGINS"]?.split(",").map(v => v.trim()).filter(Boolean), maxBodyBytes: parsePositiveInt("XERO_HTTP_MAX_BODY_BYTES", process.env["XERO_HTTP_MAX_BODY_BYTES"], 1_048_576, 16_777_216) }).listen(port, host, () => process.stderr.write(`[xero-mcp] HTTP listening on ${host}:${port}/mcp\n`));
19
20
  }
20
21
  else {
21
22
  await createConfiguredServer().connect(new StdioServerTransport());
@@ -1,12 +1,13 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
- import { getPackageVersion } from "../helpers/get-package-version.js";
2
+ import { getPackageName, getPackageVersion } from "../helpers/get-package-version.js";
3
+ import { enforceStrictToolInputs } from "../strict-tools.js";
3
4
  export class XeroMcpServer {
4
5
  static instance = null;
5
6
  constructor() { }
6
7
  static GetServer(fresh = false) {
7
8
  if (fresh || XeroMcpServer.instance === null) {
8
9
  XeroMcpServer.instance = new McpServer({
9
- name: "Xero MCP Server",
10
+ name: getPackageName(),
10
11
  version: getPackageVersion(),
11
12
  }, {
12
13
  instructions: [
@@ -43,6 +44,7 @@ export class XeroMcpServer {
43
44
  "For a full query playbook read the MCP resource: xero://guidance/agent-playbook",
44
45
  ].join("\n"),
45
46
  });
47
+ enforceStrictToolInputs(XeroMcpServer.instance);
46
48
  }
47
49
  return XeroMcpServer.instance;
48
50
  }
@@ -0,0 +1,29 @@
1
+ import { z } from "zod";
2
+ function isSchema(value) {
3
+ return typeof value === "object" && value !== null && "_def" in value;
4
+ }
5
+ function isRawShape(value) {
6
+ if (typeof value !== "object" || value === null || isSchema(value))
7
+ return false;
8
+ const values = Object.values(value);
9
+ return values.length === 0 || values.some(isSchema);
10
+ }
11
+ function strictSchema(schema) {
12
+ if (schema === undefined)
13
+ return z.object({}).strict();
14
+ if (isRawShape(schema))
15
+ return z.object(schema).strict();
16
+ if (isSchema(schema) && typeof schema.strict === "function")
17
+ return schema.strict();
18
+ return schema;
19
+ }
20
+ /** Make every tool object reject undeclared arguments, including no-argument tools. */
21
+ export function enforceStrictToolInputs(server) {
22
+ const mutable = server;
23
+ const createRegisteredTool = mutable._createRegisteredTool.bind(server);
24
+ mutable._createRegisteredTool = (...args) => {
25
+ // SDK 1.29 funnels both tool() and registerTool() through this method.
26
+ args[3] = strictSchema(args[3]);
27
+ return createRegisteredTool(...args);
28
+ };
29
+ }
@@ -4,6 +4,6 @@ import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
4
4
  import { jsonToolResponse } from "../../types/lookup-result.js";
5
5
  const BatchInvoiceLookupTool = CreateXeroTool("xero_batch_invoice_lookup", "Look up multiple exact Xero InvoiceNumber values in one batch request. Accepts an array of strings, preserves numeric-looking invoice numbers as strings, and reports exact matches, duplicates, and unmatched values for each input.", {
6
6
  invoiceNumbers: z.array(z.string().min(1)).min(1).max(100),
7
- type: z.enum(["ACCREC", "ACCPAY"]).optional(),
7
+ type: z.enum(["ACCREC", "ACCPAY"]).optional().describe("ACCREC = AR sales/customer invoices; ACCPAY = AP purchase/supplier bills. Omit to search both."),
8
8
  }, async ({ invoiceNumbers, type }) => jsonToolResponse(await batchXeroInvoiceLookup(invoiceNumbers, type)));
9
9
  export default BatchInvoiceLookupTool;
@@ -3,15 +3,15 @@ import { findXeroContact } from "../../handlers/find-xero-contact.handler.js";
3
3
  import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
4
4
  import { failedLookup, jsonToolResponse } from "../../types/lookup-result.js";
5
5
  import { STRUCTURED_PAGE_GUIDANCE } from "../../helpers/pagination-guidance.js";
6
- const FindContactTool = CreateXeroTool("xero_find_contact", "Resolve a Xero customer or supplier using supported identifiers. Ambiguous matches are returned explicitly and never selected automatically.", {
6
+ const FindContactTool = CreateXeroTool("xero_find_contact", "Resolve a Xero contact using one or more supported identifiers. role is optional: role=customer filters IsCustomer=true for AR workflows; role=supplier filters IsSupplier=true for AP workflows. These are contact classifications, not invoice-direction filters: a contact may be a customer, supplier, both, or Type: Unknown. Omit role to search every classification, including Unknown. Name matching is case-insensitive: use matchMode=contains when you have a partial name (for example, 'Servers Australia' can match 'Servers Australia Pty Ltd'), or exact when you require the complete name. Ambiguous matches are returned explicitly and never selected automatically. NOT_FOUND means no contact matched the supplied identifier(s), not that the contact cannot exist; the searched field may be blank in Xero.", {
7
7
  contactId: z.string().uuid().optional(),
8
- name: z.string().min(1).optional(),
8
+ name: z.string().min(1).optional().describe("Contact name. Matching is case-insensitive; use matchMode=contains for a partial name."),
9
9
  contactNumber: z.string().min(1).optional(),
10
10
  accountNumber: z.string().min(1).optional(),
11
11
  email: z.string().email().optional(),
12
12
  taxNumber: z.string().min(1).optional().describe("GST/VAT/ABN/NZBN tax identifier as stored by Xero."),
13
- role: z.enum(["customer", "supplier"]).optional(),
14
- matchMode: z.enum(["exact", "contains"]).default("exact"),
13
+ role: z.enum(["customer", "supplier"]).optional().describe("Contact classification: customer = IsCustomer=true (AR), supplier = IsSupplier=true (AP). Contacts may be both or neither. This does not filter invoice direction. Omit to include Type: Unknown."),
14
+ matchMode: z.enum(["exact", "contains"]).default("exact").describe("Case-insensitive matching mode. Use contains for a partial name; exact requires the complete field value."),
15
15
  page: z.number().int().min(1).default(1).describe(`Page number for paginated matches. ${STRUCTURED_PAGE_GUIDANCE}`),
16
16
  pageSize: z.number().int().min(1).max(50).default(10).describe(`Maximum matches returned on this page (1-50, default 10). ${STRUCTURED_PAGE_GUIDANCE}`),
17
17
  }, async (params) => {
@@ -5,18 +5,18 @@ import { z } from "zod";
5
5
  import { formatUtcDatetime } from "../../helpers/datetime.js";
6
6
  const ListContactsTool = CreateXeroTool("list-contacts", "List contacts from Xero. " +
7
7
  "Use searchTerm for name/email lookup — do NOT list all contacts and scan them. " +
8
- "Use contactRole to restrict to customers (AR workflows) or suppliers (AP workflows). " +
8
+ "Use contactRole to restrict to customers (IsCustomer=true, AR workflows) or suppliers (IsSupplier=true, AP workflows). This is a contact classification, not an invoice-direction filter; contacts may be customer, supplier, both, or neither. Omit contactRole to include Type: Unknown. " +
9
9
  "Common patterns: " +
10
10
  "find a customer by name → searchTerm=<name>, contactRole=customer; " +
11
11
  "all active suppliers → contactRole=supplier, status=ACTIVE; " +
12
12
  "recently updated contacts → fromDate=<date>. " +
13
13
  "Each contact in the response includes: name, contactID, firstName, lastName, emailAddress, " +
14
- "accountNumber (user-defined), taxNumber (NZBN/ABN/VAT), isCustomer/isSupplier flags, " +
14
+ "accountNumber (user-defined), taxNumber (NZBN/ABN/VAT), and Type derived from the isCustomer/isSupplier flags (Customer, Supplier, both, or Unknown). Type: Unknown means the contact is not classified as either role, not that it does not exist. " +
15
15
  "phones (type + number, short form), addresses (type + line1/city/region/postcode/country, short form), " +
16
16
  "AR/AP tax types, defaultCurrency, contactStatus, contactGroups, and lastUpdated.", {
17
17
  page: z.number().optional().describe(`Page number for pagination (starts at 1). ${PAGE_NUMBER_GUIDANCE}`),
18
18
  searchTerm: z.string().optional().describe("Case-insensitive search across Name, FirstName, LastName, ContactNumber, EmailAddress. Use this instead of listing all contacts."),
19
- contactRole: z.enum(["customer", "supplier"]).optional().describe("Filter to customers only (IsCustomer==true) or suppliers only (IsSupplier==true). Use customer for AR work, supplier for AP work."),
19
+ contactRole: z.enum(["customer", "supplier"]).optional().describe("Contact classification filter: customer = IsCustomer==true (AR), supplier = IsSupplier==true (AP). Contacts can be both or neither. This does not filter invoices; omit it to include Type: Unknown."),
20
20
  fromDate: z.string().optional().describe("Return contacts updated on or after this date (YYYY-MM-DD)."),
21
21
  toDate: z.string().optional().describe("Return contacts updated on or before this date (YYYY-MM-DD)."),
22
22
  status: z.enum(["ACTIVE", "ARCHIVED"]).optional().describe("Filter by contact status. Defaults to ACTIVE (excludes archived contacts). Pass ARCHIVED only if you specifically need deactivated contacts."),
@@ -4,6 +4,6 @@ import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
4
4
  import { jsonToolResponse } from "../../types/lookup-result.js";
5
5
  const LookupInvoiceTool = CreateXeroTool("xero_lookup_invoice", "Look up one Xero invoice or purchase bill by its exact InvoiceNumber value and report exact, duplicate, or unmatched results.", {
6
6
  invoiceNumber: z.string().min(1),
7
- type: z.enum(["ACCREC", "ACCPAY"]).optional(),
7
+ type: z.enum(["ACCREC", "ACCPAY"]).optional().describe("ACCREC = AR sales/customer invoices; ACCPAY = AP purchase/supplier bills. Omit to search both."),
8
8
  }, async ({ invoiceNumber, type }) => jsonToolResponse(await batchXeroInvoiceLookup([invoiceNumber], type)));
9
9
  export default LookupInvoiceTool;
@@ -3,18 +3,18 @@ import { searchXeroTransactions } from "../../handlers/search-xero-transactions.
3
3
  import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
4
4
  import { jsonToolResponse } from "../../types/lookup-result.js";
5
5
  import { STRUCTURED_PAGE_GUIDANCE } from "../../helpers/pagination-guidance.js";
6
- const SearchTransactionsTool = CreateXeroTool("xero_search_transactions", "Search Xero sales invoices and purchase bills by invoice number, reference, contact, date, amount, status, or type. Uses Xero server-side filters where available, verifies the requested match mode, and returns compact match, ambiguity, pagination, and error metadata.", {
6
+ const SearchTransactionsTool = CreateXeroTool("xero_search_transactions", "Search Xero sales invoices and purchase bills by invoice number, reference, contact, date, amount, status, or type. Set type=ACCREC for Accounts Receivable sales invoices (money owed to you) or type=ACCPAY for Accounts Payable purchase bills (money you owe); omitting type searches both. The supplier and contactId filters identify the contact but do not imply ACCPAY or ACCREC, so set type whenever direction matters. This tool searches invoices/bills, not bank transactions. Uses Xero server-side filters where available, verifies the requested match mode, and returns compact match, ambiguity, pagination, and error metadata.", {
7
7
  invoiceNumber: z.string().min(1).optional(),
8
8
  reference: z.string().min(1).optional(),
9
- contactId: z.string().uuid().optional(),
10
- supplier: z.string().min(1).optional().describe("Contact/supplier name."),
9
+ contactId: z.string().uuid().optional().describe("Contact on the invoice or bill. Does not imply ACCREC or ACCPAY; set type separately."),
10
+ supplier: z.string().min(1).optional().describe("Contact name on an invoice or bill. Despite the parameter name, this can match either AR or AP and does not imply ACCPAY; set type separately."),
11
11
  fromDate: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional(),
12
12
  toDate: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional(),
13
13
  amount: z.number().nonnegative().optional().describe("Exact invoice total."),
14
14
  minAmount: z.number().nonnegative().optional(),
15
15
  maxAmount: z.number().nonnegative().optional(),
16
16
  statuses: z.array(z.enum(["DRAFT", "SUBMITTED", "AUTHORISED", "PAID", "VOIDED", "DELETED"])).min(1).optional(),
17
- type: z.enum(["ACCREC", "ACCPAY"]).optional(),
17
+ type: z.enum(["ACCREC", "ACCPAY"]).optional().describe("ACCREC = AR sales/customer invoices; ACCPAY = AP purchase/supplier bills. Omit only when both directions are wanted."),
18
18
  matchMode: z.enum(["exact", "contains", "candidate"]).default("exact"),
19
19
  page: z.number().int().min(1).default(1).describe(`Page number for paginated matches. ${STRUCTURED_PAGE_GUIDANCE}`),
20
20
  pageSize: z.number().int().min(1).max(100).default(25).describe(`Maximum matches returned on this page (1-100, default 25). ${STRUCTURED_PAGE_GUIDANCE}`),
@@ -3,10 +3,11 @@ import { CoreDeleteTools, PayrollDeleteTools } from "./delete/index.js";
3
3
  import { CoreGetTools, PayrollGetTools } from "./get/index.js";
4
4
  import { CoreListTools, ReportListTools, PayrollListTools } from "./list/index.js";
5
5
  import { CoreUpdateTools, PayrollUpdateTools } from "./update/index.js";
6
+ import { readWriteEnabled } from "../helpers/write-gate.js";
6
7
  export function ToolFactory(server) {
7
8
  const enableReports = process.env.XERO_ENABLE_REPORTS !== "false";
8
9
  const enablePayroll = process.env.XERO_ENABLE_PAYROLL === "true";
9
- const enableReadWrite = process.env.XERO_ENABLE_READWRITE === "true";
10
+ const enableReadWrite = readWriteEnabled("XERO_READWRITE", { name: "XERO_ENABLE_READWRITE" });
10
11
  const allTools = [
11
12
  ...CoreListTools,
12
13
  ...CoreGetTools,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamnetwork-nz/xero-mcp-server",
3
- "version": "1.15.0",
3
+ "version": "1.15.2",
4
4
  "description": "MCP server implementation for Xero integration - TEAMnetwork",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -19,11 +19,11 @@
19
19
  "lint": "eslint ."
20
20
  },
21
21
  "dependencies": {
22
- "@modelcontextprotocol/sdk": "^1.23.4",
22
+ "@modelcontextprotocol/sdk": "^1.29.0",
23
23
  "dotenv": "^16.4.7",
24
24
  "openid-client": "^6.8.1",
25
25
  "xero-node": "^13.3.0",
26
- "zod": "3.25"
26
+ "zod": "^3.25.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@eslint/js": "^9.39.1",