@mindstone/mcp-server-xero 0.0.15

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 (137) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +199 -0
  3. package/dist/clients/xero-client.js +134 -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/create-xero-bank-transaction.handler.js +50 -0
  7. package/dist/handlers/create-xero-contact.handler.js +49 -0
  8. package/dist/handlers/create-xero-credit-note.handler.js +49 -0
  9. package/dist/handlers/create-xero-invoice.handler.js +55 -0
  10. package/dist/handlers/create-xero-item.handler.js +59 -0
  11. package/dist/handlers/create-xero-manual-journal.handler.js +57 -0
  12. package/dist/handlers/create-xero-payment.handler.js +49 -0
  13. package/dist/handlers/create-xero-payroll-timesheet.handler.js +28 -0
  14. package/dist/handlers/create-xero-quote.handler.js +54 -0
  15. package/dist/handlers/create-xero-tracking-category.handler.js +35 -0
  16. package/dist/handlers/create-xero-tracking-option.handler.js +31 -0
  17. package/dist/handlers/delete-xero-payroll-timesheet.handler.js +28 -0
  18. package/dist/handlers/download-xero-invoice-attachment.handler.js +26 -0
  19. package/dist/handlers/get-xero-payroll-timesheet.handler.js +28 -0
  20. package/dist/handlers/history-handler-factory.js +46 -0
  21. package/dist/handlers/list-aged-payables-by-contact.handler.js +37 -0
  22. package/dist/handlers/list-aged-receivables-by-contact.handler.js +37 -0
  23. package/dist/handlers/list-xero-accounts.handler.js +32 -0
  24. package/dist/handlers/list-xero-bank-transactions.handler.js +31 -0
  25. package/dist/handlers/list-xero-contact-groups.handler.js +34 -0
  26. package/dist/handlers/list-xero-contacts.handler.js +37 -0
  27. package/dist/handlers/list-xero-credit-notes.handler.js +34 -0
  28. package/dist/handlers/list-xero-invoice-attachments.handler.js +20 -0
  29. package/dist/handlers/list-xero-invoices.handler.js +59 -0
  30. package/dist/handlers/list-xero-items.handler.js +32 -0
  31. package/dist/handlers/list-xero-manual-journals.handler.js +33 -0
  32. package/dist/handlers/list-xero-organisation-details.handler.js +32 -0
  33. package/dist/handlers/list-xero-payments.handler.js +53 -0
  34. package/dist/handlers/list-xero-payroll-employee-leave-balances.handler.js +42 -0
  35. package/dist/handlers/list-xero-payroll-employee-leave-types.handler.js +42 -0
  36. package/dist/handlers/list-xero-payroll-employee-leave.handler.js +44 -0
  37. package/dist/handlers/list-xero-payroll-employees.handler.js +31 -0
  38. package/dist/handlers/list-xero-payroll-leave-periods.handler.js +44 -0
  39. package/dist/handlers/list-xero-payroll-leave-types.handler.js +40 -0
  40. package/dist/handlers/list-xero-profit-and-loss.handler.js +52 -0
  41. package/dist/handlers/list-xero-quotes.handler.js +37 -0
  42. package/dist/handlers/list-xero-report-balance-sheet.handler.js +34 -0
  43. package/dist/handlers/list-xero-tax-rates.handler.js +30 -0
  44. package/dist/handlers/list-xero-timesheets.handler.js +29 -0
  45. package/dist/handlers/list-xero-tracking-categories.handler.js +29 -0
  46. package/dist/handlers/list-xero-trial-balance.handler.js +42 -0
  47. package/dist/handlers/revert-xero-payroll-timesheet.handler.js +28 -0
  48. package/dist/handlers/update-xero-bank-transaction.handler.js +56 -0
  49. package/dist/handlers/update-xero-contact.handler.js +66 -0
  50. package/dist/handlers/update-xero-credit-note.handler.js +61 -0
  51. package/dist/handlers/update-xero-invoice.handler.js +63 -0
  52. package/dist/handlers/update-xero-item.handler.js +46 -0
  53. package/dist/handlers/update-xero-manual-journal.handler.js +46 -0
  54. package/dist/handlers/update-xero-payroll-timesheet-add-line.handler.js +28 -0
  55. package/dist/handlers/update-xero-payroll-timesheet-update-line.handler.js +28 -0
  56. package/dist/handlers/update-xero-quote.handler.js +78 -0
  57. package/dist/handlers/update-xero-tracking-category.handler.js +43 -0
  58. package/dist/handlers/update-xero-tracking-options.handler.js +51 -0
  59. package/dist/helpers/create-xero-tool.js +6 -0
  60. package/dist/helpers/ensure-error.js +13 -0
  61. package/dist/helpers/format-aged-report-filter.js +8 -0
  62. package/dist/helpers/format-error.js +57 -0
  63. package/dist/helpers/format-line-item.js +13 -0
  64. package/dist/helpers/format-token-error.js +34 -0
  65. package/dist/helpers/format-tracking-option.js +7 -0
  66. package/dist/helpers/get-client-headers.js +8 -0
  67. package/dist/helpers/get-deeplink.js +41 -0
  68. package/dist/helpers/get-external-link.js +8 -0
  69. package/dist/helpers/get-package-version.js +20 -0
  70. package/dist/index.js +16 -0
  71. package/dist/server/xero-mcp-server.js +14 -0
  72. package/dist/tools/create/create-bank-transaction.tool.js +57 -0
  73. package/dist/tools/create/create-contact.tool.js +56 -0
  74. package/dist/tools/create/create-credit-note.tool.js +53 -0
  75. package/dist/tools/create/create-invoice.tool.js +76 -0
  76. package/dist/tools/create/create-item.tool.js +61 -0
  77. package/dist/tools/create/create-manual-journal.tool.js +116 -0
  78. package/dist/tools/create/create-payment.tool.js +71 -0
  79. package/dist/tools/create/create-payroll-timesheet.tool.js +40 -0
  80. package/dist/tools/create/create-quote.tool.js +57 -0
  81. package/dist/tools/create/create-tracking-category.tool.js +28 -0
  82. package/dist/tools/create/create-tracking-options.tool.js +30 -0
  83. package/dist/tools/create/index.js +24 -0
  84. package/dist/tools/delete/delete-payroll-timesheet.tool.js +28 -0
  85. package/dist/tools/delete/index.js +4 -0
  86. package/dist/tools/get/get-invoice-attachment.tool.js +45 -0
  87. package/dist/tools/get/get-payroll-timesheet.tool.js +49 -0
  88. package/dist/tools/get/index.js +6 -0
  89. package/dist/tools/history/index.js +141 -0
  90. package/dist/tools/list/index.js +54 -0
  91. package/dist/tools/list/list-accounts.tool.js +39 -0
  92. package/dist/tools/list/list-aged-payables-by-contact.tool.js +49 -0
  93. package/dist/tools/list/list-aged-receivables-by-contact.tool.js +49 -0
  94. package/dist/tools/list/list-bank-transactions.tool.js +63 -0
  95. package/dist/tools/list/list-contact-groups.tool.js +48 -0
  96. package/dist/tools/list/list-contacts.tool.js +70 -0
  97. package/dist/tools/list/list-credit-notes.tool.js +70 -0
  98. package/dist/tools/list/list-invoice-attachments.tool.js +42 -0
  99. package/dist/tools/list/list-invoices.tool.js +141 -0
  100. package/dist/tools/list/list-items.tool.js +53 -0
  101. package/dist/tools/list/list-manual-journals.tool.js +83 -0
  102. package/dist/tools/list/list-organisation-details.tool.js +90 -0
  103. package/dist/tools/list/list-payments.tool.js +84 -0
  104. package/dist/tools/list/list-payroll-employee-leave-balances.tool.js +39 -0
  105. package/dist/tools/list/list-payroll-employee-leave-types.tool.js +57 -0
  106. package/dist/tools/list/list-payroll-employee-leave.tool.js +42 -0
  107. package/dist/tools/list/list-payroll-employees.tool.js +48 -0
  108. package/dist/tools/list/list-payroll-leave-periods.tool.js +45 -0
  109. package/dist/tools/list/list-payroll-leave-types.tool.js +39 -0
  110. package/dist/tools/list/list-payroll-timesheets.tool.js +39 -0
  111. package/dist/tools/list/list-profit-and-loss.tool.js +45 -0
  112. package/dist/tools/list/list-quotes.tool.js +72 -0
  113. package/dist/tools/list/list-report-balance-sheet.tool.js +39 -0
  114. package/dist/tools/list/list-tax-rates.tool.js +49 -0
  115. package/dist/tools/list/list-tracking-categories.tool.js +39 -0
  116. package/dist/tools/list/list-trial-balance.tool.js +41 -0
  117. package/dist/tools/tool-factory.js +24 -0
  118. package/dist/tools/update/approve-payroll-timesheet.tool.js +29 -0
  119. package/dist/tools/update/index.js +28 -0
  120. package/dist/tools/update/revert-payroll-timesheet.tool.js +29 -0
  121. package/dist/tools/update/update-bank-transaction.tool.js +56 -0
  122. package/dist/tools/update/update-contact.tool.js +69 -0
  123. package/dist/tools/update/update-credit-note.tool.js +56 -0
  124. package/dist/tools/update/update-invoice.tool.js +74 -0
  125. package/dist/tools/update/update-item.tool.js +62 -0
  126. package/dist/tools/update/update-manual-journal-tool.js +89 -0
  127. package/dist/tools/update/update-payroll-timesheet-add-line.tool.js +34 -0
  128. package/dist/tools/update/update-payroll-timesheet-update-line.tool.js +35 -0
  129. package/dist/tools/update/update-quote.tool.js +61 -0
  130. package/dist/tools/update/update-tracking-category.tool.js +30 -0
  131. package/dist/tools/update/update-tracking-options.tool.js +35 -0
  132. package/dist/types/list-report-balance-sheet-params.js +1 -0
  133. package/dist/types/timeframeType.js +1 -0
  134. package/dist/types/tool-definition.js +1 -0
  135. package/dist/types/tool-list.js +1 -0
  136. package/dist/types/tool-response.js +1 -0
  137. package/package.json +63 -0
