@agledger/mcp-server 1.4.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/dist/errors.d.ts +6 -0
  2. package/dist/errors.d.ts.map +1 -1
  3. package/dist/errors.js +8 -0
  4. package/dist/errors.js.map +1 -1
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +0 -2
  7. package/dist/index.js.map +1 -1
  8. package/dist/server.d.ts +6 -2
  9. package/dist/server.d.ts.map +1 -1
  10. package/dist/server.js +71 -76
  11. package/dist/server.js.map +1 -1
  12. package/dist/tool-scopes.js +3 -2
  13. package/dist/tool-scopes.js.map +1 -1
  14. package/dist/tools/a2a.d.ts.map +1 -1
  15. package/dist/tools/a2a.js +22 -222
  16. package/dist/tools/a2a.js.map +1 -1
  17. package/dist/tools/agent-mandates.d.ts.map +1 -1
  18. package/dist/tools/agent-mandates.js +11 -75
  19. package/dist/tools/agent-mandates.js.map +1 -1
  20. package/dist/tools/agents-refs.d.ts.map +1 -1
  21. package/dist/tools/agents-refs.js +10 -61
  22. package/dist/tools/agents-refs.js.map +1 -1
  23. package/dist/tools/capabilities.d.ts.map +1 -1
  24. package/dist/tools/capabilities.js +3 -15
  25. package/dist/tools/capabilities.js.map +1 -1
  26. package/dist/tools/code-mode.d.ts.map +1 -1
  27. package/dist/tools/code-mode.js +4 -35
  28. package/dist/tools/code-mode.js.map +1 -1
  29. package/dist/tools/compliance.d.ts.map +1 -1
  30. package/dist/tools/compliance.js +4 -13
  31. package/dist/tools/compliance.js.map +1 -1
  32. package/dist/tools/dashboard.d.ts.map +1 -1
  33. package/dist/tools/dashboard.js +4 -13
  34. package/dist/tools/dashboard.js.map +1 -1
  35. package/dist/tools/disputes.d.ts.map +1 -1
  36. package/dist/tools/disputes.js +5 -37
  37. package/dist/tools/disputes.js.map +1 -1
  38. package/dist/tools/enterprises.d.ts.map +1 -1
  39. package/dist/tools/enterprises.js +7 -39
  40. package/dist/tools/enterprises.js.map +1 -1
  41. package/dist/tools/events.d.ts.map +1 -1
  42. package/dist/tools/events.js +2 -20
  43. package/dist/tools/events.js.map +1 -1
  44. package/dist/tools/federation-admin.d.ts.map +1 -1
  45. package/dist/tools/federation-admin.js +25 -257
  46. package/dist/tools/federation-admin.js.map +1 -1
  47. package/dist/tools/federation.d.ts.map +1 -1
  48. package/dist/tools/federation.js +21 -198
  49. package/dist/tools/federation.js.map +1 -1
  50. package/dist/tools/health.d.ts.map +1 -1
  51. package/dist/tools/health.js +2 -14
  52. package/dist/tools/health.js.map +1 -1
  53. package/dist/tools/mandates.d.ts.map +1 -1
  54. package/dist/tools/mandates.js +11 -83
  55. package/dist/tools/mandates.js.map +1 -1
  56. package/dist/tools/openclaw.d.ts.map +1 -1
  57. package/dist/tools/openclaw.js +6 -33
  58. package/dist/tools/openclaw.js.map +1 -1
  59. package/dist/tools/receipts.d.ts.map +1 -1
  60. package/dist/tools/receipts.js +5 -96
  61. package/dist/tools/receipts.js.map +1 -1
  62. package/dist/tools/reputation.d.ts.map +1 -1
  63. package/dist/tools/reputation.js +4 -13
  64. package/dist/tools/reputation.js.map +1 -1
  65. package/dist/tools/schemas.d.ts.map +1 -1
  66. package/dist/tools/schemas.js +34 -159
  67. package/dist/tools/schemas.js.map +1 -1
  68. package/dist/tools/verification-keys.d.ts.map +1 -1
  69. package/dist/tools/verification-keys.js +2 -23
  70. package/dist/tools/verification-keys.js.map +1 -1
  71. package/dist/tools/verification.d.ts.map +1 -1
  72. package/dist/tools/verification.js +3 -28
  73. package/dist/tools/verification.js.map +1 -1
  74. package/package.json +1 -1
  75. package/src/errors.ts +9 -0
  76. package/src/index.ts +1 -3
  77. package/src/server.ts +77 -71
  78. package/src/tool-scopes.ts +3 -3
  79. package/src/tools/a2a.ts +22 -235
  80. package/src/tools/agent-mandates.ts +11 -77
  81. package/src/tools/agents-refs.ts +10 -65
  82. package/src/tools/capabilities.ts +3 -16
  83. package/src/tools/compliance.ts +4 -13
  84. package/src/tools/dashboard.ts +4 -13
  85. package/src/tools/disputes.ts +5 -38
  86. package/src/tools/enterprises.ts +7 -39
  87. package/src/tools/events.ts +2 -21
  88. package/src/tools/federation-admin.ts +25 -282
  89. package/src/tools/federation.ts +21 -218
  90. package/src/tools/health.ts +2 -15
  91. package/src/tools/mandates.ts +11 -85
  92. package/src/tools/openclaw.ts +6 -52
  93. package/src/tools/receipts.ts +5 -97
  94. package/src/tools/reputation.ts +4 -13
  95. package/src/tools/schemas.ts +34 -166
  96. package/src/tools/verification-keys.ts +2 -25
  97. package/src/tools/verification.ts +3 -30
  98. package/tests/conformance.test.ts +197 -0
  99. package/tests/conformance.ts +65 -0
  100. package/tests/harness.ts +55 -0
  101. package/tests/mock-client.ts +71 -0
  102. package/tests/profiles.test.ts +120 -0
  103. package/tests/resources/contract-types.test.ts +82 -0
  104. package/tests/tools/a2a.test.ts +213 -0
  105. package/tests/tools/agent-mandates.test.ts +196 -0
  106. package/tests/tools/agents-refs.test.ts +190 -0
  107. package/tests/tools/capabilities.test.ts +80 -0
  108. package/tests/tools/compliance.test.ts +123 -0
  109. package/tests/tools/dashboard.test.ts +111 -0
  110. package/tests/tools/disputes.test.ts +123 -0
  111. package/tests/tools/enterprises.test.ts +171 -0
  112. package/tests/tools/events.test.ts +56 -0
  113. package/tests/tools/federation-admin.test.ts +468 -0
  114. package/tests/tools/federation.test.ts +522 -0
  115. package/tests/tools/health.test.ts +56 -0
  116. package/tests/tools/mandates.test.ts +143 -0
  117. package/tests/tools/openclaw.test.ts +148 -0
  118. package/tests/tools/receipts.test.ts +157 -0
  119. package/tests/tools/reputation.test.ts +108 -0
  120. package/tests/tools/schemas.test.ts +374 -0
  121. package/tests/tools/verification-keys.test.ts +56 -0
  122. package/tests/tools/verification.test.ts +64 -0
  123. package/src/tools/code-mode.ts +0 -461
  124. package/tests/code-mode-manifest.test.ts +0 -144
  125. package/tests/enterprises.test.ts +0 -96
  126. package/tests/schemas.test.ts +0 -531
