Skip to content

Commit 2c927e9

Browse files
feat: list tools for invoices, journals, payments and quotes
1 parent 7dc6db8 commit 2c927e9

File tree

6 files changed

+116
-1
lines changed

6 files changed

+116
-1
lines changed

src/Tools/Invoices.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { XeroClientSession } from "../XeroApiClient.js";
2+
import { IMcpServerTool } from "./IMcpServerTool.js";
3+
import { z } from "zod";
4+
5+
export const ListInvoicesTool: IMcpServerTool = {
6+
requestSchema: {
7+
name: "list_invoices",
8+
description: "List all invoices",
9+
inputSchema: { type: "object", properties: {} },
10+
output: { content: [{ type: "text", text: z.string() }] },
11+
},
12+
requestHandler: async () => {
13+
const response =
14+
await XeroClientSession.xeroClient.accountingApi.getInvoices(
15+
XeroClientSession.activeTenantId()!!
16+
);
17+
const invoices = response.body.invoices || [];
18+
return {
19+
content: [
20+
{
21+
type: "text",
22+
text: JSON.stringify(invoices),
23+
},
24+
],
25+
};
26+
},
27+
};

src/Tools/Journals.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { XeroClientSession } from "../XeroApiClient.js";
2+
import { IMcpServerTool } from "./IMcpServerTool.js";
3+
import { z } from "zod";
4+
5+
export const ListJournalsTool: IMcpServerTool = {
6+
requestSchema: {
7+
name: "list_journals",
8+
description: "List all journals",
9+
inputSchema: { type: "object", properties: {} },
10+
output: { content: [{ type: "text", text: z.string() }] },
11+
},
12+
requestHandler: async () => {
13+
const response =
14+
await XeroClientSession.xeroClient.accountingApi.getJournals(
15+
XeroClientSession.activeTenantId()!!
16+
);
17+
const journals = response.body.journals || [];
18+
return {
19+
content: [
20+
{
21+
type: "text",
22+
text: JSON.stringify(journals),
23+
},
24+
],
25+
};
26+
},
27+
};

src/Tools/McpToolsFactory.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@ import { AuthenticateTool } from "./Authenticate.js";
33
import { ListBankTransactionsTool } from "./BankTransactions.js";
44
import { ListContactsTool } from "./Contacts.js";
55
import { IMcpServerTool } from "./IMcpServerTool.js";
6+
import { ListInvoicesTool } from "./Invoices.js";
7+
import { ListJournalsTool } from "./Journals.js";
68
import { ListOrganisationsTool } from "./Organisations.js";
9+
import { ListPaymentsTool } from "./Payments.js";
10+
import { ListQuotesTool } from "./Quotes.js";
711

812
export const McpToolsFactory = (function () {
913
const tools: IMcpServerTool[] = [
1014
AuthenticateTool,
1115
ListAccountsTool,
1216
ListBankTransactionsTool,
1317
ListContactsTool,
18+
ListInvoicesTool,
19+
ListJournalsTool,
1420
ListOrganisationsTool,
21+
ListPaymentsTool,
22+
ListQuotesTool,
1523
// register new tools here alphabetically
1624
];
1725

src/Tools/Payments.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { XeroClientSession } from "../XeroApiClient.js";
2+
import { IMcpServerTool } from "./IMcpServerTool.js";
3+
import { z } from "zod";
4+
5+
export const ListPaymentsTool: IMcpServerTool = {
6+
requestSchema: {
7+
name: "list_payments",
8+
description: "List all payments",
9+
inputSchema: { type: "object", properties: {} },
10+
output: { content: [{ type: "text", text: z.string() }] },
11+
},
12+
requestHandler: async () => {
13+
const response =
14+
await XeroClientSession.xeroClient.accountingApi.getPayments(
15+
XeroClientSession.activeTenantId()!!
16+
);
17+
const payments = response.body.payments || [];
18+
return {
19+
content: [
20+
{
21+
type: "text",
22+
text: JSON.stringify(payments),
23+
},
24+
],
25+
};
26+
},
27+
};

src/Tools/Quotes.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { XeroClientSession } from "../XeroApiClient.js";
2+
import { IMcpServerTool } from "./IMcpServerTool.js";
3+
import { z } from "zod";
4+
5+
export const ListQuotesTool: IMcpServerTool = {
6+
requestSchema: {
7+
name: "list_quotes",
8+
description: "List all quotes",
9+
inputSchema: { type: "object", properties: {} },
10+
output: { content: [{ type: "text", text: z.string() }] },
11+
},
12+
requestHandler: async () => {
13+
const response = await XeroClientSession.xeroClient.accountingApi.getQuotes(
14+
XeroClientSession.activeTenantId()!!
15+
);
16+
const quotes = response.body.quotes || [];
17+
return {
18+
content: [
19+
{
20+
type: "text",
21+
text: JSON.stringify(quotes),
22+
},
23+
],
24+
};
25+
},
26+
};

src/XeroApiClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const client_id = process.env.XERO_CLIENT_ID;
55
const client_secret = process.env.XERO_CLIENT_SECRET;
66
const redirectUrl = process.env.XERO_REDIRECT_URI;
77
const scopes =
8-
"offline_access openid profile email accounting.transactions accounting.budgets.read accounting.reports.read accounting.journals.read accounting.settings accounting.settings.read accounting.contacts accounting.contacts.read accounting.attachments accounting.attachments.read files files.read assets assets.read projects projects.read";
8+
"offline_access openid profile accounting.transactions accounting.contacts.read accounting.journals.read";
99

1010
if (!client_id || !client_secret || !redirectUrl) {
1111
throw Error(

0 commit comments

Comments
 (0)