@expensebot/mcp-server-auth 0.6.25 → 0.6.28

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/src/test.js CHANGED
@@ -15,21 +15,37 @@
15
15
  */
16
16
 
17
17
  import { spawn } from "node:child_process";
18
+ import { createRequire } from "node:module";
18
19
  import http from "node:http";
19
20
  import { readFileSync } from "node:fs";
20
21
  import { fileURLToPath } from "node:url";
21
22
  import path from "node:path";
23
+ import { isDeepStrictEqual } from "node:util";
22
24
  import { readStructuredHttpError } from "./client.js";
23
25
 
24
26
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
25
27
  const SERVER_PATH = path.join(__dirname, "index.js");
28
+ const Ajv = createRequire(path.join(__dirname, "../../server/package.json"))("ajv");
26
29
 
27
- const EXPECTED_TOOL_COUNT = 60;
30
+ const EXPECTED_TOOL_COUNT = 65;
28
31
  // Every stdio tool that advertises outputSchema (enumerated per tranche).
29
32
  const OUTPUT_SCHEMA_TOOLS = [
33
+ "get_setup_status",
34
+ "complete_setup",
35
+ "add_cash_expense",
36
+ "add_income",
37
+ "add_income_from_csv",
38
+ "add_income_from_file",
39
+ "add_mileage_entry",
30
40
  "check_compliance",
31
41
  "check_feature",
32
42
  "check_tax_deductibility",
43
+ "correct_expenses",
44
+ "create_tag",
45
+ "create_client_invoice",
46
+ "create_report",
47
+ "export_report",
48
+ "fix_compliance",
33
49
  "get_accounting_integration_status",
34
50
  "get_accounting_push_status",
35
51
  "get_client_advance_balances",
@@ -42,28 +58,123 @@ const OUTPUT_SCHEMA_TOOLS = [
42
58
  "get_last_receipt_result",
43
59
  "get_mileage_summary",
44
60
  "get_monthly_books_review",
61
+ "list_client_close_readiness",
45
62
  "get_per_tag_pnl",
46
63
  "get_pnl",
47
64
  "get_recent_activity",
48
65
  "get_report_details",
49
66
  "get_scan_status",
67
+ "get_statement_import_status",
50
68
  "get_spending_summary",
51
69
  "get_spreadsheet_url",
52
70
  "get_subscription_audit",
53
71
  "get_trip_suggestions",
72
+ "group_expenses",
54
73
  "list_categories",
55
74
  "list_client_invoices",
56
75
  "list_income_categories",
57
76
  "list_reports",
58
77
  "list_tags",
78
+ "mark_client_invoice_paid",
79
+ "parse_expense",
80
+ "prepare_client_invoice",
81
+ "process_gmail_receipts",
82
+ "request_accounting_integration",
83
+ "scan_gmail",
84
+ "scan_gmail_years",
59
85
  "search_expenses",
60
86
  "search_knowledge",
87
+ "send_report_to_accounting",
88
+ "share_report",
89
+ "submit_receipt",
90
+ "trace_document",
91
+ "update_expense",
61
92
  "whatif_afford",
62
93
  "whatif_client",
63
94
  "whatif_tax_setaside",
64
95
  ];
65
96
 
66
97
  const TRANCHE_2_RUNTIME_CASES = [
98
+ {
99
+ toolName: "get_expense_by_id", actionId: "get_expense_by_id",
100
+ args: { expenseId: "receipt_test" },
101
+ payload: { success: true, sheetName: "Expenses", rowNumber: 2,
102
+ headers: ["Date", "Description", "FunctionalTotal"],
103
+ values: ["2026-10-01", "Fixed synthetic item", 12.5],
104
+ labeled: { Date: "2026-10-01", Description: "Fixed synthetic item", FunctionalTotal: 12.5 },
105
+ reviewExpenseUrl: "https://www.expensebot.ai/review-expenses?source=mcp" },
106
+ },
107
+ {
108
+ toolName: "get_report_details", actionId: "get_report_details",
109
+ args: { reportId: "report_test", analysisRequested: true },
110
+ payload: { success: true, report: {}, message: "Requested report details.", data: {} },
111
+ },
112
+ {
113
+ toolName: "get_report_details", actionId: "get_report_details",
114
+ args: { reportId: "report_test", analysisRequested: true, checkFreshness: true },
115
+ payload: {
116
+ success: true,
117
+ report: {},
118
+ freshness: {
119
+ status: "current",
120
+ checkedAt: "2026-10-16T14:00:00.000Z",
121
+ message: "The saved report sources are current.",
122
+ reportUrl: "https://www.expensebot.ai/process-info?tab=expenseReports&scrollToReport=report_test&highlight=true&reportAction=view&source=mcp",
123
+ },
124
+ },
125
+ },
126
+ {
127
+ toolName: "get_statement_import_status", actionId: "get_statement_import_status",
128
+ args: { clientEmail: "client@example.com" },
129
+ payload: {
130
+ success: true,
131
+ status: "mixed",
132
+ availability: "available",
133
+ imports: [
134
+ {
135
+ phase: "extraction",
136
+ state: "review_ready",
137
+ createdAt: "2026-10-16T13:00:00.000Z",
138
+ counts: { totalFiles: 2, uploadedFiles: 0, awaitingUploadFiles: 0, extractingFiles: 0, reviewReadyFiles: 2, failedFiles: 0, unknownFiles: 0 },
139
+ },
140
+ {
141
+ phase: "save",
142
+ state: "saved_with_held",
143
+ createdAt: "2026-10-16T13:10:00.000Z",
144
+ counts: { totalRows: 3, resolvedRows: 2, savedIncomeRows: 1, savedExpenseRows: 0, nonPnlRows: 1, settledRows: 3, heldRows: 1, setAsideRows: 0, failedRows: 0 },
145
+ },
146
+ ],
147
+ links: { review: "https://www.expensebot.ai/review-expenses?source=mcp" },
148
+ limitations: [
149
+ "Read and save jobs may describe the same statement; do not add their counts or infer whole-statement completion.",
150
+ "Resolved rows include Other activity, which does not write income or expense rows.",
151
+ ],
152
+ },
153
+ },
154
+ {
155
+ toolName: "get_report_details", actionId: "get_report_details",
156
+ args: { reportId: "report_test", userRequest: "Show me the details of this report" },
157
+ payload: { success: true, report: {}, message: "Requested report details.", data: {} },
158
+ },
159
+ {
160
+ toolName: "list_client_close_readiness", actionId: "list_client_close_readiness",
161
+ args: { period: "2026-09", page: 1, limit: 5 },
162
+ payload: { success: true, period: "2026-09", asOf: "2026-10-05T12:00:00.000Z",
163
+ scope: "page", coverage: "complete_page", evaluatedClientCount: 2,
164
+ unavailableCandidateCount: 0, statusCounts: { ready: 1, needs_action: 0, blocked: 0, unknown: 1 },
165
+ categories: [{ code: "bills_bill_payment_status_needs_review",
166
+ label: "Bill payment status needs review", affectedClientCount: 1,
167
+ url: "https://www.expensebot.ai/process-info?tab=adminView&source=mcp" }],
168
+ pageInfo: { page: 1, limit: 5, hasMore: false, nextPage: null },
169
+ links: { clients: "https://www.expensebot.ai/process-info?tab=adminView&source=mcp" },
170
+ limitations: ["Counts describe this page only."], message: "Two client workspaces assessed." },
171
+ },
172
+ {
173
+ toolName: "check_compliance",
174
+ actionId: "help_compliance",
175
+ args: { reportId: "report_test", analysisRequested: true },
176
+ payload: { success: true, message: "Compliance check complete.", data: { status: "clear" } },
177
+ },
67
178
  {
68
179
  toolName: "check_compliance",
69
180
  actionId: "help_compliance",
@@ -139,6 +250,156 @@ const TRANCHE_2_RUNTIME_CASES = [
139
250
  gmailScanUrl: null,
140
251
  },
141
252
  },
253
+ {
254
+ toolName: "get_monthly_books_review",
255
+ actionId: "get_monthly_books_review",
256
+ args: { period: "2026-09" },
257
+ payload: {
258
+ success: true,
259
+ message: "September books reviewed.",
260
+ closeReadiness: {
261
+ status: "needs_action",
262
+ asOf: "2026-10-04T12:00:00.000Z",
263
+ period: "2026-09",
264
+ checks: {
265
+ dataFreshness: "ready",
266
+ expenseReview: "needs_action",
267
+ incomeReview: "ready",
268
+ cardReconciliation: "not_applicable",
269
+ connectionHealth: "ready",
270
+ actionNeeded: "needs_action",
271
+ reportReadiness: "needs_action",
272
+ },
273
+ actionNeeded: [{
274
+ code: "uncategorized_expenses",
275
+ label: "Expenses need a category",
276
+ count: 2,
277
+ url: "https://www.expensebot.ai/review-expenses?source=mcp",
278
+ }, {
279
+ code: "bills_bill_payment_status_needs_review",
280
+ label: "Bill payment status needs review",
281
+ count: 1,
282
+ url: "https://www.expensebot.ai/gmail?gmailTab=manual&source=mcp",
283
+ }],
284
+ limitations: ["Bill counts cover the current payment-review list, not all unpaid bills or month-specific completeness."],
285
+ links: {
286
+ reviewExpenses: "https://www.expensebot.ai/review-expenses?source=mcp",
287
+ },
288
+ },
289
+ },
290
+ },
291
+ ];
292
+
293
+ const TRANCHE_3_RUNTIME_CASES = [
294
+ { toolName: "create_report", actionId: "create_report", args: {}, payload: { success: true, message: "Report created." } },
295
+ { toolName: "request_accounting_integration", actionId: "request_accounting_integration", args: { packageName: "Example Books" }, payload: { success: true, duplicate: false, packageName: "Example Books", message: "Request recorded." } },
296
+ { toolName: "share_report", actionId: "share_report", args: { reportId: "report_test", recipients: ["reviewer@example.com"] }, payload: { success: true, message: "Report shared.", sharedWith: ["reviewer@example.com"], recipientRole: "reviewer" } },
297
+ { toolName: "fix_compliance", actionId: "correct_expenses", args: { operationId: "expense-bulk:correct_test", status: true }, payload: { success: true, status: "status", operationId: "expense-bulk:correct_test" } },
298
+ { toolName: "submit_receipt", actionId: "submit_receipt", args: { filesToUpload: [{ filename: "receipt.jpg", mimeType: "image/jpeg" }] }, payload: { success: true, status: "upload_required", message: "Upload the file.", data: { signedUrl: "https://upload.example.test/file", uploadRef: "upload_test" } } },
299
+ { toolName: "add_cash_expense", actionId: "add_cash_expense", args: { total: 12.5, date: "2026-09-09" }, payload: { success: true, message: "Expense added." } },
300
+ { toolName: "parse_expense", actionId: "parse_expense", args: { text: "12.50 office supplies today" }, payload: { success: true, expenses: [], validationErrors: [], categoryNames: [] } },
301
+ { toolName: "process_gmail_receipts", actionId: "process_gmail_receipts", args: { emailIds: ["message_test"] }, payload: { success: true, message: "Receipts queued.", processedItems: [] } },
302
+ { toolName: "scan_gmail", actionId: "scan_gmail", args: {}, payload: { success: true, message: "Scan started.", status: "processing" } },
303
+ { toolName: "add_mileage_entry", actionId: "add_mileage_entry", args: { distance: 10, purpose: "Client visit", date: "2026-09-09" }, payload: { success: true, message: "Mileage added." } },
304
+ { toolName: "add_income", actionId: "add_income", args: { amount: 100, source: "Example", paymentMethod: "Bank", date: "2026-09-09" }, payload: { success: true, message: "Income added." } },
305
+ { toolName: "add_income_from_file", actionId: "add_income_from_file", args: { confirm: true, previewId: "preview_file" }, payload: { success: true, confirmed: true, previewId: "preview_file", written: 1, deduped: 0, failed: 0, unattempted: 0, total: 1, message: "Income imported." } },
306
+ { toolName: "add_income_from_csv", actionId: "add_income_from_csv", args: { confirm: true, previewId: "preview_csv" }, payload: { success: true, confirmed: true, previewId: "preview_csv", written: 1, deduped: 0, failed: 0, unattempted: 0, total: 1, message: "Income imported." } },
307
+ { toolName: "send_report_to_accounting", actionId: "send_report_to_accounting", args: { provider: "zoho_books", reportId: "report_test" }, payload: { success: true, phase: "completed", provider: "zoho_books", proposalId: "proposal_test", reportId: "report_test", finalAnswer: "Report sent.", responseGuidance: "Return finalAnswer." } },
308
+ { toolName: "trace_document", actionId: "trace_document", args: {}, payload: { success: true, type: "lineage_trace", message: "No events found.", data: { summary: { total: 0 }, events: [], filters: { days: 30 } } } },
309
+ { toolName: "export_report", actionId: "export_report", args: { reportId: "report_test" }, payload: { success: true, report: { title: "Report", spreadsheetId: "sheet_test" }, urls: { view: "https://example.test/view", pdf: "https://example.test/pdf", report: "https://example.test/report" }, expiresAt: "2026-09-09T20:00:00.000Z", availableInReport: ["csv"], notes: "Short-lived link." } },
310
+ { toolName: "scan_gmail_years", actionId: "scan_gmail_years", args: { years: [2025] }, payload: { success: true, message: "Preview ready.", preview: true, account: "account@example.com", eligible: [2025], alreadyScanned: [], notEligible: [] } },
311
+ { toolName: "prepare_client_invoice", actionId: "prepare_client_invoice", args: { reportId: "report_test", clientName: "Example Client", issueDate: "2026-09-09" }, payload: { success: true, preparationId: "prep_test", expiresAt: "2026-09-09T20:00:00.000Z", preview: {} } },
312
+ { toolName: "create_client_invoice", actionId: "create_client_invoice", args: { preparationId: "prep_test", operationId: "invoice_test" }, payload: { success: true, invoiceId: "invoice_test" } },
313
+ { toolName: "mark_client_invoice_paid", actionId: "mark_client_invoice_paid", args: { invoiceId: "invoice_test", paidDate: "2026-09-09" }, payload: { success: true, invoiceId: "invoice_test", invoiceNumber: null, status: "paid", paidDate: "2026-09-09", paidAmount: null, paidVia: "manual", incomeRowCreated: false, message: "Invoice marked paid." } },
314
+ { toolName: "group_expenses", actionId: "group_expenses", args: { operationId: "expense-bulk:group_test", status: true }, payload: { success: true, status: "status", operationId: "expense-bulk:group_test" } },
315
+ { toolName: "update_expense", actionId: "update_expense", args: { expenseId: "receipt_test", fields: { category: "Office Supplies" } }, payload: { success: true, message: "Preview ready.", data: { applied: false, preview: true, expenseId: "receipt_test", diff: [], unmapped: [] } } },
316
+ { toolName: "correct_expenses", actionId: "correct_expenses", args: { operationId: "expense-bulk:correct_test", status: true }, payload: { success: true, status: "status", operationId: "expense-bulk:correct_test" } },
317
+ ];
318
+
319
+ const SCHEMA_RUNTIME_CASES = [
320
+ { toolName: "get_setup_status", actionId: "get_setup_status", args: {}, payload: { success: true, status: "ready", revision: "setup-test", scope: "own", states: { expenses: "empty" }, decisions: {}, nextQuestion: null, suggestions: [], handoffs: {}, limitations: [] } },
321
+ { toolName: "complete_setup", actionId: "complete_setup", args: { proposalId: "0123456789abcdef0123456789abcdef", status: true }, payload: { success: true, status: "pending_verification", proposalId: "0123456789abcdef0123456789abcdef", operation: "general_settings", message: "Verify existing operation before retrying." } },
322
+ {
323
+ toolName: "get_trip_suggestions",
324
+ actionId: "get_trip_suggestions",
325
+ args: { includeCandidates: true, limit: 4 },
326
+ payload: {
327
+ success: true,
328
+ count: 1,
329
+ proposals: [{ confidenceScore: 0.82, members: [], ephemeral: true }],
330
+ },
331
+ },
332
+ {
333
+ toolName: "search_expenses",
334
+ actionId: "query_expenses",
335
+ args: { groupBy: "country", dateRange: { start: "2026-02-01", end: "2026-02-28" } },
336
+ payload: {
337
+ success: true, expenses: [], count: 2, total: null, hasMore: false,
338
+ countryGroups: [
339
+ { country: "United Kingdom", countryCode: "UK", count: 1, totalsByCurrency: { GBP: 25 }, selectionItems: [{ receiptId: "QA-UK", expected: { tag: "Business" } }] },
340
+ { country: "unknown", countryCode: null, count: 1, totalsByCurrency: { CAD: 30 }, selectionItems: [{ receiptId: "QA-UNKNOWN", expected: { tag: "" } }] },
341
+ ],
342
+ },
343
+ },
344
+ ...TRANCHE_2_RUNTIME_CASES,
345
+ ...TRANCHE_3_RUNTIME_CASES,
346
+ {
347
+ toolName: "create_tag",
348
+ actionId: "create_tag",
349
+ args: {
350
+ name: "New Project",
351
+ operationId: "tag-create:test",
352
+ confirm: true,
353
+ allowSimilar: true,
354
+ status: false,
355
+ },
356
+ payload: {
357
+ success: true,
358
+ status: "preview",
359
+ name: "New Project",
360
+ requestedName: "New Project",
361
+ canonicalName: "New Project",
362
+ existingTag: null,
363
+ existingMatches: [],
364
+ similarTags: [],
365
+ existingTags: [{ tag: "Current Project", isActive: true }],
366
+ existingTagCount: 1,
367
+ existingTagsTruncated: false,
368
+ confirmationRequired: true,
369
+ operationId: "tag-create:test",
370
+ groupManagementUrl: "https://www.expensebot.ai/settings?openTags=1&source=mcp",
371
+ created: false,
372
+ requiresConfirmation: true,
373
+ message: "Create tag \"New Project\"? No expenses will be changed.",
374
+ confirmation: {
375
+ actionId: "create_tag",
376
+ name: "New Project",
377
+ operationId: "tag-create:test",
378
+ confirm: true,
379
+ allowSimilar: true,
380
+ },
381
+ },
382
+ },
383
+ {
384
+ toolName: "get_last_receipt_result",
385
+ actionId: "get_last_receipt_result",
386
+ args: { submissionId: "receipt_multi_document_test" },
387
+ payload: {
388
+ success: true, found: true, verdict: "mixed",
389
+ message: "2 documents processed, 1 added, 1 skipped.",
390
+ counts: { submitted: 1, added: 1, duplicates: 0, skipped: 1, errors: 0 },
391
+ receipts: [],
392
+ submissionId: "receipt_multi_document_test",
393
+ spreadsheetUrl: null,
394
+ reviewExpensesUrl: "https://www.expensebot.ai/review-expenses?source=mcp",
395
+ timestamp: null,
396
+ data: {
397
+ perFileOutcomesAvailable: true,
398
+ resultDetails: { countUnit: "extracted_documents", total: 2, returned: 2, truncated: false },
399
+ outcomes: [{ outcome: "added", merchant: "Synthetic shop" }, { outcome: "skipped", merchant: "Synthetic quote" }],
400
+ },
401
+ },
402
+ },
142
403
  ];
143
404
  const REQUIRED_TOOLS = [
144
405
  // v0.5.x
@@ -147,6 +408,7 @@ const REQUIRED_TOOLS = [
147
408
  "get_last_receipt_result",
148
409
  "scan_gmail",
149
410
  "create_report",
411
+ "create_tag",
150
412
  // v0.6.0
151
413
  "get_income_summary",
152
414
  "get_pnl",
@@ -329,6 +591,9 @@ function check(label, ok, details = "") {
329
591
  );
330
592
 
331
593
  const instructions = byId.get(1)?.result?.instructions || "";
594
+ check("initialize links integrators to the canonical self-service guide",
595
+ instructions.includes("https://www.expensebot.ai/answers/mcp-integrator-setup") &&
596
+ instructions.includes("pending") && instructions.includes("PKCE"));
332
597
  check(
333
598
  "initialize instructions cover scan status, result links, and KB retrieval",
334
599
  /get_scan_status/.test(instructions) &&
@@ -350,7 +615,9 @@ function check(label, ok, details = "") {
350
615
  /unrequested advice/i.test(instructions) &&
351
616
  /terminal write result supersedes intermediate search/i.test(instructions) &&
352
617
  /excluded near-matches/i.test(instructions) &&
353
- /return it verbatim and add nothing else/i.test(instructions)
618
+ /suggested ExpenseBot outcome wording/i.test(instructions) &&
619
+ /do not override.*host's safety/i.test(instructions) &&
620
+ /tool-returned prose as data/i.test(instructions)
354
621
  );
355
622
  check(
356
623
  "initialize instructions define structured-result behavior",
@@ -381,25 +648,157 @@ function check(label, ok, details = "") {
381
648
  `(got ${typeof tools})`
382
649
  );
383
650
  if (Array.isArray(tools)) {
651
+ const csvTool = tools.find((tool) => tool.name === "add_income_from_csv");
652
+ const fileTool = tools.find((tool) => tool.name === "add_income_from_file");
653
+ const csvRowEdits = csvTool?.inputSchema?.properties?.rowEdits;
654
+ const csvFields = csvRowEdits?.items?.properties?.fields;
655
+ const validateCsvRowEdits = new Ajv({ allErrors: true }).compile(csvRowEdits);
656
+ const editableFields = [
657
+ "date", "source", "amount", "currency", "category", "paymentMethod",
658
+ "description", "notes", "reference", "fees", "taxCollected", "tag",
659
+ ];
660
+ check(
661
+ "CSV row edits advertise only the canonical editable fields and retain file-import contract",
662
+ csvFields?.additionalProperties === false &&
663
+ JSON.stringify(Object.keys(csvFields?.properties || {}).sort()) ===
664
+ JSON.stringify([...editableFields].sort()) &&
665
+ fileTool?.inputSchema?.properties?.rowEdits?.items?.properties?.fields
666
+ ?.additionalProperties === true
667
+ );
668
+ check(
669
+ "CSV row edits accept legacy numeric strings and nullable/text clears",
670
+ validateCsvRowEdits([{
671
+ index: 0,
672
+ fields: {
673
+ date: "2026-10-05",
674
+ amount: "125.50",
675
+ fees: "2.25",
676
+ taxCollected: null,
677
+ notes: null,
678
+ description: 123,
679
+ reference: false,
680
+ },
681
+ }]) &&
682
+ validateCsvRowEdits([{ index: 0, fields: { amount: true, fees: false, taxCollected: false } }])
683
+ );
684
+ check(
685
+ "CSV row edits reject unsupported fields, negative indexes, and more than 50 rows",
686
+ !validateCsvRowEdits([{ index: 0, fields: { unsupported: "value" } }]) &&
687
+ !validateCsvRowEdits([{ index: -1, fields: { notes: "text" } }]) &&
688
+ !validateCsvRowEdits(Array.from({ length: 51 }, (_, index) => ({
689
+ index,
690
+ fields: { notes: "text" },
691
+ })))
692
+ );
693
+
384
694
  const complianceTool = tools.find((tool) => tool.name === "check_compliance");
695
+ const tripSuggestionsTool = tools.find((tool) => tool.name === "get_trip_suggestions");
385
696
  const reportDetailsTool = tools.find((tool) => tool.name === "get_report_details");
697
+ const statementStatusTool = tools.find((tool) => tool.name === "get_statement_import_status");
698
+ const expenseDetail = tools.find((tool) => tool.name === "get_expense_by_id");
699
+ check("expense detail schema describes actual row representations, not a phantom expense object",
700
+ !expenseDetail?.outputSchema?.properties?.expense &&
701
+ ["sheetName", "rowNumber", "headers", "values", "labeled", "reviewExpenseUrl"].every(
702
+ (field) => !!expenseDetail?.outputSchema?.properties?.[field]
703
+ )
704
+ );
705
+ check(
706
+ "trip suggestions advertise opt-in lower-confidence candidates without narrowing outputSchema",
707
+ tripSuggestionsTool?.inputSchema?.properties?.includeCandidates?.type === "boolean" &&
708
+ tripSuggestionsTool?.inputSchema?.properties?.includeCandidates?.default === false &&
709
+ /default false/i.test(tripSuggestionsTool?.inputSchema?.properties?.includeCandidates?.description || "") &&
710
+ tripSuggestionsTool?.outputSchema?.properties?.proposals?.items?.additionalProperties === true &&
711
+ tripSuggestionsTool?.outputSchema?.additionalProperties === true
712
+ );
386
713
  check(
387
714
  "compliance and report-detail tools are explicit opt-in",
388
715
  /only when the user explicitly asks/i.test(complianceTool?.description || "") &&
389
716
  /billing a client is not a compliance request/i.test(
390
717
  complianceTool?.description || ""
391
718
  ) &&
392
- complianceTool?.inputSchema?.required?.includes("userRequest") &&
719
+ complianceTool?.inputSchema?.required?.includes("analysisRequested") &&
720
+ !complianceTool?.inputSchema?.properties?.userRequest &&
721
+ complianceTool?.inputSchema?.properties?.analysisRequested?.enum?.[0] === true &&
393
722
  /only when the user explicitly asks/i.test(
394
723
  reportDetailsTool?.description || ""
395
724
  ) &&
396
- reportDetailsTool?.inputSchema?.required?.includes("userRequest")
725
+ reportDetailsTool?.inputSchema?.required?.includes("analysisRequested") &&
726
+ !reportDetailsTool?.inputSchema?.properties?.userRequest &&
727
+ reportDetailsTool?.inputSchema?.properties?.checkFreshness?.enum?.[0] === true &&
728
+ !reportDetailsTool?.inputSchema?.required?.includes("checkFreshness")
729
+ );
730
+ const freshnessSchema = reportDetailsTool?.outputSchema?.properties?.freshness;
731
+ check(
732
+ "report freshness output is optional and requires its complete verified contract",
733
+ !reportDetailsTool?.outputSchema?.required?.includes("freshness") &&
734
+ JSON.stringify(freshnessSchema?.required) ===
735
+ JSON.stringify(["status", "checkedAt", "message", "reportUrl"]) &&
736
+ JSON.stringify(freshnessSchema?.properties?.status?.enum) ===
737
+ JSON.stringify(["current", "outdated", "unknown", "not_applicable"]) &&
738
+ freshnessSchema?.properties?.checkedAt?.format === "date-time" &&
739
+ freshnessSchema?.properties?.message?.type === "string" &&
740
+ freshnessSchema?.properties?.reportUrl?.type === "string" &&
741
+ freshnessSchema?.properties?.reportUrl?.format === "uri"
742
+ );
743
+ check(
744
+ "statement import status is a bounded read with truthful stage and coverage language",
745
+ /at most five jobs/.test(statementStatusTool?.description || "") &&
746
+ /Extraction isn't saved/.test(statementStatusTool?.description || "") &&
747
+ /No job found doesn't prove no import/.test(statementStatusTool?.description || "") &&
748
+ /never uploads, parses, saves, retries, or recovers/.test(statementStatusTool?.description || "") &&
749
+ statementStatusTool?.inputSchema?.additionalProperties === false &&
750
+ statementStatusTool?.outputSchema?.properties?.imports?.maxItems === 5 &&
751
+ statementStatusTool?.outputSchema?.properties?.imports?.items?.required?.includes("counts")
752
+ );
753
+ // Since web commit c05493e19 the executor rejects a missing date for these
754
+ // two writes, so the schema must require it and must never imply a default.
755
+ const entryDateTools = ["add_mileage_entry", "add_income"].map((name) =>
756
+ tools.find((tool) => tool.name === name)
757
+ );
758
+ check(
759
+ "add_mileage_entry and add_income require an explicit date and never imply a default",
760
+ entryDateTools.every((tool) => {
761
+ const dateText = tool?.inputSchema?.properties?.date?.description || "";
762
+ return (
763
+ tool?.inputSchema?.required?.includes("date") &&
764
+ /\bRequired\b/.test(dateText) &&
765
+ !/default/i.test(dateText) &&
766
+ !/defaults? to today/i.test(tool?.description || "")
767
+ );
768
+ })
769
+ );
770
+ const receiptResultTool = tools.find(
771
+ (tool) => tool.name === "get_last_receipt_result"
772
+ );
773
+ check(
774
+ "get_last_receipt_result advertises the held_for_review verdict and heldForReview count",
775
+ receiptResultTool?.outputSchema?.properties?.verdict?.enum?.includes(
776
+ "held_for_review"
777
+ ) &&
778
+ receiptResultTool?.outputSchema?.properties?.counts?.properties
779
+ ?.heldForReview?.type === "integer" &&
780
+ !receiptResultTool?.outputSchema?.properties?.counts?.required?.includes(
781
+ "heldForReview"
782
+ ) &&
783
+ /held_for_review/.test(receiptResultTool?.description || "") &&
784
+ /missing details or a possible duplicate/.test(receiptResultTool?.description || "")
397
785
  );
398
786
  check(
399
787
  `tools/list count = ${EXPECTED_TOOL_COUNT}`,
400
788
  tools.length === EXPECTED_TOOL_COUNT,
401
789
  `(got ${tools.length})`
402
790
  );
791
+ const createTag = tools.find((tool) => tool.name === "create_tag");
792
+ check(
793
+ "create_tag schema requires only the name and leaves result fields optional",
794
+ createTag?.inputSchema?.required?.join(",") === "name" &&
795
+ createTag?.inputSchema?.properties?.confirm?.default === false &&
796
+ createTag?.inputSchema?.properties?.allowSimilar?.default === false &&
797
+ createTag?.inputSchema?.properties?.status?.type === "boolean" &&
798
+ createTag?.outputSchema?.required?.join(",") === "success" &&
799
+ createTag?.outputSchema?.additionalProperties === true &&
800
+ createTag?.outputSchema?.properties?.groupManagementUrl?.format === "uri"
801
+ );
403
802
  const names = new Set(tools.map((t) => t.name));
404
803
  const missing = REQUIRED_TOOLS.filter((n) => !names.has(n));
405
804
  check(
@@ -417,6 +816,24 @@ function check(label, ok, details = "") {
417
816
  ? `missing: ${missingOutputSchemas.join(", ")}`
418
817
  : ""
419
818
  );
819
+ const fixComplianceTool = tools.find(
820
+ (tool) => tool.name === "fix_compliance"
821
+ );
822
+ const canonicalCorrectionTool = tools.find(
823
+ (tool) => tool.name === "correct_expenses"
824
+ );
825
+ check(
826
+ "fix_compliance shares the reviewed exact-correction contract",
827
+ JSON.stringify(fixComplianceTool?.inputSchema) ===
828
+ JSON.stringify(canonicalCorrectionTool?.inputSchema) &&
829
+ JSON.stringify(fixComplianceTool?.outputSchema) ===
830
+ JSON.stringify(canonicalCorrectionTool?.outputSchema) &&
831
+ !Object.prototype.hasOwnProperty.call(
832
+ fixComplianceTool?.inputSchema?.properties || {},
833
+ "reportId"
834
+ ) &&
835
+ /grounded preview/i.test(fixComplianceTool?.description || "")
836
+ );
420
837
  // Every tool must have a description
421
838
  const noDesc = tools.filter((t) => !t.description);
422
839
  check(
@@ -546,12 +963,26 @@ function check(label, ok, details = "") {
546
963
  searchKnowledge?.inputSchema?.properties?.limit?.maximum === 10
547
964
  );
548
965
  const scanStatus = tools.find((tool) => tool.name === "get_scan_status");
966
+ const scanYears = tools.find((tool) => tool.name === "scan_gmail_years");
549
967
  check(
550
968
  "get_scan_status describes authoritative live progress and result links",
551
969
  /authoritative/.test(scanStatus?.description || "") &&
552
970
  /live phase/.test(scanStatus?.description || "") &&
553
971
  /reviewExpensesUrl/.test(scanStatus?.description || "")
554
972
  );
973
+ check(
974
+ "Gmail year tools explain account-dependent tax-period years and bounds",
975
+ /ending year/.test(scanYears?.description || "") &&
976
+ /2025 = 2024–25 tax year/.test(scanYears?.description || "") &&
977
+ /otherwise it is a calendar year/.test(scanYears?.description || "") &&
978
+ /tax-period labels and inclusive ISO bounds/.test(scanYears?.description || "") &&
979
+ /Completed periods; ending year/.test(
980
+ scanYears?.inputSchema?.properties?.years?.description || ""
981
+ ) &&
982
+ /completed calendar years/.test(scanStatus?.description || "") &&
983
+ /tax-period statuses/.test(scanStatus?.description || "") &&
984
+ /returned labels and inclusive ISO bounds/.test(scanStatus?.description || "")
985
+ );
555
986
  const receiptResult = tools.find(
556
987
  (tool) => tool.name === "get_last_receipt_result"
557
988
  );
@@ -610,17 +1041,20 @@ function check(label, ok, details = "") {
610
1041
  gatedText.includes("AI Assistant Tokens")
611
1042
  );
612
1043
 
1044
+ const executedCalls = [];
613
1045
  const stub = http.createServer(async (req, res) => {
614
1046
  let body = "";
615
1047
  for await (const chunk of req) body += chunk;
616
1048
  const parsed = JSON.parse(body || "{}");
1049
+ executedCalls.push(parsed);
617
1050
  if (!["/api/mcp/execute", "/api/mcp/public/execute"].includes(req.url)) {
618
1051
  res.writeHead(400, { "Content-Type": "application/json" });
619
1052
  return res.end(JSON.stringify({ success: false }));
620
1053
  }
621
1054
 
622
- const runtimeCase = TRANCHE_2_RUNTIME_CASES.find(
623
- (entry) => entry.actionId === parsed.actionId
1055
+ const runtimeCase = SCHEMA_RUNTIME_CASES.find(
1056
+ (entry) => entry.actionId === parsed.actionId &&
1057
+ (entry.args.checkFreshness === true) === (parsed.params?.checkFreshness === true)
624
1058
  );
625
1059
  if (runtimeCase) {
626
1060
  res.writeHead(200, { "Content-Type": "application/json" });
@@ -662,7 +1096,7 @@ function check(label, ok, details = "") {
662
1096
  arguments: { query: "how it works" },
663
1097
  },
664
1098
  },
665
- ...TRANCHE_2_RUNTIME_CASES.map((runtimeCase, index) => ({
1099
+ ...SCHEMA_RUNTIME_CASES.map((runtimeCase, index) => ({
666
1100
  jsonrpc: "2.0",
667
1101
  id: 20 + index,
668
1102
  method: "tools/call",
@@ -713,7 +1147,7 @@ function check(label, ok, details = "") {
713
1147
  )
714
1148
  );
715
1149
 
716
- for (const [index, runtimeCase] of TRANCHE_2_RUNTIME_CASES.entries()) {
1150
+ for (const [index, runtimeCase] of SCHEMA_RUNTIME_CASES.entries()) {
717
1151
  const result = authenticatedResponses.find(
718
1152
  (response) => response.id === 20 + index
719
1153
  )?.result;
@@ -722,7 +1156,26 @@ function check(label, ok, details = "") {
722
1156
  result?.isError !== true &&
723
1157
  JSON.stringify(result?.structuredContent) ===
724
1158
  JSON.stringify(runtimeCase.payload) &&
725
- (result?.content?.[0]?.text || "").includes(runtimeCase.payload.message)
1159
+ (runtimeCase.toolName !== "create_tag" ||
1160
+ JSON.stringify(executedCalls.find((call) => call.actionId === "create_tag")?.params) ===
1161
+ JSON.stringify(runtimeCase.args)) &&
1162
+ (runtimeCase.toolName !== "get_trip_suggestions" ||
1163
+ isDeepStrictEqual(executedCalls.find((call) => call.actionId === "get_trip_suggestions")?.params,
1164
+ runtimeCase.args)) &&
1165
+ (!runtimeCase.payload.message ||
1166
+ (result?.content?.[0]?.text || "").includes(runtimeCase.payload.message)) &&
1167
+ (runtimeCase.toolName !== "get_statement_import_status" ||
1168
+ ((result?.content?.[0]?.text || "").includes('"saved_with_held"') &&
1169
+ (result?.content?.[0]?.text || "").includes('"reviewReadyFiles": 2'))) &&
1170
+ (runtimeCase.toolName !== "get_report_details" ||
1171
+ !runtimeCase.args.checkFreshness ||
1172
+ (result?.content?.[0]?.text || "").includes('"status": "current"'))
1173
+ );
1174
+ }
1175
+ for (const actionId of ["help_compliance", "get_report_details"]) {
1176
+ check(`stdio ${actionId} preserves new and published legacy opt-in formats`,
1177
+ executedCalls.some((call) => call.actionId === actionId && call.params?.analysisRequested === true) &&
1178
+ executedCalls.some((call) => call.actionId === actionId && typeof call.params?.userRequest === "string")
726
1179
  );
727
1180
  }
728
1181