@teamnetwork-nz/xero-mcp-server 1.10.0 → 1.11.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 +2 -0
- package/dist/handlers/list-xero-overpayments.handler.js +41 -0
- package/dist/handlers/list-xero-prepayments.handler.js +41 -0
- package/dist/tools/list/index.js +4 -0
- package/dist/tools/list/list-overpayments.tool.js +78 -0
- package/dist/tools/list/list-prepayments.tool.js +77 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -181,6 +181,8 @@ Date inputs to the Xero API (invoice dates, fromDate, toDate, etc.) are `YYYY-MM
|
|
|
181
181
|
|---|---|
|
|
182
182
|
| `list-payments` | List payments |
|
|
183
183
|
| `create-payment` | Record a payment against an invoice |
|
|
184
|
+
| `list-overpayments` | List overpayments (not returned by `list-payments`) |
|
|
185
|
+
| `list-prepayments` | List prepayments (not returned by `list-payments`) |
|
|
184
186
|
| `list-credit-notes` | List credit notes |
|
|
185
187
|
| `create-credit-note` | Create a credit note |
|
|
186
188
|
| `update-credit-note` | Update a draft credit note |
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
import { getClientHeaders } from "../helpers/get-client-headers.js";
|
|
4
|
+
import { dateWhereConditions, statusWhereConditions, joinWhere } from "../helpers/build-where-clause.js";
|
|
5
|
+
async function getOverpayments(contactId, page, fromDate, toDate, statuses, pageSize = 50, hasRemainingCredit) {
|
|
6
|
+
await xeroClient.authenticate();
|
|
7
|
+
// Default to active statuses — exclude VOIDED unless explicitly requested
|
|
8
|
+
const effectiveStatuses = statuses?.length ? statuses : ["AUTHORISED", "PAID"];
|
|
9
|
+
const whereParts = [
|
|
10
|
+
...(contactId ? [`Contact.ContactID=guid("${contactId}")`] : []),
|
|
11
|
+
...dateWhereConditions("Date", fromDate, toDate),
|
|
12
|
+
...statusWhereConditions("Status", effectiveStatuses),
|
|
13
|
+
...(hasRemainingCredit ? ["RemainingCredit>0"] : []),
|
|
14
|
+
];
|
|
15
|
+
const where = joinWhere(whereParts);
|
|
16
|
+
const response = await xeroClient.accountingApi.getOverpayments(xeroClient.tenantId, undefined, // ifModifiedSince
|
|
17
|
+
where, "Date DESC", // order
|
|
18
|
+
page, undefined, // unitdp
|
|
19
|
+
pageSize, getClientHeaders());
|
|
20
|
+
return response.body.overpayments ?? [];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* List overpayments from Xero
|
|
24
|
+
*/
|
|
25
|
+
export async function listXeroOverpayments(page = 1, contactId, fromDate, toDate, statuses, pageSize = 50, hasRemainingCredit) {
|
|
26
|
+
try {
|
|
27
|
+
const overpayments = await getOverpayments(contactId, page, fromDate, toDate, statuses, pageSize, hasRemainingCredit);
|
|
28
|
+
return {
|
|
29
|
+
result: overpayments,
|
|
30
|
+
isError: false,
|
|
31
|
+
error: null,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
return {
|
|
36
|
+
result: null,
|
|
37
|
+
isError: true,
|
|
38
|
+
error: formatError(error),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
import { getClientHeaders } from "../helpers/get-client-headers.js";
|
|
4
|
+
import { dateWhereConditions, statusWhereConditions, joinWhere } from "../helpers/build-where-clause.js";
|
|
5
|
+
async function getPrepayments(contactId, page, fromDate, toDate, statuses, pageSize = 50, hasRemainingCredit) {
|
|
6
|
+
await xeroClient.authenticate();
|
|
7
|
+
// Default to active statuses — exclude VOIDED unless explicitly requested
|
|
8
|
+
const effectiveStatuses = statuses?.length ? statuses : ["AUTHORISED", "PAID"];
|
|
9
|
+
const whereParts = [
|
|
10
|
+
...(contactId ? [`Contact.ContactID=guid("${contactId}")`] : []),
|
|
11
|
+
...dateWhereConditions("Date", fromDate, toDate),
|
|
12
|
+
...statusWhereConditions("Status", effectiveStatuses),
|
|
13
|
+
...(hasRemainingCredit ? ["RemainingCredit>0"] : []),
|
|
14
|
+
];
|
|
15
|
+
const where = joinWhere(whereParts);
|
|
16
|
+
const response = await xeroClient.accountingApi.getPrepayments(xeroClient.tenantId, undefined, // ifModifiedSince
|
|
17
|
+
where, "Date DESC", // order
|
|
18
|
+
page, undefined, // unitdp
|
|
19
|
+
pageSize, getClientHeaders());
|
|
20
|
+
return response.body.prepayments ?? [];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* List prepayments from Xero
|
|
24
|
+
*/
|
|
25
|
+
export async function listXeroPrepayments(page = 1, contactId, fromDate, toDate, statuses, pageSize = 50, hasRemainingCredit) {
|
|
26
|
+
try {
|
|
27
|
+
const prepayments = await getPrepayments(contactId, page, fromDate, toDate, statuses, pageSize, hasRemainingCredit);
|
|
28
|
+
return {
|
|
29
|
+
result: prepayments,
|
|
30
|
+
isError: false,
|
|
31
|
+
error: null,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
return {
|
|
36
|
+
result: null,
|
|
37
|
+
isError: true,
|
|
38
|
+
error: formatError(error),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
package/dist/tools/list/index.js
CHANGED
|
@@ -8,7 +8,9 @@ import ListInvoicesTool from "./list-invoices.tool.js";
|
|
|
8
8
|
import ListItemsTool from "./list-items.tool.js";
|
|
9
9
|
import ListManualJournalsTool from "./list-manual-journals.tool.js";
|
|
10
10
|
import ListOrganisationDetailsTool from "./list-organisation-details.tool.js";
|
|
11
|
+
import ListOverpaymentsTool from "./list-overpayments.tool.js";
|
|
11
12
|
import ListPaymentsTool from "./list-payments.tool.js";
|
|
13
|
+
import ListPrepaymentsTool from "./list-prepayments.tool.js";
|
|
12
14
|
import ListPayrollEmployeeLeaveBalancesTool from "./list-payroll-employee-leave-balances.tool.js";
|
|
13
15
|
import ListPayrollEmployeeLeaveTypesTool from "./list-payroll-employee-leave-types.tool.js";
|
|
14
16
|
import ListPayrollEmployeeLeaveTool from "./list-payroll-employee-leave.tool.js";
|
|
@@ -34,6 +36,8 @@ export const CoreListTools = [
|
|
|
34
36
|
ListQuotesTool,
|
|
35
37
|
ListTaxRatesTool,
|
|
36
38
|
ListPaymentsTool,
|
|
39
|
+
ListOverpaymentsTool,
|
|
40
|
+
ListPrepaymentsTool,
|
|
37
41
|
ListBankTransactionsTool,
|
|
38
42
|
ListOrganisationDetailsTool,
|
|
39
43
|
ListContactGroupsTool,
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { listXeroOverpayments } from "../../handlers/list-xero-overpayments.handler.js";
|
|
3
|
+
import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
|
|
4
|
+
import { formatUtcDatetime } from "../../helpers/datetime.js";
|
|
5
|
+
const ListOverpaymentsTool = CreateXeroTool("list-overpayments", "List overpayments from Xero. Overpayments are a SEPARATE record type from Payments — " +
|
|
6
|
+
"they're created when a customer pays more than an invoice total, or a supplier is paid " +
|
|
7
|
+
"more than a bill total, and are NOT returned by list-payments. " +
|
|
8
|
+
"Required for accurate contact statements/balances: an overpayment reduces what's owed " +
|
|
9
|
+
"even before it's allocated to a specific invoice, and its Allocations show which " +
|
|
10
|
+
"invoices it was later applied against. " +
|
|
11
|
+
"Common patterns: " +
|
|
12
|
+
"all overpayment activity for a contact → contactId; " +
|
|
13
|
+
"unallocated overpayments still available to apply → hasRemainingCredit=true.", {
|
|
14
|
+
page: z.number().default(1).describe("Page number for pagination (starts at 1)."),
|
|
15
|
+
contactId: z.string().optional().describe("Filter by contact ID."),
|
|
16
|
+
fromDate: z.string().optional().describe("Overpayment date on or after this date (YYYY-MM-DD)."),
|
|
17
|
+
toDate: z.string().optional().describe("Overpayment date on or before this date (YYYY-MM-DD)."),
|
|
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."),
|
|
19
|
+
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("Results per page (1–100, default 50)."),
|
|
21
|
+
}, async ({ page, contactId, fromDate, toDate, statuses, hasRemainingCredit, pageSize }) => {
|
|
22
|
+
const response = await listXeroOverpayments(page, contactId, fromDate, toDate, statuses, pageSize, hasRemainingCredit);
|
|
23
|
+
if (response.error !== null) {
|
|
24
|
+
return {
|
|
25
|
+
content: [
|
|
26
|
+
{
|
|
27
|
+
type: "text",
|
|
28
|
+
text: `Error listing overpayments: ${response.error}`,
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const overpayments = response.result;
|
|
34
|
+
return {
|
|
35
|
+
content: [
|
|
36
|
+
{
|
|
37
|
+
type: "text",
|
|
38
|
+
text: `Found ${overpayments?.length || 0} overpayments:`,
|
|
39
|
+
},
|
|
40
|
+
...(overpayments?.map((overpayment) => ({
|
|
41
|
+
type: "text",
|
|
42
|
+
text: [
|
|
43
|
+
`Overpayment ID: ${overpayment.overpaymentID}`,
|
|
44
|
+
`Type: ${overpayment.type || "Unknown"}`,
|
|
45
|
+
`Status: ${overpayment.status || "Unknown"}`,
|
|
46
|
+
overpayment.contact
|
|
47
|
+
? `Contact: ${overpayment.contact.name} (${overpayment.contact.contactID})`
|
|
48
|
+
: null,
|
|
49
|
+
overpayment.date ? `Date: ${overpayment.date}` : null,
|
|
50
|
+
`Total: ${overpayment.total || 0}`,
|
|
51
|
+
overpayment.remainingCredit !== undefined
|
|
52
|
+
? `Remaining Credit: ${overpayment.remainingCredit}`
|
|
53
|
+
: null,
|
|
54
|
+
overpayment.appliedAmount !== undefined
|
|
55
|
+
? `Applied Amount: ${overpayment.appliedAmount}`
|
|
56
|
+
: null,
|
|
57
|
+
overpayment.allocations?.length
|
|
58
|
+
? `Allocations:\n${overpayment.allocations
|
|
59
|
+
.map((allocation) => ` - ${allocation.amount} on ${allocation.date} → Invoice ${allocation.invoice?.invoiceNumber ?? allocation.invoice?.invoiceID ?? "Unknown"}`)
|
|
60
|
+
.join("\n")}`
|
|
61
|
+
: null,
|
|
62
|
+
overpayment.currencyCode
|
|
63
|
+
? `Currency: ${overpayment.currencyCode}`
|
|
64
|
+
: null,
|
|
65
|
+
overpayment.currencyRate
|
|
66
|
+
? `Currency Rate: ${overpayment.currencyRate}`
|
|
67
|
+
: null,
|
|
68
|
+
overpayment.updatedDateUTC
|
|
69
|
+
? `Last Updated: ${formatUtcDatetime(overpayment.updatedDateUTC)}`
|
|
70
|
+
: null,
|
|
71
|
+
]
|
|
72
|
+
.filter(Boolean)
|
|
73
|
+
.join("\n"),
|
|
74
|
+
})) || []),
|
|
75
|
+
],
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
export default ListOverpaymentsTool;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { listXeroPrepayments } from "../../handlers/list-xero-prepayments.handler.js";
|
|
3
|
+
import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
|
|
4
|
+
import { formatUtcDatetime } from "../../helpers/datetime.js";
|
|
5
|
+
const ListPrepaymentsTool = CreateXeroTool("list-prepayments", "List prepayments from Xero. Prepayments are a SEPARATE record type from Payments — " +
|
|
6
|
+
"they're created when a customer pays before an invoice is raised (or a supplier is paid " +
|
|
7
|
+
"in advance), and are NOT returned by list-payments. " +
|
|
8
|
+
"Required for accurate contact statements/balances: a prepayment sits as credit on the " +
|
|
9
|
+
"contact until allocated, and its Allocations show which invoices it was later applied against. " +
|
|
10
|
+
"Common patterns: " +
|
|
11
|
+
"all prepayment activity for a contact → contactId; " +
|
|
12
|
+
"unallocated prepayments still available to apply → hasRemainingCredit=true.", {
|
|
13
|
+
page: z.number().default(1).describe("Page number for pagination (starts at 1)."),
|
|
14
|
+
contactId: z.string().optional().describe("Filter by contact ID."),
|
|
15
|
+
fromDate: z.string().optional().describe("Prepayment date on or after this date (YYYY-MM-DD)."),
|
|
16
|
+
toDate: z.string().optional().describe("Prepayment date on or before this date (YYYY-MM-DD)."),
|
|
17
|
+
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
|
+
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("Results per page (1–100, default 50)."),
|
|
20
|
+
}, async ({ page, contactId, fromDate, toDate, statuses, hasRemainingCredit, pageSize }) => {
|
|
21
|
+
const response = await listXeroPrepayments(page, contactId, fromDate, toDate, statuses, pageSize, hasRemainingCredit);
|
|
22
|
+
if (response.error !== null) {
|
|
23
|
+
return {
|
|
24
|
+
content: [
|
|
25
|
+
{
|
|
26
|
+
type: "text",
|
|
27
|
+
text: `Error listing prepayments: ${response.error}`,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const prepayments = response.result;
|
|
33
|
+
return {
|
|
34
|
+
content: [
|
|
35
|
+
{
|
|
36
|
+
type: "text",
|
|
37
|
+
text: `Found ${prepayments?.length || 0} prepayments:`,
|
|
38
|
+
},
|
|
39
|
+
...(prepayments?.map((prepayment) => ({
|
|
40
|
+
type: "text",
|
|
41
|
+
text: [
|
|
42
|
+
`Prepayment ID: ${prepayment.prepaymentID}`,
|
|
43
|
+
`Type: ${prepayment.type || "Unknown"}`,
|
|
44
|
+
`Status: ${prepayment.status || "Unknown"}`,
|
|
45
|
+
prepayment.contact
|
|
46
|
+
? `Contact: ${prepayment.contact.name} (${prepayment.contact.contactID})`
|
|
47
|
+
: null,
|
|
48
|
+
prepayment.date ? `Date: ${prepayment.date}` : null,
|
|
49
|
+
`Total: ${prepayment.total || 0}`,
|
|
50
|
+
prepayment.remainingCredit !== undefined
|
|
51
|
+
? `Remaining Credit: ${prepayment.remainingCredit}`
|
|
52
|
+
: null,
|
|
53
|
+
prepayment.appliedAmount !== undefined
|
|
54
|
+
? `Applied Amount: ${prepayment.appliedAmount}`
|
|
55
|
+
: null,
|
|
56
|
+
prepayment.allocations?.length
|
|
57
|
+
? `Allocations:\n${prepayment.allocations
|
|
58
|
+
.map((allocation) => ` - ${allocation.amount} on ${allocation.date} → Invoice ${allocation.invoice?.invoiceNumber ?? allocation.invoice?.invoiceID ?? "Unknown"}`)
|
|
59
|
+
.join("\n")}`
|
|
60
|
+
: null,
|
|
61
|
+
prepayment.currencyCode
|
|
62
|
+
? `Currency: ${prepayment.currencyCode}`
|
|
63
|
+
: null,
|
|
64
|
+
prepayment.currencyRate
|
|
65
|
+
? `Currency Rate: ${prepayment.currencyRate}`
|
|
66
|
+
: null,
|
|
67
|
+
prepayment.updatedDateUTC
|
|
68
|
+
? `Last Updated: ${formatUtcDatetime(prepayment.updatedDateUTC)}`
|
|
69
|
+
: null,
|
|
70
|
+
]
|
|
71
|
+
.filter(Boolean)
|
|
72
|
+
.join("\n"),
|
|
73
|
+
})) || []),
|
|
74
|
+
],
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
export default ListPrepaymentsTool;
|