@@ -1,48 +1,10 @@
1
1
  import { z } from 'zod';
2
2
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
  import type { AgledgerClient } from '@agledger/sdk';
4
- import { apiErrorResult } from '../errors.js';
5
- import { ContractTypeEnum, MandateStatusEnum, NextStepsField, OperatingModeEnum, RiskClassificationEnum } from '../enums.js';
4
+ import { apiErrorResult, toStructuredContent } from '../errors.js';
5
+ import { ContractTypeEnum, MandateStatusEnum } from '../enums.js';
6
6
  import { toolMeta } from '../tool-scopes.js';
7
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
8
  export function registerMandateTools(mcp: McpServer, client: AgledgerClient): void {
47
9
  mcp.registerTool(
48
10
  'get_mandate',
@@ -52,7 +14,6 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
52
14
  inputSchema: {
53
15
  mandateId: z.string().describe('UUID of the mandate to retrieve'),
54
16
  },
55
- outputSchema: MandateOutputSchema,
56
17
  annotations: {
57
18
  readOnlyHint: true,
58
19
  destructiveHint: false,
@@ -64,10 +25,7 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
64
25
  async (args) => {
65
26
  try {
66
27
  const mandate = await client.mandates.get(args.mandateId);
67
- return {
68
- content: [{ type: 'text', text: `Mandate ${mandate.id}: status=${mandate.status}, type=${mandate.contractType}.` }],
69
- structuredContent: mandate as unknown as Record<string, unknown>,
70
- };
28
+ return { content: [], structuredContent: toStructuredContent(mandate) };
71
29
  } catch (err) {
72
30
  return apiErrorResult(err);
73
31
  }
@@ -91,7 +49,6 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
91
49
  limit: z.number().optional().describe('Page size (default: 20)'),
92
50
  offset: z.number().optional().describe('Page offset (default: 0)'),
93
51
  },
94
- outputSchema: SearchResultOutputSchema,
95
52
  annotations: {
96
53
  readOnlyHint: true,
97
54
  destructiveHint: false,
@@ -103,10 +60,7 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
103
60
  async (args) => {
104
61
  try {
105
62
  const result = await client.mandates.search(args);
106
- return {
107
- content: [{ type: 'text', text: `Found ${result.total} mandates (showing ${result.data.length}).` }],
108
- structuredContent: result as unknown as Record<string, unknown>,
109
- };
63
+ return { content: [], structuredContent: toStructuredContent(result) };
110
64
  } catch (err) {
111
65
  return apiErrorResult(err);
112
66
  }
@@ -121,7 +75,6 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
121
75
  inputSchema: {
122
76
  mandateId: z.string().describe('UUID of the mandate to activate'),
123
77
  },
124
- outputSchema: MandateOutputSchema,
125
78
  annotations: {
126
79
  readOnlyHint: false,
127
80
  destructiveHint: false,
@@ -133,10 +86,7 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
133
86
  async (args) => {
134
87
  try {
135
88
  const mandate = await client.mandates.transition(args.mandateId, 'activate');
136
- return {
137
- content: [{ type: 'text', text: `Mandate ${mandate.id} activated. Status is now ${mandate.status}.` }],
138
- structuredContent: mandate as unknown as Record<string, unknown>,
139
- };
89
+ return { content: [], structuredContent: toStructuredContent(mandate) };
140
90
  } catch (err) {
141
91
  return apiErrorResult(err);
142
92
  }
@@ -152,7 +102,6 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
152
102
  mandateId: z.string().describe('UUID of the mandate to cancel'),
153
103
  reason: z.string().optional().describe('Reason for cancellation'),
154
104
  },
155
- outputSchema: MandateOutputSchema,
156
105
  annotations: {
157
106
  readOnlyHint: false,
158
107
  destructiveHint: true,
@@ -164,10 +113,7 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
164
113
  async (args) => {
165
114
  try {
166
115
  const mandate = await client.mandates.cancel(args.mandateId, args.reason);
167
- return {
168
- content: [{ type: 'text', text: `Mandate ${mandate.id} cancelled. Status is now ${mandate.status}.` }],
169
- structuredContent: mandate as unknown as Record<string, unknown>,
170
- };
116
+ return { content: [], structuredContent: toStructuredContent(mandate) };
171
117
  } catch (err) {
172
118
  return apiErrorResult(err);
173
119
  }
@@ -183,7 +129,6 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
183
129
  mandateId: z.string().describe('UUID of the mandate to update'),
184
130
  updates: z.record(z.string(), z.unknown()).describe('Fields to update (criteria, deadline, etc.)'),
185
131
  },
186
- outputSchema: MandateOutputSchema,
187
132
  annotations: {
188
133
  readOnlyHint: false,
189
134
  destructiveHint: false,
@@ -195,10 +140,7 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
195
140
  async (args) => {
196
141
  try {
197
142
  const mandate = await client.mandates.update(args.mandateId, args.updates);
198
- return {
199
- content: [{ type: 'text', text: `Mandate ${mandate.id} updated. Status: ${mandate.status}.` }],
200
- structuredContent: mandate as unknown as Record<string, unknown>,
201
- };
143
+ return { content: [], structuredContent: toStructuredContent(mandate) };
202
144
  } catch (err) {
203
145
  return apiErrorResult(err);
204
146
  }
@@ -214,7 +156,6 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
214
156
  mandateId: z.string().describe('UUID of the mandate to request revision for'),
215
157
  reason: z.string().optional().describe('Why revision is needed'),
216
158
  },
217
- outputSchema: MandateOutputSchema,
218
159
  annotations: {
219
160
  readOnlyHint: false,
220
161
  destructiveHint: false,
@@ -226,10 +167,7 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
226
167
  async (args) => {
227
168
  try {
228
169
  const mandate = await client.mandates.requestRevision(args.mandateId, args.reason);
229
- return {
230
- content: [{ type: 'text', text: `Mandate ${mandate.id} moved to REVISION_REQUESTED. The performer should submit a new receipt.` }],
231
- structuredContent: mandate as unknown as Record<string, unknown>,
232
- };
170
+ return { content: [], structuredContent: toStructuredContent(mandate) };
233
171
  } catch (err) {
234
172
  return apiErrorResult(err);
235
173
  }
@@ -246,7 +184,6 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
246
184
  agentId: z.string().describe('Agent ID of the performer to delegate to'),
247
185
  commissionPct: z.number().optional().describe('Commission percentage for the delegated agent'),
248
186
  },
249
- outputSchema: MandateOutputSchema,
250
187
  annotations: {
251
188
  readOnlyHint: false,
252
189
  destructiveHint: false,
@@ -268,10 +205,7 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
268
205
  criteria: parent.criteria,
269
206
  commissionPct: args.commissionPct,
270
207
  });
271
- return {
272
- content: [{ type: 'text', text: `Mandate ${args.mandateId} delegated to agent ${args.agentId}. Child mandate: ${childMandate.id}.` }],
273
- structuredContent: childMandate as unknown as Record<string, unknown>,
274
- };
208
+ return { content: [], structuredContent: toStructuredContent(childMandate) };
275
209
  } catch (err) {
276
210
  return apiErrorResult(err);
277
211
  }
@@ -297,12 +231,7 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
297
231
  async (args) => {
298
232
  try {
299
233
  const graph = await client.mandates.getGraph(args.mandateId);
300
- const nodes = (graph as any).nodes?.length ?? 0;
301
- const edges = (graph as any).edges?.length ?? 0;
302
- return {
303
- content: [{ type: 'text', text: `Delegation graph for mandate ${args.mandateId}: ${nodes} node(s), ${edges} edge(s).` }],
304
- structuredContent: graph as unknown as Record<string, unknown>,
305
- };
234
+ return { content: [], structuredContent: toStructuredContent(graph) };
306
235
  } catch (err) {
307
236
  return apiErrorResult(err);
308
237
  }
@@ -326,10 +255,7 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
326
255
  async () => {
327
256
  try {
328
257
  const summary = await client.mandates.getSummary();
329
- return {
330
- content: [{ type: 'text', text: `Mandate summary: ${JSON.stringify(summary)}.` }],
331
- structuredContent: summary as unknown as Record<string, unknown>,
332
- };
258
+ return { content: [], structuredContent: toStructuredContent(summary) };
333
259
  } catch (err) {
334
260
  return apiErrorResult(err);
335
261
  }
@@ -1,34 +1,9 @@
1
1
  import { z } from 'zod';
2
2
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
  import type { AgledgerClient } from '@agledger/sdk';
4
- import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
5
- import { apiErrorResult } from '../errors.js';
4
+ import { apiErrorResult, toStructuredContent } from '../errors.js';
6
5
  import { toolMeta } from '../tool-scopes.js';
7
6
 
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
7
  export function registerOpenClawTools(mcp: McpServer, client: AgledgerClient): void {
33
8
 
34
9
  // 1. Notarize — create an agreement
@@ -42,7 +17,6 @@ export function registerOpenClawTools(mcp: McpServer, client: AgledgerClient): v
42
17
  payload: z.record(z.string(), z.unknown()).describe('Agreement criteria'),
43
18
  performerHint: z.string().optional().describe('Who should do the work'),
44
19
  },
45
- outputSchema: NotarizeOutputSchema,
46
20
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
47
21
  _meta: toolMeta('agledger_notarize'),
48
22
  },
@@ -53,10 +27,7 @@ export function registerOpenClawTools(mcp: McpServer, client: AgledgerClient): v
53
27
  payload: args.payload,
54
28
  performerHint: args.performerHint,
55
29
  });
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
- );
30
+ return { content: [], structuredContent: toStructuredContent(result) };
60
31
  } catch (e) { return apiErrorResult(e); }
61
32
  },
62
33
  );
@@ -70,17 +41,13 @@ export function registerOpenClawTools(mcp: McpServer, client: AgledgerClient): v
70
41
  inputSchema: {
71
42
  mandateId: z.string().describe('Mandate ID to accept'),
72
43
  },
73
- outputSchema: MandateOutputSchema,
74
44
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
75
45
  _meta: toolMeta('agledger_accept'),
76
46
  },
77
47
  async (args) => {
78
48
  try {
79
49
  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
- );
50
+ return { content: [], structuredContent: toStructuredContent(mandate) };
84
51
  } catch (e) { return apiErrorResult(e); }
85
52
  },
