@agledger/mcp-server 1.4.3 → 2.0.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 (133) hide show
  1. package/dist/api-client.d.ts +16 -0
  2. package/dist/api-client.d.ts.map +1 -0
  3. package/dist/api-client.js +52 -0
  4. package/dist/api-client.js.map +1 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +17 -60
  7. package/dist/index.js.map +1 -1
  8. package/dist/server.d.ts +2 -13
  9. package/dist/server.d.ts.map +1 -1
  10. package/dist/server.js +113 -111
  11. package/dist/server.js.map +1 -1
  12. package/dist/tool-scopes.d.ts.map +1 -1
  13. package/dist/tool-scopes.js +0 -3
  14. package/dist/tool-scopes.js.map +1 -1
  15. package/dist/tools/a2a.d.ts.map +1 -1
  16. package/dist/tools/a2a.js +20 -220
  17. package/dist/tools/a2a.js.map +1 -1
  18. package/dist/tools/agent-mandates.d.ts.map +1 -1
  19. package/dist/tools/agent-mandates.js +10 -74
  20. package/dist/tools/agent-mandates.js.map +1 -1
  21. package/dist/tools/agents-refs.d.ts.map +1 -1
  22. package/dist/tools/agents-refs.js +9 -61
  23. package/dist/tools/agents-refs.js.map +1 -1
  24. package/dist/tools/capabilities.d.ts.map +1 -1
  25. package/dist/tools/capabilities.js +2 -14
  26. package/dist/tools/capabilities.js.map +1 -1
  27. package/dist/tools/code-mode.d.ts.map +1 -1
  28. package/dist/tools/code-mode.js +4 -35
  29. package/dist/tools/code-mode.js.map +1 -1
  30. package/dist/tools/compliance.d.ts.map +1 -1
  31. package/dist/tools/compliance.js +3 -37
  32. package/dist/tools/compliance.js.map +1 -1
  33. package/dist/tools/dashboard.d.ts.map +1 -1
  34. package/dist/tools/dashboard.js +3 -37
  35. package/dist/tools/dashboard.js.map +1 -1
  36. package/dist/tools/disputes.d.ts.map +1 -1
  37. package/dist/tools/disputes.js +4 -41
  38. package/dist/tools/disputes.js.map +1 -1
  39. package/dist/tools/enterprises.d.ts.map +1 -1
  40. package/dist/tools/enterprises.js +6 -62
  41. package/dist/tools/enterprises.js.map +1 -1
  42. package/dist/tools/events.d.ts.map +1 -1
  43. package/dist/tools/events.js +1 -19
  44. package/dist/tools/events.js.map +1 -1
  45. package/dist/tools/federation-admin.d.ts.map +1 -1
  46. package/dist/tools/federation-admin.js +24 -256
  47. package/dist/tools/federation-admin.js.map +1 -1
  48. package/dist/tools/federation.d.ts.map +1 -1
  49. package/dist/tools/federation.js +20 -197
  50. package/dist/tools/federation.js.map +1 -1
  51. package/dist/tools/health.d.ts.map +1 -1
  52. package/dist/tools/health.js +1 -13
  53. package/dist/tools/health.js.map +1 -1
  54. package/dist/tools/mandates.d.ts.map +1 -1
  55. package/dist/tools/mandates.js +10 -93
  56. package/dist/tools/mandates.js.map +1 -1
  57. package/dist/tools/openclaw.d.ts.map +1 -1
  58. package/dist/tools/openclaw.js +5 -32
  59. package/dist/tools/openclaw.js.map +1 -1
  60. package/dist/tools/receipts.d.ts.map +1 -1
  61. package/dist/tools/receipts.js +4 -94
  62. package/dist/tools/receipts.js.map +1 -1
  63. package/dist/tools/reputation.d.ts.map +1 -1
  64. package/dist/tools/reputation.js +3 -33
  65. package/dist/tools/reputation.js.map +1 -1
  66. package/dist/tools/schemas.d.ts.map +1 -1
  67. package/dist/tools/schemas.js +16 -186
  68. package/dist/tools/schemas.js.map +1 -1
  69. package/dist/tools/verification-keys.d.ts.map +1 -1
  70. package/dist/tools/verification-keys.js +1 -22
  71. package/dist/tools/verification-keys.js.map +1 -1
  72. package/dist/tools/verification.d.ts.map +1 -1
  73. package/dist/tools/verification.js +2 -27
  74. package/dist/tools/verification.js.map +1 -1
  75. package/package.json +2 -3
  76. package/src/api-client.ts +72 -0
  77. package/src/index.ts +27 -62
  78. package/src/server.ts +136 -122
  79. package/tests/api-client.test.ts +147 -0
  80. package/tests/harness.ts +8 -35
  81. package/tests/integration.test.ts +373 -0
  82. package/tests/server.test.ts +286 -0
  83. package/src/enums.ts +0 -47
  84. package/src/errors.ts +0 -44
  85. package/src/resources/contract-types.ts +0 -130
  86. package/src/tool-scopes.ts +0 -184
  87. package/src/tools/a2a.ts +0 -643
  88. package/src/tools/agent-mandates.ts +0 -325
  89. package/src/tools/agents-refs.ts +0 -288
  90. package/src/tools/capabilities.ts +0 -76
  91. package/src/tools/code-mode.ts +0 -461
  92. package/src/tools/compliance.ts +0 -104
  93. package/src/tools/dashboard.ts +0 -98
  94. package/src/tools/disputes.ts +0 -159
  95. package/src/tools/enterprises.ts +0 -259
  96. package/src/tools/events.ts +0 -52
  97. package/src/tools/federation-admin.ts +0 -922
  98. package/src/tools/federation.ts +0 -784
  99. package/src/tools/health.ts +0 -43
  100. package/src/tools/mandates.ts +0 -349
  101. package/src/tools/openclaw.ts +0 -168
  102. package/src/tools/receipts.ts +0 -225
  103. package/src/tools/reputation.ts +0 -100
  104. package/src/tools/schemas.ts +0 -713
  105. package/src/tools/verification-keys.ts +0 -56
  106. package/src/tools/verification.ts +0 -86
  107. package/tests/conformance.test.ts +0 -219
  108. package/tests/conformance.ts +0 -75
  109. package/tests/drift/code-mode-manifest.test.ts +0 -144
  110. package/tests/integration/output-schema-validation.test.ts +0 -167
  111. package/tests/mock-client.ts +0 -71
  112. package/tests/profiles.test.ts +0 -135
  113. package/tests/resources/contract-types.test.ts +0 -82
  114. package/tests/tools/a2a.test.ts +0 -241
  115. package/tests/tools/agent-mandates.test.ts +0 -206
  116. package/tests/tools/agents-refs.test.ts +0 -199
  117. package/tests/tools/capabilities.test.ts +0 -86
  118. package/tests/tools/code-mode.test.ts +0 -168
  119. package/tests/tools/compliance.test.ts +0 -131
  120. package/tests/tools/dashboard.test.ts +0 -120
  121. package/tests/tools/disputes.test.ts +0 -131
  122. package/tests/tools/enterprises.test.ts +0 -181
  123. package/tests/tools/events.test.ts +0 -61
  124. package/tests/tools/federation-admin.test.ts +0 -509
  125. package/tests/tools/federation.test.ts +0 -556
  126. package/tests/tools/health.test.ts +0 -67
  127. package/tests/tools/mandates.test.ts +0 -155
  128. package/tests/tools/openclaw.test.ts +0 -160
  129. package/tests/tools/receipts.test.ts +0 -170
  130. package/tests/tools/reputation.test.ts +0 -117
  131. package/tests/tools/schemas.test.ts +0 -397
  132. package/tests/tools/verification-keys.test.ts +0 -62
  133. package/tests/tools/verification.test.ts +0 -74