@@ -0,0 +1,57 @@
1
+ import { AxiosError } from "axios";
2
+ function isXeroSdkError(error) {
3
+ if (typeof error !== "object" || error === null)
4
+ return false;
5
+ const response = error.response;
6
+ if (typeof response !== "object" || response === null)
7
+ return false;
8
+ return typeof response.statusCode === "number";
9
+ }
10
+ function formatHttpStatus(status) {
11
+ switch (status) {
12
+ case 401:
13
+ return "Authentication failed. Please check your Xero credentials.";
14
+ case 403:
15
+ return "You don't have permission to access this resource in Xero.";
16
+ case 404:
17
+ return "The requested resource was not found in Xero.";
18
+ case 429:
19
+ return "Too many requests to Xero. Please try again in a moment.";
20
+ default:
21
+ return "";
22
+ }
23
+ }
24
+ /**
25
+ * Format error messages for return to the LLM.
26
+ *
27
+ * Never stringify unknown error objects. The xero-node SDK rejects with a
28
+ * plain object whose request headers can contain bearer tokens, so only
29
+ * whitelisted response fields are exposed.
30
+ */
31
+ export function formatError(error) {
32
+ if (error instanceof AxiosError) {
33
+ const status = error.response?.status;
34
+ const detail = error.response?.data?.Detail;
35
+ if (status !== undefined) {
36
+ const mapped = formatHttpStatus(status);
37
+ if (mapped)
38
+ return mapped;
39
+ }
40
+ return detail || "An error occurred while communicating with Xero.";
41
+ }
42
+ if (isXeroSdkError(error)) {
43
+ const status = error.response.statusCode;
44
+ const mapped = formatHttpStatus(status);
45
+ if (mapped)
46
+ return mapped;
47
+ const body = error.response.body;
48
+ const problem = body?.problem;
49
+ const title = problem?.title ?? body?.httpStatusCode ?? "HTTP error";
50
+ const detail = problem?.detail ?? body?.Detail;
51
+ return detail ? `${status} ${title}: ${detail}` : `${status} ${title}`;
52
+ }
53
+ if (error instanceof Error) {
54
+ return error.message;
55
+ }
56
+ return "An unexpected error occurred while communicating with Xero.";
57
+ }
@@ -0,0 +1,13 @@
1
+ export const formatLineItem = (lineItem) => {
2
+ return [
3
+ `Item ID: ${lineItem.item}`,
4
+ `Item Code: ${lineItem.itemCode}`,
5
+ `Description: ${lineItem.description}`,
6
+ `Quantity: ${lineItem.quantity}`,
7
+ `Unit Amount: ${lineItem.unitAmount}`,
8
+ `Account Code: ${lineItem.accountCode}`,
9
+ `Tax Type: ${lineItem.taxType}`,
10
+ `Tracking: ${lineItem.tracking}`,
11
+ `Line Amount: ${lineItem.lineAmount}`,
12
+ ].join("\n");
13
+ };
@@ -0,0 +1,34 @@
1
+ import axios from "axios";
2
+ const REQUIRED_SCOPE_MESSAGE = "Xero authentication failed: your Custom Connection is missing required scopes. " +
3
+ "Go to https://developer.xero.com/app/manage, select your app, and ensure these scopes are enabled: " +
4
+ "accounting.transactions, accounting.contacts, accounting.settings, accounting.reports.read, " +
5
+ "accounting.attachments.read, payroll.settings, payroll.employees, payroll.timesheets";
6
+ function isRecord(value) {
7
+ return typeof value === "object" && value !== null;
8
+ }
9
+ function isInvalidScopeResponse(data) {
10
+ return isRecord(data) && data.error === "invalid_scope";
11
+ }
12
+ export function formatTokenRequestError(error) {
13
+ if (!axios.isAxiosError(error)) {
14
+ return "Xero authentication failed. Please check your Xero connection details.";
15
+ }
16
+ const data = error.response?.data;
17
+ if (isInvalidScopeResponse(data)) {
18
+ return REQUIRED_SCOPE_MESSAGE;
19
+ }
20
+ const status = error.response?.status;
21
+ switch (status) {
22
+ case 401:
23
+ return "Xero authentication failed. Please check your Xero client ID and client secret.";
24
+ case 403:
25
+ return "Xero authentication failed. The Xero connection does not have permission for the requested scopes.";
26
+ case 429:
27
+ return "Xero authentication failed because Xero rate limited the token request. Please try again in a moment.";
28
+ default:
29
+ if (status !== undefined) {
30
+ return `Xero authentication failed with HTTP ${status}. Please check your Xero connection details.`;
31
+ }
32
+ return "Xero authentication failed before Xero returned a response. Please check your network connection and connection details.";
33
+ }
34
+ }
@@ -0,0 +1,7 @@
1
+ export const formatTrackingOption = (option) => {
2
+ return [
3
+ `Option ID: ${option.trackingOptionID}`,
4
+ `Name: ${option.name}`,
5
+ `Status: ${option.status}`
6
+ ].join("\n");
7
+ };
@@ -0,0 +1,8 @@
1
+ import { getPackageVersion } from "./get-package-version.js";
2
+ export const getClientHeaders = () => {
3
+ return {
4
+ headers: {
5
+ "user-agent": `xero-mcp-server-${getPackageVersion()}`,
6
+ },
7
+ };
8
+ };
@@ -0,0 +1,41 @@
1
+ import { xeroClient } from "../clients/xero-client.js";
2
+ import { contactDeepLink, creditNoteDeepLink, invoiceDeepLink, paymentDeepLink, manualJournalDeepLink, quoteDeepLink, billDeepLink, } from "../consts/deeplinks.js";
3
+ export var DeepLinkType;
4
+ (function (DeepLinkType) {
5
+ DeepLinkType[DeepLinkType["CONTACT"] = 0] = "CONTACT";
6
+ DeepLinkType[DeepLinkType["CREDIT_NOTE"] = 1] = "CREDIT_NOTE";
7
+ DeepLinkType[DeepLinkType["INVOICE"] = 2] = "INVOICE";
8
+ DeepLinkType[DeepLinkType["MANUAL_JOURNAL"] = 3] = "MANUAL_JOURNAL";
9
+ DeepLinkType[DeepLinkType["QUOTE"] = 4] = "QUOTE";
10
+ DeepLinkType[DeepLinkType["PAYMENT"] = 5] = "PAYMENT";
11
+ DeepLinkType[DeepLinkType["BILL"] = 6] = "BILL";
12
+ })(DeepLinkType || (DeepLinkType = {}));
13
+ /**
14
+ * Gets a deep link for a specific type and item ID.
15
+ * This will also fetch the org short code from the Xero client.
16
+ * @param type
17
+ * @param itemId
18
+ * @returns
19
+ */
20
+ export const getDeepLink = async (type, itemId) => {
21
+ const orgShortCode = await xeroClient.getShortCode();
22
+ if (!orgShortCode) {
23
+ throw new Error("Failed to retrieve organisation short code");
24
+ }
25
+ switch (type) {
26
+ case DeepLinkType.CONTACT:
27
+ return contactDeepLink(orgShortCode, itemId);
28
+ case DeepLinkType.CREDIT_NOTE:
29
+ return creditNoteDeepLink(orgShortCode, itemId);
30
+ case DeepLinkType.MANUAL_JOURNAL:
31
+ return manualJournalDeepLink(itemId);
32
+ case DeepLinkType.INVOICE:
33
+ return invoiceDeepLink(orgShortCode, itemId);
34
+ case DeepLinkType.QUOTE:
35
+ return quoteDeepLink(orgShortCode, itemId);
36
+ case DeepLinkType.PAYMENT:
37
+ return paymentDeepLink(orgShortCode, itemId);
38
+ case DeepLinkType.BILL:
39
+ return billDeepLink(orgShortCode, itemId);
40
+ }
41
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Helper function to encode a URL for external links
3
+ * @param url The URL to encode for external linking
4
+ * @returns The encoded URL string
5
+ */
6
+ export const getExternalLink = (url) => {
7
+ return encodeURIComponent(url);
8
+ };
@@ -0,0 +1,20 @@
1
+ import { readFileSync } from 'fs';
2
+ import { fileURLToPath } from 'url';
3
+ import { dirname, join } from 'path';
4
+ /**
5
+ * Gets the package version from package.json
6
+ * @returns The package version string
7
+ */
8
+ export function getPackageVersion() {
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = dirname(__filename);
11
+ const packagePath = join(__dirname, '../../package.json');
12
+ try {
13
+ const packageJson = JSON.parse(readFileSync(packagePath, 'utf-8'));
14
+ return packageJson.version;
15
+ }
16
+ catch (error) {
17
+ console.warn('Failed to read package version:', error);
18
+ return '0.0.0'; // Fallback version
19
+ }
20
+ }
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
+ import { XeroMcpServer } from "./server/xero-mcp-server.js";
4
+ import { ToolFactory } from "./tools/tool-factory.js";
5
+ const main = async () => {
6
+ // Create an MCP server
7
+ const server = XeroMcpServer.GetServer();
8
+ ToolFactory(server);
9
+ // Start receiving messages on stdin and sending messages on stdout
10
+ const transport = new StdioServerTransport();
11
+ await server.connect(transport);
12
+ };
13
+ main().catch((error) => {
14
+ console.error("Error:", error);
15
+ process.exit(1);
16
+ });
@@ -0,0 +1,14 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ export class XeroMcpServer {
3
+ static instance = null;
4
+ constructor() { }
5
+ static GetServer() {
6
+ if (XeroMcpServer.instance === null) {
7
+ XeroMcpServer.instance = new McpServer({
8
+ name: "Xero MCP Server",
9
+ version: "1.0.0",
10
+ });
11
+ }
12
+ return XeroMcpServer.instance;
13
+ }
14
+ }
@@ -0,0 +1,57 @@
1
+ import { z } from "zod";
2
+ import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
3
+ import { createXeroBankTransaction } from "../../handlers/create-xero-bank-transaction.handler.js";
4
+ import { bankTransactionDeepLink } from "../../consts/deeplinks.js";
5
+ const lineItemSchema = z.object({
6
+ description: z.string(),
7
+ quantity: z.number(),
8
+ unitAmount: z.number(),
9
+ accountCode: z.string(),
10
+ taxType: z.string(),
11
+ });
12
+ const CreateBankTransactionTool = CreateXeroTool("create-bank-transaction", `Create a bank transaction in Xero.
13
+ When a bank transaction is created, a deep link to the bank transaction in Xero is returned.
14
+ This deep link can be used to view the bank transaction in Xero directly.
15
+ This link should be displayed to the user.`, {
16
+ type: z.enum(["RECEIVE", "SPEND"]),
17
+ bankAccountId: z.string(),
18
+ contactId: z.string(),
19
+ lineItems: z.array(lineItemSchema),
20
+ reference: z.string().optional(),
21
+ date: z.string()
22
+ .optional()
23
+ .describe("If no date is provided, the date will default to today's date")
24
+ }, async ({ type, bankAccountId, contactId, lineItems, reference, date }) => {
25
+ const result = await createXeroBankTransaction(type, bankAccountId, contactId, lineItems, reference, date);
26
+ if (result.isError) {
27
+ return {
28
+ content: [
29
+ {
30
+ type: "text",
31
+ text: `Error creating bank transaction: ${result.error}`
32
+ }
33
+ ]
34
+ };
35
+ }
36
+ const bankTransaction = result.result;
37
+ const deepLink = bankTransaction.bankAccount.accountID && bankTransaction.bankTransactionID
38
+ ? bankTransactionDeepLink(bankTransaction.bankAccount.accountID, bankTransaction.bankTransactionID)
39
+ : null;
40
+ return {
41
+ content: [
42
+ {
43
+ type: "text",
44
+ text: [
45
+ "Bank transaction successfully:",
46
+ `ID: ${bankTransaction?.bankTransactionID}`,
47
+ `Date: ${bankTransaction?.date}`,
48
+ `Contact: ${bankTransaction?.contact?.name}`,
49
+ `Total: ${bankTransaction?.total}`,
50
+ `Status: ${bankTransaction?.status}`,
51
+ deepLink ? `Link to view: ${deepLink}` : null
52
+ ].filter(Boolean).join("\n"),
53
+ },
54
+ ],
55
+ };
56
+ });
57
+ export default CreateBankTransactionTool;
@@ -0,0 +1,56 @@
1
+ import { createXeroContact } from "../../handlers/create-xero-contact.handler.js";
2
+ import { z } from "zod";
3
+ import { DeepLinkType, getDeepLink } from "../../helpers/get-deeplink.js";
4
+ import { ensureError } from "../../helpers/ensure-error.js";
5
+ import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
6
+ const CreateContactTool = CreateXeroTool("create-contact", "Create a contact in Xero.\
7
+ When a contact is created, a deep link to the contact in Xero is returned. \
8
+ This deep link can be used to view the contact in Xero directly. \
9
+ This link should be displayed to the user.", {
10
+ name: z.string(),
11
+ email: z.string().email().optional(),
12
+ phone: z.string().optional(),
13
+ }, async ({ name, email, phone }) => {
14
+ try {
15
+ const response = await createXeroContact(name, email, phone);
16
+ if (response.isError) {
17
+ return {
18
+ content: [
19
+ {
20
+ type: "text",
21
+ text: `Error creating contact: ${response.error}`,
22
+ },
23
+ ],
24
+ };
25
+ }
26
+ const contact = response.result;
27
+ const deepLink = contact.contactID
28
+ ? await getDeepLink(DeepLinkType.CONTACT, contact.contactID)
29
+ : null;
30
+ return {
31
+ content: [
32
+ {
33
+ type: "text",
34
+ text: [
35
+ `Contact created: ${contact.name} (ID: ${contact.contactID})`,
36
+ deepLink ? `Link to view: ${deepLink}` : null,
37
+ ]
38
+ .filter(Boolean)
39
+ .join("\n"),
40
+ },
41
+ ],
42
+ };
43
+ }
44
+ catch (error) {
45
+ const err = ensureError(error);
46
+ return {
47
+ content: [
48
+ {
49
+ type: "text",
50
+ text: `Error creating contact: ${err.message}`,
51
+ },
52
+ ],
53
+ };
54
+ }
55
+ });
56
+ export default CreateContactTool;
@@ -0,0 +1,53 @@
1
+ import { z } from "zod";
2
+ import { createXeroCreditNote } from "../../handlers/create-xero-credit-note.handler.js";
3
+ import { DeepLinkType, getDeepLink } from "../../helpers/get-deeplink.js";
4
+ import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
5
+ const lineItemSchema = z.object({
6
+ description: z.string(),
7
+ quantity: z.number(),
8
+ unitAmount: z.number(),
9
+ accountCode: z.string(),
10
+ taxType: z.string(),
11
+ });
12
+ const CreateCreditNoteTool = CreateXeroTool("create-credit-note", "Create a credit note in Xero.\
13
+ When a credit note is created, a deep link to the credit note in Xero is returned. \
14
+ This deep link can be used to view the credit note in Xero directly. \
15
+ This link should be displayed to the user.", {
16
+ contactId: z.string(),
17
+ lineItems: z.array(lineItemSchema),
18
+ reference: z.string().optional(),
19
+ }, async ({ contactId, lineItems, reference }) => {
20
+ const result = await createXeroCreditNote(contactId, lineItems, reference);
21
+ if (result.isError) {
22
+ return {
23
+ content: [
24
+ {
25
+ type: "text",
26
+ text: `Error creating credit note: ${result.error}`,
27
+ },
28
+ ],
29
+ };
30
+ }
31
+ const creditNote = result.result;
32
+ const deepLink = creditNote.creditNoteID
33
+ ? await getDeepLink(DeepLinkType.CREDIT_NOTE, creditNote.creditNoteID)
34
+ : null;
35
+ return {
36
+ content: [
37
+ {
38
+ type: "text",
39
+ text: [
40
+ "Credit note created successfully:",
41
+ `ID: ${creditNote?.creditNoteID}`,
42
+ `Contact: ${creditNote?.contact?.name}`,
43
+ `Total: ${creditNote?.total}`,
44
+ `Status: ${creditNote?.status}`,
45
+ deepLink ? `Link to view: ${deepLink}` : null,
46
+ ]
47
+ .filter(Boolean)
48
+ .join("\n"),
49
+ },
50
+ ],
51
+ };
52
+ });
53
+ export default CreateCreditNoteTool;
@@ -0,0 +1,76 @@
1
+ import { z } from "zod";
2
+ import { createXeroInvoice } from "../../handlers/create-xero-invoice.handler.js";
3
+ import { DeepLinkType, getDeepLink } from "../../helpers/get-deeplink.js";
4
+ import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
5
+ import { CurrencyCode, Invoice } from "xero-node";
6
+ const trackingSchema = z.object({
7
+ name: z.string().describe("The name of the tracking category. Can be obtained from the list-tracking-categories tool"),
8
+ option: z.string().describe("The name of the tracking option. Can be obtained from the list-tracking-categories tool"),
9
+ trackingCategoryID: z.string().describe("The ID of the tracking category. \
10
+ Can be obtained from the list-tracking-categories tool"),
11
+ });
12
+ const lineItemSchema = z.object({
13
+ description: z.string().describe("The description of the line item"),
14
+ quantity: z.number().describe("The quantity of the line item"),
15
+ unitAmount: z.number().describe("The price per unit of the line item"),
16
+ accountCode: z.string().describe("The account code of the line item - can be obtained from the list-accounts tool"),
17
+ taxType: z.string().describe("The tax type of the line item - can be obtained from the list-tax-rates tool"),
18
+ itemCode: z.string().describe("The item code of the line item - can be obtained from the list-items tool \
19
+ If the item is not listed, add without an item code and ask the user if they would like to add an item code.").optional(),
20
+ tracking: z.array(trackingSchema).describe("Up to 2 tracking categories and options can be added to the line item. \
21
+ Can be obtained from the list-tracking-categories tool. \
22
+ Only use if prompted by the user.").optional(),
23
+ });
24
+ const CreateInvoiceTool = CreateXeroTool("create-invoice", "Create an invoice in Xero.\
25
+ When an invoice is created, a deep link to the invoice in Xero is returned. \
26
+ This deep link can be used to view the invoice in Xero directly. \
27
+ This link should be displayed to the user.", {
28
+ contactId: z.string().describe("The ID of the contact to create the invoice for. \
29
+ Can be obtained from the list-contacts tool."),
30
+ lineItems: z.array(lineItemSchema),
31
+ type: z.enum(["ACCREC", "ACCPAY"]).describe("The type of invoice to create. \
32
+ ACCREC is for sales invoices, Accounts Receivable, or customer invoices. \
33
+ ACCPAY is for purchase invoices, Accounts Payable invoices, supplier invoices, or bills. \
34
+ If the type is not specified, the default is ACCREC."),
35
+ reference: z.string().describe("A reference number for the invoice.").optional(),
36
+ date: z.string().describe("The date the invoice was created (YYYY-MM-DD format).").optional(),
37
+ currencyCode: z.nativeEnum(CurrencyCode).describe("Optional invoice currency, such as USD. Only use a currency enabled in the connected Xero organisation.").optional(),
38
+ }, async ({ contactId, lineItems, type, reference, date, currencyCode }) => {
39
+ const xeroInvoiceType = type === "ACCREC" ? Invoice.TypeEnum.ACCREC : Invoice.TypeEnum.ACCPAY;
40
+ const result = await createXeroInvoice(contactId, lineItems, xeroInvoiceType, reference, date, currencyCode);
41
+ if (result.isError) {
42
+ return {
43
+ content: [
44
+ {
45
+ type: "text",
46
+ text: `Error creating invoice: ${result.error}`,
47
+ },
48
+ ],
49
+ };
50
+ }
51
+ const invoice = result.result;
52
+ const deepLink = invoice.invoiceID
53
+ ? await getDeepLink(invoice.type === Invoice.TypeEnum.ACCREC ? DeepLinkType.INVOICE : DeepLinkType.BILL, invoice.invoiceID)
54
+ : null;
55
+ return {
56
+ content: [
57
+ {
58
+ type: "text",
59
+ text: [
60
+ "Invoice created successfully:",
61
+ `ID: ${invoice?.invoiceID}`,
62
+ `Contact: ${invoice?.contact?.name}`,
63
+ `Type: ${invoice?.type}`,
64
+ `Date: ${invoice?.date}`,
65
+ invoice?.currencyCode ? `Currency: ${invoice.currencyCode}` : null,
66
+ `Total: ${invoice?.total}`,
67
+ `Status: ${invoice?.status}`,
68
+ deepLink ? `Link to view: ${deepLink}` : null,
69
+ ]
70
+ .filter(Boolean)
71
+ .join("\n"),
72
+ },
73
+ ],
74
+ };
75
+ });
76
+ export default CreateInvoiceTool;
@@ -0,0 +1,61 @@
1
+ import { z } from "zod";
2
+ import { createXeroItem } from "../../handlers/create-xero-item.handler.js";
3
+ import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
4
+ const purchaseDetailsSchema = z.object({
5
+ unitPrice: z.number(),
6
+ taxType: z.string().optional(),
7
+ accountCode: z.string().optional(),
8
+ });
9
+ const salesDetailsSchema = z.object({
10
+ unitPrice: z.number(),
11
+ taxType: z.string().optional(),
12
+ accountCode: z.string().optional(),
13
+ });
14
+ const CreateItemTool = CreateXeroTool("create-item", "Create an item in Xero.", {
15
+ code: z.string(),
16
+ name: z.string(),
17
+ description: z.string().optional(),
18
+ purchaseDescription: z.string().optional(),
19
+ purchaseDetails: purchaseDetailsSchema.optional(),
20
+ salesDetails: salesDetailsSchema.optional(),
21
+ isTrackedAsInventory: z.boolean().optional(),
22
+ inventoryAssetAccountCode: z.string().optional(),
23
+ }, async ({ code, name, description, purchaseDescription, purchaseDetails, salesDetails, isTrackedAsInventory, inventoryAssetAccountCode, }) => {
24
+ const result = await createXeroItem({
25
+ code,
26
+ name,
27
+ description,
28
+ purchaseDescription,
29
+ purchaseDetails,
30
+ salesDetails,
31
+ isTrackedAsInventory,
32
+ inventoryAssetAccountCode,
33
+ });
34
+ if (result.isError) {
35
+ return {
36
+ content: [
37
+ {
38
+ type: "text",
39
+ text: `Error creating item: ${result.error}`,
40
+ },
41
+ ],
42
+ };
43
+ }
44
+ const item = result.result;
45
+ return {
46
+ content: [
47
+ {
48
+ type: "text",
49
+ text: [
50
+ "Item created successfully:",
51
+ `ID: ${item?.itemID}`,
52
+ `Code: ${item?.code}`,
53
+ `Name: ${item?.name}`,
54
+ ]
55
+ .filter(Boolean)
56
+ .join("\n"),
57
+ },
58
+ ],
59
+ };
60
+ });
61
+ export default CreateItemTool;
@@ -0,0 +1,116 @@
1
+ import { z } from "zod";
2
+ import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
3
+ import { createXeroManualJournal } from "../../handlers/create-xero-manual-journal.handler.js";
4
+ import { DeepLinkType, getDeepLink } from "../../helpers/get-deeplink.js";
5
+ import { ensureError } from "../../helpers/ensure-error.js";
6
+ const CreateManualJournalTool = CreateXeroTool("create-manual-journal", "Create a manual journal in Xero.\
7
+ Retrieve a list of account codes in Xero to use for the journal lines.\
8
+ Journal lines must contain at least two individual journal lines with account codes, \
9
+ use basic accounting account types pairing when not specified, \
10
+ and make sure journal line pairs have credit and debit balanced.", {
11
+ narration: z
12
+ .string()
13
+ .describe("Description of manual journal being posted"),
14
+ manualJournalLines: z
15
+ .array(z.object({
16
+ lineAmount: z
17
+ .number()
18
+ .describe("Total for manual journal line. Debits are positive, credits are negative value"),
19
+ accountCode: z.string().describe("Account code for the journal line"),
20
+ description: z
21
+ .string()
22
+ .optional()
23
+ .describe("Optional description for manual journal line"),
24
+ taxType: z
25
+ .string()
26
+ .optional()
27
+ .describe("Optional tax type for the manual journal line"),
28
+ // TODO: TODO: tracking can be added here
29
+ }))
30
+ .describe("The manualJournalLines element must contain at least two individual manualJournalLine sub-elements"),
31
+ date: z.string().optional().describe("Optional date in YYYY-MM-DD format"),
32
+ lineAmountTypes: z
33
+ .enum(["EXCLUSIVE", "INCLUSIVE", "NO_TAX"])
34
+ .optional()
35
+ .describe("Optional line amount types (EXCLUSIVE, INCLUSIVE, NO_TAX), NO_TAX by default"),
36
+ status: z
37
+ .enum(["DRAFT", "POSTED", "DELETED", "VOIDED", "ARCHIVED"])
38
+ .optional()
39
+ .describe("Optional status of the manual journal (DRAFT, POSTED, DELETED, VOIDED, ARCHIVED), DRAFT by default"),
40
+ url: z
41
+ .string()
42
+ .optional()
43
+ .describe("Optional URL link to a source document"),
44
+ showOnCashBasisReports: z
45
+ .boolean()
46
+ .optional()
47
+ .describe("Optional boolean to show on cash basis reports, default is true"),
48
+ }, async (args) => {
49
+ try {
50
+ const response = await createXeroManualJournal(args.narration, args.manualJournalLines, args.date, args.lineAmountTypes, args.status, args.url, args.showOnCashBasisReports);
51
+ if (response.isError) {
52
+ return {
53
+ content: [
54
+ {
55
+ type: "text",
56
+ text: `Error creating manual journal: ${response.error}`,
57
+ },
58
+ ],
59
+ };
60
+ }
61
+ const manualJournal = response.result;
62
+ const deepLink = manualJournal.manualJournalID
63
+ ? await getDeepLink(DeepLinkType.MANUAL_JOURNAL, manualJournal.manualJournalID)
64
+ : null;
65
+ return {
66
+ content: [
67
+ {
68
+ type: "text",
69
+ text: [
70
+ `Manual journal created: ${manualJournal.narration} (ID: ${manualJournal.manualJournalID})`,
71
+ manualJournal.date ? `Date: ${manualJournal.date}` : null,
72
+ manualJournal.status
73
+ ? `Status: ${manualJournal.status}`
74
+ : "No status",
75
+ manualJournal.journalLines
76
+ ? manualJournal.journalLines.map((line) => ({
77
+ type: "text",
78
+ text: [
79
+ `Line Amount: ${line.lineAmount}`,
80
+ line.accountCode
81
+ ? `Account Code: ${line.accountCode}`
82
+ : "No account code",
83
+ line.description
84
+ ? `Description: ${line.description}`
85
+ : "No description",
86
+ line.taxType
87
+ ? `Tax Type: ${line.taxType}`
88
+ : "No tax type",
89
+ `Tax Amount: ${line.taxAmount}`,
90
+ ]
91
+ .filter(Boolean)
92
+ .join("\n"),
93
+ }))
94
+ : [{ type: "text", text: "No journal lines" }],
95
+ `Show on Cash Basis Reports: ${manualJournal.showOnCashBasisReports}`,
96
+ deepLink ? `Link to view: ${deepLink}` : null,
97
+ ]
98
+ .filter(Boolean)
99
+ .join("\n"),
100
+ },
101
+ ],
102
+ };
103
+ }
104
+ catch (error) {
105
+ const err = ensureError(error);
106
+ return {
107
+ content: [
108
+ {
109
+ type: "text",
110
+ text: `Error creating manual journal: ${err.message}`,
111
+ },
112
+ ],
113
+ };
114
+ }
115
+ });
116
+ export default CreateManualJournalTool;