@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
@@ -0,0 +1,286 @@
1
+ import { describe, it, expect, beforeAll, afterAll, afterEach, vi } from 'vitest';
2
+ import type { Tool } from '@modelcontextprotocol/sdk/types.js';
3
+ import { createTestHarness, type TestHarness } from './harness.js';
4
+
5
+ let harness: TestHarness;
6
+ let tools: Tool[];
7
+
8
+ beforeAll(async () => {
9
+ harness = await createTestHarness();
10
+ ({ tools } = await harness.client.listTools());
11
+ });
12
+
13
+ afterAll(async () => {
14
+ await harness.cleanup();
15
+ });
16
+
17
+ afterEach(() => {
18
+ vi.unstubAllGlobals();
19
+ });
20
+
21
+ describe('tool registration', () => {
22
+ it('registers exactly 2 tools', () => {
23
+ expect(tools).toHaveLength(2);
24
+ });
25
+
26
+ it('registers agledger_discover', () => {
27
+ const tool = tools.find((t) => t.name === 'agledger_discover');
28
+ expect(tool).toBeDefined();
29
+ expect(tool!.description).toContain('health');
30
+ expect(tool!.description).toContain('identity');
31
+ });
32
+
33
+ it('registers agledger_api', () => {
34
+ const tool = tools.find((t) => t.name === 'agledger_api');
35
+ expect(tool).toBeDefined();
36
+ expect(tool!.description).toContain('nextSteps');
37
+ });
38
+ });
39
+
40
+ describe('agledger_discover', () => {
41
+ it('returns health and identity on success', async () => {
42
+ const mockFetch = vi
43
+ .fn()
44
+ .mockResolvedValueOnce(
45
+ new Response(JSON.stringify({ status: 'ok', version: '1.0.0' }), {
46
+ status: 200,
47
+ headers: { 'content-type': 'application/json' },
48
+ }),
49
+ )
50
+ .mockResolvedValueOnce(
51
+ new Response(JSON.stringify({ agentId: 'agent-1', scopes: ['mandates:read'] }), {
52
+ status: 200,
53
+ headers: { 'content-type': 'application/json' },
54
+ }),
55
+ );
56
+ vi.stubGlobal('fetch', mockFetch);
57
+
58
+ const result = await harness.client.callTool({ name: 'agledger_discover', arguments: {} });
59
+
60
+ expect(result.isError).toBeFalsy();
61
+ const content = result.structuredContent as Record<string, unknown>;
62
+ expect(content.health).toEqual({ status: 'ok', version: '1.0.0' });
63
+ expect(content.identity).toEqual({ agentId: 'agent-1', scopes: ['mandates:read'] });
64
+ });
65
+
66
+ it('returns partial results when one call fails', async () => {
67
+ const mockFetch = vi
68
+ .fn()
69
+ .mockResolvedValueOnce(
70
+ new Response(JSON.stringify({ status: 'ok' }), {
71
+ status: 200,
72
+ headers: { 'content-type': 'application/json' },
73
+ }),
74
+ )
75
+ .mockRejectedValueOnce(new TypeError('fetch failed'));
76
+ vi.stubGlobal('fetch', mockFetch);
77
+
78
+ const result = await harness.client.callTool({ name: 'agledger_discover', arguments: {} });
79
+
80
+ expect(result.isError).toBeFalsy();
81
+ const content = result.structuredContent as Record<string, unknown>;
82
+ expect(content.health).toEqual({ status: 'ok' });
83
+ expect(content.identity).toEqual({ error: 'fetch failed' });
84
+ });
85
+ });
86
+
87
+ describe('agledger_api', () => {
88
+ it('passes through successful GET response', async () => {
89
+ const apiResponse = {
90
+ data: [{ id: 'm-1', status: 'ACTIVE' }],
91
+ nextSteps: [{ action: 'Get mandate', method: 'GET', href: '/mandates/m-1' }],
92
+ };
93
+ vi.stubGlobal(
94
+ 'fetch',
95
+ vi.fn().mockResolvedValueOnce(
96
+ new Response(JSON.stringify(apiResponse), {
97
+ status: 200,
98
+ headers: { 'content-type': 'application/json' },
99
+ }),
100
+ ),
101
+ );
102
+
103
+ const result = await harness.client.callTool({
104
+ name: 'agledger_api',
105
+ arguments: { method: 'GET', path: '/mandates', params: { limit: 10 } },
106
+ });
107
+
108
+ expect(result.isError).toBeFalsy();
109
+ expect(result.structuredContent).toEqual(apiResponse);
110
+ });
111
+
112
+ it('passes through POST body', async () => {
113
+ const apiResponse = { id: 'm-2', status: 'CREATED' };
114
+ const mockFetch = vi.fn().mockResolvedValueOnce(
115
+ new Response(JSON.stringify(apiResponse), {
116
+ status: 201,
117
+ headers: { 'content-type': 'application/json' },
118
+ }),
119
+ );
120
+ vi.stubGlobal('fetch', mockFetch);
121
+
122
+ await harness.client.callTool({
123
+ name: 'agledger_api',
124
+ arguments: {
125
+ method: 'POST',
126
+ path: '/mandates',
127
+ params: { contractType: 'ACH-PROC-v1', platform: 'test' },
128
+ },
129
+ });
130
+
131
+ const [url, options] = mockFetch.mock.calls[0] as [string, RequestInit];
132
+ expect(url).toContain('/mandates');
133
+ expect(options.method).toBe('POST');
134
+ expect(JSON.parse(options.body as string)).toEqual({
135
+ contractType: 'ACH-PROC-v1',
136
+ platform: 'test',
137
+ });
138
+ });
139
+
140
+ it('forwards full API error body', async () => {
141
+ const errorBody = {
142
+ message: 'Mandate not found',
143
+ code: 'NOT_FOUND',
144
+ docUrl: 'https://docs.agledger.ai/errors/NOT_FOUND',
145
+ suggestion: 'Check the mandate ID and try again.',
146
+ };
147
+ vi.stubGlobal(
148
+ 'fetch',
149
+ vi.fn().mockResolvedValueOnce(
150
+ new Response(JSON.stringify(errorBody), {
151
+ status: 404,
152
+ headers: { 'content-type': 'application/json' },
153
+ }),
154
+ ),
155
+ );
156
+
157
+ const result = await harness.client.callTool({
158
+ name: 'agledger_api',
159
+ arguments: { method: 'GET', path: '/mandates/bad-id' },
160
+ });
161
+
162
+ expect(result.isError).toBe(true);
163
+ const content = result.structuredContent as Record<string, unknown>;
164
+ expect(content.docUrl).toBe('https://docs.agledger.ai/errors/NOT_FOUND');
165
+ expect(content.suggestion).toBe('Check the mandate ID and try again.');
166
+ });
167
+
168
+ it('forwards 403 with missingScopes', async () => {
169
+ const errorBody = {
170
+ message: 'Insufficient permissions',
171
+ code: 'FORBIDDEN',
172
+ missingScopes: ['mandates:write'],
173
+ suggestion: 'Request mandates:write scope on your API key.',
174
+ };
175
+ vi.stubGlobal(
176
+ 'fetch',
177
+ vi.fn().mockResolvedValueOnce(
178
+ new Response(JSON.stringify(errorBody), {
179
+ status: 403,
180
+ headers: { 'content-type': 'application/json' },
181
+ }),
182
+ ),
183
+ );
184
+
185
+ const result = await harness.client.callTool({
186
+ name: 'agledger_api',
187
+ arguments: { method: 'POST', path: '/mandates', params: {} },
188
+ });
189
+
190
+ expect(result.isError).toBe(true);
191
+ const content = result.structuredContent as Record<string, unknown>;
192
+ expect(content.missingScopes).toEqual(['mandates:write']);
193
+ });
194
+
195
+ it('rejects path not starting with /', async () => {
196
+ const result = await harness.client.callTool({
197
+ name: 'agledger_api',
198
+ arguments: { method: 'GET', path: 'mandates' },
199
+ });
200
+
201
+ expect(result.isError).toBe(true);
202
+ const text = (result.content as Array<{ type: string; text: string }>)[0].text;
203
+ expect(text).toContain('Path must start with /');
204
+ });
205
+
206
+ it('handles network errors without crashing', async () => {
207
+ vi.stubGlobal(
208
+ 'fetch',
209
+ vi.fn().mockRejectedValueOnce(new TypeError('fetch failed: DNS resolution failed')),
210
+ );
211
+
212
+ const result = await harness.client.callTool({
213
+ name: 'agledger_api',
214
+ arguments: { method: 'GET', path: '/health' },
215
+ });
216
+
217
+ expect(result.isError).toBe(true);
218
+ const text = (result.content as Array<{ type: string; text: string }>)[0].text;
219
+ expect(text).toContain('Network error');
220
+ });
221
+
222
+ it('handles timeout without crashing', async () => {
223
+ vi.stubGlobal(
224
+ 'fetch',
225
+ vi
226
+ .fn()
227
+ .mockRejectedValueOnce(
228
+ Object.assign(new DOMException('The operation was aborted', 'AbortError'), {}),
229
+ ),
230
+ );
231
+
232
+ const result = await harness.client.callTool({
233
+ name: 'agledger_api',
234
+ arguments: { method: 'GET', path: '/health' },
235
+ });
236
+
237
+ expect(result.isError).toBe(true);
238
+ const text = (result.content as Array<{ type: string; text: string }>)[0].text;
239
+ expect(text).toContain('timed out');
240
+ });
241
+
242
+ it('handles non-JSON responses', async () => {
243
+ vi.stubGlobal(
244
+ 'fetch',
245
+ vi.fn().mockResolvedValueOnce(
246
+ new Response('<html>Bad Gateway</html>', {
247
+ status: 502,
248
+ headers: { 'content-type': 'text/html' },
249
+ }),
250
+ ),
251
+ );
252
+
253
+ const result = await harness.client.callTool({
254
+ name: 'agledger_api',
255
+ arguments: { method: 'GET', path: '/health' },
256
+ });
257
+
258
+ expect(result.isError).toBe(true);
259
+ const content = result.structuredContent as Record<string, unknown>;
260
+ expect(content._raw).toBe('<html>Bad Gateway</html>');
261
+ expect(content._contentType).toBe('text/html');
262
+ });
263
+
264
+ it('sends query params for GET requests', async () => {
265
+ const mockFetch = vi.fn().mockResolvedValueOnce(
266
+ new Response(JSON.stringify({ data: [] }), {
267
+ status: 200,
268
+ headers: { 'content-type': 'application/json' },
269
+ }),
270
+ );
271
+ vi.stubGlobal('fetch', mockFetch);
272
+
273
+ await harness.client.callTool({
274
+ name: 'agledger_api',
275
+ arguments: {
276
+ method: 'GET',
277
+ path: '/mandates/search',
278
+ params: { status: 'ACTIVE', limit: 20 },
279
+ },
280
+ });
281
+
282
+ const url = new URL(mockFetch.mock.calls[0][0] as string);
283
+ expect(url.searchParams.get('status')).toBe('ACTIVE');
284
+ expect(url.searchParams.get('limit')).toBe('20');
285
+ });
286
+ });
package/src/enums.ts DELETED
@@ -1,47 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- export const ContractTypeEnum = z.enum([
4
- 'ACH-PROC-v1',
5
- 'ACH-DLVR-v1',
6
- 'ACH-DATA-v1',
7
- 'ACH-TXN-v1',
8
- 'ACH-ORCH-v1',
9
- 'ACH-COMM-v1',
10
- 'ACH-AUTH-v1',
11
- 'ACH-INFRA-v1',
12
- 'ACH-DEL-v1',
13
- 'ACH-ANALYZE-v1',
14
- 'ACH-COORD-v1',
15
- 'ACH-MON-v1',
16
- 'ACH-REVIEW-v1',
17
- ]).describe('AGLedger standard contract type identifier');
18
-
19
- export const MandateStatusEnum = z.enum([
20
- 'CREATED', 'PROPOSED', 'ACTIVE', 'PROCESSING',
21
- 'REVISION_REQUESTED', 'FULFILLED', 'FAILED',
22
- 'REMEDIATED', 'EXPIRED', 'CANCELLED', 'REJECTED',
23
- ]).describe('Mandate lifecycle status');
24
-
25
- export const HubStateEnum = z.enum(['OFFERED', 'ACCEPTED', 'ACTIVE', 'COMPLETED', 'DISPUTED', 'TERMINAL']).describe('Federation hub-level mandate state');
26
- export const GatewayStatusEnum = z.enum(['active', 'suspended', 'revoked']).describe('Federation gateway registration status');
27
- export const RevocationReasonEnum = z.enum(['key_compromise', 'decommission', 'administrative']).describe('Reason for revoking a federation gateway');
28
- export const FederationSignalEnum = z.enum(['SETTLE', 'HOLD', 'RELEASE']).describe('Settlement signal type');
29
- export const FederationOutcomeEnum = z.enum(['PASS', 'FAIL']).describe('Federation verification outcome');
30
-
31
- export const OperatingModeEnum = z.enum(['cleartext', 'encrypted']).describe('Operating mode for the mandate');
32
- export const RiskClassificationEnum = z.enum(['high', 'limited', 'minimal', 'unclassified']).describe('EU AI Act risk classification');
33
- export const DisputeStatusEnum = z.enum([
34
- 'OPENED', 'TIER_1_REVIEW', 'EVIDENCE_WINDOW', 'TIER_2_REVIEW',
35
- 'ESCALATED', 'TIER_3_ARBITRATION', 'RESOLVED', 'WITHDRAWN',
36
- ]).describe('Dispute lifecycle status');
37
- export const StructuralValidationEnum = z.enum(['ACCEPTED', 'INVALID']).describe('Receipt structural validation result');
38
- export const VerificationOutcomeEnum = z.enum(['PASS', 'FAIL', 'REVIEW_REQUIRED']).describe('Verification outcome (system verdict)');
39
-
40
- export const NextStepSchema = z.object({
41
- action: z.string().describe('What to do next'),
42
- method: z.enum(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']).describe('HTTP method'),
43
- href: z.string().describe('Relative URL template'),
44
- description: z.string().describe('Why this step matters'),
45
- }).describe('Suggested next API call');
46
-
47
- export const NextStepsField = z.array(NextStepSchema).nullable().optional().describe('Suggested next API calls — guides agents through the lifecycle');
package/src/errors.ts DELETED
@@ -1,44 +0,0 @@
1
- import { AgledgerApiError, PermissionError } from '@agledger/sdk';
2
- import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
3
-
4
- /**
5
- * Convert a typed SDK response to structuredContent.
6
- * JSON round-trip strips class instances, functions, and non-serializable values,
7
- * producing a clean Record<string, unknown>.
8
- */
9
- export function toStructuredContent<T>(value: T): Record<string, unknown> {
10
- return JSON.parse(JSON.stringify(value)) as Record<string, unknown>;
11
- }
12
-
13
- export function errorResult(message: string, details?: Record<string, unknown>): CallToolResult {
14
- let text = `Error: ${message}`;
15
- if (details) text += `\n\nDetails: ${JSON.stringify(details)}`;
16
- return {
17
- content: [{ type: 'text', text }],
18
- isError: true,
19
- };
20
- }
21
-
22
- export function apiErrorResult(e: unknown): CallToolResult {
23
- if (e instanceof PermissionError) {
24
- if (e.missingScopes.length > 0) {
25
- return errorResult(`Insufficient scopes. Missing: ${e.missingScopes.join(', ')}. Use GET /auth/me to check your key's scopes.`);
26
- }
27
- return errorResult('Agent not approved for this enterprise. Use approve_enterprise_agent to approve the agent, or set agentApprovalRequired=false via set_enterprise_config.');
28
- }
29
- if (e instanceof AgledgerApiError) {
30
- const extra: Record<string, unknown> = {};
31
- if (e.code) extra.code = e.code;
32
- if (e.docUrl) extra.docUrl = e.docUrl;
33
- if (e.details && typeof e.details === 'object' && !Array.isArray(e.details)) {
34
- const d = e.details as Record<string, unknown>;
35
- if (d.examplePayload) extra.examplePayload = d.examplePayload;
36
- if (d.requiredFields) extra.requiredFields = d.requiredFields;
37
- if (d.optionalFields) extra.optionalFields = d.optionalFields;
38
- }
39
- if (e.validationErrors.length > 0) extra.validationErrors = e.validationErrors;
40
- if (e.suggestion) extra.suggestion = e.suggestion;
41
- return errorResult(e.message, Object.keys(extra).length > 0 ? extra : undefined);
42
- }
43
- return errorResult(e instanceof Error ? e.message : String(e));
44
- }
@@ -1,130 +0,0 @@
1
- import { ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
- import type { AgledgerClient } from '@agledger/sdk';
4
- import type { ContractType } from '@agledger/sdk';
5
-
6
- const CONTRACT_TYPES: { type: ContractType; description: string }[] = [
7
- { type: 'ACH-PROC-v1', description: 'General procurement (goods, services, supplies)' },
8
- { type: 'ACH-DLVR-v1', description: 'Deliverables (reports, documents, artifacts)' },
9
- { type: 'ACH-DATA-v1', description: 'Data processing (ETL, analysis, transformation)' },
10
- { type: 'ACH-TXN-v1', description: 'Transactions (payments, transfers, settlements)' },
11
- { type: 'ACH-ORCH-v1', description: 'Orchestration (delegation, task coordination)' },
12
- { type: 'ACH-COMM-v1', description: 'Communication (email, chat, webhooks, notifications)' },
13
- { type: 'ACH-AUTH-v1', description: 'Authorization (permissions, credentials, access control)' },
14
- { type: 'ACH-INFRA-v1', description: 'Infrastructure (DDL, cloud provisioning, config changes)' },
15
- { type: 'ACH-DEL-v1', description: 'Destructive operations (deletions, cancellations, refunds, reversals)' },
16
- { type: 'ACH-ANALYZE-v1', description: 'Research, analysis, and investigation tasks' },
17
- { type: 'ACH-COORD-v1', description: 'Multi-party coordination and consensus building' },
18
- { type: 'ACH-MON-v1', description: 'Monitoring, alerting, and observability tasks' },
19
- { type: 'ACH-REVIEW-v1', description: 'Review, approval, and sign-off workflows' },
20
- ];
21
-
22
- const VALID_TYPES = new Set(CONTRACT_TYPES.map((ct) => ct.type));
23
-
24
- export function registerContractTypeResources(mcp: McpServer, client: AgledgerClient): void {
25
- mcp.registerResource(
26
- 'contract-types',
27
- 'schema://contract-types',
28
- {
29
- description: 'List of all 9 AGLedger standard contract types with descriptions.',
30
- mimeType: 'application/json',
31
- },
32
- async () => {
33
- return {
34
- contents: [
35
- {
36
- uri: 'schema://contract-types',
37
- mimeType: 'application/json',
38
- text: JSON.stringify(CONTRACT_TYPES, null, 2),
39
- },
40
- ],
41
- };
42
- },
43
- );
44
-
45
- const template = new ResourceTemplate(
46
- 'schema://contract-types/{type}',
47
- {
48
- list: async () => {
49
- return {
50
- resources: CONTRACT_TYPES.map((ct) => ({
51
- uri: `schema://contract-types/${ct.type}`,
52
- name: ct.type,
53
- description: ct.description,
54
- mimeType: 'application/json',
55
- })),
56
- };
57
- },
58
- complete: {
59
- type: async (value: string) => {
60
- return CONTRACT_TYPES
61
- .map((ct) => ct.type)
62
- .filter((t) => t.toLowerCase().startsWith(value.toLowerCase()));
63
- },
64
- },
65
- },
66
- );
67
-
68
- mcp.registerResource(
69
- 'contract-type-schema',
70
- template,
71
- {
72
- description: 'Individual AGLedger contract type schema with mandate/receipt JSON Schemas and verification rules.',
73
- mimeType: 'application/json',
74
- },
75
- async (_uri, variables) => {
76
- const contractType = variables.type as string;
77
-
78
- if (!VALID_TYPES.has(contractType as ContractType)) {
79
- return {
80
- contents: [
81
- {
82
- uri: `schema://contract-types/${contractType}`,
83
- mimeType: 'application/json',
84
- text: JSON.stringify({
85
- error: `Unknown contract type: ${contractType}. Valid types: ${[...VALID_TYPES].join(', ')}`,
86
- }),
87
- },
88
- ],
89
- };
90
- }
91
-
92
- try {
93
- const schema = await client.schemas.get(contractType as ContractType);
94
- const info = CONTRACT_TYPES.find((ct) => ct.type === contractType);
95
-
96
- return {
97
- contents: [
98
- {
99
- uri: `schema://contract-types/${contractType}`,
100
- mimeType: 'application/json',
101
- text: JSON.stringify(
102
- {
103
- contractType: schema.contractType,
104
- description: info?.description ?? '',
105
- mandateSchema: schema.mandateSchema,
106
- receiptSchema: schema.receiptSchema,
107
- rulesConfig: schema.rulesConfig ?? null,
108
- },
109
- null,
110
- 2,
111
- ),
112
- },
113
- ],
114
- };
115
- } catch (err) {
116
- return {
117
- contents: [
118
- {
119
- uri: `schema://contract-types/${contractType}`,
120
- mimeType: 'application/json',
121
- text: JSON.stringify({
122
- error: err instanceof Error ? err.message : String(err),
123
- }),
124
- },
125
- ],
126
- };
127
- }
128
- },
129
- );
130
- }
@@ -1,184 +0,0 @@
1
- /**
2
- * Required scopes for each tool, keyed by tool name.
3
- * Read scopes grant access; write scopes imply read.
4
- */
5
- export const TOOL_SCOPES: Record<string, string[]> = {
6
- // Mandates
7
- create_mandate: ['mandates:write'],
8
- get_mandate: ['mandates:read'],
9
- search_mandates: ['mandates:read'],
10
- update_mandate: ['mandates:write'],
11
- activate_mandate: ['mandates:write'],
12
- cancel_mandate: ['mandates:write'],
13
- settle_mandate: ['mandates:write'],
14
- request_revision: ['mandates:write'],
15
- delegate_mandate: ['mandates:write'],
16
- get_mandate_graph: ['mandates:read'],
17
- get_mandate_summary: ['mandates:read'],
18
- get_sub_mandates: ['mandates:read'],
19
- get_delegation_chain: ['mandates:read'],
20
- report_outcome: ['mandates:write'],
21
-
22
- // Mandates (agent)
23
- propose_mandate: ['mandates:write'],
24
- propose_agent_mandate: ['mandates:write'],
25
- accept_proposal: ['mandates:write'],
26
- reject_proposal: ['mandates:write'],
27
- counter_proposal: ['mandates:write'],
28
- check_proposals: ['mandates:read'],
29
- list_my_proposals: ['mandates:read'],
30
- list_principal_mandates: ['mandates:read'],
31
-
32
- // A2A
33
- accept_mandate: ['mandates:write'],
34
- reject_mandate: ['mandates:write'],
35
- accept_counter_proposal: ['mandates:write'],
36
- my_mandates: ['mandates:read'],
37
-
38
- // Receipts
39
- submit_receipt: ['receipts:write'],
40
- get_receipt: ['receipts:read'],
41
- list_receipts: ['receipts:read'],
42
- // Verification
43
- verify_mandate: ['mandates:write'],
44
- get_verification_status: ['mandates:read'],
45
-
46
- // Disputes
47
- create_dispute: ['disputes:manage'],
48
- get_dispute: ['disputes:read'],
49
- escalate_dispute: ['disputes:manage'],
50
- submit_dispute_evidence: ['disputes:manage'],
51
-
52
- // Events / Audit
53
- get_audit_trail: ['audit:read'],
54
-
55
- // Schemas
56
- list_contract_schemas: ['schemas:read'],
57
- get_contract_schema: ['schemas:read'],
58
- get_schema_rules: ['schemas:read'],
59
- get_schema_versions: ['schemas:read'],
60
- get_schema_version: ['schemas:read'],
61
- diff_schema_versions: ['schemas:read'],
62
- get_meta_schema: ['schemas:read'],
63
- get_blank_schema_template: ['schemas:read'],
64
- get_schema_template: ['schemas:read'],
65
- preview_schema: ['schemas:read'],
66
- check_schema_compatibility: ['schemas:read'],
67
- register_schema: ['schemas:write'],
68
- delete_schema: ['schemas:write'],
69
- export_schema: ['schemas:read'],
70
- import_schema: ['schemas:write'],
71
- validate_receipt_schema: ['schemas:read'],
72
-
73
- // Enterprise management
74
- approve_enterprise_agent: ['agents:manage'],
75
- revoke_enterprise_agent: ['agents:manage'],
76
- list_enterprise_agents: ['agents:read'],
77
- create_enterprise: ['admin:trust'],
78
- create_agent: ['admin:trust'],
79
- set_enterprise_config: ['admin:trust'],
80
-
81
- // Agents & References
82
- get_agent: ['agents:read'],
83
- update_agent: ['agents:manage'],
84
- add_agent_references: ['agents:manage'],
85
- get_agent_references: ['agents:read'],
86
- lookup_reference: ['agents:read'],
87
- add_mandate_references: ['mandates:write'],
88
- get_mandate_references: ['mandates:read'],
89
-
90
- // Capabilities
91
- get_agent_capabilities: ['agents:read'],
92
- declare_capabilities: ['agents:manage'],
93
-
94
- // Reputation
95
- get_agent_reputation: ['reputation:read'],
96
- get_reputation_by_type: ['reputation:read'],
97
- get_agent_history: ['reputation:read'],
98
- check_reputation: ['reputation:read'],
99
-
100
- // Dashboard
101
- get_dashboard_summary: ['dashboard:read'],
102
- get_dashboard_metrics: ['dashboard:read'],
103
- get_dashboard_alerts: ['dashboard:read'],
104
-
105
- // Compliance
106
- create_compliance_record: ['compliance:write'],
107
- list_compliance_records: ['compliance:read'],
108
- get_eu_ai_act_report: ['compliance:read'],
109
-
110
- // Health
111
- check_api_health: [],
112
-
113
- // Verification Keys (public, no auth required)
114
- list_verification_keys: [],
115
-
116
- // Federation Gateway
117
- federation_register: [],
118
- federation_heartbeat: [],
119
- federation_register_agent: [],
120
- federation_list_agents: [],
121
- federation_submit_transition: [],
122
- federation_relay_signal: [],
123
- federation_rotate_key: [],
124
- federation_revoke: [],
125
- federation_catch_up: [],
126
- federation_stream: [],
127
- federation_publish_schema: [],
128
- federation_confirm_schema_publish: [],
129
- federation_list_contract_types: [],
130
- federation_get_contract_type: [],
131
- federation_get_mandate_criteria: [],
132
- federation_submit_mandate_criteria: [],
133
- federation_contribute_reputation: [],
134
- federation_get_agent_reputation: [],
135
- federation_broadcast_revocations: [],
136
- federation_sync_agent_directory: [],
137
-
138
- // Federation Admin
139
- federation_create_token: ['admin:system'],
140
- federation_list_gateways: ['admin:system'],
141
- federation_admin_revoke: ['admin:system'],
142
- federation_query_mandates: ['admin:system'],
143
- federation_audit_log: ['admin:system'],
144
- federation_health: ['admin:system'],
145
- federation_reset_sequence: ['admin:system'],
146
- federation_list_dlq: ['admin:system'],
147
- federation_retry_dlq: ['admin:system'],
148
- federation_delete_dlq: ['admin:system'],
149
- federation_rotate_hub_key: ['admin:system'],
150
- federation_list_hub_keys: ['admin:system'],
151
- federation_activate_hub_key: ['admin:system'],
152
- federation_expire_hub_key: ['admin:system'],
153
- federation_register_peer: ['admin:system'],
154
- federation_list_peers: ['admin:system'],
155
- federation_get_peer: ['admin:system'],
156
- federation_revoke_peer: ['admin:system'],
157
- federation_resync_peer: ['admin:system'],
158
- federation_create_peering_token: ['admin:system'],
159
- federation_delete_schema_version: ['admin:system'],
160
- federation_list_reputation_contributions: ['admin:system'],
161
- federation_reset_reputation: ['admin:system'],
162
- federation_get_mandate_criteria_status: ['admin:system'],
163
-
164
- // Code mode
165
- sdk_execute: [],
166
- sdk_describe: [],
167
-
168
- // OpenClaw
169
- agledger_notarize: ['mandates:write', 'receipts:write'],
170
- agledger_receipt: ['receipts:write'],
171
- agledger_status: ['mandates:read'],
172
- agledger_accept: ['mandates:write'],
173
- agledger_verdict: ['mandates:write'],
174
- };
175
-
176
- /**
177
- * Build `_meta` object for a tool, including `requiredScopes`.
178
- * Returns undefined if no scopes are mapped (passthrough).
179
- */
180
- export function toolMeta(toolName: string): Record<string, unknown> | undefined {
181
- const scopes = TOOL_SCOPES[toolName];
182
- if (!scopes || scopes.length === 0) return undefined;
183
- return { requiredScopes: scopes };
184
- }