@teamnetwork-nz/xero-mcp-server 1.14.1 → 1.15.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.
- package/README.md +20 -2
- package/dist/handlers/list-xero-profit-and-loss.handler.js +16 -3
- package/dist/helpers/pagination-guidance.js +3 -0
- package/dist/http-server.js +83 -0
- package/dist/index.js +15 -6
- package/dist/server/xero-mcp-server.js +2 -2
- package/dist/tools/list/find-contact.tool.js +3 -2
- package/dist/tools/list/list-bank-transactions.tool.js +3 -2
- package/dist/tools/list/list-bill-attachments.tool.js +1 -1
- package/dist/tools/list/list-contacts.tool.js +3 -2
- package/dist/tools/list/list-credit-notes.tool.js +3 -2
- package/dist/tools/list/list-invoices.tool.js +3 -2
- package/dist/tools/list/list-manual-journals.tool.js +3 -2
- package/dist/tools/list/list-overpayments.tool.js +3 -2
- package/dist/tools/list/list-payments.tool.js +3 -2
- package/dist/tools/list/list-prepayments.tool.js +3 -2
- package/dist/tools/list/list-quotes.tool.js +1 -1
- package/dist/tools/list/search-transactions.tool.js +3 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# TEAMnetwork Xero MCP Server
|
|
2
2
|
|
|
3
|
+
## Streamable HTTP
|
|
4
|
+
|
|
5
|
+
Set `XERO_TRANSPORT=http` to serve stateless MCP at `/mcp`. It binds to `127.0.0.1` by default; remote binding requires `XERO_HTTP_BEARER_TOKEN` and `XERO_HTTP_ALLOWED_HOSTS`. Optional controls include `XERO_HTTP_PORT`, `XERO_HTTP_ALLOWED_ORIGINS`, and `XERO_HTTP_MAX_BODY_BYTES`. A health endpoint is available at `/health`.
|
|
6
|
+
|
|
3
7
|
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
8
|
|
|
5
9
|
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.
|
|
@@ -233,11 +237,25 @@ Date inputs to the Xero API (invoice dates, fromDate, toDate, etc.) are `YYYY-MM
|
|
|
233
237
|
| `list-aged-payables-by-contact` | Aged payables for a contact |
|
|
234
238
|
|
|
235
239
|
`list-profit-and-loss` enforces a single-calendar-month base range and returns
|
|
236
|
-
comparison-column metadata containing each label,
|
|
237
|
-
Multi-month base ranges are rejected
|
|
240
|
+
comparison-column metadata containing each label, MCP-derived date window, MTD flag,
|
|
241
|
+
`source: MCP_DERIVED`, and `verifiedCallShape: true`. Multi-month base ranges are rejected
|
|
242
|
+
because Xero can return misleading rolling totals. Comparison calls with `periods>=1` also
|
|
243
|
+
require the current calendar month as the base; completed-month comparisons are rejected.
|
|
238
244
|
For N completed monthly columns, request the current month with `periods=N` and ignore
|
|
239
245
|
the first MTD column, or make N separate calls with `periods=0`.
|
|
240
246
|
|
|
247
|
+
### Pagination
|
|
248
|
+
|
|
249
|
+
For tools with `page` and `pageSize`, `Found N` is the count for the current page, not a
|
|
250
|
+
total. To retrieve the complete filtered result set, increment `page` until a page contains
|
|
251
|
+
fewer records than `pageSize`. `xero_search_transactions` and `xero_find_contact` expose
|
|
252
|
+
`pagination.complete`, `pagination.truncated`, and `pagination.nextPage` instead. Xero does
|
|
253
|
+
not expose a configurable page size for `list-quotes`; continue until it returns an empty page.
|
|
254
|
+
|
|
255
|
+
Attachment filenames are non-authoritative and may contain amounts that differ from the
|
|
256
|
+
bill's gross total. Use Xero invoice `SubTotal`, `TotalTax`, and `Total` fields for financial
|
|
257
|
+
reconciliation, and retrieve binary attachment content only when explicitly needed.
|
|
258
|
+
|
|
241
259
|
### Payroll *(requires `XERO_ENABLE_PAYROLL=true`)*
|
|
242
260
|
| Tool | Description |
|
|
243
261
|
|---|---|
|
|
@@ -4,6 +4,7 @@ import { getClientHeaders } from "../helpers/get-client-headers.js";
|
|
|
4
4
|
import { ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
|
|
5
5
|
import { localDateString } from "../helpers/datetime.js";
|
|
6
6
|
export const PROFIT_AND_LOSS_RANGE_ERROR = "list-profit-and-loss requires fromDate and toDate to span a single calendar month; for N monthly columns, call N times with periods=0, or set fromDate=1st-of-current-month, toDate=last-day-of-current-month, periods=N and drop the first (MTD) column.";
|
|
7
|
+
export const PROFIT_AND_LOSS_COMPARISON_ERROR = "list-profit-and-loss comparison periods require the current calendar month as the base; completed-month bases can return misleading comparison slices. Set fromDate to the first day and toDate to the last day of the current month, use periods=N, and drop the first (MTD) column, or call each completed month separately with periods=0.";
|
|
7
8
|
function parseDateOnly(value) {
|
|
8
9
|
const date = new Date(`${value}T00:00:00Z`);
|
|
9
10
|
if (Number.isNaN(date.getTime()) || date.toISOString().slice(0, 10) !== value) {
|
|
@@ -11,7 +12,7 @@ function parseDateOnly(value) {
|
|
|
11
12
|
}
|
|
12
13
|
return date;
|
|
13
14
|
}
|
|
14
|
-
export function validateProfitAndLossDateRange(fromDate, toDate) {
|
|
15
|
+
export function validateProfitAndLossDateRange(fromDate, toDate, periods = 0, timeframe = "MONTH", today = localDateString()) {
|
|
15
16
|
if (!fromDate || !toDate)
|
|
16
17
|
return;
|
|
17
18
|
const from = parseDateOnly(fromDate);
|
|
@@ -19,6 +20,16 @@ export function validateProfitAndLossDateRange(fromDate, toDate) {
|
|
|
19
20
|
if (to < from || from.getUTCFullYear() !== to.getUTCFullYear() || from.getUTCMonth() !== to.getUTCMonth()) {
|
|
20
21
|
throw new McpError(ErrorCode.InvalidParams, PROFIT_AND_LOSS_RANGE_ERROR);
|
|
21
22
|
}
|
|
23
|
+
if (periods >= 1 && (timeframe === undefined || timeframe === "MONTH")) {
|
|
24
|
+
const current = parseDateOnly(today);
|
|
25
|
+
const isCurrentCalendarMonth = from.getUTCFullYear() === current.getUTCFullYear() &&
|
|
26
|
+
from.getUTCMonth() === current.getUTCMonth() &&
|
|
27
|
+
from.getUTCDate() === 1 &&
|
|
28
|
+
isLastDayOfMonth(to);
|
|
29
|
+
if (!isCurrentCalendarMonth) {
|
|
30
|
+
throw new McpError(ErrorCode.InvalidParams, PROFIT_AND_LOSS_COMPARISON_ERROR);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
22
33
|
}
|
|
23
34
|
function shiftDate(value, months) {
|
|
24
35
|
const day = value.getUTCDate();
|
|
@@ -36,7 +47,7 @@ function isLastDayOfMonth(value) {
|
|
|
36
47
|
export function buildComparisonColumnMetadata(report, fromDate, toDate, periods = 0, timeframe = "MONTH", today = localDateString()) {
|
|
37
48
|
if (!fromDate || !toDate)
|
|
38
49
|
return [];
|
|
39
|
-
validateProfitAndLossDateRange(fromDate, toDate);
|
|
50
|
+
validateProfitAndLossDateRange(fromDate, toDate, periods, timeframe, today);
|
|
40
51
|
const from = parseDateOnly(fromDate);
|
|
41
52
|
const to = parseDateOnly(toDate);
|
|
42
53
|
const todayDate = parseDateOnly(today);
|
|
@@ -62,6 +73,8 @@ export function buildComparisonColumnMetadata(report, fromDate, toDate, periods
|
|
|
62
73
|
fromDate: isoDate(columnFrom),
|
|
63
74
|
toDate: isoDate(isMonthToDate ? todayDate : requestedTo),
|
|
64
75
|
isMonthToDate,
|
|
76
|
+
source: "MCP_DERIVED",
|
|
77
|
+
verifiedCallShape: true,
|
|
65
78
|
};
|
|
66
79
|
});
|
|
67
80
|
}
|
|
@@ -91,7 +104,7 @@ async function fetchProfitAndLoss(fromDate, toDate, periods, timeframe, standard
|
|
|
91
104
|
* @param paymentsOnly Optional boolean to include only accounts with payments
|
|
92
105
|
*/
|
|
93
106
|
export async function listXeroProfitAndLoss(fromDate, toDate, periods, timeframe, standardLayout, paymentsOnly) {
|
|
94
|
-
validateProfitAndLossDateRange(fromDate, toDate);
|
|
107
|
+
validateProfitAndLossDateRange(fromDate, toDate, periods, timeframe);
|
|
95
108
|
try {
|
|
96
109
|
const profitAndLoss = await fetchProfitAndLoss(fromDate, toDate, periods, timeframe, standardLayout, paymentsOnly);
|
|
97
110
|
if (!profitAndLoss) {
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export const PAGE_NUMBER_GUIDANCE = 'The "Found N" count is for the current page, not the total in Xero.';
|
|
2
|
+
export const PAGE_SIZE_GUIDANCE = "To retrieve all matching records, increment page until a page returns fewer than pageSize records.";
|
|
3
|
+
export const STRUCTURED_PAGE_GUIDANCE = "Follow pagination.nextPage while pagination.complete is false; pagination.returned is the current page count, not the total in Xero.";
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { timingSafeEqual } from "node:crypto";
|
|
2
|
+
import http from "node:http";
|
|
3
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
4
|
+
const loopback = new Set(["127.0.0.1", "::1", "localhost"]);
|
|
5
|
+
const send = (res, status, body) => {
|
|
6
|
+
res.writeHead(status, { "Content-Type": "application/json" }).end(JSON.stringify(body));
|
|
7
|
+
};
|
|
8
|
+
const error = (res, status, code, message) => send(res, status, { jsonrpc: "2.0", error: { code, message }, id: null });
|
|
9
|
+
const matches = (value, expected) => {
|
|
10
|
+
if (!value?.startsWith("Bearer "))
|
|
11
|
+
return false;
|
|
12
|
+
const supplied = Buffer.from(value.slice(7));
|
|
13
|
+
const wanted = Buffer.from(expected);
|
|
14
|
+
return supplied.length === wanted.length && timingSafeEqual(supplied, wanted);
|
|
15
|
+
};
|
|
16
|
+
const readBody = (req, limit) => new Promise((resolve, reject) => {
|
|
17
|
+
const chunks = [];
|
|
18
|
+
let size = 0;
|
|
19
|
+
let oversized = false;
|
|
20
|
+
req.on("data", (chunk) => { size += chunk.length; oversized ||= size > limit; if (!oversized)
|
|
21
|
+
chunks.push(chunk); });
|
|
22
|
+
req.on("end", () => {
|
|
23
|
+
if (oversized)
|
|
24
|
+
return reject(Object.assign(new Error("Request body too large"), { statusCode: 413 }));
|
|
25
|
+
try {
|
|
26
|
+
resolve(JSON.parse(Buffer.concat(chunks).toString("utf8")));
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
reject(Object.assign(new Error("Invalid JSON body"), { statusCode: 400 }));
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
req.on("error", reject);
|
|
33
|
+
});
|
|
34
|
+
export function validateHttpOptions(o) {
|
|
35
|
+
if (!Number.isInteger(o.port) || o.port < 1 || o.port > 65535)
|
|
36
|
+
throw new Error(`Invalid HTTP port: ${o.port}`);
|
|
37
|
+
if (o.maxBodyBytes !== undefined && (!Number.isInteger(o.maxBodyBytes) || o.maxBodyBytes < 1))
|
|
38
|
+
throw new Error(`Invalid HTTP body limit: ${o.maxBodyBytes}`);
|
|
39
|
+
if (!loopback.has(o.host) && !o.bearerToken)
|
|
40
|
+
throw new Error("A bearer token is required when binding beyond loopback");
|
|
41
|
+
if (!loopback.has(o.host) && !o.allowedHosts?.length)
|
|
42
|
+
throw new Error("HTTP_ALLOWED_HOSTS is required when binding beyond loopback");
|
|
43
|
+
}
|
|
44
|
+
export function createHttpServer(factory, o) {
|
|
45
|
+
validateHttpOptions(o);
|
|
46
|
+
const hosts = new Set(o.allowedHosts?.map(v => v.toLowerCase()));
|
|
47
|
+
const origins = new Set(o.allowedOrigins?.map(v => v.toLowerCase()));
|
|
48
|
+
return http.createServer(async (req, res) => {
|
|
49
|
+
const path = new URL(req.url ?? "/", "http://localhost").pathname;
|
|
50
|
+
if (path === "/health")
|
|
51
|
+
return send(res, 200, { status: "ok", server: o.serverName });
|
|
52
|
+
if (path !== "/mcp")
|
|
53
|
+
return void res.writeHead(404).end();
|
|
54
|
+
if (hosts.size && !hosts.has((req.headers.host ?? "").toLowerCase()))
|
|
55
|
+
return error(res, 403, -32000, "Host not allowed");
|
|
56
|
+
if (req.headers.origin && !origins.has(req.headers.origin.toLowerCase()))
|
|
57
|
+
return error(res, 403, -32000, "Origin not allowed");
|
|
58
|
+
if (o.bearerToken && !matches(req.headers.authorization, o.bearerToken)) {
|
|
59
|
+
res.setHeader("WWW-Authenticate", "Bearer");
|
|
60
|
+
return error(res, 401, -32001, "Unauthorized");
|
|
61
|
+
}
|
|
62
|
+
if (req.method !== "POST") {
|
|
63
|
+
res.setHeader("Allow", "POST");
|
|
64
|
+
return error(res, 405, -32000, "Method not allowed");
|
|
65
|
+
}
|
|
66
|
+
const server = factory();
|
|
67
|
+
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
|
|
68
|
+
try {
|
|
69
|
+
const body = await readBody(req, o.maxBodyBytes ?? 1048576);
|
|
70
|
+
await server.connect(transport);
|
|
71
|
+
await transport.handleRequest(req, res, body);
|
|
72
|
+
res.once("close", () => { void transport.close(); void server.close(); });
|
|
73
|
+
}
|
|
74
|
+
catch (cause) {
|
|
75
|
+
void transport.close();
|
|
76
|
+
void server.close();
|
|
77
|
+
if (!res.headersSent) {
|
|
78
|
+
const status = cause.statusCode ?? 500;
|
|
79
|
+
error(res, status, status === 400 ? -32700 : -32603, status < 500 ? cause.message : "Internal server error");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -3,14 +3,23 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
3
3
|
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
|
+
import { createHttpServer } from "./http-server.js";
|
|
6
7
|
const main = async () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const createConfiguredServer = () => {
|
|
9
|
+
const server = XeroMcpServer.GetServer(true);
|
|
10
|
+
ToolFactory(server);
|
|
11
|
+
registerResources(server);
|
|
12
|
+
return server;
|
|
13
|
+
};
|
|
11
14
|
// Start receiving messages on stdin and sending messages on stdout
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
if ((process.env["XERO_TRANSPORT"] ?? "stdio") === "http") {
|
|
16
|
+
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`));
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
await createConfiguredServer().connect(new StdioServerTransport());
|
|
22
|
+
}
|
|
14
23
|
};
|
|
15
24
|
main().catch((error) => {
|
|
16
25
|
console.error("Error:", error);
|
|
@@ -3,8 +3,8 @@ import { getPackageVersion } from "../helpers/get-package-version.js";
|
|
|
3
3
|
export class XeroMcpServer {
|
|
4
4
|
static instance = null;
|
|
5
5
|
constructor() { }
|
|
6
|
-
static GetServer() {
|
|
7
|
-
if (XeroMcpServer.instance === null) {
|
|
6
|
+
static GetServer(fresh = false) {
|
|
7
|
+
if (fresh || XeroMcpServer.instance === null) {
|
|
8
8
|
XeroMcpServer.instance = new McpServer({
|
|
9
9
|
name: "Xero MCP Server",
|
|
10
10
|
version: getPackageVersion(),
|
|
@@ -2,6 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
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
|
+
import { STRUCTURED_PAGE_GUIDANCE } from "../../helpers/pagination-guidance.js";
|
|
5
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
7
|
contactId: z.string().uuid().optional(),
|
|
7
8
|
name: z.string().min(1).optional(),
|
|
@@ -11,8 +12,8 @@ const FindContactTool = CreateXeroTool("xero_find_contact", "Resolve a Xero cust
|
|
|
11
12
|
taxNumber: z.string().min(1).optional().describe("GST/VAT/ABN/NZBN tax identifier as stored by Xero."),
|
|
12
13
|
role: z.enum(["customer", "supplier"]).optional(),
|
|
13
14
|
matchMode: z.enum(["exact", "contains"]).default("exact"),
|
|
14
|
-
page: z.number().int().min(1).default(1),
|
|
15
|
-
pageSize: z.number().int().min(1).max(50).default(10),
|
|
15
|
+
page: z.number().int().min(1).default(1).describe(`Page number for paginated matches. ${STRUCTURED_PAGE_GUIDANCE}`),
|
|
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}`),
|
|
16
17
|
}, async (params) => {
|
|
17
18
|
if (![params.contactId, params.name, params.contactNumber, params.accountNumber, params.email, params.taxNumber].some(Boolean)) {
|
|
18
19
|
return jsonToolResponse(failedLookup("At least one supported contact identifier is required."));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
|
|
3
|
+
import { PAGE_NUMBER_GUIDANCE, PAGE_SIZE_GUIDANCE } from "../../helpers/pagination-guidance.js";
|
|
3
4
|
import { listXeroBankTransactions } from "../../handlers/list-xero-bank-transactions.handler.js";
|
|
4
5
|
import { formatLineItem } from "../../helpers/format-line-item.js";
|
|
5
6
|
import { formatXeroDate } from "../../helpers/datetime.js";
|
|
@@ -11,14 +12,14 @@ const ListBankTransactionsTool = CreateXeroTool("list-bank-transactions", "List
|
|
|
11
12
|
"money out → transactionType=SPEND with date range; " +
|
|
12
13
|
"transfers → transactionType=SPEND-TRANSFER or RECEIVE-TRANSFER. " +
|
|
13
14
|
"Always set a fromDate/toDate or isReconciled filter before paginating.", {
|
|
14
|
-
page: z.number().describe(
|
|
15
|
+
page: z.number().describe(`Page number for pagination (starts at 1). ${PAGE_NUMBER_GUIDANCE}`),
|
|
15
16
|
bankAccountId: z.string().optional().describe("Filter by bank account ID. Get IDs from list-accounts."),
|
|
16
17
|
fromDate: z.string().optional().describe("Transactions on or after this date (YYYY-MM-DD)."),
|
|
17
18
|
toDate: z.string().optional().describe("Transactions on or before this date (YYYY-MM-DD)."),
|
|
18
19
|
status: z.enum(["AUTHORISED", "DELETED", "VOIDED"]).optional().describe("Filter by status. Defaults to AUTHORISED (active transactions only). Pass DELETED or VOIDED only if you explicitly need those records."),
|
|
19
20
|
isReconciled: z.boolean().optional().describe("Filter by reconciliation status. Use isReconciled=false to find unreconciled transactions. Never scan pages to find unreconciled items — use this filter."),
|
|
20
21
|
transactionType: z.enum(["SPEND", "RECEIVE", "SPEND-TRANSFER", "RECEIVE-TRANSFER", "SPEND-PREPAYMENT", "RECEIVE-PREPAYMENT", "SPEND-OVERPAYMENT", "RECEIVE-OVERPAYMENT"]).optional().describe("Filter by transaction type. SPEND = money out, RECEIVE = money in, *-TRANSFER = bank transfers."),
|
|
21
|
-
pageSize: z.number().min(1).max(100).optional().default(50).describe(
|
|
22
|
+
pageSize: z.number().min(1).max(100).optional().default(50).describe(`Results per page (1–100, default 50). ${PAGE_SIZE_GUIDANCE}`),
|
|
22
23
|
}, async ({ bankAccountId, page, fromDate, toDate, status, isReconciled, transactionType, pageSize }) => {
|
|
23
24
|
const response = await listXeroBankTransactions(page, bankAccountId, fromDate, toDate, status, pageSize, isReconciled, transactionType);
|
|
24
25
|
if (response.isError) {
|
|
@@ -2,7 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
import { listXeroInvoiceAttachments } from "../../handlers/list-xero-invoice-attachments.handler.js";
|
|
3
3
|
import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
|
|
4
4
|
import { failedLookup, jsonToolResponse } from "../../types/lookup-result.js";
|
|
5
|
-
const ListBillAttachmentsTool = CreateXeroTool("xero_list_bill_attachments", "List compact attachment metadata for a Xero bill or invoice. Binary content is never included; use xero_get_bill_attachment for explicit retrieval.", { invoiceId: z.string().uuid() }, async ({ invoiceId }) => {
|
|
5
|
+
const ListBillAttachmentsTool = CreateXeroTool("xero_list_bill_attachments", "List compact attachment metadata for a Xero bill or invoice. Attachment filenames are non-authoritative and may contain an amount different from the bill's gross total; use the Xero invoice SubTotal, TotalTax, and Total fields for reconciliation. Binary content is never included; use xero_get_bill_attachment for explicit retrieval.", { invoiceId: z.string().uuid() }, async ({ invoiceId }) => {
|
|
6
6
|
const response = await listXeroInvoiceAttachments(invoiceId);
|
|
7
7
|
if (response.isError)
|
|
8
8
|
return jsonToolResponse(failedLookup(response.error));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { listXeroContacts } from "../../handlers/list-xero-contacts.handler.js";
|
|
2
2
|
import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
|
|
3
|
+
import { PAGE_NUMBER_GUIDANCE, PAGE_SIZE_GUIDANCE } from "../../helpers/pagination-guidance.js";
|
|
3
4
|
import { z } from "zod";
|
|
4
5
|
import { formatUtcDatetime } from "../../helpers/datetime.js";
|
|
5
6
|
const ListContactsTool = CreateXeroTool("list-contacts", "List contacts from Xero. " +
|
|
@@ -13,13 +14,13 @@ const ListContactsTool = CreateXeroTool("list-contacts", "List contacts from Xer
|
|
|
13
14
|
"accountNumber (user-defined), taxNumber (NZBN/ABN/VAT), isCustomer/isSupplier flags, " +
|
|
14
15
|
"phones (type + number, short form), addresses (type + line1/city/region/postcode/country, short form), " +
|
|
15
16
|
"AR/AP tax types, defaultCurrency, contactStatus, contactGroups, and lastUpdated.", {
|
|
16
|
-
page: z.number().optional().describe(
|
|
17
|
+
page: z.number().optional().describe(`Page number for pagination (starts at 1). ${PAGE_NUMBER_GUIDANCE}`),
|
|
17
18
|
searchTerm: z.string().optional().describe("Case-insensitive search across Name, FirstName, LastName, ContactNumber, EmailAddress. Use this instead of listing all contacts."),
|
|
18
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
20
|
fromDate: z.string().optional().describe("Return contacts updated on or after this date (YYYY-MM-DD)."),
|
|
20
21
|
toDate: z.string().optional().describe("Return contacts updated on or before this date (YYYY-MM-DD)."),
|
|
21
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."),
|
|
22
|
-
pageSize: z.number().min(1).max(100).optional().default(50).describe(
|
|
23
|
+
pageSize: z.number().min(1).max(100).optional().default(50).describe(`Results per page (1–100, default 50). ${PAGE_SIZE_GUIDANCE}`),
|
|
23
24
|
}, async (params) => {
|
|
24
25
|
const { page, searchTerm, contactRole, fromDate, toDate, status, pageSize } = params;
|
|
25
26
|
const response = await listXeroContacts(page, searchTerm, fromDate, toDate, status, pageSize, contactRole);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { listXeroCreditNotes } from "../../handlers/list-xero-credit-notes.handler.js";
|
|
3
3
|
import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
|
|
4
|
+
import { PAGE_NUMBER_GUIDANCE, PAGE_SIZE_GUIDANCE } from "../../helpers/pagination-guidance.js";
|
|
4
5
|
import { formatUtcDatetime, formatXeroDate } from "../../helpers/datetime.js";
|
|
5
6
|
const ListCreditNotesTool = CreateXeroTool("list-credit-notes", "List credit notes from Xero. " +
|
|
6
7
|
"ACCREC = sales credit notes (issued to customers). ACCPAY = purchase credit notes (received from suppliers). " +
|
|
@@ -10,14 +11,14 @@ const ListCreditNotesTool = CreateXeroTool("list-credit-notes", "List credit not
|
|
|
10
11
|
"supplier credits → type=ACCPAY. " +
|
|
11
12
|
"Results include RemainingCredit/AppliedAmount and, where Xero returns them, the invoices " +
|
|
12
13
|
"each credit note has been allocated against — no need to diff invoice Total vs AmountDue to find this.", {
|
|
13
|
-
page: z.number().describe(
|
|
14
|
+
page: z.number().describe(`Page number for pagination (starts at 1). ${PAGE_NUMBER_GUIDANCE}`),
|
|
14
15
|
type: z.enum(["ACCREC", "ACCPAY"]).optional().describe("ACCREC = sales/customer credit notes. ACCPAY = purchase/supplier credit notes."),
|
|
15
16
|
contactId: z.string().optional().describe("Filter by contact ID."),
|
|
16
17
|
fromDate: z.string().optional().describe("Credit note date on or after this date (YYYY-MM-DD)."),
|
|
17
18
|
toDate: z.string().optional().describe("Credit note date on or before this date (YYYY-MM-DD)."),
|
|
18
19
|
statuses: z.array(z.enum(["DRAFT", "SUBMITTED", "AUTHORISED", "PAID", "VOIDED", "DELETED"])).optional().describe("Filter by status. Defaults to [DRAFT, SUBMITTED, AUTHORISED, PAID] — active records only. Pass VOIDED or DELETED explicitly only if those records are specifically needed."),
|
|
19
20
|
hasRemainingCredit: z.boolean().optional().describe("If true, only returns credit notes with RemainingCredit>0 (i.e. not yet fully allocated). Use to find credits available to apply."),
|
|
20
|
-
pageSize: z.number().min(1).max(100).optional().default(50).describe(
|
|
21
|
+
pageSize: z.number().min(1).max(100).optional().default(50).describe(`Results per page (1–100, default 50). ${PAGE_SIZE_GUIDANCE}`),
|
|
21
22
|
}, async ({ page, type, contactId, fromDate, toDate, statuses, hasRemainingCredit, pageSize }) => {
|
|
22
23
|
const response = await listXeroCreditNotes(page, contactId, fromDate, toDate, statuses, pageSize, type, hasRemainingCredit);
|
|
23
24
|
if (response.error !== null) {
|
|
@@ -3,6 +3,7 @@ import { listXeroInvoices } from "../../handlers/list-xero-invoices.handler.js";
|
|
|
3
3
|
import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
|
|
4
4
|
import { formatLineItem } from "../../helpers/format-line-item.js";
|
|
5
5
|
import { formatUtcDatetime, formatXeroDate } from "../../helpers/datetime.js";
|
|
6
|
+
import { PAGE_NUMBER_GUIDANCE, PAGE_SIZE_GUIDANCE } from "../../helpers/pagination-guidance.js";
|
|
6
7
|
const ListInvoicesTool = CreateXeroTool("list-invoices", "List invoices from Xero. " +
|
|
7
8
|
"ACCREC = sales invoices (Accounts Receivable, money owed to you). " +
|
|
8
9
|
"ACCPAY = bills/purchase invoices (Accounts Payable, money you owe suppliers). " +
|
|
@@ -13,7 +14,7 @@ const ListInvoicesTool = CreateXeroTool("list-invoices", "List invoices from Xer
|
|
|
13
14
|
"bills to pay → type=ACCPAY, statuses=[AUTHORISED], minAmountDue=0.01; " +
|
|
14
15
|
"recent drafts → statuses=[DRAFT], fromDate=<date>. " +
|
|
15
16
|
"Set pageSize to the minimum needed. Only paginate if the user asks for more.", {
|
|
16
|
-
page: z.number().describe(
|
|
17
|
+
page: z.number().describe(`Page number for pagination. Starts at 1. ${PAGE_NUMBER_GUIDANCE}`),
|
|
17
18
|
type: z.enum(["ACCREC", "ACCPAY"]).optional().describe("ACCREC = sales invoices / accounts receivable. ACCPAY = bills / accounts payable. Always set this unless you genuinely need both."),
|
|
18
19
|
contactIds: z.array(z.string()).optional().describe("Filter by one or more contact IDs."),
|
|
19
20
|
invoiceNumbers: z.array(z.string()).optional().describe("Filter by specific invoice numbers. Line items are included in the response when this is set."),
|
|
@@ -25,7 +26,7 @@ const ListInvoicesTool = CreateXeroTool("list-invoices", "List invoices from Xer
|
|
|
25
26
|
toDate: z.string().optional().describe("Invoice date on or before this date (YYYY-MM-DD)."),
|
|
26
27
|
minAmountDue: z.number().optional().describe("Only return invoices with AmountDue greater than this value. Use 0.01 to exclude fully paid invoices without needing to filter by date."),
|
|
27
28
|
overdueOnly: z.boolean().optional().describe("If true, returns only invoices past their due date with an outstanding balance. Equivalent to AmountDue>0 AND DueDate<=today. Use with type=ACCREC and statuses=[AUTHORISED] for AR chasing."),
|
|
28
|
-
pageSize: z.number().min(1).max(1000).optional().default(100).describe(
|
|
29
|
+
pageSize: z.number().min(1).max(1000).optional().default(100).describe(`Results per page (1-1000, default 100). Use a smaller value if you only need a few results. ${PAGE_SIZE_GUIDANCE}`),
|
|
29
30
|
}, async ({ page, type, contactIds, invoiceNumbers, statuses, fromDate, toDate, minAmountDue, overdueOnly, pageSize }) => {
|
|
30
31
|
const response = await listXeroInvoices(page, contactIds, invoiceNumbers, statuses, fromDate, toDate, pageSize, type, minAmountDue, overdueOnly);
|
|
31
32
|
if (response.error !== null) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { listXeroManualJournals } from "../../handlers/list-xero-manual-journals.handler.js";
|
|
2
2
|
import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
|
|
3
|
+
import { PAGE_NUMBER_GUIDANCE, PAGE_SIZE_GUIDANCE } from "../../helpers/pagination-guidance.js";
|
|
3
4
|
import { z } from "zod";
|
|
4
5
|
import { formatUtcDatetime, formatXeroDate } from "../../helpers/datetime.js";
|
|
5
6
|
const ListManualJournalsTool = CreateXeroTool("list-manual-journals", `List all manual journals from Xero.
|
|
@@ -16,8 +17,8 @@ If they want the next page, call this tool again with the next page number, modi
|
|
|
16
17
|
.string()
|
|
17
18
|
.optional()
|
|
18
19
|
.describe("Optional date YYYY-MM-DD to filter journals modified after this date"),
|
|
19
|
-
page: z.number().optional().describe(
|
|
20
|
-
pageSize: z.number().min(1).max(100).optional().default(50).describe(
|
|
20
|
+
page: z.number().optional().describe(`Optional page number for pagination. ${PAGE_NUMBER_GUIDANCE}`),
|
|
21
|
+
pageSize: z.number().min(1).max(100).optional().default(50).describe(`Number of results per page (1–100, default 50). ${PAGE_SIZE_GUIDANCE}`),
|
|
21
22
|
}, async (args) => {
|
|
22
23
|
const response = await listXeroManualJournals(args?.page, args?.manualJournalId, args?.modifiedAfter, args?.pageSize);
|
|
23
24
|
if (response.isError) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { listXeroOverpayments } from "../../handlers/list-xero-overpayments.handler.js";
|
|
3
3
|
import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
|
|
4
|
+
import { PAGE_NUMBER_GUIDANCE, PAGE_SIZE_GUIDANCE } from "../../helpers/pagination-guidance.js";
|
|
4
5
|
import { formatUtcDatetime, formatXeroDate } from "../../helpers/datetime.js";
|
|
5
6
|
const ListOverpaymentsTool = CreateXeroTool("list-overpayments", "List overpayments from Xero. Overpayments are a SEPARATE record type from Payments — " +
|
|
6
7
|
"they're created when a customer pays more than an invoice total, or a supplier is paid " +
|
|
@@ -11,13 +12,13 @@ const ListOverpaymentsTool = CreateXeroTool("list-overpayments", "List overpayme
|
|
|
11
12
|
"Common patterns: " +
|
|
12
13
|
"all overpayment activity for a contact → contactId; " +
|
|
13
14
|
"unallocated overpayments still available to apply → hasRemainingCredit=true.", {
|
|
14
|
-
page: z.number().default(1).describe(
|
|
15
|
+
page: z.number().default(1).describe(`Page number for pagination (starts at 1). ${PAGE_NUMBER_GUIDANCE}`),
|
|
15
16
|
contactId: z.string().optional().describe("Filter by contact ID."),
|
|
16
17
|
fromDate: z.string().optional().describe("Overpayment date on or after this date (YYYY-MM-DD)."),
|
|
17
18
|
toDate: z.string().optional().describe("Overpayment date on or before this date (YYYY-MM-DD)."),
|
|
18
19
|
statuses: z.array(z.enum(["AUTHORISED", "PAID", "VOIDED"])).optional().describe("Filter by status. Defaults to [AUTHORISED, PAID] — active records only. Pass VOIDED explicitly only if those records are specifically needed."),
|
|
19
20
|
hasRemainingCredit: z.boolean().optional().describe("If true, only returns overpayments with RemainingCredit>0 (i.e. not yet fully allocated). Use to find credit available to apply."),
|
|
20
|
-
pageSize: z.number().min(1).max(100).optional().default(50).describe(
|
|
21
|
+
pageSize: z.number().min(1).max(100).optional().default(50).describe(`Results per page (1–100, default 50). ${PAGE_SIZE_GUIDANCE}`),
|
|
21
22
|
}, async ({ page, contactId, fromDate, toDate, statuses, hasRemainingCredit, pageSize }) => {
|
|
22
23
|
const response = await listXeroOverpayments(page, contactId, fromDate, toDate, statuses, pageSize, hasRemainingCredit);
|
|
23
24
|
if (response.error !== null) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { listXeroPayments } from "../../handlers/list-xero-payments.handler.js";
|
|
3
3
|
import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
|
|
4
|
+
import { PAGE_NUMBER_GUIDANCE, PAGE_SIZE_GUIDANCE } from "../../helpers/pagination-guidance.js";
|
|
4
5
|
import { formatUtcDatetime, formatXeroDate } from "../../helpers/datetime.js";
|
|
5
6
|
function paymentFormatter(payment) {
|
|
6
7
|
return [
|
|
@@ -44,7 +45,7 @@ const ListPaymentsTool = CreateXeroTool("list-payments", "List payments recorded
|
|
|
44
45
|
"all payments from/to a contact → contactId; " +
|
|
45
46
|
"payments in a date range → fromDate + toDate. " +
|
|
46
47
|
"Note: this shows payment records only, not invoice balances. Use list-invoices with minAmountDue to find unpaid invoices.", {
|
|
47
|
-
page: z.number().default(1).describe(
|
|
48
|
+
page: z.number().default(1).describe(`Page number for pagination (starts at 1). ${PAGE_NUMBER_GUIDANCE}`),
|
|
48
49
|
contactId: z.string().optional().describe("Filter payments by contact (matches Invoice.Contact.ContactID). Use to find all payments from or to a specific customer or supplier."),
|
|
49
50
|
invoiceNumber: z.string().optional().describe("Filter by invoice number."),
|
|
50
51
|
invoiceId: z.string().optional().describe("Filter by invoice ID."),
|
|
@@ -52,7 +53,7 @@ const ListPaymentsTool = CreateXeroTool("list-payments", "List payments recorded
|
|
|
52
53
|
reference: z.string().optional().describe("Filter by payment reference."),
|
|
53
54
|
fromDate: z.string().optional().describe("Payments on or after this date (YYYY-MM-DD)."),
|
|
54
55
|
toDate: z.string().optional().describe("Payments on or before this date (YYYY-MM-DD)."),
|
|
55
|
-
pageSize: z.number().min(1).max(100).optional().default(50).describe(
|
|
56
|
+
pageSize: z.number().min(1).max(100).optional().default(50).describe(`Results per page (1–100, default 50). ${PAGE_SIZE_GUIDANCE}`),
|
|
56
57
|
}, async ({ page, contactId, invoiceNumber, invoiceId, paymentId, reference, fromDate, toDate, pageSize }) => {
|
|
57
58
|
const response = await listXeroPayments(page, {
|
|
58
59
|
contactId,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { listXeroPrepayments } from "../../handlers/list-xero-prepayments.handler.js";
|
|
3
3
|
import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
|
|
4
|
+
import { PAGE_NUMBER_GUIDANCE, PAGE_SIZE_GUIDANCE } from "../../helpers/pagination-guidance.js";
|
|
4
5
|
import { formatUtcDatetime, formatXeroDate } from "../../helpers/datetime.js";
|
|
5
6
|
const ListPrepaymentsTool = CreateXeroTool("list-prepayments", "List prepayments from Xero. Prepayments are a SEPARATE record type from Payments — " +
|
|
6
7
|
"they're created when a customer pays before an invoice is raised (or a supplier is paid " +
|
|
@@ -10,13 +11,13 @@ const ListPrepaymentsTool = CreateXeroTool("list-prepayments", "List prepayments
|
|
|
10
11
|
"Common patterns: " +
|
|
11
12
|
"all prepayment activity for a contact → contactId; " +
|
|
12
13
|
"unallocated prepayments still available to apply → hasRemainingCredit=true.", {
|
|
13
|
-
page: z.number().default(1).describe(
|
|
14
|
+
page: z.number().default(1).describe(`Page number for pagination (starts at 1). ${PAGE_NUMBER_GUIDANCE}`),
|
|
14
15
|
contactId: z.string().optional().describe("Filter by contact ID."),
|
|
15
16
|
fromDate: z.string().optional().describe("Prepayment date on or after this date (YYYY-MM-DD)."),
|
|
16
17
|
toDate: z.string().optional().describe("Prepayment date on or before this date (YYYY-MM-DD)."),
|
|
17
18
|
statuses: z.array(z.enum(["AUTHORISED", "PAID", "VOIDED"])).optional().describe("Filter by status. Defaults to [AUTHORISED, PAID] — active records only. Pass VOIDED explicitly only if those records are specifically needed."),
|
|
18
19
|
hasRemainingCredit: z.boolean().optional().describe("If true, only returns prepayments with RemainingCredit>0 (i.e. not yet fully allocated). Use to find credit available to apply."),
|
|
19
|
-
pageSize: z.number().min(1).max(100).optional().default(50).describe(
|
|
20
|
+
pageSize: z.number().min(1).max(100).optional().default(50).describe(`Results per page (1–100, default 50). ${PAGE_SIZE_GUIDANCE}`),
|
|
20
21
|
}, async ({ page, contactId, fromDate, toDate, statuses, hasRemainingCredit, pageSize }) => {
|
|
21
22
|
const response = await listXeroPrepayments(page, contactId, fromDate, toDate, statuses, pageSize, hasRemainingCredit);
|
|
22
23
|
if (response.error !== null) {
|
|
@@ -3,7 +3,7 @@ import { listXeroQuotes } from "../../handlers/list-xero-quotes.handler.js";
|
|
|
3
3
|
import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
|
|
4
4
|
import { formatUtcDatetime, formatXeroDate } from "../../helpers/datetime.js";
|
|
5
5
|
const ListQuotesTool = CreateXeroTool("list-quotes", "List quotes in Xero. Supports filtering by contact, quote number, status, and date range.", {
|
|
6
|
-
page: z.number().describe("Page number for pagination (starts at 1)."),
|
|
6
|
+
page: z.number().describe("Page number for pagination (starts at 1). Xero does not expose a pageSize for quotes; to retrieve all matching quotes, increment page until Xero returns an empty page. The 'Found N' count is for the current page, not the total in Xero."),
|
|
7
7
|
contactId: z.string().optional().describe("Filter by contact ID."),
|
|
8
8
|
quoteNumber: z.string().optional().describe("Filter by quote number."),
|
|
9
9
|
dateFrom: z.string().optional().describe("Return quotes on or after this date (YYYY-MM-DD)."),
|
|
@@ -2,6 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
import { searchXeroTransactions } from "../../handlers/search-xero-transactions.handler.js";
|
|
3
3
|
import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
|
|
4
4
|
import { jsonToolResponse } from "../../types/lookup-result.js";
|
|
5
|
+
import { STRUCTURED_PAGE_GUIDANCE } from "../../helpers/pagination-guidance.js";
|
|
5
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
7
|
invoiceNumber: z.string().min(1).optional(),
|
|
7
8
|
reference: z.string().min(1).optional(),
|
|
@@ -15,7 +16,7 @@ const SearchTransactionsTool = CreateXeroTool("xero_search_transactions", "Searc
|
|
|
15
16
|
statuses: z.array(z.enum(["DRAFT", "SUBMITTED", "AUTHORISED", "PAID", "VOIDED", "DELETED"])).min(1).optional(),
|
|
16
17
|
type: z.enum(["ACCREC", "ACCPAY"]).optional(),
|
|
17
18
|
matchMode: z.enum(["exact", "contains", "candidate"]).default("exact"),
|
|
18
|
-
page: z.number().int().min(1).default(1),
|
|
19
|
-
pageSize: z.number().int().min(1).max(100).default(25),
|
|
19
|
+
page: z.number().int().min(1).default(1).describe(`Page number for paginated matches. ${STRUCTURED_PAGE_GUIDANCE}`),
|
|
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}`),
|
|
20
21
|
}, async (params) => jsonToolResponse(await searchXeroTransactions(params)));
|
|
21
22
|
export default SearchTransactionsTool;
|