86
53
  );
@@ -95,7 +62,6 @@ export function registerOpenClawTools(mcp: McpServer, client: AgledgerClient): v
95
62
  mandateId: z.string().describe('Mandate ID this receipt is for'),
96
63
  payload: z.record(z.string(), z.unknown()).describe('Evidence of completion'),
97
64
  },
98
- outputSchema: ReceiptOutputSchema,
99
65
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
100
66
  _meta: toolMeta('agledger_receipt'),
101
67
  },
@@ -104,10 +70,7 @@ export function registerOpenClawTools(mcp: McpServer, client: AgledgerClient): v
104
70
  const result = await client.notarize.submitReceipt(args.mandateId, {
105
71
  payload: args.payload,
106
72
  });
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
- );
73
+ return { content: [], structuredContent: toStructuredContent(result) };
111
74
  } catch (e) { return apiErrorResult(e); }
112
75
  },
113
76
  );
@@ -123,7 +86,6 @@ export function registerOpenClawTools(mcp: McpServer, client: AgledgerClient): v
123
86
  verdict: z.enum(['PASS', 'FAIL']).describe('PASS to accept, FAIL to reject'),
124
87
  reason: z.string().optional().describe('Why'),
125
88
  },
126
- outputSchema: MandateOutputSchema,
127
89
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
128
90
  _meta: toolMeta('agledger_verdict'),
