@expensebot/mcp-server-auth 0.6.22 → 0.6.23

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,6 +15,7 @@
15
15
  */
16
16
 
17
17
  import { spawn } from "node:child_process";
18
+ import http from "node:http";
18
19
  import { readFileSync } from "node:fs";
19
20
  import { fileURLToPath } from "node:url";
20
21
  import path from "node:path";
@@ -23,7 +24,122 @@ import { readStructuredHttpError } from "./client.js";
23
24
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
24
25
  const SERVER_PATH = path.join(__dirname, "index.js");
25
26
 
26
- const EXPECTED_TOOL_COUNT = 56;
27
+ const EXPECTED_TOOL_COUNT = 60;
28
+ // Every stdio tool that advertises outputSchema (enumerated per tranche).
29
+ const OUTPUT_SCHEMA_TOOLS = [
30
+ "check_compliance",
31
+ "check_feature",
32
+ "check_tax_deductibility",
33
+ "get_accounting_integration_status",
34
+ "get_accounting_push_status",
35
+ "get_client_advance_balances",
36
+ "get_client_invoice",
37
+ "get_credits_refunds",
38
+ "get_deep_analytics",
39
+ "get_expense_by_id",
40
+ "get_expense_splits",
41
+ "get_income_summary",
42
+ "get_last_receipt_result",
43
+ "get_mileage_summary",
44
+ "get_monthly_books_review",
45
+ "get_per_tag_pnl",
46
+ "get_pnl",
47
+ "get_recent_activity",
48
+ "get_report_details",
49
+ "get_scan_status",
50
+ "get_spending_summary",
51
+ "get_spreadsheet_url",
52
+ "get_subscription_audit",
53
+ "get_trip_suggestions",
54
+ "list_categories",
55
+ "list_client_invoices",
56
+ "list_income_categories",
57
+ "list_reports",
58
+ "list_tags",
59
+ "search_expenses",
60
+ "search_knowledge",
61
+ "whatif_afford",
62
+ "whatif_client",
63
+ "whatif_tax_setaside",
64
+ ];
65
+
66
+ const TRANCHE_2_RUNTIME_CASES = [
67
+ {
68
+ toolName: "check_compliance",
69
+ actionId: "help_compliance",
70
+ args: { reportId: "report_test", userRequest: "Check this report" },
71
+ payload: {
72
+ success: true,
73
+ message: "Compliance check complete.",
74
+ data: { status: "clear" },
75
+ },
76
+ },
77
+ {
78
+ toolName: "check_feature",
79
+ actionId: "check_feature",
80
+ args: { feature: "Google Sheets" },
81
+ payload: {
82
+ success: true,
83
+ message: "Feature check complete.",
84
+ data: { available: true },
85
+ },
86
+ },
87
+ {
88
+ toolName: "check_tax_deductibility",
89
+ actionId: "tax_query",
90
+ args: { query: "Is this deductible?", category: "Office Supplies" },
91
+ payload: {
92
+ success: true,
93
+ message: "Tax guidance is available.",
94
+ data: { outcome: "review_guidance" },
95
+ },
96
+ },
97
+ {
98
+ toolName: "whatif_afford",
99
+ actionId: "whatif_afford",
100
+ args: { deltaMonthly: 250 },
101
+ payload: {
102
+ success: true,
103
+ message: "Affordability scenario complete.",
104
+ data: { verdict: "yes" },
105
+ },
106
+ },
107
+ {
108
+ toolName: "whatif_client",
109
+ actionId: "whatif_client",
110
+ args: { clientName: "Example Client", mode: "lose" },
111
+ payload: {
112
+ success: true,
113
+ message: "Client scenario complete.",
114
+ data: { verdict: "review" },
115
+ },
116
+ },
117
+ {
118
+ toolName: "whatif_tax_setaside",
119
+ actionId: "whatif_tax_setaside",
120
+ args: {},
121
+ payload: {
122
+ success: true,
123
+ message: "Tax set-aside scenario complete.",
124
+ data: { verdict: "on_track" },
125
+ },
126
+ },
127
+ {
128
+ toolName: "get_scan_status",
129
+ actionId: "get_scan_status",
130
+ args: {},
131
+ payload: {
132
+ success: true,
133
+ message: "No scans yet.",
134
+ status: null,
135
+ scanInProgress: false,
136
+ latestScan: null,
137
+ spreadsheetUrl: null,
138
+ reviewExpensesUrl: null,
139
+ gmailScanUrl: null,
140
+ },
141
+ },
142
+ ];
27
143
  const REQUIRED_TOOLS = [
28
144
  // v0.5.x
29
145
  "search_expenses",
@@ -106,11 +222,15 @@ const REQUESTS = [
106
222
  },
107
223
  ];
