@agledger/mcp-server 1.2.0 → 1.3.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 (137) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/dist/enums.d.ts +0 -1
  4. package/dist/enums.d.ts.map +1 -1
  5. package/dist/enums.js +0 -1
  6. package/dist/enums.js.map +1 -1
  7. package/dist/errors.d.ts +0 -1
  8. package/dist/errors.d.ts.map +1 -1
  9. package/dist/errors.js +0 -1
  10. package/dist/errors.js.map +1 -1
  11. package/dist/index.d.ts +0 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +1 -2
  14. package/dist/index.js.map +1 -1
  15. package/dist/resources/contract-types.d.ts +0 -1
  16. package/dist/resources/contract-types.d.ts.map +1 -1
  17. package/dist/resources/contract-types.js +0 -3
  18. package/dist/resources/contract-types.js.map +1 -1
  19. package/dist/server.d.ts +0 -1
  20. package/dist/server.d.ts.map +1 -1
  21. package/dist/server.js +6 -3
  22. package/dist/server.js.map +1 -1
  23. package/dist/tool-scopes.d.ts +0 -12
  24. package/dist/tool-scopes.d.ts.map +1 -1
  25. package/dist/tool-scopes.js +20 -30
  26. package/dist/tool-scopes.js.map +1 -1
  27. package/dist/tools/a2a.d.ts +0 -1
  28. package/dist/tools/a2a.d.ts.map +1 -1
  29. package/dist/tools/a2a.js +21 -52
  30. package/dist/tools/a2a.js.map +1 -1
  31. package/dist/tools/agent-mandates.d.ts +0 -1
  32. package/dist/tools/agent-mandates.d.ts.map +1 -1
  33. package/dist/tools/agent-mandates.js +0 -10
  34. package/dist/tools/agent-mandates.js.map +1 -1
  35. package/dist/tools/agents-refs.d.ts +0 -1
  36. package/dist/tools/agents-refs.d.ts.map +1 -1
  37. package/dist/tools/agents-refs.js +0 -8
  38. package/dist/tools/agents-refs.js.map +1 -1
  39. package/dist/tools/capabilities.d.ts +0 -1
  40. package/dist/tools/capabilities.d.ts.map +1 -1
  41. package/dist/tools/capabilities.js +0 -3
  42. package/dist/tools/capabilities.js.map +1 -1
  43. package/dist/tools/code-mode.d.ts +0 -1
  44. package/dist/tools/code-mode.d.ts.map +1 -1
  45. package/dist/tools/code-mode.js +4 -10
  46. package/dist/tools/code-mode.js.map +1 -1
  47. package/dist/tools/compliance.d.ts +0 -1
  48. package/dist/tools/compliance.d.ts.map +1 -1
  49. package/dist/tools/compliance.js +0 -1
  50. package/dist/tools/compliance.js.map +1 -1
  51. package/dist/tools/dashboard.d.ts +0 -1
  52. package/dist/tools/dashboard.d.ts.map +1 -1
  53. package/dist/tools/dashboard.js +0 -1
  54. package/dist/tools/dashboard.js.map +1 -1
  55. package/dist/tools/disputes.d.ts +0 -1
  56. package/dist/tools/disputes.d.ts.map +1 -1
  57. package/dist/tools/disputes.js +0 -5
  58. package/dist/tools/disputes.js.map +1 -1
  59. package/dist/tools/enterprises.d.ts +0 -1
  60. package/dist/tools/enterprises.d.ts.map +1 -1
  61. package/dist/tools/enterprises.js +0 -7
  62. package/dist/tools/enterprises.js.map +1 -1
  63. package/dist/tools/events.d.ts +0 -1
  64. package/dist/tools/events.d.ts.map +1 -1
  65. package/dist/tools/events.js +0 -2
  66. package/dist/tools/events.js.map +1 -1
  67. package/dist/tools/federation-admin.d.ts +0 -1
  68. package/dist/tools/federation-admin.d.ts.map +1 -1
  69. package/dist/tools/federation-admin.js +0 -25
  70. package/dist/tools/federation-admin.js.map +1 -1
  71. package/dist/tools/federation.d.ts +0 -1
  72. package/dist/tools/federation.d.ts.map +1 -1
  73. package/dist/tools/federation.js +0 -21
  74. package/dist/tools/federation.js.map +1 -1
  75. package/dist/tools/health.d.ts +0 -1
  76. package/dist/tools/health.d.ts.map +1 -1
  77. package/dist/tools/health.js +0 -2
  78. package/dist/tools/health.js.map +1 -1
  79. package/dist/tools/mandates.d.ts +0 -1
  80. package/dist/tools/mandates.d.ts.map +1 -1
  81. package/dist/tools/mandates.js +0 -11
  82. package/dist/tools/mandates.js.map +1 -1
  83. package/dist/tools/openclaw.d.ts +0 -5
  84. package/dist/tools/openclaw.d.ts.map +1 -1
  85. package/dist/tools/openclaw.js +0 -5
  86. package/dist/tools/openclaw.js.map +1 -1
  87. package/dist/tools/receipts.d.ts +0 -1
  88. package/dist/tools/receipts.d.ts.map +1 -1
  89. package/dist/tools/receipts.js +3 -8
  90. package/dist/tools/receipts.js.map +1 -1
  91. package/dist/tools/reputation.d.ts +0 -1
  92. package/dist/tools/reputation.d.ts.map +1 -1
  93. package/dist/tools/reputation.js +0 -1
  94. package/dist/tools/reputation.js.map +1 -1
  95. package/dist/tools/schemas.d.ts +0 -1
  96. package/dist/tools/schemas.d.ts.map +1 -1
  97. package/dist/tools/schemas.js +0 -17
  98. package/dist/tools/schemas.js.map +1 -1
  99. package/dist/tools/verification-keys.d.ts +4 -0
  100. package/dist/tools/verification-keys.d.ts.map +1 -0
  101. package/dist/tools/verification-keys.js +48 -0
  102. package/dist/tools/verification-keys.js.map +1 -0
  103. package/dist/tools/verification.d.ts +0 -1
  104. package/dist/tools/verification.d.ts.map +1 -1
  105. package/dist/tools/verification.js +0 -3
  106. package/dist/tools/verification.js.map +1 -1
  107. package/package.json +2 -7
  108. package/src/enums.ts +46 -0
  109. package/src/errors.ts +35 -0
  110. package/src/index.ts +100 -0
  111. package/src/resources/contract-types.ts +130 -0
  112. package/src/server.ts +132 -0
  113. package/src/tool-scopes.ts +180 -0
  114. package/src/tools/a2a.ts +519 -0
  115. package/src/tools/agent-mandates.ts +325 -0
  116. package/src/tools/agents-refs.ts +287 -0
  117. package/src/tools/capabilities.ts +76 -0
  118. package/src/tools/code-mode.ts +461 -0
  119. package/src/tools/compliance.ts +79 -0
  120. package/src/tools/dashboard.ts +73 -0
  121. package/src/tools/disputes.ts +154 -0
  122. package/src/tools/enterprises.ts +235 -0
  123. package/src/tools/events.ts +52 -0
  124. package/src/tools/federation-admin.ts +922 -0
  125. package/src/tools/federation.ts +784 -0
  126. package/src/tools/health.ts +43 -0
  127. package/src/tools/mandates.ts +382 -0
  128. package/src/tools/openclaw.ts +168 -0
  129. package/src/tools/receipts.ts +179 -0
  130. package/src/tools/reputation.ts +78 -0
  131. package/src/tools/schemas.ts +667 -0
  132. package/src/tools/verification-keys.ts +56 -0
  133. package/src/tools/verification.ts +85 -0
  134. package/tests/code-mode-manifest.test.ts +144 -0
  135. package/tests/enterprises.test.ts +96 -0
  136. package/tests/schemas.test.ts +531 -0
  137. package/tsconfig.json +12 -0
