@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.
@@ -0,0 +1,75 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { readFileSync } from 'node:fs';
4
+ import { createRequire } from 'node:module';
5
+ import { buildToolList, routeToolCall } from '../../mcp-server-remote/src/tools.js';
6
+ const Ajv = createRequire(new URL('../../server/package.json', import.meta.url))('ajv');
7
+ const catalog = JSON.parse(readFileSync(new URL('../../mcp-server-remote/src/tools.generated.json', import.meta.url))).tools;
8
+ const tools = buildToolList();
9
+ const setup = tools.find(t => t.name === 'complete_setup');
10
+ const validate = new Ajv({ allErrors: true }).compile(setup.inputSchema);
11
+
12
+ test('setup exposes explicit scopes and truthful mutation annotations', () => {
13
+ const read = tools.find(t => t.name === 'get_setup_status');
14
+ assert.deepEqual(read.securitySchemes, [{ type: 'oauth2', scopes: ['setup.read'] }]);
15
+ assert.deepEqual(setup.securitySchemes, [{ type: 'oauth2', scopes: ['setup.write'] }]);
16
+ assert.equal(read.annotations.readOnlyHint, true);
17
+ assert.deepEqual(routeToolCall('get_setup_status', { clientEmail: 'ignored@example.test' }), { actionId: 'get_setup_status', params: {} });
18
+ assert.equal(setup.annotations.readOnlyHint, false);
19
+ assert.equal(setup.annotations.destructiveHint, true);
20
+ assert.equal(setup.annotations.openWorldHint, true);
21
+ assert.equal(new Ajv().compile(read.inputSchema)({ clientEmail: 'other@example.test' }), false);
22
+ });
23
+
24
+ test('typed previews, proposal-only confirmation and readback preserve payloads', () => {
25
+ const cases = [
26
+ { operation: 'general_settings', answers: { homeCountry: 'CA', homeCurrency: 'CAD', businessName: 'Example' } },
27
+ { operation: 'personal_rules', answers: { personalCardLast4: ['1234'], ambiguousFallback: null } },
28
+ { operation: 'setup_decision', answers: { step: 'other_inbox', action: 'no_other_inbox' } },
29
+ { operation: 'personal_learning', answers: { stage: 'answer', questionId: 'q-test', answer: 'mixed', revision: 2 } },
30
+ { operation: 'invite_clients', answers: { recipients: [{ name: 'Example', email: 'example@example.test' }] } },
31
+ { proposalId: '0123456789abcdef0123456789abcdef', confirm: true },
32
+ { proposalId: '0123456789abcdef0123456789abcdef', status: true },
33
+ ];
34
+ for (const args of cases) {
35
+ assert.equal(validate(args), true, JSON.stringify(validate.errors));
36
+ assert.deepEqual(routeToolCall('complete_setup', args), { actionId: 'complete_setup', params: args });
37
+ }
38
+ for (const args of [
39
+ { proposalId: '0123456789abcdef0123456789abcdef', confirm: false },
40
+ { operation: 'general_settings', answers: { unknownSetting: true } },
41
+ { operation: 'personal_rules', answers: { personalCardLast4: ['12345'] } },
42
+ { operation: 'invite_clients', answers: { recipients: [{ name: 'Example', email: 'invalid' }] } },
43
+ ]) assert.equal(validate(args), false, JSON.stringify(args));
44
+ });
45
+
46
+ test('setup schemas describe fields and stay inside the unchanged catalog cap', () => {
47
+ const visit = node => {
48
+ if (!node || typeof node !== 'object') return;
49
+ for (const [name, field] of Object.entries(node.properties || {})) {
50
+ assert.ok(field.description, name);
51
+ visit(field);
52
+ }
53
+ for (const variant of node.oneOf || []) visit(variant);
54
+ if (node.items) visit(node.items);
55
+ };
56
+ visit(setup.inputSchema);
57
+ for (const name of ['get_setup_status', 'complete_setup']) {
58
+ const tool = catalog.find(t => t.name === name);
59
+ assert.ok(Object.keys(tool.outputSchema.properties).length > 5);
60
+ }
61
+ assert.ok(Buffer.byteLength(JSON.stringify({ tools })) <= 163000);
62
+ });
63
+
64
+ // OpenAI rejected every candidate selection call when one new tool had a root
65
+ // oneOf, despite local JSON Schema and Gemini validation succeeding. Nested
66
+ // answer variants remain valid; canonical execution owns mode exclusivity.
67
+ test('every advertised function has an OpenAI-compatible object root', () => {
68
+ for (const tool of tools) {
69
+ assert.equal(tool.inputSchema.type, 'object', tool.name);
70
+ for (const key of ['oneOf', 'anyOf', 'allOf', 'enum', 'const', 'not']) {
71
+ assert.equal(Object.hasOwn(tool.inputSchema, key), false, `${tool.name}.${key}`);
72
+ }
73
+ }
74
+ assert.equal(setup.inputSchema.properties.answers.oneOf.length, 5);
75
+ });