@@ -1,155 +0,0 @@
1
- import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
2
- import { registerMandateTools } from '../../src/tools/mandates.js';
3
- import { createTestHarness, type TestHarness } from '../harness.js';
4
- import { assertErrorResult, assertSuccessResult } from '../conformance.js';
5
-
6
- const MOCK_MANDATE = {
7
- id: 'm-1',
8
- enterpriseId: 'e-1',
9
- agentId: 'agent-1',
10
- contractType: 'ACH-PROC-v1',
11
- contractVersion: '1.0.0',
12
- platform: 'test-platform',
13
- status: 'CREATED',
14
- criteria: { item: 'widget', quantity: 10 },
15
- tolerance: null,
16
- deadline: '2026-05-01T00:00:00Z',
17
- version: 1,
18
- createdAt: '2026-04-13T00:00:00Z',
19
- updatedAt: '2026-04-13T00:00:00Z',
20
- };
21
-
22
- describe('mandate tools', () => {
23
- let harness: TestHarness;
24
-
25
- const EXPECTED_TOOLS = [
26
- 'activate_mandate', 'cancel_mandate', 'delegate_mandate',
27
- 'get_mandate', 'get_mandate_graph', 'get_mandate_summary',
28
- 'request_revision', 'search_mandates', 'update_mandate',
29
- ];
30
-
31
- beforeAll(async () => {
32
- harness = await createTestHarness({
33
- registerFns: [registerMandateTools],
34
- mockOverrides: {
35
- mandates: {
36
- get: vi.fn().mockResolvedValue(MOCK_MANDATE),
37
- search: vi.fn().mockResolvedValue({ data: [MOCK_MANDATE], total: 1, limit: 20, offset: 0 }),
38
- transition: vi.fn().mockResolvedValue({ ...MOCK_MANDATE, status: 'ACTIVE' }),
39
- cancel: vi.fn().mockResolvedValue({ ...MOCK_MANDATE, status: 'CANCELLED' }),
40
- update: vi.fn().mockResolvedValue(MOCK_MANDATE),
41
- requestRevision: vi.fn().mockResolvedValue({ ...MOCK_MANDATE, status: 'REVISION_REQUESTED' }),
42
- delegate: vi.fn().mockResolvedValue({ ...MOCK_MANDATE, id: 'm-child', parentMandateId: 'm-1' }),
43
- getGraph: vi.fn().mockResolvedValue({ nodes: [{ id: 'm-1' }], edges: [] }),
44
- getSummary: vi.fn().mockResolvedValue({ CREATED: 5, ACTIVE: 3, FULFILLED: 10 }),
45
- },
46
- },
47
- });
48
- });
49
-
50
- afterAll(async () => { await harness.cleanup(); });
51
-
52
- it('registers exactly 9 tools', async () => {
53
- const { tools } = await harness.client.listTools();
54
- expect(tools.map((t: any) => t.name).sort()).toEqual(EXPECTED_TOOLS);
55
- });
56
-
57
- describe('get_mandate', () => {
58
- it('returns mandate on success', async () => {
59
- const result = await harness.client.callTool({ name: 'get_mandate', arguments: { mandateId: 'm-1' } });
60
- assertSuccessResult(result as any);
61
- expect((result as any).content[0].text).toContain('status=CREATED');
62
- expect((result as any).content[0].text).toContain('ACH-PROC-v1');
63
- });
64
-
65
- it('returns error on failure', async () => {
66
- (harness.mockSdk.mandates as any).get.mockRejectedValueOnce(new Error('Not found'));
67
- const result = await harness.client.callTool({ name: 'get_mandate', arguments: { mandateId: 'bad' } });
68
- assertErrorResult(result as any);
69
- });
70
- });
71
-
72
- describe('search_mandates', () => {
73
- it('returns search results', async () => {
74
- const result = await harness.client.callTool({
75
- name: 'search_mandates',
76
- arguments: { enterpriseId: 'e-1', status: 'CREATED' },
77
- });
78
- assertSuccessResult(result as any);
79
- expect((result as any).content[0].text).toContain('Found 1 mandates');
80
- });
81
- });
82
-
83
- describe('activate_mandate', () => {
84
- it('activates and returns updated mandate', async () => {
85
- const result = await harness.client.callTool({ name: 'activate_mandate', arguments: { mandateId: 'm-1' } });
86
- assertSuccessResult(result as any);
87
- expect((result as any).content[0].text).toContain('activated');
88
- expect((harness.mockSdk.mandates as any).transition).toHaveBeenCalledWith('m-1', 'activate');
89
- });
90
- });
91
-
92
- describe('cancel_mandate', () => {
93
- it('cancels mandate with reason', async () => {
94
- const result = await harness.client.callTool({
95
- name: 'cancel_mandate',
96
- arguments: { mandateId: 'm-1', reason: 'no longer needed' },
97
- });
98
- assertSuccessResult(result as any);
99
- expect((result as any).content[0].text).toContain('cancelled');
100
- });
101
- });
102
-
103
- describe('update_mandate', () => {
104
- it('updates mandate fields', async () => {
105
- const result = await harness.client.callTool({
106
- name: 'update_mandate',
107
- arguments: { mandateId: 'm-1', updates: { deadline: '2026-06-01T00:00:00Z' } },
108
- });
109
- assertSuccessResult(result as any);
110
- expect((result as any).content[0].text).toContain('updated');
111
- });
112
- });
113
-
114
- describe('request_revision', () => {
115
- it('requests revision with reason', async () => {
116
- const result = await harness.client.callTool({
117
- name: 'request_revision',
118
- arguments: { mandateId: 'm-1', reason: 'Incomplete evidence' },
119
- });
120
- assertSuccessResult(result as any);
121
- expect((result as any).content[0].text).toContain('REVISION_REQUESTED');
122
- });
123
- });
124
-
125
- describe('delegate_mandate', () => {
126
- it('delegates to another agent (multi-step: get parent + delegate)', async () => {
127
- const result = await harness.client.callTool({
128
- name: 'delegate_mandate',
129
- arguments: { mandateId: 'm-1', agentId: 'agent-2' },
130
- });
131
- assertSuccessResult(result as any);
132
- expect((result as any).content[0].text).toContain('delegated');
133
- expect((result as any).content[0].text).toContain('agent-2');
134
- expect((harness.mockSdk.mandates as any).get).toHaveBeenCalledWith('m-1');
135
- expect((harness.mockSdk.mandates as any).delegate).toHaveBeenCalled();
136
- });
137
- });
138
-
139
- describe('get_mandate_graph', () => {
140
- it('returns delegation graph', async () => {
141
- const result = await harness.client.callTool({ name: 'get_mandate_graph', arguments: { mandateId: 'm-1' } });
142
- assertSuccessResult(result as any);
143
- expect((result as any).content[0].text).toContain('1 node(s)');
144
- expect((result as any).content[0].text).toContain('0 edge(s)');
145
- });
146
- });
147
-
148
- describe('get_mandate_summary', () => {
149
- it('returns mandate counts by status', async () => {
150
- const result = await harness.client.callTool({ name: 'get_mandate_summary', arguments: {} });
151
- assertSuccessResult(result as any);
152
- expect((result as any).content[0].text).toContain('CREATED');
153
- });
154
- });
155
- });
@@ -1,160 +0,0 @@
1
- import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
2
- import { registerOpenClawTools } from '../../src/tools/openclaw.js';
3
- import { createTestHarness, type TestHarness } from '../harness.js';
4
- import { assertErrorResult, assertSuccessResult } from '../conformance.js';
5
-
6
- const MOCK_NOTARIZE_RESULT = {
7
- id: 'm-1',
8
- payloadHash: 'abc123def456',
9
- status: 'CREATED',
10
- contractType: 'ACH-DLVR-v1',
11
- };
12
-
13
- const MOCK_MANDATE = {
14
- id: 'm-1',
15
- status: 'ACTIVE',
16
- contractType: 'ACH-DLVR-v1',
17
- };
18
-
19
- const MOCK_RECEIPT = {
20
- id: 'r-1',
21
- payloadHash: 'receipt-hash-789',
22
- };
23
-
24
- describe('openclaw tools', () => {
25
- let harness: TestHarness;
26
-
27
- const EXPECTED_TOOLS = [
28
- 'agledger_accept', 'agledger_notarize', 'agledger_receipt',
29
- 'agledger_status', 'agledger_verdict',
30
- ];
31
-
32
- beforeAll(async () => {
33
- harness = await createTestHarness({
34
- registerFns: [registerOpenClawTools],
35
- mockOverrides: {
36
- notarize: {
37
- createMandate: vi.fn().mockResolvedValue(MOCK_NOTARIZE_RESULT),
38
- acceptMandate: vi.fn().mockResolvedValue(MOCK_MANDATE),
39
- submitReceipt: vi.fn().mockResolvedValue(MOCK_RECEIPT),
40
- renderVerdict: vi.fn().mockResolvedValue({ ...MOCK_MANDATE, status: 'FULFILLED' }),
41
- getMandate: vi.fn().mockResolvedValue(MOCK_MANDATE),
42
- },
43
- },
44
- });
45
- });
46
-
47
- afterAll(async () => { await harness.cleanup(); });
48
-
49
- it('registers exactly 5 tools', async () => {
50
- const { tools } = await harness.client.listTools();
51
- expect(tools.map((t: any) => t.name).sort()).toEqual(EXPECTED_TOOLS);
52
- });
53
-
54
- describe('agledger_notarize', () => {
55
- it('creates a notarized agreement', async () => {
56
- const result = await harness.client.callTool({
57
- name: 'agledger_notarize',
58
- arguments: {
59
- contractType: 'ACH-DLVR-v1',
60
- payload: { report: 'quarterly-summary' },
61
- },
62
- });
63
- assertSuccessResult(result as any);
64
- expect((result as any).content[0].text).toContain('m-1');
65
- expect((result as any).content[0].text).toContain('notarized');
66
- expect((result as any).content[0].text).toContain('abc123def456');
67
- });
68
-
69
- it('returns error on failure', async () => {
70
- (harness.mockSdk.notarize as any).createMandate.mockRejectedValueOnce(new Error('Bad contract type'));
71
- const result = await harness.client.callTool({
72
- name: 'agledger_notarize',
73
- arguments: { contractType: 'INVALID', payload: {} },
74
- });
75
- assertErrorResult(result as any);
76
- });
77
- });
78
-
79
- describe('agledger_accept', () => {
80
- it('accepts an agreement', async () => {
81
- const result = await harness.client.callTool({ name: 'agledger_accept', arguments: { mandateId: 'm-1' } });
82
- assertSuccessResult(result as any);
83
- expect((result as any).content[0].text).toContain('accepted');
84
- expect((result as any).content[0].text).toContain('m-1');
85
- });
86
-
87
- it('returns error on failure', async () => {
88
- (harness.mockSdk.notarize as any).acceptMandate.mockRejectedValueOnce(new Error('Not found'));
89
- const result = await harness.client.callTool({ name: 'agledger_accept', arguments: { mandateId: 'bad' } });
90
- assertErrorResult(result as any);
91
- });
92
- });
93
-
94
- describe('agledger_receipt', () => {
95
- it('submits a receipt', async () => {
96
- const result = await harness.client.callTool({
97
- name: 'agledger_receipt',
98
- arguments: { mandateId: 'm-1', payload: { delivered: true } },
99
- });
100
- assertSuccessResult(result as any);
101
- expect((result as any).content[0].text).toContain('r-1');
102
- expect((result as any).content[0].text).toContain('receipt-hash-789');
103
- });
104
-
105
- it('returns error on failure', async () => {
106
- (harness.mockSdk.notarize as any).submitReceipt.mockRejectedValueOnce(new Error('Invalid state'));
107
- const result = await harness.client.callTool({
108
- name: 'agledger_receipt',
109
- arguments: { mandateId: 'bad', payload: {} },
110
- });
111
- assertErrorResult(result as any);
112
- });
113
- });
114
-
115
- describe('agledger_verdict', () => {
116
- it('renders PASS verdict', async () => {
117
- const result = await harness.client.callTool({
118
- name: 'agledger_verdict',
119
- arguments: { mandateId: 'm-1', verdict: 'PASS', reason: 'Good work' },
120
- });
121
- assertSuccessResult(result as any);
122
- expect((result as any).content[0].text).toContain('accepted');
123
- expect((result as any).content[0].text).toContain('m-1');
124
- });
125
-
126
- it('renders FAIL verdict', async () => {
127
- (harness.mockSdk.notarize as any).renderVerdict.mockResolvedValueOnce({ ...MOCK_MANDATE, status: 'FAILED' });
128
- const result = await harness.client.callTool({
129
- name: 'agledger_verdict',
130
- arguments: { mandateId: 'm-1', verdict: 'FAIL', reason: 'Incomplete' },
131
- });
132
- assertSuccessResult(result as any);
133
- expect((result as any).content[0].text).toContain('rejected');
134
- });
135
-
136
- it('returns error on failure', async () => {
137
- (harness.mockSdk.notarize as any).renderVerdict.mockRejectedValueOnce(new Error('Not found'));
138
- const result = await harness.client.callTool({
139
- name: 'agledger_verdict',
140
- arguments: { mandateId: 'bad', verdict: 'PASS' },
141
- });
142
- assertErrorResult(result as any);
143
- });
144
- });
145
-
146
- describe('agledger_status', () => {
147
- it('returns agreement status', async () => {
148
- const result = await harness.client.callTool({ name: 'agledger_status', arguments: { mandateId: 'm-1' } });
149
- assertSuccessResult(result as any);
150
- expect((result as any).content[0].text).toContain('ACTIVE');
151
- expect((result as any).content[0].text).toContain('ACH-DLVR-v1');
152
- });
153
-
154
- it('returns error on failure', async () => {
155
- (harness.mockSdk.notarize as any).getMandate.mockRejectedValueOnce(new Error('Not found'));
156
- const result = await harness.client.callTool({ name: 'agledger_status', arguments: { mandateId: 'bad' } });
157
- assertErrorResult(result as any);
158
- });
159
- });
160
- });
@@ -1,170 +0,0 @@
1
- import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
2
- import { registerReceiptTools } from '../../src/tools/receipts.js';
3
- import { createTestHarness, type TestHarness } from '../harness.js';
4
- import { assertOutputSchemaValid, assertErrorResult, assertSuccessResult } from '../conformance.js';
5
- import { PermissionError } from '@agledger/sdk';
6
-
7
- const MOCK_RECEIPT = {
8
- id: 'r-1',
9
- mandateId: 'm-1',
10
- agentId: 'agent-1',
11
- structuralValidation: 'ACCEPTED',
12
- evidence: { amount: 100 },
13
- evidenceHash: 'sha256-abc',
14
- notes: null,
15
- mandateStatus: 'PROCESSING',
16
- createdAt: '2026-04-13T00:00:00Z',
17
- updatedAt: null,
18
- };
19
-
20
- const MOCK_OUTCOME = {
21
- mandateId: 'm-1',
22
- receiptId: 'r-1',
23
- outcome: 'PASS',
24
- signal: 'SETTLE',
25
- reporterType: 'principal',
26
- reportedAt: '2026-04-13T01:00:00Z',
27
- };
28
-
29
- describe('receipt tools (default — with submit_receipt)', () => {
30
- let harness: TestHarness;
31
-
32
- beforeAll(async () => {
33
- harness = await createTestHarness({
34
- registerFns: [registerReceiptTools],
35
- mockOverrides: {
36
- receipts: {
37
- submit: vi.fn().mockResolvedValue(MOCK_RECEIPT),
38
- get: vi.fn().mockResolvedValue(MOCK_RECEIPT),
39
- list: vi.fn().mockResolvedValue({ data: [MOCK_RECEIPT], nextCursor: null }),
40
- },
41
- mandates: {
42
- reportOutcome: vi.fn().mockResolvedValue(MOCK_OUTCOME),
43
- },
44
- },
45
- });
46
- });
47
-
48
- afterAll(async () => { await harness.cleanup(); });
49
-
50
- it('registers 4 tools when skipSubmit is not set', async () => {
51
- const { tools } = await harness.client.listTools();
52
- expect(tools.map((t: any) => t.name).sort()).toEqual([
53
- 'get_receipt', 'list_receipts', 'report_outcome', 'submit_receipt',
54
- ]);
55
- });
56
-
57
- it('all tools have valid outputSchema', async () => {
58
- const { tools } = await harness.client.listTools();
59
- for (const tool of tools) assertOutputSchemaValid(tool as any);
60
- });
61
-
62
- describe('submit_receipt', () => {
63
- it('submits receipt and returns result', async () => {
64
- const result = await harness.client.callTool({
65
- name: 'submit_receipt',
66
- arguments: { mandateId: 'm-1', agentId: 'agent-1', evidence: { amount: 100 } },
67
- });
68
- assertSuccessResult(result as any);
69
- expect((result as any).content[0].text).toContain('Receipt r-1 submitted');
70
- expect((result as any).content[0].text).toContain('ACCEPTED');
71
- });
72
-
73
- it('returns error on failure', async () => {
74
- (harness.mockSdk.receipts as any).submit.mockRejectedValueOnce(new Error('Mandate not active'));
75
- const result = await harness.client.callTool({
76
- name: 'submit_receipt',
77
- arguments: { mandateId: 'm-1', agentId: 'agent-1', evidence: {} },
78
- });
79
- assertErrorResult(result as any);
80
- });
81
- });
82
-
83
- describe('report_outcome', () => {
84
- it('reports PASS verdict', async () => {
85
- const result = await harness.client.callTool({
86
- name: 'report_outcome',
87
- arguments: { mandateId: 'm-1', receiptId: 'r-1', outcome: 'PASS' },
88
- });
89
- assertSuccessResult(result as any);
90
- expect((result as any).content[0].text).toContain('accepted');
91
- expect((result as any).content[0].text).toContain('SETTLE');
92
- });
93
-
94
- it('reports FAIL verdict', async () => {
95
- (harness.mockSdk.mandates as any).reportOutcome.mockResolvedValueOnce({ ...MOCK_OUTCOME, outcome: 'FAIL', signal: 'HOLD' });
96
- const result = await harness.client.callTool({
97
- name: 'report_outcome',
98
- arguments: { mandateId: 'm-1', receiptId: 'r-1', outcome: 'FAIL' },
99
- });
100
- assertSuccessResult(result as any);
101
- expect((result as any).content[0].text).toContain('rejected');
102
- });
103
- });
104
-
105
- describe('get_receipt', () => {
106
- it('returns receipt by ID', async () => {
107
- const result = await harness.client.callTool({
108
- name: 'get_receipt',
109
- arguments: { mandateId: 'm-1', receiptId: 'r-1' },
110
- });
111
- assertSuccessResult(result as any);
112
- expect((result as any).content[0].text).toContain('Receipt r-1');
113
- });
114
- });
115
-
116
- describe('list_receipts', () => {
117
- it('lists receipts for a mandate', async () => {
118
- const result = await harness.client.callTool({
119
- name: 'list_receipts',
120
- arguments: { mandateId: 'm-1' },
121
- });
122
- assertSuccessResult(result as any);
123
- expect((result as any).content[0].text).toContain('Found 1 receipts');
124
- });
125
- });
126
-
127
- describe('error handling', () => {
128
- it('surfaces PermissionError with missing scopes', async () => {
129
- const permErr = new PermissionError({
130
- message: 'Forbidden',
131
- details: { missingScopes: ['receipts:write'] },
132
- });
133
- (harness.mockSdk.receipts as any).submit.mockRejectedValueOnce(permErr);
134
- const result = await harness.client.callTool({
135
- name: 'submit_receipt',
136
- arguments: { mandateId: 'm-1', agentId: 'agent-1', evidence: {} },
137
- });
138
- assertErrorResult(result as any);
139
- expect((result as any).content[0].text).toContain('receipts:write');
140
- });
141
- });
142
- });
143
-
144
- describe('receipt tools (skipSubmit)', () => {
145
- let harness: TestHarness;
146
-
147
- beforeAll(async () => {
148
- harness = await createTestHarness({
149
- registerFns: [(mcp, client) => registerReceiptTools(mcp, client, { skipSubmit: true })],
150
- mockOverrides: {
151
- receipts: {
152
- get: vi.fn().mockResolvedValue(MOCK_RECEIPT),
153
- list: vi.fn().mockResolvedValue({ data: [], nextCursor: null }),
154
- },
155
- mandates: {
156
- reportOutcome: vi.fn().mockResolvedValue(MOCK_OUTCOME),
157
- },
158
- },
159
- });
160
- });
161
-
162
- afterAll(async () => { await harness.cleanup(); });
163
-
164
- it('registers 3 tools (no submit_receipt)', async () => {
165
- const { tools } = await harness.client.listTools();
166
- const names = tools.map((t: any) => t.name).sort();
167
- expect(names).toEqual(['get_receipt', 'list_receipts', 'report_outcome']);
168
- expect(names).not.toContain('submit_receipt');
169
- });
170
- });
@@ -1,117 +0,0 @@
1
- import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
2
- import { registerReputationTools } from '../../src/tools/reputation.js';
3
- import { createTestHarness, type TestHarness } from '../harness.js';
4
- import { assertErrorResult, assertSuccessResult } from '../conformance.js';
5
-
6
- describe('reputation tools', () => {
7
- let harness: TestHarness;
8
-
9
- beforeAll(async () => {
10
- harness = await createTestHarness({
11
- registerFns: [registerReputationTools],
12
- mockOverrides: {
13
- reputation: {
14
- getAgent: vi.fn().mockResolvedValue({
15
- data: [
16
- { contractType: 'ACH-PROC-v1', compositeScore: 0.95 },
17
- ],
18
- }),
19
- getByContractType: vi.fn().mockResolvedValue({
20
- compositeScore: 0.92,
21
- reliabilityScore: 0.95,
22
- accuracyScore: 0.90,
23
- efficiencyScore: 0.88,
24
- }),
25
- getHistory: vi.fn().mockResolvedValue({
26
- data: [
27
- { mandateId: 'm-1', outcome: 'PASS' },
28
- { mandateId: 'm-2', outcome: 'FAIL' },
29
- ],
30
- }),
31
- },
32
- },
33
- });
34
- });
35
-
36
- afterAll(async () => {
37
- await harness.cleanup();
38
- });
39
-
40
- it('registers exactly 3 tools', async () => {
41
- const { tools } = await harness.client.listTools();
42
- expect(tools.map((t: any) => t.name).sort()).toEqual([
43
- 'get_agent_history',
44
- 'get_agent_reputation',
45
- 'get_reputation_by_type',
46
- ]);
47
- });
48
-
49
- describe('get_agent_reputation', () => {
50
- it('returns reputation scores on success', async () => {
51
- const result = await harness.client.callTool({
52
- name: 'get_agent_reputation',
53
- arguments: { agentId: 'agent-001' },
54
- });
55
- assertSuccessResult(result as any);
56
- expect((result as any).content[0].text).toContain('agent-001');
57
- expect((result as any).content[0].text).toContain('1 contract type score');
58
- expect((harness.mockSdk.reputation as any).getAgent).toHaveBeenCalledWith('agent-001');
59
- });
60
-
61
- it('returns error on failure', async () => {
62
- (harness.mockSdk.reputation as any).getAgent.mockRejectedValueOnce(new Error('Agent not found'));
63
- const result = await harness.client.callTool({
64
- name: 'get_agent_reputation',
65
- arguments: { agentId: 'agent-missing' },
66
- });
67
- assertErrorResult(result as any);
68
- expect((result as any).content[0].text).toContain('Agent not found');
69
- });
70
- });
71
-
72
- describe('get_reputation_by_type', () => {
73
- it('returns score for a specific contract type', async () => {
74
- const result = await harness.client.callTool({
75
- name: 'get_reputation_by_type',
76
- arguments: { agentId: 'agent-001', contractType: 'ACH-PROC-v1' },
77
- });
78
- assertSuccessResult(result as any);
79
- const text = (result as any).content[0].text;
80
- expect(text).toContain('composite=0.92');
81
- expect(text).toContain('reliability=0.95');
82
- expect((harness.mockSdk.reputation as any).getByContractType).toHaveBeenCalledWith('agent-001', 'ACH-PROC-v1');
83
- });
84
-
85
- it('returns error on failure', async () => {
86
- (harness.mockSdk.reputation as any).getByContractType.mockRejectedValueOnce(new Error('No data'));
87
- const result = await harness.client.callTool({
88
- name: 'get_reputation_by_type',
89
- arguments: { agentId: 'agent-001', contractType: 'ACH-UNKNOWN-v1' },
90
- });
91
- assertErrorResult(result as any);
92
- expect((result as any).content[0].text).toContain('No data');
93
- });
94
- });
95
-
96
- describe('get_agent_history', () => {
97
- it('returns transaction history on success', async () => {
98
- const result = await harness.client.callTool({
99
- name: 'get_agent_history',
100
- arguments: { agentId: 'agent-001' },
101
- });
102
- assertSuccessResult(result as any);
103
- expect((result as any).content[0].text).toContain('2 transaction(s)');
104
- expect((harness.mockSdk.reputation as any).getHistory).toHaveBeenCalledWith('agent-001', {});
105
- });
106
-
107
- it('returns error on failure', async () => {
108
- (harness.mockSdk.reputation as any).getHistory.mockRejectedValueOnce(new Error('Timeout'));
109
- const result = await harness.client.callTool({
110
- name: 'get_agent_history',
111
- arguments: { agentId: 'agent-001' },
112
- });
113
- assertErrorResult(result as any);
114
- expect((result as any).content[0].text).toContain('Timeout');
115
- });
116
- });
117
- });