@@ -0,0 +1,43 @@
1
+ import { z } from 'zod';
2
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import type { AgledgerClient } from '@agledger/sdk';
4
+ import { apiErrorResult } from '../errors.js';
5
+ import { toolMeta } from '../tool-scopes.js';
6
+
7
+ const HealthOutputSchema = z.object({
8
+ status: z.string().describe('API health status (e.g. "ok", "degraded")'),
9
+ version: z.string().optional().describe('API version string'),
10
+ uptime: z.number().optional().describe('API uptime in seconds'),
11
+ database: z.string().optional().describe('Database connection status'),
12
+ timestamp: z.string().describe('ISO 8601 timestamp of the health check'),
13
+ }).describe('AGLedger API health check response');
14
+
15
+ export function registerHealthTools(mcp: McpServer, client: AgledgerClient): void {
16
+ mcp.registerTool(
17
+ 'check_api_health',
18
+ {
19
+ title: 'Check API Health',
20
+ description: 'Check the health status of the AGLedger API, including database connectivity and uptime.',
21
+ inputSchema: {},
22
+ outputSchema: HealthOutputSchema,
23
+ annotations: {
24
+ readOnlyHint: true,
25
+ destructiveHint: false,
26
+ idempotentHint: true,
27
+ openWorldHint: true,
28
+ },
29
+ _meta: toolMeta('check_api_health'),
30
+ },
31
+ async () => {
32
+ try {
33
+ const health = await client.health.check();
34
+ return {
35
+ content: [{ type: 'text', text: `API health: status=${health.status}${health.version ? `, version=${health.version}` : ''}${health.database ? `, db=${health.database}` : ''}.` }],
36
+ structuredContent: health as unknown as Record<string, unknown>,
37
+ };
38
+ } catch (err) {
39
+ return apiErrorResult(err);
40
+ }
41
+ },
42
+ );
43
+ }
@@ -0,0 +1,382 @@
1
+ import { z } from 'zod';
2
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import type { AgledgerClient } from '@agledger/sdk';
4
+ import { apiErrorResult } from '../errors.js';
5
+ import { ContractTypeEnum, MandateStatusEnum, NextStepsField, OperatingModeEnum, RiskClassificationEnum } from '../enums.js';
6
+ import { toolMeta } from '../tool-scopes.js';
7
+
8
+ const MandateOutputSchema = z.object({
9
+ id: z.string().describe('Mandate UUID'),
10
+ enterpriseId: z.string().describe('Enterprise that owns this mandate'),
11
+ agentId: z.string().nullable().optional().describe('Assigned agent ID'),
12
+ contractType: ContractTypeEnum,
13
+ contractVersion: z.string().describe('Contract version string'),
14
+ platform: z.string().describe('Platform identifier'),
15
+ platformRef: z.string().nullable().optional().describe('Platform-specific reference'),
16
+ status: MandateStatusEnum,
17
+ criteria: z.record(z.string(), z.unknown()).describe('Acceptance criteria object'),
18
+ tolerance: z.record(z.string(), z.unknown()).nullable().optional().describe('Tolerance bands'),
19
+ deadline: z.string().nullable().optional().describe('ISO 8601 deadline'),
20
+ commissionPct: z.number().nullable().optional().describe('Commission percentage'),
21
+ operatingMode: OperatingModeEnum.nullable().optional(),
22
+ verificationMode: z.enum(['auto', 'principal', 'gated']).nullable().optional().describe('Verification mode'),
23
+ riskClassification: RiskClassificationEnum.nullable().optional(),
24
+ euAiActDomain: z.string().nullable().optional().describe('EU AI Act domain'),
25
+ humanOversight: z.record(z.string(), z.unknown()).nullable().optional().describe('Human oversight configuration'),
26
+ parentMandateId: z.string().nullable().optional().describe('Parent mandate ID for delegation chains'),
27
+ rootMandateId: z.string().nullable().optional().describe('Root mandate ID in delegation chain'),
28
+ chainDepth: z.number().nullable().optional().describe('Depth in delegation chain'),
29
+ version: z.number().describe('Optimistic concurrency version'),
30
+ createdAt: z.string().describe('ISO 8601 creation timestamp'),
31
+ updatedAt: z.string().describe('ISO 8601 last update timestamp'),
32
+ activatedAt: z.string().nullable().optional().describe('ISO 8601 activation timestamp'),
33
+ fulfilledAt: z.string().nullable().optional().describe('ISO 8601 fulfillment timestamp'),
34
+ lastVerdictReason: z.string().nullable().optional().describe('Reason from the most recent principal verdict'),
35
+ lastVerdictAt: z.string().nullable().optional().describe('ISO 8601 timestamp of the most recent verdict'),
36
+ nextSteps: NextStepsField,
37
+ }).passthrough().describe('AGLedger mandate object');
38
+
39
+ const SearchResultOutputSchema = z.object({
40
+ data: z.array(MandateOutputSchema).describe('Array of matching mandates'),
41
+ total: z.number().describe('Total count of matching mandates'),
42
+ limit: z.number().describe('Page size'),
43
+ offset: z.number().describe('Page offset'),
44
+ }).describe('Paginated mandate search results');
45
+
46
+ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): void {
47
+ mcp.registerTool(
48
+ 'create_mandate',
49
+ {
50
+ title: 'Create Mandate',
51
+ description: 'Create a new AGLedger mandate with acceptance criteria, contract type, and optional tolerance bands.',
52
+ inputSchema: {
53
+ enterpriseId: z.string().describe('Enterprise ID that owns this mandate'),
54
+ contractType: ContractTypeEnum,
55
+ contractVersion: z.string().describe('Contract version (e.g. "1.0")'),
56
+ platform: z.string().describe('Platform identifier (e.g. "openai", "anthropic")'),
57
+ platformRef: z.string().optional().describe('Platform-specific reference ID'),
58
+ criteria: z.record(z.string(), z.unknown()).describe('Acceptance criteria JSON object'),
59
+ tolerance: z.record(z.string(), z.unknown()).optional().describe('Tolerance bands for criteria'),
60
+ deadline: z.string().optional().describe('ISO 8601 deadline for mandate fulfillment'),
61
+ agentId: z.string().optional().describe('Agent ID to assign the mandate to'),
62
+ commissionPct: z.number().optional().describe('Commission percentage (0-100)'),
63
+ operatingMode: OperatingModeEnum.optional(),
64
+ verificationMode: z.enum(['auto', 'principal', 'gated']).optional().describe('Verification mode: auto (rules auto-settle, default), principal (hold for principal verdict), gated (run rules then hold for principal)'),
65
+ riskClassification: RiskClassificationEnum.optional(),
66
+ euAiActDomain: z.string().optional().describe('EU AI Act domain classification'),
67
+ humanOversight: z.record(z.string(), z.unknown()).optional().describe('Human oversight configuration'),
68
+ },
69
+ outputSchema: MandateOutputSchema,
70
+ annotations: {
71
+ readOnlyHint: false,
72
+ destructiveHint: false,
73
+ idempotentHint: false,
74
+ openWorldHint: true,
75
+ },
76
+ _meta: toolMeta('create_mandate'),
77
+ },
78
+ async (args) => {
79
+ try {
80
+ const mandate = await client.mandates.create(args);
81
+ return {
82
+ content: [{ type: 'text', text: `Mandate ${mandate.id} created with status ${mandate.status}.` }],
83
+ structuredContent: mandate as unknown as Record<string, unknown>,
84
+ };
85
+ } catch (err) {
86
+ return apiErrorResult(err);
87
+ }
88
+ },
89
+ );
90
+
91
+ mcp.registerTool(
92
+ 'get_mandate',
93
+ {
94
+ title: 'Get Mandate',
95
+ description: 'Retrieve an AGLedger mandate by its ID.',
96
+ inputSchema: {
97
+ mandateId: z.string().describe('UUID of the mandate to retrieve'),
98
+ },
99
+ outputSchema: MandateOutputSchema,
100
+ annotations: {
101
+ readOnlyHint: true,
102
+ destructiveHint: false,
103
+ idempotentHint: true,
104
+ openWorldHint: true,
105
+ },
106
+ _meta: toolMeta('get_mandate'),
107
+ },
108
+ async (args) => {
109
+ try {
110
+ const mandate = await client.mandates.get(args.mandateId);
111
+ return {
112
+ content: [{ type: 'text', text: `Mandate ${mandate.id}: status=${mandate.status}, type=${mandate.contractType}.` }],
113
+ structuredContent: mandate as unknown as Record<string, unknown>,
114
+ };
115
+ } catch (err) {
116
+ return apiErrorResult(err);
117
+ }
118
+ },
119
+ );
120
+
121
+ mcp.registerTool(
122
+ 'search_mandates',
123
+ {
124
+ title: 'Search Mandates',
125
+ description: 'Search AGLedger mandates with filters (status, contract type, agent, date range).',
126
+ inputSchema: {
127
+ enterpriseId: z.string().describe('Enterprise ID to search within (required)'),
128
+ status: MandateStatusEnum.optional().describe('Filter by mandate status'),
129
+ contractType: ContractTypeEnum.optional().describe('Filter by contract type'),
130
+ agentId: z.string().optional().describe('Filter by assigned agent ID'),
131
+ from: z.string().optional().describe('ISO 8601 start date filter'),
132
+ to: z.string().optional().describe('ISO 8601 end date filter'),
133
+ sort: z.string().optional().describe('Sort field (e.g. "createdAt")'),
134
+ order: z.enum(['asc', 'desc']).optional().describe('Sort order'),
135
+ limit: z.number().optional().describe('Page size (default: 20)'),
136
+ offset: z.number().optional().describe('Page offset (default: 0)'),
137
+ },
138
+ outputSchema: SearchResultOutputSchema,
139
+ annotations: {
140
+ readOnlyHint: true,
141
+ destructiveHint: false,
142
+ idempotentHint: true,
143
+ openWorldHint: true,
144
+ },
145
+ _meta: toolMeta('search_mandates'),
146
+ },
147
+ async (args) => {
148
+ try {
149
+ const result = await client.mandates.search(args);
150
+ return {
151
+ content: [{ type: 'text', text: `Found ${result.total} mandates (showing ${result.data.length}).` }],
152
+ structuredContent: result as unknown as Record<string, unknown>,
153
+ };
154
+ } catch (err) {
155
+ return apiErrorResult(err);
156
+ }
157
+ },
158
+ );
159
+
160
+ mcp.registerTool(
161
+ 'activate_mandate',
162
+ {
163
+ title: 'Activate Mandate',
164
+ description: 'Transition a mandate to ACTIVE status. The mandate must be in CREATED status.',
165
+ inputSchema: {
166
+ mandateId: z.string().describe('UUID of the mandate to activate'),
167
+ },
168
+ outputSchema: MandateOutputSchema,
169
+ annotations: {
170
+ readOnlyHint: false,
171
+ destructiveHint: false,
172
+ idempotentHint: true,
173
+ openWorldHint: true,
174
+ },
175
+ _meta: toolMeta('activate_mandate'),
176
+ },
177
+ async (args) => {
178
+ try {
179
+ const mandate = await client.mandates.transition(args.mandateId, 'activate');
180
+ return {
181
+ content: [{ type: 'text', text: `Mandate ${mandate.id} activated. Status is now ${mandate.status}.` }],
182
+ structuredContent: mandate as unknown as Record<string, unknown>,
183
+ };
184
+ } catch (err) {
185
+ return apiErrorResult(err);
186
+ }
187
+ },
188
+ );
189
+
190
+ mcp.registerTool(
191
+ 'cancel_mandate',
192
+ {
193
+ title: 'Cancel Mandate',
194
+ description: 'Cancel an AGLedger mandate. This is a destructive operation.',
195
+ inputSchema: {
196
+ mandateId: z.string().describe('UUID of the mandate to cancel'),
197
+ reason: z.string().optional().describe('Reason for cancellation'),
198
+ },
199
+ outputSchema: MandateOutputSchema,
200
+ annotations: {
201
+ readOnlyHint: false,
202
+ destructiveHint: true,
203
+ idempotentHint: false,
204
+ openWorldHint: true,
205
+ },
206
+ _meta: toolMeta('cancel_mandate'),
207
+ },
208
+ async (args) => {
209
+ try {
210
+ const mandate = await client.mandates.cancel(args.mandateId, args.reason);
211
+ return {
212
+ content: [{ type: 'text', text: `Mandate ${mandate.id} cancelled. Status is now ${mandate.status}.` }],
213
+ structuredContent: mandate as unknown as Record<string, unknown>,
214
+ };
215
+ } catch (err) {
216
+ return apiErrorResult(err);
217
+ }
218
+ },
219
+ );
220
+
221
+ mcp.registerTool(
222
+ 'update_mandate',
223
+ {
224
+ title: 'Update Mandate',
225
+ description: 'Update mutable fields on a CREATED mandate (criteria, deadline, commission). Cannot update after activation.',
226
+ inputSchema: {
227
+ mandateId: z.string().describe('UUID of the mandate to update'),
228
+ updates: z.record(z.string(), z.unknown()).describe('Fields to update (criteria, deadline, etc.)'),
229
+ },
230
+ outputSchema: MandateOutputSchema,
231
+ annotations: {
232
+ readOnlyHint: false,
233
+ destructiveHint: false,
234
+ idempotentHint: true,
235
+ openWorldHint: true,
236
+ },
237
+ _meta: toolMeta('update_mandate'),
238
+ },
239
+ async (args) => {
240
+ try {
241
+ const mandate = await client.mandates.update(args.mandateId, args.updates);
242
+ return {
243
+ content: [{ type: 'text', text: `Mandate ${mandate.id} updated. Status: ${mandate.status}.` }],
244
+ structuredContent: mandate as unknown as Record<string, unknown>,
245
+ };
246
+ } catch (err) {
247
+ return apiErrorResult(err);
248
+ }
249
+ },
250
+ );
251
+
252
+ mcp.registerTool(
253
+ 'request_revision',
254
+ {
255
+ title: 'Request Revision',
256
+ description: 'Request the performer to revise their submitted work. Use when a receipt was submitted but the evidence is insufficient. The performer can then submit a new receipt.',
257
+ inputSchema: {
258
+ mandateId: z.string().describe('UUID of the mandate to request revision for'),
259
+ reason: z.string().optional().describe('Why revision is needed'),
260
+ },
261
+ outputSchema: MandateOutputSchema,
262
+ annotations: {
263
+ readOnlyHint: false,
264
+ destructiveHint: false,
265
+ idempotentHint: false,
266
+ openWorldHint: true,
267
+ },
268
+ _meta: toolMeta('request_revision'),
269
+ },
270
+ async (args) => {
271
+ try {
272
+ const mandate = await client.mandates.requestRevision(args.mandateId, args.reason);
273
+ return {
274
+ content: [{ type: 'text', text: `Mandate ${mandate.id} moved to REVISION_REQUESTED. The performer should submit a new receipt.` }],
275
+ structuredContent: mandate as unknown as Record<string, unknown>,
276
+ };
277
+ } catch (err) {
278
+ return apiErrorResult(err);
279
+ }
280
+ },
281
+ );
282
+
283
+ mcp.registerTool(
284
+ 'delegate_mandate',
285
+ {
286
+ title: 'Delegate Mandate',
287
+ description: 'Delegate a mandate to another agent by creating a child mandate in the delegation chain.',
288
+ inputSchema: {
289
+ mandateId: z.string().describe('UUID of the parent mandate to delegate from'),
290
+ agentId: z.string().describe('Agent ID of the performer to delegate to'),
291
+ commissionPct: z.number().optional().describe('Commission percentage for the delegated agent'),
292
+ },
293
+ outputSchema: MandateOutputSchema,
294
+ annotations: {
295
+ readOnlyHint: false,
296
+ destructiveHint: false,
297
+ idempotentHint: false,
298
+ openWorldHint: true,
299
+ },
300
+ _meta: toolMeta('delegate_mandate'),
301
+ },
302
+ async (args) => {
303
+ try {
304
+ // Fetch the parent mandate to get contract details for delegation
305
+ const parent = await client.mandates.get(args.mandateId);
306
+ const childMandate = await client.mandates.delegate(args.mandateId, {
307
+ principalAgentId: parent.agentId ?? '',
308
+ performerAgentId: args.agentId,
309
+ contractType: parent.contractType,
310
+ contractVersion: parent.contractVersion,
311
+ platform: parent.platform,
312
+ criteria: parent.criteria,
313
+ commissionPct: args.commissionPct,
314
+ });
315
+ return {
316
+ content: [{ type: 'text', text: `Mandate ${args.mandateId} delegated to agent ${args.agentId}. Child mandate: ${childMandate.id}.` }],
317
+ structuredContent: childMandate as unknown as Record<string, unknown>,
318
+ };
319
+ } catch (err) {
320
+ return apiErrorResult(err);
321
+ }
322
+ },
323
+ );
324
+
325
+ mcp.registerTool(
326
+ 'get_mandate_graph',
327
+ {
328
+ title: 'Get Mandate Graph',
329
+ description: 'Get the delegation graph for a mandate. Returns nodes and edges representing the full delegation tree.',
330
+ inputSchema: {
331
+ mandateId: z.string().describe('UUID of the mandate to get the delegation graph for'),
332
+ },
333
+ annotations: {
334
+ readOnlyHint: true,
335
+ destructiveHint: false,
336
+ idempotentHint: true,
337
+ openWorldHint: true,
338
+ },
339
+ _meta: toolMeta('get_mandate_graph'),
340
+ },
341
+ async (args) => {
342
+ try {
343
+ const graph = await client.mandates.getGraph(args.mandateId);
344
+ const nodes = (graph as any).nodes?.length ?? 0;
345
+ const edges = (graph as any).edges?.length ?? 0;
346
+ return {
347
+ content: [{ type: 'text', text: `Delegation graph for mandate ${args.mandateId}: ${nodes} node(s), ${edges} edge(s).` }],
348
+ structuredContent: graph as unknown as Record<string, unknown>,
349
+ };
350
+ } catch (err) {
351
+ return apiErrorResult(err);
352
+ }
353
+ },
354
+ );
355
+
356
+ mcp.registerTool(
357
+ 'get_mandate_summary',
358
+ {
359
+ title: 'Get Mandate Summary',
360
+ description: 'Get mandate counts grouped by status. Use for dashboard-level visibility.',
361
+ inputSchema: {},
362
+ annotations: {
363
+ readOnlyHint: true,
364
+ destructiveHint: false,
365
+ idempotentHint: true,
366
+ openWorldHint: true,
367
+ },
368
+ _meta: toolMeta('get_mandate_summary'),
369
+ },
370
+ async () => {
371
+ try {
372
+ const summary = await client.mandates.getSummary();
373
+ return {
374
+ content: [{ type: 'text', text: `Mandate summary: ${JSON.stringify(summary)}.` }],
375
+ structuredContent: summary as unknown as Record<string, unknown>,
376
+ };
377
+ } catch (err) {
378
+ return apiErrorResult(err);
379
+ }
380
+ },
381
+ );
382
+ }
@@ -0,0 +1,168 @@
1
+ import { z } from 'zod';
2
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import type { AgledgerClient } from '@agledger/sdk';
4
+ import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
5
+ import { apiErrorResult } from '../errors.js';
6
+ import { toolMeta } from '../tool-scopes.js';
7
+
8
+ const NotarizeOutputSchema = z.object({
9
+ id: z.string().describe('Mandate ID'),
10
+ payloadHash: z.string().describe('Integrity hash'),
11
+ status: z.string().describe('Mandate status'),
12
+ contractType: z.string().describe('Contract type'),
13
+ }).passthrough().describe('Notarization result');
14
+
15
+ const MandateOutputSchema = z.object({
16
+ id: z.string().describe('Mandate ID'),
17
+ status: z.string().describe('Current status'),
18
+ contractType: z.string().describe('Contract type'),
19
+ }).passthrough().describe('Mandate details');
20
+
21
+ const ReceiptOutputSchema = z.object({
22
+ id: z.string().describe('Receipt ID'),
23
+ payloadHash: z.string().describe('Integrity hash'),
24
+ }).passthrough().describe('Receipt submission result');
25
+
26
+ function ok(text: string, data?: Record<string, unknown>): CallToolResult {
27
+ const result: CallToolResult = { content: [{ type: 'text', text }] };
28
+ if (data) result.structuredContent = data;
29
+ return result;
30
+ }
31
+
32
+ export function registerOpenClawTools(mcp: McpServer, client: AgledgerClient): void {
33
+
34
+ // 1. Notarize — create an agreement
35
+ mcp.registerTool(
36
+ 'agledger_notarize',
37
+ {
38
+ title: 'Notarize Agreement',
39
+ description: 'Create a notarized agreement. Returns mandate ID + hash. You keep the payload.',
40
+ inputSchema: {
41
+ contractType: z.string().describe('e.g. ACH-DLVR-v1, ACH-DATA-v1, ACH-ORCH-v1'),
42
+ payload: z.record(z.string(), z.unknown()).describe('Agreement criteria'),
43
+ performerHint: z.string().optional().describe('Who should do the work'),
44
+ },
45
+ outputSchema: NotarizeOutputSchema,
46
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
47
+ _meta: toolMeta('agledger_notarize'),
48
+ },
49
+ async (args) => {
50
+ try {
51
+ const result = await client.notarize.createMandate({
52
+ contractType: args.contractType as any,
53
+ payload: args.payload,
54
+ performerHint: args.performerHint,
55
+ });
56
+ return ok(
57
+ `Agreement ${result.id} notarized (${args.contractType}). Hash: ${result.payloadHash}. Send mandate ID + payload to performer, then call agledger_verdict after delivery.`,
58
+ result as unknown as Record<string, unknown>,
59
+ );
60
+ } catch (e) { return apiErrorResult(e); }
61
+ },
62
+ );
63
+
64
+ // 2. Accept — performer commits to the agreement
65
+ mcp.registerTool(
66
+ 'agledger_accept',
67
+ {
68
+ title: 'Accept Agreement',
69
+ description: 'Accept a notarized agreement. Signals commitment to deliver.',
70
+ inputSchema: {
71
+ mandateId: z.string().describe('Mandate ID to accept'),
72
+ },
73
+ outputSchema: MandateOutputSchema,
74
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
75
+ _meta: toolMeta('agledger_accept'),
76
+ },
77
+ async (args) => {
78
+ try {
79
+ const mandate = await client.notarize.acceptMandate(args.mandateId);
80
+ return ok(
81
+ `Agreement ${mandate.id} accepted. Do the work, then call agledger_receipt.`,
82
+ mandate as unknown as Record<string, unknown>,
83
+ );
84
+ } catch (e) { return apiErrorResult(e); }
85
+ },
86
+ );
87
+
88
+ // 3. Receipt — performer submits evidence of completion
89
+ mcp.registerTool(
90
+ 'agledger_receipt',
91
+ {
92
+ title: 'Submit Receipt',
93
+ description: 'Submit evidence of completed work. Returns receipt hash.',
94
+ inputSchema: {
95
+ mandateId: z.string().describe('Mandate ID this receipt is for'),
96
+ payload: z.record(z.string(), z.unknown()).describe('Evidence of completion'),
97
+ },
98
+ outputSchema: ReceiptOutputSchema,
99
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
100
+ _meta: toolMeta('agledger_receipt'),
101
+ },
102
+ async (args) => {
103
+ try {
104
+ const result = await client.notarize.submitReceipt(args.mandateId, {
105
+ payload: args.payload,
106
+ });
107
+ return ok(
108
+ `Receipt ${result.id} submitted for ${args.mandateId}. Hash: ${result.payloadHash}. Principal should call agledger_verdict.`,
109
+ result as unknown as Record<string, unknown>,
110
+ );
111
+ } catch (e) { return apiErrorResult(e); }
112
+ },
113
+ );
114
+
115
+ // 4. Verdict — principal accepts or rejects delivery
116
+ mcp.registerTool(
117
+ 'agledger_verdict',
118
+ {
119
+ title: 'Render Verdict',
120
+ description: 'Accept or reject delivered work. Closes the agreement.',
121
+ inputSchema: {
122
+ mandateId: z.string().describe('Mandate ID'),
123
+ verdict: z.enum(['PASS', 'FAIL']).describe('PASS to accept, FAIL to reject'),
124
+ reason: z.string().optional().describe('Why'),
125
+ },
126
+ outputSchema: MandateOutputSchema,
127
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
128
+ _meta: toolMeta('agledger_verdict'),
129
+ },
130
+ async (args) => {
131
+ try {
132
+ const mandate = await client.notarize.renderVerdict(args.mandateId, {
133
+ verdict: args.verdict,
134
+ reason: args.reason,
135
+ });
136
+ const verb = args.verdict === 'PASS' ? 'accepted' : 'rejected';
137
+ return ok(
138
+ `Agreement ${mandate.id} ${verb}. Status: ${mandate.status}.`,
139
+ mandate as unknown as Record<string, unknown>,
140
+ );
141
+ } catch (e) { return apiErrorResult(e); }
142
+ },
143
+ );
144
+
145
+ // 5. Status — check agreement state
146
+ mcp.registerTool(
147
+ 'agledger_status',
148
+ {
149
+ title: 'Agreement Status',
150
+ description: 'Check current state of an agreement.',
151
+ inputSchema: {
152
+ mandateId: z.string().describe('Mandate ID'),
153
+ },
154
+ outputSchema: MandateOutputSchema,
155
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
156
+ _meta: toolMeta('agledger_status'),
157
+ },
158
+ async (args) => {
159
+ try {
160
+ const mandate = await client.notarize.getMandate(args.mandateId);
161
+ return ok(
162
+ `Agreement ${mandate.id}: ${mandate.status} (${mandate.contractType})`,
163
+ mandate as unknown as Record<string, unknown>,
164
+ );
165
+ } catch (e) { return apiErrorResult(e); }
166
+ },
167
+ );
168
+ }