129
91
  },
@@ -133,11 +95,7 @@ export function registerOpenClawTools(mcp: McpServer, client: AgledgerClient): v
133
95
  verdict: args.verdict,
134
96
  reason: args.reason,
135
97
  });
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
- );
98
+ return { content: [], structuredContent: toStructuredContent(mandate) };
141
99
  } catch (e) { return apiErrorResult(e); }
142
100
  },
143
101
  );
@@ -151,17 +109,13 @@ export function registerOpenClawTools(mcp: McpServer, client: AgledgerClient): v
151
109
  inputSchema: {
152
110
  mandateId: z.string().describe('Mandate ID'),
153
111
  },
154
- outputSchema: MandateOutputSchema,
155
112
  annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
156
113
  _meta: toolMeta('agledger_status'),
157
114
  },
158
115
  async (args) => {
159
116
  try {
160
117
  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
- );
118
+ return { content: [], structuredContent: toStructuredContent(mandate) };
165
119
  } catch (e) { return apiErrorResult(e); }
166
120
  },
167
121
  );
@@ -1,52 +1,9 @@
1
1
  import { z } from 'zod';
2
2
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
  import type { AgledgerClient } from '@agledger/sdk';
4
- import { apiErrorResult } from '../errors.js';
5
- import { NextStepsField, StructuralValidationEnum } from '../enums.js';
4
+ import { apiErrorResult, toStructuredContent } from '../errors.js';
6
5
  import { toolMeta } from '../tool-scopes.js';
