@agledger/mcp-server 1.4.1 → 1.5.0

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.
Files changed (126) hide show
  1. package/dist/errors.d.ts +6 -0
  2. package/dist/errors.d.ts.map +1 -1
  3. package/dist/errors.js +8 -0
  4. package/dist/errors.js.map +1 -1
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +0 -2
  7. package/dist/index.js.map +1 -1
  8. package/dist/server.d.ts +6 -2
  9. package/dist/server.d.ts.map +1 -1
  10. package/dist/server.js +71 -76
  11. package/dist/server.js.map +1 -1
  12. package/dist/tool-scopes.js +3 -2
  13. package/dist/tool-scopes.js.map +1 -1
  14. package/dist/tools/a2a.d.ts.map +1 -1
  15. package/dist/tools/a2a.js +22 -222
  16. package/dist/tools/a2a.js.map +1 -1
  17. package/dist/tools/agent-mandates.d.ts.map +1 -1
  18. package/dist/tools/agent-mandates.js +11 -75
  19. package/dist/tools/agent-mandates.js.map +1 -1
  20. package/dist/tools/agents-refs.d.ts.map +1 -1
  21. package/dist/tools/agents-refs.js +10 -61
  22. package/dist/tools/agents-refs.js.map +1 -1
  23. package/dist/tools/capabilities.d.ts.map +1 -1
  24. package/dist/tools/capabilities.js +3 -15
  25. package/dist/tools/capabilities.js.map +1 -1
  26. package/dist/tools/code-mode.d.ts.map +1 -1
  27. package/dist/tools/code-mode.js +4 -35
  28. package/dist/tools/code-mode.js.map +1 -1
  29. package/dist/tools/compliance.d.ts.map +1 -1
  30. package/dist/tools/compliance.js +4 -13
  31. package/dist/tools/compliance.js.map +1 -1
  32. package/dist/tools/dashboard.d.ts.map +1 -1
  33. package/dist/tools/dashboard.js +4 -13
  34. package/dist/tools/dashboard.js.map +1 -1
  35. package/dist/tools/disputes.d.ts.map +1 -1
  36. package/dist/tools/disputes.js +5 -37
  37. package/dist/tools/disputes.js.map +1 -1
  38. package/dist/tools/enterprises.d.ts.map +1 -1
  39. package/dist/tools/enterprises.js +7 -39
  40. package/dist/tools/enterprises.js.map +1 -1
  41. package/dist/tools/events.d.ts.map +1 -1
  42. package/dist/tools/events.js +2 -20
  43. package/dist/tools/events.js.map +1 -1
  44. package/dist/tools/federation-admin.d.ts.map +1 -1
  45. package/dist/tools/federation-admin.js +25 -257
  46. package/dist/tools/federation-admin.js.map +1 -1
  47. package/dist/tools/federation.d.ts.map +1 -1
  48. package/dist/tools/federation.js +21 -198
  49. package/dist/tools/federation.js.map +1 -1
  50. package/dist/tools/health.d.ts.map +1 -1
  51. package/dist/tools/health.js +2 -14
  52. package/dist/tools/health.js.map +1 -1
  53. package/dist/tools/mandates.d.ts.map +1 -1
  54. package/dist/tools/mandates.js +11 -83
  55. package/dist/tools/mandates.js.map +1 -1
  56. package/dist/tools/openclaw.d.ts.map +1 -1
  57. package/dist/tools/openclaw.js +6 -33
  58. package/dist/tools/openclaw.js.map +1 -1
  59. package/dist/tools/receipts.d.ts.map +1 -1
  60. package/dist/tools/receipts.js +5 -96
  61. package/dist/tools/receipts.js.map +1 -1
  62. package/dist/tools/reputation.d.ts.map +1 -1
  63. package/dist/tools/reputation.js +4 -13
  64. package/dist/tools/reputation.js.map +1 -1
  65. package/dist/tools/schemas.d.ts.map +1 -1
  66. package/dist/tools/schemas.js +34 -159
  67. package/dist/tools/schemas.js.map +1 -1
  68. package/dist/tools/verification-keys.d.ts.map +1 -1
  69. package/dist/tools/verification-keys.js +2 -23
  70. package/dist/tools/verification-keys.js.map +1 -1
  71. package/dist/tools/verification.d.ts.map +1 -1
  72. package/dist/tools/verification.js +3 -28
  73. package/dist/tools/verification.js.map +1 -1
  74. package/package.json +1 -1
  75. package/src/errors.ts +9 -0
  76. package/src/index.ts +1 -3
  77. package/src/server.ts +77 -71
  78. package/src/tool-scopes.ts +3 -3
  79. package/src/tools/a2a.ts +22 -235
  80. package/src/tools/agent-mandates.ts +11 -77
  81. package/src/tools/agents-refs.ts +10 -65
  82. package/src/tools/capabilities.ts +3 -16
  83. package/src/tools/compliance.ts +4 -13
  84. package/src/tools/dashboard.ts +4 -13
  85. package/src/tools/disputes.ts +5 -38
  86. package/src/tools/enterprises.ts +7 -39
  87. package/src/tools/events.ts +2 -21
  88. package/src/tools/federation-admin.ts +25 -282
  89. package/src/tools/federation.ts +21 -218
  90. package/src/tools/health.ts +2 -15
  91. package/src/tools/mandates.ts +11 -85
  92. package/src/tools/openclaw.ts +6 -52
  93. package/src/tools/receipts.ts +5 -97
  94. package/src/tools/reputation.ts +4 -13
  95. package/src/tools/schemas.ts +34 -166
  96. package/src/tools/verification-keys.ts +2 -25
  97. package/src/tools/verification.ts +3 -30
  98. package/tests/conformance.test.ts +197 -0
  99. package/tests/conformance.ts +65 -0
  100. package/tests/harness.ts +55 -0
  101. package/tests/mock-client.ts +71 -0
  102. package/tests/profiles.test.ts +120 -0
  103. package/tests/resources/contract-types.test.ts +82 -0
  104. package/tests/tools/a2a.test.ts +213 -0
  105. package/tests/tools/agent-mandates.test.ts +196 -0
  106. package/tests/tools/agents-refs.test.ts +190 -0
  107. package/tests/tools/capabilities.test.ts +80 -0
  108. package/tests/tools/compliance.test.ts +123 -0
  109. package/tests/tools/dashboard.test.ts +111 -0
  110. package/tests/tools/disputes.test.ts +123 -0
  111. package/tests/tools/enterprises.test.ts +171 -0
  112. package/tests/tools/events.test.ts +56 -0
  113. package/tests/tools/federation-admin.test.ts +468 -0
  114. package/tests/tools/federation.test.ts +522 -0
  115. package/tests/tools/health.test.ts +56 -0
  116. package/tests/tools/mandates.test.ts +143 -0
  117. package/tests/tools/openclaw.test.ts +148 -0
  118. package/tests/tools/receipts.test.ts +157 -0
  119. package/tests/tools/reputation.test.ts +108 -0
  120. package/tests/tools/schemas.test.ts +374 -0
  121. package/tests/tools/verification-keys.test.ts +56 -0
  122. package/tests/tools/verification.test.ts +64 -0
  123. package/src/tools/code-mode.ts +0 -461
  124. package/tests/code-mode-manifest.test.ts +0 -144
  125. package/tests/enterprises.test.ts +0 -96
  126. package/tests/schemas.test.ts +0 -531
