@expensebot/mcp-server-auth 0.6.22 → 0.6.24
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 -4
- package/package.json +3 -2
- package/scripts/sync-check.js +150 -0
- package/server.json +37 -0
- package/src/client.js +1 -1
- package/src/index.js +1121 -133
- package/src/test.js +266 -4
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 =
|
|
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,14 +222,19 @@ 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: {
|
|
229
|
+
env: {
|
|
230
|
+
...process.env,
|
|
231
|
+
EXPENSEBOT_TOKEN: token,
|
|
232
|
+
...(apiBase ? { EXPENSEBOT_API_BASE: apiBase } : {}),
|
|
233
|
+
},
|
|
114
234
|
});
|
|
115
235
|
|
|
116
236
|
const responses = [];
|
|
237
|
+
let stderrBuf = "";
|
|
117
238
|
let stdoutBuf = "";
|
|
118
239
|
|
|
119
240
|
child.stdout.on("data", (chunk) => {
|
|
@@ -132,6 +253,7 @@ function runServer() {
|
|
|
132
253
|
});
|
|
133
254
|
|
|
134
255
|
child.stderr.on("data", (d) => {
|
|
256
|
+
stderrBuf += d.toString();
|
|
135
257
|
// Pass through banners only when running in verbose mode
|
|
136
258
|
if (process.env.MCP_TEST_VERBOSE) {
|
|
137
259
|
process.stderr.write(`[server] ${d}`);
|
|
@@ -144,12 +266,13 @@ function runServer() {
|
|
|
144
266
|
reject(new Error(`Server exited with code ${code}`));
|
|
145
267
|
return;
|
|
146
268
|
}
|
|
269
|
+
responses.stderr = stderrBuf;
|
|
147
270
|
resolve(responses);
|
|
148
271
|
});
|
|
149
272
|
|
|
150
273
|
// Send all requests with small delays (server needs to ack between)
|
|
151
274
|
(async () => {
|
|
152
|
-
for (const req of
|
|
275
|
+
for (const req of requests) {
|
|
153
276
|
child.stdin.write(JSON.stringify(req) + "\n");
|
|
154
277
|
await new Promise((r) => setTimeout(r, 200));
|
|
155
278
|
}
|
|
@@ -198,6 +321,12 @@ function check(label, ok, details = "") {
|
|
|
198
321
|
const byId = new Map(
|
|
199
322
|
responses.filter((r) => r.id != null).map((r) => [r.id, r])
|
|
200
323
|
);
|
|
324
|
+
check(
|
|
325
|
+
"onboarding startup message describes the full public surface",
|
|
326
|
+
/Public setup, pricing, product-help, and trial tools are available\./.test(
|
|
327
|
+
responses.stderr || ""
|
|
328
|
+
) && !/Only get_signup_link/.test(responses.stderr || "")
|
|
329
|
+
);
|
|
201
330
|
|
|
202
331
|
const instructions = byId.get(1)?.result?.instructions || "";
|
|
203
332
|
check(
|
|
@@ -223,6 +352,13 @@ function check(label, ok, details = "") {
|
|
|
223
352
|
/excluded near-matches/i.test(instructions) &&
|
|
224
353
|
/return it verbatim and add nothing else/i.test(instructions)
|
|
225
354
|
);
|
|
355
|
+
check(
|
|
356
|
+
"initialize instructions define structured-result behavior",
|
|
357
|
+
/structuredContent is present/i.test(instructions) &&
|
|
358
|
+
/authoritative machine-readable result/i.test(instructions) &&
|
|
359
|
+
/hasMore, nextCursor, and truncated/i.test(instructions) &&
|
|
360
|
+
/merge stale values/i.test(instructions)
|
|
361
|
+
);
|
|
226
362
|
check(
|
|
227
363
|
"initialize instructions preserve grouping terminology and billing boundary",
|
|
228
364
|
/call the destination a group/i.test(instructions) &&
|
|
@@ -271,6 +407,16 @@ function check(label, ok, details = "") {
|
|
|
271
407
|
missing.length === 0,
|
|
272
408
|
missing.length ? `missing: ${missing.join(", ")}` : ""
|
|
273
409
|
);
|
|
410
|
+
const missingOutputSchemas = OUTPUT_SCHEMA_TOOLS.filter(
|
|
411
|
+
(name) => !tools.find((tool) => tool.name === name)?.outputSchema
|
|
412
|
+
);
|
|
413
|
+
check(
|
|
414
|
+
"every approved schema tool advertises outputSchema",
|
|
415
|
+
missingOutputSchemas.length === 0,
|
|
416
|
+
missingOutputSchemas.length
|
|
417
|
+
? `missing: ${missingOutputSchemas.join(", ")}`
|
|
418
|
+
: ""
|
|
419
|
+
);
|
|
274
420
|
// Every tool must have a description
|
|
275
421
|
const noDesc = tools.filter((t) => !t.description);
|
|
276
422
|
check(
|
|
@@ -464,6 +610,122 @@ function check(label, ok, details = "") {
|
|
|
464
610
|
gatedText.includes("AI Assistant Tokens")
|
|
465
611
|
);
|
|
466
612
|
|
|
613
|
+
const stub = http.createServer(async (req, res) => {
|
|
614
|
+
let body = "";
|
|
615
|
+
for await (const chunk of req) body += chunk;
|
|
616
|
+
const parsed = JSON.parse(body || "{}");
|
|
617
|
+
if (!["/api/mcp/execute", "/api/mcp/public/execute"].includes(req.url)) {
|
|
618
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
619
|
+
return res.end(JSON.stringify({ success: false }));
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
const runtimeCase = TRANCHE_2_RUNTIME_CASES.find(
|
|
623
|
+
(entry) => entry.actionId === parsed.actionId
|
|
624
|
+
);
|
|
625
|
+
if (runtimeCase) {
|
|
626
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
627
|
+
return res.end(JSON.stringify(runtimeCase.payload));
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
if (parsed.actionId !== "search_knowledge") {
|
|
631
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
632
|
+
return res.end(JSON.stringify({ success: false }));
|
|
633
|
+
}
|
|
634
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
635
|
+
return res.end(
|
|
636
|
+
JSON.stringify({
|
|
637
|
+
success: true,
|
|
638
|
+
results: [
|
|
639
|
+
{
|
|
640
|
+
id: "stdio-kb-result",
|
|
641
|
+
question: "How does ExpenseBot work?",
|
|
642
|
+
answer: "Structured stdio answer",
|
|
643
|
+
},
|
|
644
|
+
],
|
|
645
|
+
})
|
|
646
|
+
);
|
|
647
|
+
});
|
|
648
|
+
await new Promise((resolve) => stub.listen(0, "127.0.0.1", resolve));
|
|
649
|
+
const stubPort = stub.address().port;
|
|
650
|
+
const authenticatedResponses = await runServer({
|
|
651
|
+
token: "test-token",
|
|
652
|
+
apiBase: `http://127.0.0.1:${stubPort}`,
|
|
653
|
+
requests: [
|
|
654
|
+
REQUESTS[0],
|
|
655
|
+
REQUESTS[1],
|
|
656
|
+
{
|
|
657
|
+
jsonrpc: "2.0",
|
|
658
|
+
id: 7,
|
|
659
|
+
method: "tools/call",
|
|
660
|
+
params: {
|
|
661
|
+
name: "search_knowledge",
|
|
662
|
+
arguments: { query: "how it works" },
|
|
663
|
+
},
|
|
664
|
+
},
|
|
665
|
+
...TRANCHE_2_RUNTIME_CASES.map((runtimeCase, index) => ({
|
|
666
|
+
jsonrpc: "2.0",
|
|
667
|
+
id: 20 + index,
|
|
668
|
+
method: "tools/call",
|
|
669
|
+
params: {
|
|
670
|
+
name: runtimeCase.toolName,
|
|
671
|
+
arguments: runtimeCase.args,
|
|
672
|
+
},
|
|
673
|
+
})),
|
|
674
|
+
],
|
|
675
|
+
});
|
|
676
|
+
const onboardingResponses = await runServer({
|
|
677
|
+
apiBase: `http://127.0.0.1:${stubPort}`,
|
|
678
|
+
requests: [
|
|
679
|
+
REQUESTS[0],
|
|
680
|
+
REQUESTS[1],
|
|
681
|
+
{
|
|
682
|
+
jsonrpc: "2.0",
|
|
683
|
+
id: 8,
|
|
684
|
+
method: "tools/call",
|
|
685
|
+
params: {
|
|
686
|
+
name: "search_knowledge",
|
|
687
|
+
arguments: { query: "how it works" },
|
|
688
|
+
},
|
|
689
|
+
},
|
|
690
|
+
],
|
|
691
|
+
});
|
|
692
|
+
await new Promise((resolve) => stub.close(resolve));
|
|
693
|
+
const stdioKnowledge = authenticatedResponses.find(
|
|
694
|
+
(response) => response.id === 7
|
|
695
|
+
)?.result;
|
|
696
|
+
check(
|
|
697
|
+
"stdio search_knowledge returns structuredContent and keeps text",
|
|
698
|
+
stdioKnowledge?.structuredContent?.results?.[0]?.id ===
|
|
699
|
+
"stdio-kb-result" &&
|
|
700
|
+
/Structured stdio answer/.test(
|
|
701
|
+
stdioKnowledge?.content?.[0]?.text || ""
|
|
702
|
+
)
|
|
703
|
+
);
|
|
704
|
+
const onboardingKnowledge = onboardingResponses.find(
|
|
705
|
+
(response) => response.id === 8
|
|
706
|
+
)?.result;
|
|
707
|
+
check(
|
|
708
|
+
"stdio onboarding search_knowledge uses the schema-compatible public MCP path",
|
|
709
|
+
onboardingKnowledge?.structuredContent?.results?.[0]?.id ===
|
|
710
|
+
"stdio-kb-result" &&
|
|
711
|
+
/Structured stdio answer/.test(
|
|
712
|
+
onboardingKnowledge?.content?.[0]?.text || ""
|
|
713
|
+
)
|
|
714
|
+
);
|
|
715
|
+
|
|
716
|
+
for (const [index, runtimeCase] of TRANCHE_2_RUNTIME_CASES.entries()) {
|
|
717
|
+
const result = authenticatedResponses.find(
|
|
718
|
+
(response) => response.id === 20 + index
|
|
719
|
+
)?.result;
|
|
720
|
+
check(
|
|
721
|
+
`stdio ${runtimeCase.toolName} returns its backend payload as structuredContent`,
|
|
722
|
+
result?.isError !== true &&
|
|
723
|
+
JSON.stringify(result?.structuredContent) ===
|
|
724
|
+
JSON.stringify(runtimeCase.payload) &&
|
|
725
|
+
(result?.content?.[0]?.text || "").includes(runtimeCase.payload.message)
|
|
726
|
+
);
|
|
727
|
+
}
|
|
728
|
+
|
|
467
729
|
console.log("");
|
|
468
730
|
if (failures.length) {
|
|
469
731
|
console.error(`✘ ${failures.length} check(s) failed:`);
|