108
224
 
109
- function runServer() {
225
+ function runServer({ token = "", apiBase, requests = REQUESTS } = {}) {
110
226
  return new Promise((resolve, reject) => {
111
227
  const child = spawn("node", [SERVER_PATH], {
112
228
  stdio: ["pipe", "pipe", "pipe"],
113
- env: { ...process.env, EXPENSEBOT_TOKEN: "" },
229
+ env: {
230
+ ...process.env,
231
+ EXPENSEBOT_TOKEN: token,
232
+ ...(apiBase ? { EXPENSEBOT_API_BASE: apiBase } : {}),
233
+ },
114
234
  });
115
235
 
116
236
  const responses = [];
@@ -149,7 +269,7 @@ function runServer() {
149
269
 
150
270
  // Send all requests with small delays (server needs to ack between)
151
271
  (async () => {
152
- for (const req of REQUESTS) {
272
+ for (const req of requests) {
153
273
  child.stdin.write(JSON.stringify(req) + "\n");
154
274
  await new Promise((r) => setTimeout(r, 200));
155
275
  }
@@ -223,6 +343,13 @@ function check(label, ok, details = "") {
223
343
  /excluded near-matches/i.test(instructions) &&
224
344
  /return it verbatim and add nothing else/i.test(instructions)
225
345
  );
346
+ check(
347
+ "initialize instructions define structured-result behavior",
348
+ /structuredContent is present/i.test(instructions) &&
349
+ /authoritative machine-readable result/i.test(instructions) &&
350
+ /hasMore, nextCursor, and truncated/i.test(instructions) &&
351
+ /merge stale values/i.test(instructions)
352
+ );
226
353
  check(
227
354
  "initialize instructions preserve grouping terminology and billing boundary",
228
355
  /call the destination a group/i.test(instructions) &&
@@ -271,6 +398,16 @@ function check(label, ok, details = "") {
271
398
  missing.length === 0,
272
399
  missing.length ? `missing: ${missing.join(", ")}` : ""
273
400
  );
401
+ const missingOutputSchemas = OUTPUT_SCHEMA_TOOLS.filter(
402
+ (name) => !tools.find((tool) => tool.name === name)?.outputSchema
403
+ );
404
+ check(
405
+ "every approved schema tool advertises outputSchema",
406
+ missingOutputSchemas.length === 0,
407
+ missingOutputSchemas.length
408
+ ? `missing: ${missingOutputSchemas.join(", ")}`
409
+ : ""
410
+ );
274
411
  // Every tool must have a description
275
412
  const noDesc = tools.filter((t) => !t.description);
276
413
  check(
@@ -464,6 +601,122 @@ function check(label, ok, details = "") {
464
601
  gatedText.includes("AI Assistant Tokens")
465
602
  );
466
603
 
604
+ const stub = http.createServer(async (req, res) => {
605
+ let body = "";
606
+ for await (const chunk of req) body += chunk;
607
+ const parsed = JSON.parse(body || "{}");
608
+ if (!["/api/mcp/execute", "/api/mcp/public/execute"].includes(req.url)) {
609
+ res.writeHead(400, { "Content-Type": "application/json" });
610
+ return res.end(JSON.stringify({ success: false }));
611
+ }
612
+
613
+ const runtimeCase = TRANCHE_2_RUNTIME_CASES.find(
614
+ (entry) => entry.actionId === parsed.actionId
615
+ );
616
+ if (runtimeCase) {
617
+ res.writeHead(200, { "Content-Type": "application/json" });
618
+ return res.end(JSON.stringify(runtimeCase.payload));
619
+ }
620
+
621
+ if (parsed.actionId !== "search_knowledge") {
622
+ res.writeHead(400, { "Content-Type": "application/json" });
623
+ return res.end(JSON.stringify({ success: false }));
624
+ }
625
+ res.writeHead(200, { "Content-Type": "application/json" });
626
+ return res.end(
627
+ JSON.stringify({
628
+ success: true,
629
+ results: [
630
+ {
631
+ id: "stdio-kb-result",
632
+ question: "How does ExpenseBot work?",
633
+ answer: "Structured stdio answer",
634
+ },
635
+ ],
636
+ })
637
+ );
638
+ });
639
+ await new Promise((resolve) => stub.listen(0, "127.0.0.1", resolve));
640
+ const stubPort = stub.address().port;
641
+ const authenticatedResponses = await runServer({
642
+ token: "test-token",
643
+ apiBase: `http://127.0.0.1:${stubPort}`,
644
+ requests: [
645
+ REQUESTS[0],
646
+ REQUESTS[1],
647
+ {
648
+ jsonrpc: "2.0",
649
+ id: 7,
650
+ method: "tools/call",
651
+ params: {
652
+ name: "search_knowledge",
653
+ arguments: { query: "how it works" },
654
+ },
655
+ },
656
+ ...TRANCHE_2_RUNTIME_CASES.map((runtimeCase, index) => ({
657
+ jsonrpc: "2.0",
658
+ id: 20 + index,
659
+ method: "tools/call",
660
+ params: {
661
+ name: runtimeCase.toolName,
662
+ arguments: runtimeCase.args,
663
+ },
664
+ })),
665
+ ],
666
+ });
667
+ const onboardingResponses = await runServer({
668
+ apiBase: `http://127.0.0.1:${stubPort}`,
669
+ requests: [
670
+ REQUESTS[0],
671
+ REQUESTS[1],
672
+ {
673
+ jsonrpc: "2.0",
674
+ id: 8,
675
+ method: "tools/call",
676
+ params: {
677
+ name: "search_knowledge",
678
+ arguments: { query: "how it works" },
679
+ },
680
+ },
681
+ ],
682
+ });
683
+ await new Promise((resolve) => stub.close(resolve));
684
+ const stdioKnowledge = authenticatedResponses.find(
685
+ (response) => response.id === 7
686
+ )?.result;
687
+ check(
688
+ "stdio search_knowledge returns structuredContent and keeps text",
689
+ stdioKnowledge?.structuredContent?.results?.[0]?.id ===
690
+ "stdio-kb-result" &&
691
+ /Structured stdio answer/.test(
692
+ stdioKnowledge?.content?.[0]?.text || ""
693
+ )
694
+ );
695
+ const onboardingKnowledge = onboardingResponses.find(
696
+ (response) => response.id === 8
697
+ )?.result;
698
+ check(
699
+ "stdio onboarding search_knowledge uses the schema-compatible public MCP path",
700
+ onboardingKnowledge?.structuredContent?.results?.[0]?.id ===
701
+ "stdio-kb-result" &&
702
+ /Structured stdio answer/.test(
703
+ onboardingKnowledge?.content?.[0]?.text || ""
704
+ )
705
+ );
706
+
707
+ for (const [index, runtimeCase] of TRANCHE_2_RUNTIME_CASES.entries()) {
708
+ const result = authenticatedResponses.find(
709
+ (response) => response.id === 20 + index
710
+ )?.result;
711
+ check(
712
+ `stdio ${runtimeCase.toolName} returns its backend payload as structuredContent`,
713
+ result?.isError !== true &&
714
+ JSON.stringify(result?.structuredContent) ===
715
+ JSON.stringify(runtimeCase.payload) &&
716
+ (result?.content?.[0]?.text || "").includes(runtimeCase.payload.message)
717
+ );
718
+ }
719
+
467
720
  console.log("");
468
721
  if (failures.length) {
469
722
  console.error(`✘ ${failures.length} check(s) failed:`);