@@ -0,0 +1,123 @@
1
+ import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
2
+ import { registerComplianceTools } from '../../src/tools/compliance.js';
3
+ import { createTestHarness, type TestHarness } from '../harness.js';
4
+ import { assertErrorResult, assertSuccessResult } from '../conformance.js';
5
+
6
+ describe('compliance tools', () => {
7
+ let harness: TestHarness;
8
+
9
+ beforeAll(async () => {
10
+ harness = await createTestHarness({
11
+ registerFns: [registerComplianceTools],
12
+ mockOverrides: {
13
+ compliance: {
14
+ createRecord: vi.fn().mockResolvedValue({
15
+ id: 'cr-001',
16
+ mandateId: 'm-001',
17
+ recordType: 'workplace_notification',
18
+ attestedBy: 'compliance-officer',
19
+ }),
20
+ listRecords: vi.fn().mockResolvedValue({
21
+ data: [
22
+ { id: 'cr-001', recordType: 'workplace_notification' },
23
+ { id: 'cr-002', recordType: 'affected_persons' },
24
+ ],
25
+ }),
26
+ getEuAiActReport: vi.fn().mockResolvedValue({
27
+ summary: {
28
+ highRiskCount: 3,
29
+ auditedCount: 2,
30
+ },
31
+ }),
32
+ },
33
+ },
34
+ });
35
+ });
36
+
37
+ afterAll(async () => {
38
+ await harness.cleanup();
39
+ });
40
+
41
+ it('registers exactly 3 tools', async () => {
42
+ const { tools } = await harness.client.listTools();
43
+ expect(tools.map((t: any) => t.name).sort()).toEqual([
44
+ 'create_compliance_record',
45
+ 'get_eu_ai_act_report',
46
+ 'list_compliance_records',
47
+ ]);
48
+ });
49
+
50
+ describe('create_compliance_record', () => {
51
+ it('creates a compliance record on success', async () => {
52
+ const result = await harness.client.callTool({
53
+ name: 'create_compliance_record',
54
+ arguments: {
55
+ mandateId: 'm-001',
56
+ recordType: 'workplace_notification',
57
+ attestation: { notified: true },
58
+ attestedBy: 'compliance-officer',
59
+ },
60
+ });
61
+ assertSuccessResult(result as any);
62
+ expect((harness.mockSdk.compliance as any).createRecord).toHaveBeenCalledWith('m-001', {
63
+ recordType: 'workplace_notification',
64
+ attestation: { notified: true },
65
+ attestedBy: 'compliance-officer',
66
+ });
67
+ });
68
+
69
+ it('returns error on failure', async () => {
70
+ (harness.mockSdk.compliance as any).createRecord.mockRejectedValueOnce(new Error('Mandate not found'));
71
+ const result = await harness.client.callTool({
72
+ name: 'create_compliance_record',
73
+ arguments: {
74
+ mandateId: 'm-missing',
75
+ recordType: 'workplace_notification',
76
+ attestation: {},
77
+ attestedBy: 'test',
78
+ },
79
+ });
80
+ assertErrorResult(result as any);
81
+ });
82
+ });
83
+
84
+ describe('list_compliance_records', () => {
85
+ it('lists records on success', async () => {
86
+ const result = await harness.client.callTool({
87
+ name: 'list_compliance_records',
88
+ arguments: { mandateId: 'm-001' },
89
+ });
90
+ assertSuccessResult(result as any);
91
+ expect((harness.mockSdk.compliance as any).listRecords).toHaveBeenCalledWith('m-001', { limit: undefined });
92
+ });
93
+
94
+ it('returns error on failure', async () => {
95
+ (harness.mockSdk.compliance as any).listRecords.mockRejectedValueOnce(new Error('Forbidden'));
96
+ const result = await harness.client.callTool({
97
+ name: 'list_compliance_records',
98
+ arguments: { mandateId: 'm-001' },
99
+ });
100
+ assertErrorResult(result as any);
101
+ });
102
+ });
103
+
104
+ describe('get_eu_ai_act_report', () => {
105
+ it('returns EU AI Act report on success', async () => {
106
+ const result = await harness.client.callTool({
107
+ name: 'get_eu_ai_act_report',
108
+ arguments: {},
109
+ });
110
+ assertSuccessResult(result as any);
111
+ expect((harness.mockSdk.compliance as any).getEuAiActReport).toHaveBeenCalledOnce();
112
+ });
113
+
114
+ it('returns error on failure', async () => {
115
+ (harness.mockSdk.compliance as any).getEuAiActReport.mockRejectedValueOnce(new Error('Service unavailable'));
116
+ const result = await harness.client.callTool({
117
+ name: 'get_eu_ai_act_report',
118
+ arguments: {},
119
+ });
120
+ assertErrorResult(result as any);
121
+ });
122
+ });
123
+ });
@@ -0,0 +1,111 @@
1
+ import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
2
+ import { registerDashboardTools } from '../../src/tools/dashboard.js';
3
+ import { createTestHarness, type TestHarness } from '../harness.js';
4
+ import { assertErrorResult, assertSuccessResult } from '../conformance.js';
5
+
6
+ describe('dashboard tools', () => {
7
+ let harness: TestHarness;
8
+
9
+ beforeAll(async () => {
10
+ harness = await createTestHarness({
11
+ registerFns: [registerDashboardTools],
12
+ mockOverrides: {
13
+ dashboard: {
14
+ getSummary: vi.fn().mockResolvedValue({
15
+ totalMandates: 150,
16
+ activeCount: 42,
17
+ fulfilledCount: 98,
18
+ }),
19
+ getMetrics: vi.fn().mockResolvedValue({
20
+ series: [
21
+ { date: '2026-04-01', mandates: 10 },
22
+ { date: '2026-04-02', mandates: 15 },
23
+ ],
24
+ }),
25
+ getAlerts: vi.fn().mockResolvedValue({
26
+ data: [
27
+ { type: 'overdue', mandateId: 'm-001' },
28
+ ],
29
+ }),
30
+ },
31
+ },
32
+ });
33
+ });
34
+
35
+ afterAll(async () => {
36
+ await harness.cleanup();
37
+ });
38
+
39
+ it('registers exactly 3 tools', async () => {
40
+ const { tools } = await harness.client.listTools();
41
+ expect(tools.map((t: any) => t.name).sort()).toEqual([
42
+ 'get_dashboard_alerts',
43
+ 'get_dashboard_metrics',
44
+ 'get_dashboard_summary',
45
+ ]);
46
+ });
47
+
48
+ describe('get_dashboard_summary', () => {
49
+ it('returns summary on success', async () => {
50
+ const result = await harness.client.callTool({
51
+ name: 'get_dashboard_summary',
52
+ arguments: {},
53
+ });
54
+ assertSuccessResult(result as any);
55
+ expect((harness.mockSdk.dashboard as any).getSummary).toHaveBeenCalledOnce();
56
+ });
57
+
58
+ it('returns error on failure', async () => {
59
+ (harness.mockSdk.dashboard as any).getSummary.mockRejectedValueOnce(new Error('Unauthorized'));
60
+ const result = await harness.client.callTool({
61
+ name: 'get_dashboard_summary',
62
+ arguments: {},
63
+ });
64
+ assertErrorResult(result as any);
65
+ });
66
+ });
67
+
68
+ describe('get_dashboard_metrics', () => {
69
+ it('returns metrics on success', async () => {
70
+ const result = await harness.client.callTool({
71
+ name: 'get_dashboard_metrics',
72
+ arguments: { from: '2026-04-01', to: '2026-04-07', granularity: 'daily' },
73
+ });
74
+ assertSuccessResult(result as any);
75
+ expect((harness.mockSdk.dashboard as any).getMetrics).toHaveBeenCalledWith({
76
+ from: '2026-04-01',
77
+ to: '2026-04-07',
78
+ granularity: 'daily',
79
+ });
80
+ });
81
+
82
+ it('returns error on failure', async () => {
83
+ (harness.mockSdk.dashboard as any).getMetrics.mockRejectedValueOnce(new Error('Bad date range'));
84
+ const result = await harness.client.callTool({
85
+ name: 'get_dashboard_metrics',
86
+ arguments: {},
87
+ });
88
+ assertErrorResult(result as any);
89
+ });
90
+ });
91
+
92
+ describe('get_dashboard_alerts', () => {
93
+ it('returns alerts on success', async () => {
94
+ const result = await harness.client.callTool({
95
+ name: 'get_dashboard_alerts',
96
+ arguments: {},
97
+ });
98
+ assertSuccessResult(result as any);
99
+ expect((harness.mockSdk.dashboard as any).getAlerts).toHaveBeenCalled();
100
+ });
101
+
102
+ it('returns error on failure', async () => {
103
+ (harness.mockSdk.dashboard as any).getAlerts.mockRejectedValueOnce(new Error('Internal error'));
104
+ const result = await harness.client.callTool({
105
+ name: 'get_dashboard_alerts',
106
+ arguments: {},
107
+ });
108
+ assertErrorResult(result as any);
109
+ });
110
+ });
111
+ });
@@ -0,0 +1,123 @@
1
+ import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
2
+ import { registerDisputeTools } from '../../src/tools/disputes.js';
3
+ import { createTestHarness, type TestHarness } from '../harness.js';
4
+ import { assertErrorResult, assertSuccessResult } from '../conformance.js';
5
+
6
+ const MOCK_DISPUTE = {
7
+ id: 'd-1',
8
+ mandateId: 'm-1',
9
+ receiptId: 'r-1',
10
+ status: 'OPENED',
11
+ reason: 'pricing_dispute',
12
+ grounds: 'pricing_dispute',
13
+ evidence: null,
14
+ currentTier: 1,
15
+ tierHistory: null,
16
+ resolution: null,
17
+ amount: null,
18
+ createdAt: '2026-04-13T00:00:00Z',
19
+ updatedAt: null,
20
+ resolvedAt: null,
21
+ };
22
+
23
+ describe('dispute tools', () => {
24
+ let harness: TestHarness;
25
+
26
+ const EXPECTED_TOOLS = [
27
+ 'create_dispute', 'escalate_dispute', 'get_dispute', 'submit_dispute_evidence',
28
+ ];
29
+
30
+ beforeAll(async () => {
31
+ harness = await createTestHarness({
32
+ registerFns: [registerDisputeTools],
33
+ mockOverrides: {
34
+ disputes: {
35
+ create: vi.fn().mockResolvedValue(MOCK_DISPUTE),
36
+ get: vi.fn().mockResolvedValue({ dispute: MOCK_DISPUTE, evidence: [] }),
37
+ escalate: vi.fn().mockResolvedValue({ ...MOCK_DISPUTE, currentTier: 2, status: 'TIER_2_REVIEW' }),
38
+ submitEvidence: vi.fn().mockResolvedValue({ id: 'ev-1', evidenceType: 'document' }),
39
+ },
40
+ },
41
+ });
42
+ });
43
+
44
+ afterAll(async () => { await harness.cleanup(); });
45
+
46
+ it('registers exactly 4 tools', async () => {
47
+ const { tools } = await harness.client.listTools();
48
+ expect(tools.map((t: any) => t.name).sort()).toEqual(EXPECTED_TOOLS);
49
+ });
50
+
51
+ describe('create_dispute', () => {
52
+ it('opens a dispute', async () => {
53
+ const result = await harness.client.callTool({
54
+ name: 'create_dispute',
55
+ arguments: { mandateId: 'm-1', grounds: 'pricing_dispute' },
56
+ });
57
+ assertSuccessResult(result as any);
58
+ });
59
+
60
+ it('returns error on failure', async () => {
61
+ (harness.mockSdk.disputes as any).create.mockRejectedValueOnce(new Error('No receipt'));
62
+ const result = await harness.client.callTool({
63
+ name: 'create_dispute',
64
+ arguments: { mandateId: 'bad', grounds: 'pricing_dispute' },
65
+ });
66
+ assertErrorResult(result as any);
67
+ });
68
+ });
69
+
70
+ describe('get_dispute', () => {
71
+ it('returns dispute details', async () => {
72
+ const result = await harness.client.callTool({ name: 'get_dispute', arguments: { mandateId: 'm-1' } });
73
+ assertSuccessResult(result as any);
74
+ expect((harness.mockSdk.disputes as any).get).toHaveBeenCalledWith('m-1');
75
+ });
76
+
77
+ it('returns error on failure', async () => {
78
+ (harness.mockSdk.disputes as any).get.mockRejectedValueOnce(new Error('Not found'));
79
+ const result = await harness.client.callTool({ name: 'get_dispute', arguments: { mandateId: 'bad' } });
80
+ assertErrorResult(result as any);
81
+ });
82
+ });
83
+
84
+ describe('escalate_dispute', () => {
85
+ it('escalates to next tier', async () => {
86
+ const result = await harness.client.callTool({ name: 'escalate_dispute', arguments: { mandateId: 'm-1' } });
87
+ assertSuccessResult(result as any);
88
+ });
89
+
90
+ it('returns error on failure', async () => {
91
+ (harness.mockSdk.disputes as any).escalate.mockRejectedValueOnce(new Error('Already at max tier'));
92
+ const result = await harness.client.callTool({ name: 'escalate_dispute', arguments: { mandateId: 'bad' } });
93
+ assertErrorResult(result as any);
94
+ });
95
+ });
96
+
97
+ describe('submit_dispute_evidence', () => {
98
+ it('submits evidence', async () => {
99
+ const result = await harness.client.callTool({
100
+ name: 'submit_dispute_evidence',
101
+ arguments: {
102
+ mandateId: 'm-1',
103
+ evidenceType: 'document',
104
+ payload: { url: 'https://example.com/doc.pdf' },
105
+ },
106
+ });
107
+ assertSuccessResult(result as any);
108
+ });
109
+
110
+ it('returns error on failure', async () => {
111
+ (harness.mockSdk.disputes as any).submitEvidence.mockRejectedValueOnce(new Error('Dispute closed'));
112
+ const result = await harness.client.callTool({
113
+ name: 'submit_dispute_evidence',
114
+ arguments: {
115
+ mandateId: 'bad',
116
+ evidenceType: 'screenshot',
117
+ payload: {},
118
+ },
119
+ });
120
+ assertErrorResult(result as any);
121
+ });
122
+ });
123
+ });
@@ -0,0 +1,171 @@
1
+ import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
2
+ import { registerEnterpriseTools } from '../../src/tools/enterprises.js';
3
+ import { createTestHarness, type TestHarness } from '../harness.js';
4
+ import { assertErrorResult, assertSuccessResult } from '../conformance.js';
5
+
6
+ const MOCK_ENTERPRISE = {
7
+ id: 'ent-1',
8
+ name: 'Acme Corp',
9
+ slug: 'acme-corp',
10
+ trustLevel: 'active',
11
+ createdAt: '2026-04-13T00:00:00Z',
12
+ };
13
+
14
+ const MOCK_AGENT = {
15
+ id: 'agent-1',
16
+ displayName: 'Data Processor',
17
+ slug: 'data-processor',
18
+ trustLevel: 'sandbox',
19
+ createdAt: '2026-04-13T00:00:00Z',
20
+ };
21
+
22
+ describe('enterprise tools', () => {
23
+ let harness: TestHarness;
24
+
25
+ const EXPECTED_TOOLS = [
26
+ 'approve_enterprise_agent', 'create_agent', 'create_enterprise',
27
+ 'list_enterprise_agents', 'revoke_enterprise_agent', 'set_enterprise_config',
28
+ ];
29
+
30
+ beforeAll(async () => {
31
+ harness = await createTestHarness({
32
+ registerFns: [registerEnterpriseTools],
33
+ mockOverrides: {
34
+ enterprises: {
35
+ approveAgent: vi.fn().mockResolvedValue({ agentId: 'agent-1', enterpriseId: 'e-1', status: 'approved' }),
36
+ revokeAgent: vi.fn().mockResolvedValue(undefined),
37
+ listAgents: vi.fn().mockResolvedValue({ data: [{ agentId: 'agent-1', status: 'approved' }] }),
38
+ },
39
+ admin: {
40
+ createEnterprise: vi.fn().mockResolvedValue(MOCK_ENTERPRISE),
41
+ createAgent: vi.fn().mockResolvedValue(MOCK_AGENT),
42
+ setEnterpriseConfig: vi.fn().mockResolvedValue({ enterpriseId: 'ent-1', config: {} }),
43
+ },
44
+ },
45
+ });
46
+ });
47
+
48
+ afterAll(async () => { await harness.cleanup(); });
49
+
50
+ it('registers exactly 6 tools', async () => {
51
+ const { tools } = await harness.client.listTools();
52
+ expect(tools.map((t: any) => t.name).sort()).toEqual(EXPECTED_TOOLS);
53
+ });
54
+
55
+ describe('approve_enterprise_agent', () => {
56
+ it('approves an agent', async () => {
57
+ const result = await harness.client.callTool({
58
+ name: 'approve_enterprise_agent',
59
+ arguments: { enterpriseId: 'ent-1', agentId: 'agent-1' },
60
+ });
61
+ assertSuccessResult(result as any);
62
+ });
63
+
64
+ it('returns error on failure', async () => {
65
+ (harness.mockSdk.enterprises as any).approveAgent.mockRejectedValueOnce(new Error('Not found'));
66
+ const result = await harness.client.callTool({
67
+ name: 'approve_enterprise_agent',
68
+ arguments: { enterpriseId: 'bad', agentId: 'bad' },
69
+ });
70
+ assertErrorResult(result as any);
71
+ });
72
+ });
73
+
74
+ describe('revoke_enterprise_agent', () => {
75
+ it('revokes an agent', async () => {
76
+ const result = await harness.client.callTool({
77
+ name: 'revoke_enterprise_agent',
78
+ arguments: { enterpriseId: 'ent-1', agentId: 'agent-1', reason: 'No longer needed' },
79
+ });
80
+ assertSuccessResult(result as any);
81
+ });
82
+
83
+ it('returns error on failure', async () => {
84
+ (harness.mockSdk.enterprises as any).revokeAgent.mockRejectedValueOnce(new Error('Not found'));
85
+ const result = await harness.client.callTool({
86
+ name: 'revoke_enterprise_agent',
87
+ arguments: { enterpriseId: 'bad', agentId: 'bad' },
88
+ });
89
+ assertErrorResult(result as any);
90
+ });
91
+ });
92
+
93
+ describe('list_enterprise_agents', () => {
94
+ it('returns agent list', async () => {
95
+ const result = await harness.client.callTool({
96
+ name: 'list_enterprise_agents',
97
+ arguments: { enterpriseId: 'ent-1' },
98
+ });
99
+ assertSuccessResult(result as any);
100
+ });
101
+
102
+ it('returns error on failure', async () => {
103
+ (harness.mockSdk.enterprises as any).listAgents.mockRejectedValueOnce(new Error('Unauthorized'));
104
+ const result = await harness.client.callTool({
105
+ name: 'list_enterprise_agents',
106
+ arguments: { enterpriseId: 'bad' },
107
+ });
108
+ assertErrorResult(result as any);
109
+ });
110
+ });
111
+
112
+ describe('create_enterprise', () => {
113
+ it('creates an enterprise', async () => {
114
+ const result = await harness.client.callTool({
115
+ name: 'create_enterprise',
116
+ arguments: { name: 'Acme Corp' },
117
+ });
118
+ assertSuccessResult(result as any);
119
+ });
120
+
121
+ it('returns error on failure', async () => {
122
+ (harness.mockSdk.admin as any).createEnterprise.mockRejectedValueOnce(new Error('Conflict'));
123
+ const result = await harness.client.callTool({
124
+ name: 'create_enterprise',
125
+ arguments: { name: 'Duplicate' },
126
+ });
127
+ assertErrorResult(result as any);
128
+ });
129
+ });
130
+
131
+ describe('create_agent', () => {
132
+ it('creates an agent', async () => {
133
+ const result = await harness.client.callTool({
134
+ name: 'create_agent',
135
+ arguments: { name: 'Data Processor', enterpriseId: 'ent-1' },
136
+ });
137
+ assertSuccessResult(result as any);
138
+ });
139
+
140
+ it('returns error on failure', async () => {
141
+ (harness.mockSdk.admin as any).createAgent.mockRejectedValueOnce(new Error('Bad request'));
142
+ const result = await harness.client.callTool({
143
+ name: 'create_agent',
144
+ arguments: { name: '' },
145
+ });
146
+ assertErrorResult(result as any);
147
+ });
148
+ });
149
+
150
+ describe('set_enterprise_config', () => {
151
+ it('replaces enterprise config', async () => {
152
+ const result = await harness.client.callTool({
153
+ name: 'set_enterprise_config',
154
+ arguments: {
155
+ enterpriseId: 'ent-1',
156
+ config: { agentApprovalRequired: true, defaultScopes: ['mandates:read'] },
157
+ },
158
+ });
159
+ assertSuccessResult(result as any);
160
+ });
161
+
162
+ it('returns error on failure', async () => {
163
+ (harness.mockSdk.admin as any).setEnterpriseConfig.mockRejectedValueOnce(new Error('Not found'));
164
+ const result = await harness.client.callTool({
165
+ name: 'set_enterprise_config',
166
+ arguments: { enterpriseId: 'bad', config: {} },
167
+ });
168
+ assertErrorResult(result as any);
169
+ });
170
+ });
171
+ });
@@ -0,0 +1,56 @@
1
+ import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
2
+ import { registerEventTools } from '../../src/tools/events.js';
3
+ import { createTestHarness, type TestHarness } from '../harness.js';
4
+ import { assertErrorResult, assertSuccessResult } from '../conformance.js';
5
+
6
+ describe('event tools', () => {
7
+ let harness: TestHarness;
8
+
9
+ beforeAll(async () => {
10
+ harness = await createTestHarness({
11
+ registerFns: [registerEventTools],
12
+ mockOverrides: {
13
+ events: {
14
+ getAuditChain: vi.fn().mockResolvedValue({
15
+ mandateId: 'm-001',
16
+ chainStart: '2026-04-01T00:00:00Z',
17
+ entries: [
18
+ { index: 0, hash: 'abc123', previousHash: null, event: 'CREATED', actor: 'agent-1', timestamp: '2026-04-01T00:00:00Z' },
19
+ { index: 1, hash: 'def456', previousHash: 'abc123', event: 'ACTIVATED', actor: 'agent-1', timestamp: '2026-04-01T00:01:00Z' },
20
+ ],
21
+ isValid: true,
22
+ }),
23
+ },
24
+ },
25
+ });
26
+ });
27
+
28
+ afterAll(async () => {
29
+ await harness.cleanup();
30
+ });
31
+
32
+ it('registers exactly 1 tool: get_audit_trail', async () => {
33
+ const { tools } = await harness.client.listTools();
34
+ expect(tools.map((t: any) => t.name)).toEqual(['get_audit_trail']);
35
+ });
36
+
37
+ describe('get_audit_trail', () => {
38
+ it('returns audit trail on success', async () => {
39
+ const result = await harness.client.callTool({
40
+ name: 'get_audit_trail',
41
+ arguments: { mandateId: 'm-001' },
42
+ });
43
+ assertSuccessResult(result as any);
44
+ expect((harness.mockSdk.events as any).getAuditChain).toHaveBeenCalledWith('m-001');
45
+ });
46
+
47
+ it('returns error on failure', async () => {
48
+ (harness.mockSdk.events as any).getAuditChain.mockRejectedValueOnce(new Error('Mandate not found'));
49
+ const result = await harness.client.callTool({
50
+ name: 'get_audit_trail',
51
+ arguments: { mandateId: 'm-missing' },
52
+ });
53
+ assertErrorResult(result as any);
54
+ });
55
+ });
56
+ });