@diy-accounting-uk/diya-submit 0.1.3 → 0.1.4
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 +4 -2
- package/lib/book-tools.js +33 -12
- package/lib/handoff-tools.js +6 -4
- package/lib/server.js +10 -10
- package/lib/submit-tools.js +29 -11
- package/lib/vat-tools.js +14 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,7 +40,9 @@ Cowork), or in Claude Code:
|
|
|
40
40
|
claude mcp add --transport http diya-submit https://submit.diyaccounting.co.uk/mcp
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
The
|
|
43
|
+
The endpoint answers `initialize`, `ping` and `tools/list` without a token, so a client or a catalogue
|
|
44
|
+
can read the tools first. The first tool call without a token gets 401 with a `WWW-Authenticate`
|
|
45
|
+
challenge. The client finds the sign-in through `/.well-known/oauth-protected-resource/mcp`, registers itself, and
|
|
44
46
|
the user signs in with their Submit account. The ci form of the URL is
|
|
45
47
|
`https://ci-submit.diyaccounting.co.uk/mcp`. The hosted tool set is `HOSTED_TOOL_NAMES` in
|
|
46
48
|
`lib/hosted-tools.js`: `open_book` reads the DIYA cloud only. The sign-in pair, the filesystem tools,
|
|
@@ -64,7 +66,7 @@ HMRC requires data about the device behind each request. The two surfaces send d
|
|
|
64
66
|
| `request_hmrc_authorisation` | HMRC's sign-in link for this session. `services` is `vat` (the default) and `itsa`; `hmrcAccount` is `live` (the default) or `synthetic`. Answers `url`, `expiresAt`, `scope`, `hmrcAccount`. The user grants access on HMRC's pages; Submit keeps HMRC's tokens and renews the access token for the rest of the session. No token reaches the chat. |
|
|
65
67
|
| `list_vat_obligations` | VAT obligations for `vrn` (or `clientId`), filtered by `from`, `to`, `status`. Uses the session's HMRC authorisation; optional `hmrcAccount` (the authorisation's own by default), `govTestScenario`. |
|
|
66
68
|
| `submit_vat_return` | Files the seven confirmed boxes (`vatDueSales`, `vatDueAcquisitions`, `vatReclaimedCurrPeriod`, `totalValueSalesExVAT`, `totalValuePurchasesExVAT`, `totalValueGoodsSuppliedExVAT`, `totalAcquisitionsExVAT`) for `periodStart` to `periodEnd`, for `vatNumber` or `clientId`. Uses the session's HMRC authorisation. Answers `receipt`, `periodKey`, `receiptId`. |
|
|
67
|
-
| `get_vat_receipt` | A stored receipt by `name` (`<receiptId>.json`); optional `clientId`. |
|
|
69
|
+
| `get_vat_receipt` | A stored VAT return receipt by `name` (`<receiptId>.json`); optional `clientId`. Answers HMRC's `processingDate`, `formBundleNumber`, `paymentIndicator` and `chargeRefNumber`. |
|
|
68
70
|
| `render_micro_entity_accounts_sandbox` | The rendered micro-entity iXBRL for confirmed figures, without reaching the Companies House gateway. Inputs: `companyNumber`, `companyName`, `periodStart`, `periodEnd`, `balanceSheet`, `averageEmployees`, `director`, `statementsAccepted`. |
|
|
69
71
|
| `render_small_company_accounts_sandbox` | The rendered small-company (FRS 102 section 1A) iXBRL for confirmed figures, without reaching the gateway. Inputs: `companyNumber`, `companyName`, `periodStart`, `periodEnd`, `averageEmployees`, `director`, `statementsAccepted` (four small-company statements) and `smallCompany` (`filleted`, `principalActivity`, `accountingPolicies`, `directors`, `balanceSheet`, `profitAndLoss`, `fixedAssetNote`). |
|
|
70
72
|
| `request_companies_house_codes` | A link where the user types the Companies House codes instead of the chat. `kind` is `accounts`, `confirmation-statement` (with `directors` in filing order) or `confirmation-statement-data`; answers `entryId`, `url`, `expiresAt`. The entry lasts ten minutes and one filing call uses it up. With `clientIds` (no `companyNumber`) the page asks for one code per practice client and each client's filing call, including through `run_for_clients`, takes only its own. |
|
package/lib/book-tools.js
CHANGED
|
@@ -107,13 +107,11 @@ async function bookChecksFor(book, lines) {
|
|
|
107
107
|
* The summary open_book answers: what the book is, whose it is, which period
|
|
108
108
|
* it covers, how many lines it holds, and the check and warning counts.
|
|
109
109
|
*/
|
|
110
|
-
function summarise(session,
|
|
111
|
-
const { book, lines, product
|
|
110
|
+
function summarise(session, bookChecks) {
|
|
111
|
+
const { book, lines, product } = session;
|
|
112
112
|
const info = book.documentInfo ?? {};
|
|
113
113
|
const entity = book.entityInformation ?? {};
|
|
114
114
|
return {
|
|
115
|
-
kind,
|
|
116
|
-
sourcePath,
|
|
117
115
|
product,
|
|
118
116
|
entity: entity.organizationIdentifier ?? null,
|
|
119
117
|
period: { start: isoDate(info.periodCoveredStart), end: isoDate(info.periodCoveredEnd) },
|
|
@@ -124,14 +122,15 @@ function summarise(session, kind, bookChecks) {
|
|
|
124
122
|
}
|
|
125
123
|
|
|
126
124
|
/**
|
|
127
|
-
*
|
|
128
|
-
* spreadsheets site's DIYA-GL pages list (GET /api/v1/books)
|
|
129
|
-
*
|
|
125
|
+
* The metadata of each book saved in the DIYA cloud, most recently updated first, over the route
|
|
126
|
+
* the spreadsheets site's DIYA-GL pages list (GET /api/v1/books): every field the route stores,
|
|
127
|
+
* the etag a replacing save sends among them. clientId lists a practice client's book set instead
|
|
128
|
+
* of the practice's own.
|
|
130
129
|
* @param {Object} session
|
|
131
130
|
* @param {{clientId?: string}} params
|
|
132
|
-
* @returns {Promise<
|
|
131
|
+
* @returns {Promise<Object[]>}
|
|
133
132
|
*/
|
|
134
|
-
export async function
|
|
133
|
+
export async function listBookMetadata(session, { clientId } = {}) {
|
|
135
134
|
const query = clientId ? `?clientId=${encodeURIComponent(clientId)}` : "";
|
|
136
135
|
const response = await fetch(`${baseUrl()}/api/v1/books${query}`, {
|
|
137
136
|
headers: { Authorization: `Bearer ${await session.credentials.accessToken()}` },
|
|
@@ -140,7 +139,29 @@ export async function listBooks(session, { clientId } = {}) {
|
|
|
140
139
|
if (!response.ok) {
|
|
141
140
|
throw new Error(body?.message || `list_books failed with HTTP ${response.status}`);
|
|
142
141
|
}
|
|
143
|
-
return
|
|
142
|
+
return body.books ?? [];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* list_books: the saved books, most recently updated first, each as the bookId open_book takes,
|
|
147
|
+
* the title, the product and the period the book covers. The route's other fields (its versions,
|
|
148
|
+
* etags, sizes, times, retention and the account's entitlement) answer no question a person asks
|
|
149
|
+
* about their books, so the tool leaves them out.
|
|
150
|
+
* @param {Object} session
|
|
151
|
+
* @param {{clientId?: string}} params
|
|
152
|
+
* @returns {Promise<{books: Array<{bookId: string, title: string|null, product: string|null,
|
|
153
|
+
* period: {start: string|null, end: string|null}}>}>}
|
|
154
|
+
*/
|
|
155
|
+
export async function listBooks(session, { clientId } = {}) {
|
|
156
|
+
const books = await listBookMetadata(session, { clientId });
|
|
157
|
+
return {
|
|
158
|
+
books: books.map((book) => ({
|
|
159
|
+
bookId: book.bookId,
|
|
160
|
+
title: book.title ?? null,
|
|
161
|
+
product: book.product ?? null,
|
|
162
|
+
period: { start: isoDate(book.periodCoveredStart), end: isoDate(book.periodCoveredEnd) },
|
|
163
|
+
})),
|
|
164
|
+
};
|
|
144
165
|
}
|
|
145
166
|
|
|
146
167
|
/**
|
|
@@ -169,7 +190,7 @@ async function openCloudBook(session, { bookId, clientId } = {}) {
|
|
|
169
190
|
session.sourcePath = null;
|
|
170
191
|
session.cloud = { bookId, clientId: clientId ?? null, etag: body.metadata.latestETag };
|
|
171
192
|
|
|
172
|
-
return summarise(session,
|
|
193
|
+
return summarise(session, await bookChecksFor(book, lines));
|
|
173
194
|
}
|
|
174
195
|
|
|
175
196
|
/**
|
|
@@ -220,7 +241,7 @@ export async function openBook(session, { path, cloud, bookId, clientId } = {})
|
|
|
220
241
|
session.product = product;
|
|
221
242
|
session.sourcePath = resolved;
|
|
222
243
|
|
|
223
|
-
return summarise(session,
|
|
244
|
+
return { kind, sourcePath: resolved, ...summarise(session, await bookChecksFor(book, lines)) };
|
|
224
245
|
}
|
|
225
246
|
|
|
226
247
|
function refuseUnlessValid(book, lines) {
|
package/lib/handoff-tools.js
CHANGED
|
@@ -34,9 +34,11 @@ const VAT_FIGURE_NAMES = [
|
|
|
34
34
|
"totalAcquisitionsExVAT",
|
|
35
35
|
];
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
// The link goes to a person, so it carries the public address of the environment, the one the
|
|
38
|
+
// customer signs in on. DIYA_SUBMIT_BASE_URL is the deployment's own host, which the tools call.
|
|
39
|
+
function publicBaseUrl() {
|
|
40
|
+
const value = process.env.DIY_SUBMIT_BASE_URL;
|
|
41
|
+
if (!value) throw new Error("DIY_SUBMIT_BASE_URL is not set");
|
|
40
42
|
return value.replace(/\/$/, "");
|
|
41
43
|
}
|
|
42
44
|
|
|
@@ -47,7 +49,7 @@ function baseUrl() {
|
|
|
47
49
|
*/
|
|
48
50
|
export function vatHandoffLink(handoff) {
|
|
49
51
|
const encoded = Buffer.from(JSON.stringify(handoff), "utf8").toString("base64url");
|
|
50
|
-
return `${
|
|
52
|
+
return `${publicBaseUrl()}${VAT_FORM_PATH}#books=${encoded}`;
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
/**
|
package/lib/server.js
CHANGED
|
@@ -358,7 +358,8 @@ export const TOOLS = {
|
|
|
358
358
|
annotations: READS,
|
|
359
359
|
description:
|
|
360
360
|
"List the books saved in the DIYA cloud, most recently updated first, signed in as the session's credentials. Each " +
|
|
361
|
-
"row carries the bookId open_book takes
|
|
361
|
+
"row carries the bookId open_book takes, the book's title, its product and the period it covers. With clientId, " +
|
|
362
|
+
"lists that practice client's books instead of the practice's own.",
|
|
362
363
|
inputSchema: {
|
|
363
364
|
clientId: z.string().optional().describe("A practice client's id, to list that client's books instead of the practice's own"),
|
|
364
365
|
},
|
|
@@ -434,8 +435,7 @@ export const TOOLS = {
|
|
|
434
435
|
"derive_vat_return does, and answers a link to the VAT form on the Submit site with the seven figures filled in " +
|
|
435
436
|
"(the form works out boxes 3 and 5 itself). This tool never files anything and reaches no outside service. The " +
|
|
436
437
|
"person opens the link, checks the figures on the page, ticks the declaration and files there; the figures filed " +
|
|
437
|
-
"are the figures the page shows.
|
|
438
|
-
"them to check, declare and file on the page.",
|
|
438
|
+
"are the figures the page shows.",
|
|
439
439
|
inputSchema: {
|
|
440
440
|
periodEnd: z.string().describe("The obligation's period end, YYYY-MM-DD; must be a month end the book's VAT interface carries"),
|
|
441
441
|
periodStart: z
|
|
@@ -606,9 +606,9 @@ export const TOOLS = {
|
|
|
606
606
|
title: "Get a VAT receipt",
|
|
607
607
|
annotations: READS,
|
|
608
608
|
description:
|
|
609
|
-
"A stored
|
|
610
|
-
"
|
|
611
|
-
"one of the practice's clients but does not change which receipt is read.",
|
|
609
|
+
"A stored VAT return receipt by its file name, over the deployed API: what HMRC answered when it accepted the " +
|
|
610
|
+
"return (the processing date, the form bundle number, the payment indicator and the charge reference). " +
|
|
611
|
+
"clientId, when given, narrows the fetch to one of the practice's clients but does not change which receipt is read.",
|
|
612
612
|
inputSchema: {
|
|
613
613
|
name: z.string().describe("The receipt file name, including .json (submit_vat_return answers receiptId without the suffix)"),
|
|
614
614
|
clientId: z.string().optional().describe("A practice client's id, to check the receipt belongs to that client"),
|
|
@@ -619,9 +619,9 @@ export const TOOLS = {
|
|
|
619
619
|
title: "List VAT receipts",
|
|
620
620
|
annotations: READS,
|
|
621
621
|
description:
|
|
622
|
-
"The receipts Submit has stored for the signed-in account,
|
|
623
|
-
"
|
|
624
|
-
"practice's clients.",
|
|
622
|
+
"The VAT return receipts Submit has stored for the signed-in account, newest first: each row carries the name " +
|
|
623
|
+
"get_vat_receipt takes, HMRC's form bundle number and the day the return was filed. clientId narrows the list to " +
|
|
624
|
+
"one of the practice's clients.",
|
|
625
625
|
inputSchema: {
|
|
626
626
|
clientId: z.string().optional().describe("A practice client's id, to list that client's receipts"),
|
|
627
627
|
},
|
|
@@ -883,7 +883,7 @@ export function createServer(session = createSession(), { toolNames, overrides =
|
|
|
883
883
|
title: tool.title,
|
|
884
884
|
description: tool.description,
|
|
885
885
|
inputSchema: tool.inputSchema,
|
|
886
|
-
annotations: tool.annotations,
|
|
886
|
+
annotations: { title: tool.title, ...tool.annotations },
|
|
887
887
|
_meta: tool._meta,
|
|
888
888
|
},
|
|
889
889
|
async (params) => {
|
package/lib/submit-tools.js
CHANGED
|
@@ -326,34 +326,52 @@ export async function submitVatReturn(session, params = {}) {
|
|
|
326
326
|
});
|
|
327
327
|
}
|
|
328
328
|
|
|
329
|
+
// The four fields HMRC answers when it accepts a VAT return, which Submit stores as the receipt.
|
|
330
|
+
const VAT_RECEIPT_FIELDS = ["processingDate", "formBundleNumber", "paymentIndicator", "chargeRefNumber"];
|
|
331
|
+
|
|
332
|
+
// A VAT return receipt's stored name: the time Submit stored it, then HMRC's form bundle number.
|
|
333
|
+
const VAT_RECEIPT_NAME = /^(\d{4}-\d{2}-\d{2})T[^/]*Z-(\d+)\.json$/;
|
|
334
|
+
|
|
329
335
|
/**
|
|
330
|
-
* get_vat_receipt: a stored receipt by its file name
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
336
|
+
* get_vat_receipt: a stored VAT return receipt by its file name, as the four fields HMRC answered
|
|
337
|
+
* when it accepted the return. clientId narrows the fetch to one of the practice's clients
|
|
338
|
+
* (hmrcReceiptGet.js checks the client belongs to this practice before reading; a client that is
|
|
339
|
+
* not this practice's own answers 403 client-not-found) — it does not change which receipt is
|
|
340
|
+
* read, since a receipt's key is the signed-in user's own regardless.
|
|
334
341
|
* @param {Object} session
|
|
335
342
|
* @param {{name: string, clientId?: string}} params
|
|
343
|
+
* @returns {Promise<{processingDate: string, formBundleNumber: string, paymentIndicator?: string, chargeRefNumber?: string}>}
|
|
336
344
|
*/
|
|
337
345
|
export async function getVatReceipt(session, params = {}) {
|
|
338
346
|
const name = requireField("get_vat_receipt", params, "name");
|
|
339
347
|
const { clientId } = params;
|
|
340
348
|
const query = clientId ? `?clientId=${encodeURIComponent(clientId)}` : "";
|
|
341
|
-
|
|
349
|
+
const stored = await callSubmitApi(session, `/api/v1/hmrc/receipt/${encodeURIComponent(name)}${query}`);
|
|
350
|
+
if (!stored?.formBundleNumber || !stored?.processingDate) throw new Error(`${name} is not the receipt of a VAT return`);
|
|
351
|
+
return Object.fromEntries(VAT_RECEIPT_FIELDS.filter((field) => stored[field] !== undefined).map((field) => [field, stored[field]]));
|
|
342
352
|
}
|
|
343
353
|
|
|
344
354
|
/**
|
|
345
|
-
* list_vat_receipts: the stored
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
* practice's
|
|
355
|
+
* list_vat_receipts: the stored VAT return receipts, newest first as the route answers them, each
|
|
356
|
+
* as the name get_vat_receipt takes, HMRC's form bundle number and the day Submit stored it. The
|
|
357
|
+
* route's other receipts (accounts, confirmation statements, Income Tax updates) and its other
|
|
358
|
+
* fields are left out. clientId narrows the list to one of the practice's clients
|
|
359
|
+
* (hmrcReceiptGet.js answers 403 client-not-found for a client that is not this practice's own).
|
|
349
360
|
* @param {Object} session
|
|
350
361
|
* @param {{clientId?: string}} params
|
|
351
|
-
* @returns {Promise<{receipts:
|
|
362
|
+
* @returns {Promise<{receipts: Array<{name: string, formBundleNumber: string, filedOn: string}>}>}
|
|
352
363
|
*/
|
|
353
364
|
export async function listVatReceipts(session, params = {}) {
|
|
354
365
|
const { clientId } = params;
|
|
355
366
|
const query = clientId ? `?clientId=${encodeURIComponent(clientId)}` : "";
|
|
356
|
-
|
|
367
|
+
const { receipts = [] } = await callSubmitApi(session, `/api/v1/hmrc/receipt${query}`);
|
|
368
|
+
return {
|
|
369
|
+
receipts: receipts
|
|
370
|
+
.filter((row) => !row.kind)
|
|
371
|
+
.map((row) => ({ name: row.name, match: VAT_RECEIPT_NAME.exec(row.name ?? "") }))
|
|
372
|
+
.filter(({ match }) => match)
|
|
373
|
+
.map(({ name, match }) => ({ name, formBundleNumber: match[2], filedOn: match[1] })),
|
|
374
|
+
};
|
|
357
375
|
}
|
|
358
376
|
|
|
359
377
|
const ACCOUNTS_STATEMENT_FIELDS = ["section477Exemption", "membersNotRequiredAudit", "directorsResponsibilities", "microEntityProvisions"];
|
package/lib/vat-tools.js
CHANGED
|
@@ -13,10 +13,20 @@
|
|
|
13
13
|
|
|
14
14
|
// vat-tools.js -- derive_vat_return: the nine VAT boxes for one obligation
|
|
15
15
|
// period from the session's loaded book. The derivation is the diya-gl
|
|
16
|
-
// package's own; this module adds
|
|
16
|
+
// package's own; this module adds the session's "no book loaded" check and
|
|
17
|
+
// keeps of each journal line only what a person checks a box against.
|
|
17
18
|
|
|
18
19
|
import { deriveVatReturn as deriveVatReturnFromBook } from "@diy-accounting-uk/diya-gl";
|
|
19
20
|
|
|
21
|
+
// The fields of a journal line behind a box. The engine also answers the line's entry and line
|
|
22
|
+
// numbers, which are the book's own keys (a bank or Stripe transaction id among them), so the
|
|
23
|
+
// tool leaves them out: the date, reference, counterparty and amount find the line in the book.
|
|
24
|
+
const LINE_FIELDS = ["date", "account", "reference", "counterparty", "gross", "contributes"];
|
|
25
|
+
|
|
26
|
+
function lineForPerson(line) {
|
|
27
|
+
return Object.fromEntries(LINE_FIELDS.map((field) => [field, line[field] ?? null]));
|
|
28
|
+
}
|
|
29
|
+
|
|
20
30
|
/**
|
|
21
31
|
* derive_vat_return: the nine boxes for the quarter ending on periodEnd,
|
|
22
32
|
* from the session's loaded book.
|
|
@@ -27,5 +37,7 @@ export async function deriveVatReturn(session, params = {}) {
|
|
|
27
37
|
if (!session.book || !session.lines) {
|
|
28
38
|
throw new Error("No book is loaded. Call open_book first.");
|
|
29
39
|
}
|
|
30
|
-
|
|
40
|
+
const derived = await deriveVatReturnFromBook(session.book, session.lines, params);
|
|
41
|
+
const lines = Object.fromEntries(Object.entries(derived.lines).map(([box, boxLines]) => [box, boxLines.map(lineForPerson)]));
|
|
42
|
+
return { ...derived, lines };
|
|
31
43
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diy-accounting-uk/diya-submit",
|
|
3
3
|
"mcpName": "io.github.diy-accounting-uk/diya-submit",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"description": "MCP server that opens a diya-gl book, derives filing figures and drives DIY Accounting Submit's HMRC and Companies House submissions",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "LicenseRef-PolyForm-Internal-Use-1.0.0",
|