@diy-accounting-uk/diya-submit 0.1.2 → 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/lib/server.js CHANGED
@@ -27,10 +27,13 @@ import { createSession, listBooks, openBook, saveBook, SAVE_FORMATS } from "./bo
27
27
  import { signIn, signOut } from "./auth.js";
28
28
  import { writeFinancePackage } from "./finance/package-writer.js";
29
29
  import { deriveCompanyTaxReturn, deriveMicroEntityAccounts, deriveSmallCompanyAccounts } from "./accounts-tools.js";
30
+ import { prepareVatReturn } from "./handoff-tools.js";
30
31
  import { deriveVatReturn } from "./vat-tools.js";
32
+ import { registerVatReviewCard, VAT_REVIEW_CARD_TOOLS, VAT_REVIEW_CARD_TOOL_META } from "./vat-review-card.js";
31
33
  import { ITSA_TOOLS } from "./itsa-tools.js";
32
34
  import { runForClients, RUN_FOR_CLIENTS_TOOLS } from "./batch-tools.js";
33
35
  import { moveBookToClient, listClients, addClient, inviteClient, clientAuthorisationStatus } from "./practice-tools.js";
36
+ import { ADDS, CHANGES, CHANGES_OUTSIDE, READS, READS_OUTSIDE } from "./tool-annotations.js";
34
37
  import {
35
38
  listVatObligations,
36
39
  listVatLiabilities,
@@ -60,6 +63,7 @@ const PACKAGE_JSON = resolve(dirname(fileURLToPath(import.meta.url)), "..", "pac
60
63
  export const SERVER_INFO = {
61
64
  name: "diya-submit",
62
65
  version: JSON.parse(readFileSync(PACKAGE_JSON, "utf8")).version,
66
+ icons: [{ src: "https://submit.diyaccounting.co.uk/images/connector-icon.png", mimeType: "image/png", sizes: ["512x512"] }],
63
67
  };
64
68
 
65
69
  const balanceSheetYearSchema = z.object({
@@ -307,6 +311,8 @@ function vatEnquirySchema() {
307
311
 
308
312
  export const TOOLS = {
309
313
  sign_in: {
314
+ title: "Sign in",
315
+ annotations: CHANGES,
310
316
  description:
311
317
  "Sign in to DIY Accounting Submit as the MCP's own Cognito app client: opens the pool's hosted UI in the " +
312
318
  "operator's browser (or prints the URL, when it cannot open one) with a PKCE code challenge, catches the " +
@@ -318,6 +324,8 @@ export const TOOLS = {
318
324
  handler: (_session, _params) => signIn(),
319
325
  },
320
326
  sign_out: {
327
+ title: "Sign out",
328
+ annotations: CHANGES,
321
329
  description:
322
330
  "Ends the MCP's own session: revokes the refresh token at Cognito, tells DIY Accounting Submit's sign-out " +
323
331
  "route to close it server-side too, then deletes the local credentials file. Best-effort on both network " +
@@ -326,6 +334,8 @@ export const TOOLS = {
326
334
  handler: (_session, _params) => signOut(),
327
335
  },
328
336
  open_book: {
337
+ title: "Open a book",
338
+ annotations: READS,
329
339
  description:
330
340
  "Open a diya-gl book from the filesystem: a directory holding book.toml and lines.jsonl, or a single file " +
331
341
  "(a DIY Accounting workbook, a package zip, a diya-gl zip, or a diya-gl JSON file). With cloud: true, opens " +
@@ -344,15 +354,20 @@ export const TOOLS = {
344
354
  handler: openBook,
345
355
  },
346
356
  list_books: {
357
+ title: "List saved books",
358
+ annotations: READS,
347
359
  description:
348
360
  "List the books saved in the DIYA cloud, most recently updated first, signed in as the session's credentials. Each " +
349
- "row carries the bookId open_book takes. With clientId, lists that practice client's books instead of the practice's own.",
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.",
350
363
  inputSchema: {
351
364
  clientId: z.string().optional().describe("A practice client's id, to list that client's books instead of the practice's own"),
352
365
  },
353
366
  handler: listBooks,
354
367
  },
355
368
  save_book: {
369
+ title: "Save the book",
370
+ annotations: CHANGES,
356
371
  description:
357
372
  "Save the session's loaded book to the filesystem. Formats: diya-gl-dir (book.toml + lines.jsonl into a " +
358
373
  "directory; the default for a path with no extension), diya-gl-zip, json, xlsx (the product's recalculating " +
@@ -370,6 +385,8 @@ export const TOOLS = {
370
385
  handler: saveBook,
371
386
  },
372
387
  write_finance_package: {
388
+ title: "Write a finance package",
389
+ annotations: CHANGES,
373
390
  description:
374
391
  "Writes a diya-gl book and its lines as the unzipped spreadsheets package directory a completed year's package " +
375
392
  "holds: one workbook for a single-file product (Basic Sole Trader, Taxi Driver), the whole named set for a " +
@@ -390,6 +407,9 @@ export const TOOLS = {
390
407
  handler: (_session, params) => writeFinancePackage(params),
391
408
  },
392
409
  derive_vat_return: {
410
+ title: "Derive a VAT return",
411
+ annotations: READS,
412
+ _meta: VAT_REVIEW_CARD_TOOL_META,
393
413
  description:
394
414
  "The nine VAT boxes for one obligation period from the session's loaded book, read from the engine's own VAT " +
395
415
  "interface: the quarter ending on periodEnd (a month end the book carries), with HMRC's field names and " +
@@ -406,7 +426,29 @@ export const TOOLS = {
406
426
  },
407
427
  handler: deriveVatReturn,
408
428
  },
429
+ prepare_vat_return: {
430
+ title: "Prepare a VAT return to file in the browser",
431
+ annotations: READS,
432
+ _meta: VAT_REVIEW_CARD_TOOL_META,
433
+ description:
434
+ "Derives the VAT return for the quarter ending on periodEnd from the session's loaded book, exactly as " +
435
+ "derive_vat_return does, and answers a link to the VAT form on the Submit site with the seven figures filled in " +
436
+ "(the form works out boxes 3 and 5 itself). This tool never files anything and reaches no outside service. The " +
437
+ "person opens the link, checks the figures on the page, ticks the declaration and files there; the figures filed " +
438
+ "are the figures the page shows.",
439
+ inputSchema: {
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
+ periodStart: z
442
+ .string()
443
+ .optional()
444
+ .describe("The obligation's period start, YYYY-MM-DD; refused unless it opens the quarter ending periodEnd"),
445
+ periodKey: z.string().optional().describe("The obligation's period key"),
446
+ },
447
+ handler: prepareVatReturn,
448
+ },
409
449
  derive_micro_entity_accounts: {
450
+ title: "Derive micro-entity accounts",
451
+ annotations: READS,
410
452
  description:
411
453
  "The seven FRS 105 balance-sheet lines the accounts filing takes, from the session's loaded book: the current " +
412
454
  "year from the engine's published balance sheet and the prior year from the book's opening balance, in whole " +
@@ -416,6 +458,8 @@ export const TOOLS = {
416
458
  handler: deriveMicroEntityAccounts,
417
459
  },
418
460
  derive_small_company_accounts: {
461
+ title: "Derive small-company accounts",
462
+ annotations: READS,
419
463
  description:
420
464
  "The figures a small company's FRS 102 section 1A accounts filing takes, from the session's loaded book: the " +
421
465
  "full profit and loss account and the balance sheet sub-lines for the current year from the engine's published " +
@@ -427,6 +471,8 @@ export const TOOLS = {
427
471
  handler: deriveSmallCompanyAccounts,
428
472
  },
429
473
  derive_company_tax_return: {
474
+ title: "Derive a Company Tax Return",
475
+ annotations: READS,
430
476
  description:
431
477
  "The figures the Company Tax Return form takes, from the session's loaded Company book: the accounting period, the " +
432
478
  "computation figures (depreciation, amortisation, entertaining, capital allowances, franked investment income, " +
@@ -440,6 +486,8 @@ export const TOOLS = {
440
486
  handler: deriveCompanyTaxReturn,
441
487
  },
442
488
  request_hmrc_authorisation: {
489
+ title: "Request HMRC authorisation",
490
+ annotations: CHANGES_OUTSIDE,
443
491
  description:
444
492
  "Answers HMRC's sign-in link for this session, so the VAT tools can call HMRC without a token in the chat. " +
445
493
  "Answers {url, expiresAt, scope, hmrcAccount}: show the user the url, wait for them to say HMRC access is " +
@@ -458,6 +506,8 @@ export const TOOLS = {
458
506
  handler: requestHmrcAuthorisation,
459
507
  },
460
508
  list_vat_obligations: {
509
+ title: "List VAT obligations",
510
+ annotations: READS_OUTSIDE,
461
511
  description:
462
512
  "The open and fulfilled VAT obligations HMRC holds for one VRN, or for one practice client's VRN when clientId " +
463
513
  "is given instead of vrn, over the deployed API. Uses the session's HMRC authorisation: call " +
@@ -477,6 +527,8 @@ export const TOOLS = {
477
527
  handler: listVatObligations,
478
528
  },
479
529
  list_vat_liabilities: {
530
+ title: "List VAT liabilities",
531
+ annotations: READS_OUTSIDE,
480
532
  description:
481
533
  "What HMRC says the business owes for VAT, by period, for one VRN over the deployed API. Uses the session's HMRC " +
482
534
  "authorisation: call request_hmrc_authorisation first if this tool says none is held.",
@@ -484,6 +536,8 @@ export const TOOLS = {
484
536
  handler: listVatLiabilities,
485
537
  },
486
538
  list_vat_payments: {
539
+ title: "List VAT payments",
540
+ annotations: READS_OUTSIDE,
487
541
  description:
488
542
  "The VAT payments HMRC has received from the business, by date, for one VRN over the deployed API. Uses the " +
489
543
  "session's HMRC authorisation: call request_hmrc_authorisation first if this tool says none is held.",
@@ -491,6 +545,8 @@ export const TOOLS = {
491
545
  handler: listVatPayments,
492
546
  },
493
547
  list_vat_penalties: {
548
+ title: "List VAT penalties",
549
+ annotations: READS_OUTSIDE,
494
550
  description:
495
551
  "The VAT penalties and late-submission points HMRC holds for one VRN over the deployed API. Uses the session's " +
496
552
  "HMRC authorisation: call request_hmrc_authorisation first if this tool says none is held.",
@@ -498,6 +554,8 @@ export const TOOLS = {
498
554
  handler: listVatPenalties,
499
555
  },
500
556
  get_vat_return: {
557
+ title: "Get a submitted VAT return",
558
+ annotations: READS_OUTSIDE,
501
559
  description:
502
560
  "One past VAT return as HMRC holds it, by its period key (the periodKey list_vat_obligations answers for a " +
503
561
  "fulfilled obligation), over the deployed API. Use it to see what HMRC holds; to read Submit's stored copy of a " +
@@ -512,6 +570,8 @@ export const TOOLS = {
512
570
  handler: getVatReturn,
513
571
  },
514
572
  submit_vat_return: {
573
+ title: "Submit a VAT return",
574
+ annotations: CHANGES_OUTSIDE,
515
575
  description:
516
576
  "Files the nine VAT boxes the user has confirmed (derive_vat_return's hmrc fields) over the deployed API, for " +
517
577
  "vatNumber or, when clientId is given instead, for that practice client's own VRN. Boxes 3 and 5 are HMRC's own " +
@@ -543,10 +603,12 @@ export const TOOLS = {
543
603
  handler: submitVatReturn,
544
604
  },
545
605
  get_vat_receipt: {
606
+ title: "Get a VAT receipt",
607
+ annotations: READS,
546
608
  description:
547
- "A stored HMRC VAT receipt by its file name, over the deployed API: Submit's own copy of what it filed. To read " +
548
- "HMRC's copy of a return by period key, use get_vat_return. clientId, when given, narrows the fetch to " +
549
- "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.",
550
612
  inputSchema: {
551
613
  name: z.string().describe("The receipt file name, including .json (submit_vat_return answers receiptId without the suffix)"),
552
614
  clientId: z.string().optional().describe("A practice client's id, to check the receipt belongs to that client"),
@@ -554,16 +616,20 @@ export const TOOLS = {
554
616
  handler: getVatReceipt,
555
617
  },
556
618
  list_vat_receipts: {
619
+ title: "List VAT receipts",
620
+ annotations: READS,
557
621
  description:
558
- "The receipts Submit has stored for the signed-in account, the list its receipts page shows: each row carries the " +
559
- "name get_vat_receipt takes. Use it to find a receipt this chat did not just file. clientId narrows the list to one of the " +
560
- "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.",
561
625
  inputSchema: {
562
626
  clientId: z.string().optional().describe("A practice client's id, to list that client's receipts"),
563
627
  },
564
628
  handler: listVatReceipts,
565
629
  },
566
630
  render_micro_entity_accounts_sandbox: {
631
+ title: "Render micro-entity accounts",
632
+ annotations: READS,
567
633
  description:
568
634
  "The rendered FRS 105 micro-entity iXBRL for confirmed figures (derive_micro_entity_accounts' answer), over the " +
569
635
  "deployed API. Never reaches the Companies House XML Gateway. The route never resolves a company from a " +
@@ -572,6 +638,8 @@ export const TOOLS = {
572
638
  handler: renderMicroEntityAccounts,
573
639
  },
574
640
  submit_micro_entity_accounts_sandbox: {
641
+ title: "Submit micro-entity accounts (sandbox)",
642
+ annotations: CHANGES_OUTSIDE,
575
643
  description:
576
644
  "Files confirmed micro-entity accounts through the Companies House XML Gateway, over the deployed API, for " +
577
645
  "companyNumber or, when clientId is given instead, for that practice client's own company number; returns the " +
@@ -589,6 +657,8 @@ export const TOOLS = {
589
657
  handler: submitMicroEntityAccounts,
590
658
  },
591
659
  render_small_company_accounts_sandbox: {
660
+ title: "Render small-company accounts",
661
+ annotations: READS,
592
662
  description:
593
663
  "The rendered FRS 102 section 1A small-company iXBRL for confirmed figures (derive_small_company_accounts' answer, " +
594
664
  "with principalActivity and accountingPolicies added), over the deployed API. Never reaches the Companies House XML " +
@@ -598,6 +668,8 @@ export const TOOLS = {
598
668
  handler: renderSmallCompanyAccounts,
599
669
  },
600
670
  submit_small_company_accounts_sandbox: {
671
+ title: "Submit small-company accounts (sandbox)",
672
+ annotations: CHANGES_OUTSIDE,
601
673
  description:
602
674
  "Files confirmed small-company accounts through the Companies House XML Gateway, over the deployed API, for " +
603
675
  "companyNumber or, when clientId is given instead, for that practice client's own company number; returns the " +
@@ -616,6 +688,8 @@ export const TOOLS = {
616
688
  handler: submitSmallCompanyAccounts,
617
689
  },
618
690
  request_companies_house_codes: {
691
+ title: "Request Companies House codes",
692
+ annotations: ADDS,
619
693
  description:
620
694
  "Answers a link where the user types the Companies House codes a filing needs, so the codes never appear in " +
621
695
  "the chat. Answers {entryId, url, expiresAt}: show the user the url, wait for them to say they have saved the " +
@@ -641,6 +715,8 @@ export const TOOLS = {
641
715
  handler: requestCompaniesHouseCodes,
642
716
  },
643
717
  get_confirmation_statement_data_sandbox: {
718
+ title: "Get confirmation statement data",
719
+ annotations: READS_OUTSIDE,
644
720
  description:
645
721
  "The register data a confirmation statement form is built from -- MadeUpDate, NextDueDate, SIC codes, " +
646
722
  "RegisteredEmailAddress, officers, PSCs, StatementOfCapital, Shareholdings, TradingOnMarket, DTR5Applies, the PSC " +
@@ -658,6 +734,8 @@ export const TOOLS = {
658
734
  handler: getConfirmationStatementData,
659
735
  },
660
736
  render_confirmation_statement_sandbox: {
737
+ title: "Render a confirmation statement",
738
+ annotations: READS,
661
739
  description:
662
740
  "The rendered ConfirmationAndVerificationStatement body for confirmed answers, over the deployed API. Never " +
663
741
  "reaches the Companies House XML Gateway; every director's personal code is masked in the rendered body before " +
@@ -666,6 +744,8 @@ export const TOOLS = {
666
744
  handler: renderConfirmationStatement,
667
745
  },
668
746
  submit_confirmation_statement_sandbox: {
747
+ title: "Submit a confirmation statement (sandbox)",
748
+ annotations: CHANGES_OUTSIDE,
669
749
  description:
670
750
  "Files a confirmed confirmation statement through the Companies House XML Gateway, over the deployed API; " +
671
751
  "returns the submission number. The company authentication code and every director's personal code are not " +
@@ -680,6 +760,8 @@ export const TOOLS = {
680
760
  handler: submitConfirmationStatement,
681
761
  },
682
762
  poll_submission: {
763
+ title: "Check a Companies House submission",
764
+ annotations: READS_OUTSIDE,
683
765
  description:
684
766
  "Accepted, rejected with reasons, or pending, for a submitted Companies House filing, over the deployed API. kind " +
685
767
  "accounts is a micro-entity or small-company accounts filing (submit_micro_entity_accounts_sandbox, submit_small_company_accounts_sandbox); kind confirmation-statement is " +
@@ -691,6 +773,8 @@ export const TOOLS = {
691
773
  handler: pollSubmission,
692
774
  },
693
775
  move_book_to_client: {
776
+ title: "Move a book to a client",
777
+ annotations: CHANGES,
694
778
  description:
695
779
  "Move one of the practice's own books to a client's book set (during migration from sole trader to practice). " +
696
780
  "Calls DIY Accounting Submit's own move route, which copies the book and every kept version, verifies each copy, " +
@@ -702,6 +786,8 @@ export const TOOLS = {
702
786
  handler: moveBookToClient,
703
787
  },
704
788
  list_clients: {
789
+ title: "List clients",
790
+ annotations: READS,
705
791
  description:
706
792
  "The signed-in practice's own client list over the deployed API: each client's id, display name, identifiers " +
707
793
  "(VRN, NINO, UTR, company number) and current HMRC authorisation state per service. Archived clients are excluded.",
@@ -709,6 +795,8 @@ export const TOOLS = {
709
795
  handler: listClients,
710
796
  },
711
797
  add_client: {
798
+ title: "Add a client",
799
+ annotations: ADDS,
712
800
  description:
713
801
  "Adds one client to the practice's list, over the deployed API. Every identifier is optional, but a given one " +
714
802
  "must match its HMRC or Companies House format.",
@@ -722,6 +810,8 @@ export const TOOLS = {
722
810
  handler: addClient,
723
811
  },
724
812
  invite_client: {
813
+ title: "Invite a client",
814
+ annotations: CHANGES_OUTSIDE,
725
815
  description:
726
816
  "Sends an HMRC Agent Authorisation invitation for one client and one service, over the deployed API. The " +
727
817
  "client's own VRN or NINO comes from the client row, not from this call. Uses the session's HMRC " +
@@ -738,6 +828,8 @@ export const TOOLS = {
738
828
  handler: inviteClient,
739
829
  },
740
830
  client_authorisation_status: {
831
+ title: "Check a client's authorisation",
832
+ annotations: READS_OUTSIDE,
741
833
  description:
742
834
  "One client's current authorisation status for one HMRC service, over the deployed API: re-reads a pending " +
743
835
  "invitation's own status, or HMRC's relationships endpoint when none is pending. Uses the session's HMRC " +
@@ -749,6 +841,8 @@ export const TOOLS = {
749
841
  handler: clientAuthorisationStatus,
750
842
  },
751
843
  run_for_clients: {
844
+ title: "Run a tool for every client",
845
+ annotations: CHANGES_OUTSIDE,
752
846
  description:
753
847
  "Runs one client-scoped tool once per client in the practice's own list (list_clients), passing each client's " +
754
848
  "clientId in turn. Returns one row per client -- {clientId, displayName, ok, result or error} -- plus a summary " +
@@ -783,13 +877,24 @@ export function createServer(session = createSession(), { toolNames, overrides =
783
877
  for (const name of names) {
784
878
  const tool = overrides[name] ?? known[name];
785
879
  if (!tool) throw new Error(`Unknown tool: ${name}`);
786
- server.registerTool(name, { description: tool.description, inputSchema: tool.inputSchema }, async (params) => {
787
- try {
788
- return asToolResult(await tool.handler(session, params));
789
- } catch (err) {
790
- return asToolError(err);
791
- }
792
- });
880
+ server.registerTool(
881
+ name,
882
+ {
883
+ title: tool.title,
884
+ description: tool.description,
885
+ inputSchema: tool.inputSchema,
886
+ annotations: { title: tool.title, ...tool.annotations },
887
+ _meta: tool._meta,
888
+ },
889
+ async (params) => {
890
+ try {
891
+ return asToolResult(await tool.handler(session, params));
892
+ } catch (err) {
893
+ return asToolError(err);
894
+ }
895
+ },
896
+ );
793
897
  }
898
+ if (names.some((name) => VAT_REVIEW_CARD_TOOLS.includes(name))) registerVatReviewCard(server);
794
899
  return server;
795
900
  }
@@ -152,7 +152,7 @@ export async function requestHmrcAuthorisation(session, params = {}) {
152
152
  return { url: granted.url, expiresAt: granted.expiresAt, scope: granted.scope, hmrcAccount: granted.hmrcAccount };
153
153
  }
154
154
 
155
- export const HMRC_GRANT_HEADER = "x-mcp-hmrc-grant";
155
+ const HMRC_GRANT_HEADER = "x-mcp-hmrc-grant";
156
156
 
157
157
  /**
158
158
  * The session's HMRC grant for one tool call: the headers that name it to Submit's API, and the
@@ -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. clientId narrows the fetch to one of the
331
- * practice's clients (hmrcReceiptGet.js checks the client belongs to this practice before
332
- * reading; a client that is not this practice's own answers 403 client-not-found) — it does not
333
- * change which receipt is read, since a receipt's key is the signed-in user's own regardless.
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
- return callSubmitApi(session, `/api/v1/hmrc/receipt/${encodeURIComponent(name)}${query}`);
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 receipts the account page lists, newest first as the route
346
- * answers them, each with the name get_vat_receipt takes. clientId narrows the list to one of the
347
- * practice's clients (hmrcReceiptGet.js answers 403 client-not-found for a client that is not this
348
- * practice's own).
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: Object[]}>}
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
- return callSubmitApi(session, `/api/v1/hmrc/receipt${query}`);
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"];
@@ -0,0 +1,18 @@
1
+ // SPDX-License-Identifier: LicenseRef-PolyForm-Internal-Use-1.0.0
2
+ // Copyright (C) 2006-2026 DIY Accounting Limited
3
+
4
+ // tool-annotations.js -- the MCP tool annotations the tool tables share. Every tool states all three
5
+ // hints, because the connector directories require each one set.
6
+
7
+ const annotations = (readOnlyHint, destructiveHint, openWorldHint) => ({ readOnlyHint, destructiveHint, openWorldHint });
8
+
9
+ // Reads and derives; touches no outside service.
10
+ export const READS = annotations(true, false, false);
11
+ // Reads from HMRC or Companies House.
12
+ export const READS_OUTSIDE = annotations(true, false, true);
13
+ // Writes or sends something that replaces or cannot be taken back; touches no outside service.
14
+ export const CHANGES = annotations(false, true, false);
15
+ // Files, invites or hands out an authorisation at HMRC or Companies House.
16
+ export const CHANGES_OUTSIDE = annotations(false, true, true);
17
+ // Adds something new and replaces nothing; touches no outside service.
18
+ export const ADDS = annotations(false, false, false);