7
6
 
8
- const ReceiptOutputSchema = z
9
- .object({
10
- id: z.string().describe('Receipt UUID'),
11
- mandateId: z.string().describe('Associated mandate UUID'),
12
- agentId: z.string().describe('Agent that submitted the receipt'),
13
- structuralValidation: StructuralValidationEnum.nullable()
14
- .optional()
15
- .describe('Structural validation result'),
16
- evidence: z.record(z.string(), z.unknown()).describe('Evidence payload'),
17
- evidenceHash: z.string().nullable().optional().describe('SHA-256 hash of evidence'),
18
- notes: z.string().nullable().optional().describe('Human-readable notes'),
19
- verificationPhase: z.string().nullable().optional().describe('Current verification phase'),
20
- verificationResult: z
21
- .record(z.string(), z.unknown())
22
- .nullable()
23
- .optional()
24
- .describe('Verification result details'),
25
- validationErrors: z
26
- .array(z.string())
27
- .nullable()
28
- .optional()
29
- .describe('Validation errors if any'),
30
- idempotencyKey: z.string().nullable().optional().describe('Idempotency key for deduplication'),
31
- createdAt: z.string().describe('ISO 8601 creation timestamp'),
32
- updatedAt: z.string().nullable().optional().describe('ISO 8601 last update timestamp'),
33
- nextSteps: NextStepsField,
34
- })
35
- .passthrough()
36
- .describe('AGLedger receipt (task attestation) object');
37
-
38
- const ReceiptListOutputSchema = z
39
- .object({
40
- data: z.array(ReceiptOutputSchema).describe('Array of receipts for the mandate'),
41
- nextCursor: z
42
- .string()
43
- .nullable()
44
- .optional()
45
- .describe('Cursor for the next page (null if no more results)'),
46
- })
47
- .passthrough()
48
- .describe('List of receipts for a mandate');
49
-
50
7
  export interface ReceiptToolsOptions {
51
8
  /** Skip submit_receipt (e.g. when a2a tools already provide it). */
52
9
  skipSubmit?: boolean;
@@ -61,13 +18,11 @@ export function registerReceiptTools(mcp: McpServer, client: AgledgerClient, opt
61
18
  'Submit a task attestation (receipt) with evidence against a mandate. REQUIRED to close the accountability loop — do NOT skip this step after completing work.',
62
19
  inputSchema: {
63
20
  mandateId: z.string().describe('UUID of the mandate this receipt is for'),
64
- agentId: z.string().describe('Agent ID submitting the receipt'),
65
21
  evidence: z
66
22
  .record(z.string(), z.unknown())
67
23
  .describe('Evidence JSON object proving task completion'),
68
24
  notes: z.string().optional().describe('Human-readable notes about the submission'),
69
25
  },
70
- outputSchema: ReceiptOutputSchema,
71
26
  annotations: {
72
27
  readOnlyHint: false,
73
28
  destructiveHint: false,
@@ -80,18 +35,7 @@ export function registerReceiptTools(mcp: McpServer, client: AgledgerClient, opt
80
35
  try {
81
36
  const { mandateId, ...submitParams } = args;
82
37
  const receipt = await client.receipts.submit(mandateId, submitParams);
83
- let text = `Receipt ${receipt.id} submitted for mandate ${mandateId}. Status: ${receipt.structuralValidation}.`;
84
- // Use denormalized mandateStatus from receipt response (no extra API call)
85
- const ms = receipt.mandateStatus;
86
- if (ms === 'FULFILLED') {
87
- text += '\n\nMandate settled to FULFILLED. Accountability loop closed.';
88
- } else if (ms === 'PROCESSING') {
89
- text += '\n\nEvidence is being verified. The principal will accept or reject.';
90
- }
91
- return {
92
- content: [{ type: 'text', text }],
93
- structuredContent: receipt as unknown as Record<string, unknown>,
94
- };
38
+ return { content: [], structuredContent: toStructuredContent(receipt) };
95
39
  } catch (err) {
96
40
  return apiErrorResult(err);
97
41
  }
@@ -113,18 +57,6 @@ export function registerReceiptTools(mcp: McpServer, client: AgledgerClient, opt
113
57
  .optional()
114
58
  .describe('Optional per-field check results'),
115
59
  },
116
- outputSchema: z
117
- .object({
118
- mandateId: z.string().describe('Mandate UUID'),
119
- receiptId: z.string().describe('Receipt UUID'),
120
- outcome: z.enum(['PASS', 'FAIL']).describe('Reported outcome'),
121
- signal: z.string().describe('Settlement signal: SETTLE, HOLD, or RELEASE'),
122
- reporterType: z.string().describe('Who reported: principal'),
123
- reportedAt: z.string().describe('ISO 8601 timestamp'),
124
- nextSteps: NextStepsField,
125
- })
126
- .passthrough()
127
- .describe('Outcome result'),
128
60
  annotations: {
129
61
  readOnlyHint: false,
130
62
  destructiveHint: false,
@@ -137,13 +69,7 @@ export function registerReceiptTools(mcp: McpServer, client: AgledgerClient, opt
137
69
  try {
138
70
  const { mandateId, ...outcomeParams } = args;
139
71
  const result = await client.mandates.reportOutcome(mandateId, outcomeParams);
140
- const verb = result.outcome === 'PASS' ? 'accepted' : 'rejected';
141
- return {
142
- content: [
143
- { type: 'text', text: `Receipt ${args.receiptId} ${verb}. Signal: ${result.signal}.` },
144
- ],
145
- structuredContent: result as unknown as Record<string, unknown>,
146
- };
72
+ return { content: [], structuredContent: toStructuredContent(result) };
147
73
  } catch (err) {
148
74
  return apiErrorResult(err);
149
75
  }
@@ -159,7 +85,6 @@ export function registerReceiptTools(mcp: McpServer, client: AgledgerClient, opt
159
85
  mandateId: z.string().describe('UUID of the associated mandate'),
160
86
  receiptId: z.string().describe('UUID of the receipt to retrieve'),
161
87
  },
162
- outputSchema: ReceiptOutputSchema,
163
88
  annotations: {
164
89
  readOnlyHint: true,
165
90
  destructiveHint: false,
@@ -171,15 +96,7 @@ export function registerReceiptTools(mcp: McpServer, client: AgledgerClient, opt
171
96
  async (args) => {
172
97
  try {
173
98
  const receipt = await client.receipts.get(args.mandateId, args.receiptId);
174
- return {
175
- content: [
176
- {
177
- type: 'text',
178
- text: `Receipt ${receipt.id}: status=${receipt.structuralValidation}, mandate=${receipt.mandateId}.`,
179
- },
180
- ],
181
- structuredContent: receipt as unknown as Record<string, unknown>,
182
- };
99
+ return { content: [], structuredContent: toStructuredContent(receipt) };
183
100
  } catch (err) {
184
101
  return apiErrorResult(err);
185
102
  }
@@ -196,7 +113,6 @@ export function registerReceiptTools(mcp: McpServer, client: AgledgerClient, opt
196
113
  limit: z.number().optional().describe('Page size (default: 20)'),
197
114
  offset: z.number().optional().describe('Page offset (default: 0)'),
198
115
  },
199
- outputSchema: ReceiptListOutputSchema,
200
116
  annotations: {
201
117
  readOnlyHint: true,
202
118
  destructiveHint: false,
@@ -209,15 +125,7 @@ export function registerReceiptTools(mcp: McpServer, client: AgledgerClient, opt
209
125
  try {
210
126
  const { mandateId, ...paginationParams } = args;
211
127
  const result = await client.receipts.list(mandateId, paginationParams);
212
- return {
213
- content: [
214
- {
215
- type: 'text',
216
- text: `Found ${result.data.length} receipts for mandate ${mandateId}.`,
217
- },
218
- ],
219
- structuredContent: result as unknown as Record<string, unknown>,
220
- };
128
+ return { content: [], structuredContent: toStructuredContent(result) };
221
129
  } catch (err) {
222
130
  return apiErrorResult(err);
223
131
  }
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
  import type { AgledgerClient } from '@agledger/sdk';
4
- import { apiErrorResult } from '../errors.js';
4
+ import { apiErrorResult, toStructuredContent } from '../errors.js';
5
5
  import { toolMeta } from '../tool-scopes.js';
6
6
 
7
7
  export function registerReputationTools(mcp: McpServer, client: AgledgerClient): void {
@@ -19,10 +19,7 @@ export function registerReputationTools(mcp: McpServer, client: AgledgerClient):
19
19
  async (args) => {
20
20
  try {
21
21
  const page = await client.reputation.getAgent(args.agentId);
22
- return {
23
- content: [{ type: 'text', text: `Agent ${args.agentId}: ${page.data.length} contract type score(s).` }],
24
- structuredContent: page as unknown as Record<string, unknown>,
25
- };
22
+ return { content: [], structuredContent: toStructuredContent(page) };
26
23
  } catch (err) { return apiErrorResult(err); }
27
24
  },
28
25
  );
@@ -42,10 +39,7 @@ export function registerReputationTools(mcp: McpServer, client: AgledgerClient):
42
39
  async (args) => {
43
40
  try {
44
41
  const score = await client.reputation.getByContractType(args.agentId, args.contractType);
45
- return {
46
- content: [{ type: 'text', text: `Agent ${args.agentId} [${args.contractType}]: composite=${score.compositeScore}, reliability=${score.reliabilityScore}, accuracy=${score.accuracyScore}, efficiency=${score.efficiencyScore}.` }],
47
- structuredContent: score as unknown as Record<string, unknown>,
48
- };
42
+ return { content: [], structuredContent: toStructuredContent(score) };
49
43
  } catch (err) { return apiErrorResult(err); }
50
44
  },
51
45
  );
@@ -68,10 +62,7 @@ export function registerReputationTools(mcp: McpServer, client: AgledgerClient):
68
62
  try {
69
63
  const { agentId, ...params } = args;
70
64
  const page = await client.reputation.getHistory(agentId, params);
71
- return {
72
- content: [{ type: 'text', text: `Agent ${agentId}: ${page.data.length} transaction(s).` }],
73
- structuredContent: page as unknown as Record<string, unknown>,
74
- };
65
+ return { content: [], structuredContent: toStructuredContent(page) };
75
66
  } catch (err) { return apiErrorResult(err); }
76
67
  },
77
68
  );