@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.
- package/dist/errors.d.ts +6 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +8 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +6 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +71 -76
- package/dist/server.js.map +1 -1
- package/dist/tool-scopes.js +3 -2
- package/dist/tool-scopes.js.map +1 -1
- package/dist/tools/a2a.d.ts.map +1 -1
- package/dist/tools/a2a.js +22 -222
- package/dist/tools/a2a.js.map +1 -1
- package/dist/tools/agent-mandates.d.ts.map +1 -1
- package/dist/tools/agent-mandates.js +11 -75
- package/dist/tools/agent-mandates.js.map +1 -1
- package/dist/tools/agents-refs.d.ts.map +1 -1
- package/dist/tools/agents-refs.js +10 -61
- package/dist/tools/agents-refs.js.map +1 -1
- package/dist/tools/capabilities.d.ts.map +1 -1
- package/dist/tools/capabilities.js +3 -15
- package/dist/tools/capabilities.js.map +1 -1
- package/dist/tools/code-mode.d.ts.map +1 -1
- package/dist/tools/code-mode.js +4 -35
- package/dist/tools/code-mode.js.map +1 -1
- package/dist/tools/compliance.d.ts.map +1 -1
- package/dist/tools/compliance.js +4 -13
- package/dist/tools/compliance.js.map +1 -1
- package/dist/tools/dashboard.d.ts.map +1 -1
- package/dist/tools/dashboard.js +4 -13
- package/dist/tools/dashboard.js.map +1 -1
- package/dist/tools/disputes.d.ts.map +1 -1
- package/dist/tools/disputes.js +5 -37
- package/dist/tools/disputes.js.map +1 -1
- package/dist/tools/enterprises.d.ts.map +1 -1
- package/dist/tools/enterprises.js +7 -39
- package/dist/tools/enterprises.js.map +1 -1
- package/dist/tools/events.d.ts.map +1 -1
- package/dist/tools/events.js +2 -20
- package/dist/tools/events.js.map +1 -1
- package/dist/tools/federation-admin.d.ts.map +1 -1
- package/dist/tools/federation-admin.js +25 -257
- package/dist/tools/federation-admin.js.map +1 -1
- package/dist/tools/federation.d.ts.map +1 -1
- package/dist/tools/federation.js +21 -198
- package/dist/tools/federation.js.map +1 -1
- package/dist/tools/health.d.ts.map +1 -1
- package/dist/tools/health.js +2 -14
- package/dist/tools/health.js.map +1 -1
- package/dist/tools/mandates.d.ts.map +1 -1
- package/dist/tools/mandates.js +11 -83
- package/dist/tools/mandates.js.map +1 -1
- package/dist/tools/openclaw.d.ts.map +1 -1
- package/dist/tools/openclaw.js +6 -33
- package/dist/tools/openclaw.js.map +1 -1
- package/dist/tools/receipts.d.ts.map +1 -1
- package/dist/tools/receipts.js +5 -96
- package/dist/tools/receipts.js.map +1 -1
- package/dist/tools/reputation.d.ts.map +1 -1
- package/dist/tools/reputation.js +4 -13
- package/dist/tools/reputation.js.map +1 -1
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/schemas.js +34 -159
- package/dist/tools/schemas.js.map +1 -1
- package/dist/tools/verification-keys.d.ts.map +1 -1
- package/dist/tools/verification-keys.js +2 -23
- package/dist/tools/verification-keys.js.map +1 -1
- package/dist/tools/verification.d.ts.map +1 -1
- package/dist/tools/verification.js +3 -28
- package/dist/tools/verification.js.map +1 -1
- package/package.json +1 -1
- package/src/errors.ts +9 -0
- package/src/index.ts +1 -3
- package/src/server.ts +77 -71
- package/src/tool-scopes.ts +3 -3
- package/src/tools/a2a.ts +22 -235
- package/src/tools/agent-mandates.ts +11 -77
- package/src/tools/agents-refs.ts +10 -65
- package/src/tools/capabilities.ts +3 -16
- package/src/tools/compliance.ts +4 -13
- package/src/tools/dashboard.ts +4 -13
- package/src/tools/disputes.ts +5 -38
- package/src/tools/enterprises.ts +7 -39
- package/src/tools/events.ts +2 -21
- package/src/tools/federation-admin.ts +25 -282
- package/src/tools/federation.ts +21 -218
- package/src/tools/health.ts +2 -15
- package/src/tools/mandates.ts +11 -85
- package/src/tools/openclaw.ts +6 -52
- package/src/tools/receipts.ts +5 -97
- package/src/tools/reputation.ts +4 -13
- package/src/tools/schemas.ts +34 -166
- package/src/tools/verification-keys.ts +2 -25
- package/src/tools/verification.ts +3 -30
- package/tests/conformance.test.ts +197 -0
- package/tests/conformance.ts +65 -0
- package/tests/harness.ts +55 -0
- package/tests/mock-client.ts +71 -0
- package/tests/profiles.test.ts +120 -0
- package/tests/resources/contract-types.test.ts +82 -0
- package/tests/tools/a2a.test.ts +213 -0
- package/tests/tools/agent-mandates.test.ts +196 -0
- package/tests/tools/agents-refs.test.ts +190 -0
- package/tests/tools/capabilities.test.ts +80 -0
- package/tests/tools/compliance.test.ts +123 -0
- package/tests/tools/dashboard.test.ts +111 -0
- package/tests/tools/disputes.test.ts +123 -0
- package/tests/tools/enterprises.test.ts +171 -0
- package/tests/tools/events.test.ts +56 -0
- package/tests/tools/federation-admin.test.ts +468 -0
- package/tests/tools/federation.test.ts +522 -0
- package/tests/tools/health.test.ts +56 -0
- package/tests/tools/mandates.test.ts +143 -0
- package/tests/tools/openclaw.test.ts +148 -0
- package/tests/tools/receipts.test.ts +157 -0
- package/tests/tools/reputation.test.ts +108 -0
- package/tests/tools/schemas.test.ts +374 -0
- package/tests/tools/verification-keys.test.ts +56 -0
- package/tests/tools/verification.test.ts +64 -0
- package/src/tools/code-mode.ts +0 -461
- package/tests/code-mode-manifest.test.ts +0 -144
- package/tests/enterprises.test.ts +0 -96
- package/tests/schemas.test.ts +0 -531
package/src/tools/a2a.ts
CHANGED
|
@@ -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 { ContractTypeEnum } from '../enums.js';
|
|
6
6
|
import { toolMeta } from '../tool-scopes.js';
|
|
7
7
|
|
|
@@ -10,56 +10,6 @@ export interface A2aToolsConfig {
|
|
|
10
10
|
enterpriseId?: string;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const A2aMandateOutputSchema = z
|
|
14
|
-
.object({
|
|
15
|
-
id: z.string().describe('Mandate ID'),
|
|
16
|
-
status: z.string().describe('Mandate lifecycle status'),
|
|
17
|
-
contractType: z.string().describe('Contract type identifier'),
|
|
18
|
-
principalAgentId: z.string().optional().describe('Agent who proposed the work'),
|
|
19
|
-
agentId: z.string().optional().describe('Agent assigned to do the work'),
|
|
20
|
-
})
|
|
21
|
-
.passthrough()
|
|
22
|
-
.describe('Mandate details');
|
|
23
|
-
|
|
24
|
-
const ProposalsOutputSchema = z
|
|
25
|
-
.object({
|
|
26
|
-
proposals: z.array(A2aMandateOutputSchema).describe('Pending proposals'),
|
|
27
|
-
active: z.array(A2aMandateOutputSchema).describe('Active mandates needing receipts'),
|
|
28
|
-
verified: z.array(A2aMandateOutputSchema).describe('Mandates ready to settle'),
|
|
29
|
-
})
|
|
30
|
-
.describe('Current proposals and obligations');
|
|
31
|
-
|
|
32
|
-
const ReceiptResultOutputSchema = z
|
|
33
|
-
.object({
|
|
34
|
-
receipt: z
|
|
35
|
-
.object({
|
|
36
|
-
id: z.string().describe('Receipt ID'),
|
|
37
|
-
status: z.string().describe('Receipt status'),
|
|
38
|
-
})
|
|
39
|
-
.passthrough()
|
|
40
|
-
.describe('Submitted receipt'),
|
|
41
|
-
mandateStatus: z.string().describe('Mandate status after receipt submission'),
|
|
42
|
-
})
|
|
43
|
-
.describe('Receipt submission result');
|
|
44
|
-
|
|
45
|
-
const MandateListOutputSchema = z
|
|
46
|
-
.object({
|
|
47
|
-
mandates: z.array(A2aMandateOutputSchema).describe('All mandates'),
|
|
48
|
-
byStatus: z
|
|
49
|
-
.record(z.string(), z.array(A2aMandateOutputSchema))
|
|
50
|
-
.describe('Mandates grouped by status'),
|
|
51
|
-
})
|
|
52
|
-
.describe('Mandate list grouped by status');
|
|
53
|
-
|
|
54
|
-
const ReputationOutputSchema = z
|
|
55
|
-
.object({
|
|
56
|
-
agentId: z.string().describe('Agent ID'),
|
|
57
|
-
score: z.number().optional().describe('Reputation score'),
|
|
58
|
-
fulfillmentRate: z.number().optional().describe('Fulfillment rate'),
|
|
59
|
-
})
|
|
60
|
-
.passthrough()
|
|
61
|
-
.describe('Agent reputation details');
|
|
62
|
-
|
|
63
13
|
function getEnterpriseId(config: A2aToolsConfig): string {
|
|
64
14
|
return config.enterpriseId ?? process.env.AGLEDGER_ENTERPRISE_ID ?? '';
|
|
65
15
|
}
|
|
@@ -74,7 +24,7 @@ export function registerA2aTools(
|
|
|
74
24
|
{
|
|
75
25
|
title: 'Create Mandate',
|
|
76
26
|
description:
|
|
77
|
-
'Create a mandate for work you will do. Your identity is inferred from your API key. The mandate is auto-activated so you can submit a receipt immediately. Use propose_mandate instead when delegating to another agent.',
|
|
27
|
+
'Create a mandate for work you will do. Your identity is inferred from your API key. The mandate is auto-activated so you can submit a receipt immediately. Use propose_mandate instead when delegating to another agent. Criteria describe WHAT must be done (e.g. {"task": "generate report", "format": "PDF"}). Do NOT put receipt evidence fields (item_description, total_cost, etc.) in criteria — those go in submit_receipt evidence.',
|
|
78
28
|
inputSchema: {
|
|
79
29
|
contractType: ContractTypeEnum,
|
|
80
30
|
criteria: z
|
|
@@ -84,7 +34,6 @@ export function registerA2aTools(
|
|
|
84
34
|
projectRef: z.string().optional().describe('Project grouping ID'),
|
|
85
35
|
deadline: z.string().optional().describe('ISO 8601 future deadline'),
|
|
86
36
|
},
|
|
87
|
-
outputSchema: A2aMandateOutputSchema,
|
|
88
37
|
annotations: {
|
|
89
38
|
readOnlyHint: false,
|
|
90
39
|
destructiveHint: false,
|
|
@@ -115,15 +64,7 @@ export function registerA2aTools(
|
|
|
115
64
|
deadline,
|
|
116
65
|
autoActivate: true,
|
|
117
66
|
});
|
|
118
|
-
return {
|
|
119
|
-
content: [
|
|
120
|
-
{
|
|
121
|
-
type: 'text',
|
|
122
|
-
text: `Mandate ${mandate.id} created and activated (${mandate.contractType}). Status: ${mandate.status}. Do the work, then call submit_receipt with mandateId="${mandate.id}" and evidence of completion. This is REQUIRED to close the accountability loop.`,
|
|
123
|
-
},
|
|
124
|
-
],
|
|
125
|
-
structuredContent: mandate as unknown as Record<string, unknown>,
|
|
126
|
-
};
|
|
67
|
+
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
127
68
|
} catch (err) {
|
|
128
69
|
return apiErrorResult(err);
|
|
129
70
|
}
|
|
@@ -146,7 +87,6 @@ export function registerA2aTools(
|
|
|
146
87
|
parentMandateId: z.string().optional().describe('Parent mandate if delegating'),
|
|
147
88
|
deadline: z.string().optional().describe('ISO 8601 future deadline'),
|
|
148
89
|
},
|
|
149
|
-
outputSchema: A2aMandateOutputSchema,
|
|
150
90
|
annotations: {
|
|
151
91
|
readOnlyHint: false,
|
|
152
92
|
destructiveHint: false,
|
|
@@ -177,15 +117,7 @@ export function registerA2aTools(
|
|
|
177
117
|
parentMandateId: args.parentMandateId,
|
|
178
118
|
deadline,
|
|
179
119
|
});
|
|
180
|
-
return {
|
|
181
|
-
content: [
|
|
182
|
-
{
|
|
183
|
-
type: 'text',
|
|
184
|
-
text: `Mandate ${mandate.id} proposed (${mandate.contractType}). Status: ${mandate.status}. The performer must call accept_mandate to begin. CRITICAL: after work is done, call submit_receipt — this is REQUIRED to close the accountability loop. A mandate without a receipt is an unfulfilled commitment.`,
|
|
185
|
-
},
|
|
186
|
-
],
|
|
187
|
-
structuredContent: mandate as unknown as Record<string, unknown>,
|
|
188
|
-
};
|
|
120
|
+
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
189
121
|
} catch (err) {
|
|
190
122
|
return apiErrorResult(err);
|
|
191
123
|
}
|
|
@@ -201,7 +133,6 @@ export function registerA2aTools(
|
|
|
201
133
|
inputSchema: {
|
|
202
134
|
mandateId: z.string().describe('Mandate ID to accept'),
|
|
203
135
|
},
|
|
204
|
-
outputSchema: A2aMandateOutputSchema,
|
|
205
136
|
annotations: {
|
|
206
137
|
readOnlyHint: false,
|
|
207
138
|
destructiveHint: false,
|
|
@@ -223,37 +154,7 @@ export function registerA2aTools(
|
|
|
223
154
|
}
|
|
224
155
|
}
|
|
225
156
|
|
|
226
|
-
|
|
227
|
-
const evidenceTemplates: Record<string, string> = {
|
|
228
|
-
'ACH-ANALYZE-v1':
|
|
229
|
-
'{"deliverable": "your analysis text", "deliverable_type": "report", "summary": "key findings"}',
|
|
230
|
-
'ACH-COORD-v1':
|
|
231
|
-
'{"deliverable": "coordination outcome", "deliverable_type": "report", "summary": "what was coordinated"}',
|
|
232
|
-
'ACH-DATA-v1': '{"deliverable": "data results", "deliverable_type": "report"}',
|
|
233
|
-
'ACH-DLVR-v1': '{"deliverable": "artifact content", "deliverable_type": "document"}',
|
|
234
|
-
'ACH-PROC-v1':
|
|
235
|
-
'{"item_secured": "item name", "quantity": 1, "total_cost": {"amount": 100, "currency": "USD"}, "supplier": {"id": "S1", "name": "Supplier"}, "confirmation_ref": "REF-1"}',
|
|
236
|
-
'ACH-TXN-v1':
|
|
237
|
-
'{"confirmations": [{"ref": "T1", "type": "payment", "provider": "provider", "cost": {"amount": 100, "currency": "USD"}}]}',
|
|
238
|
-
'ACH-COMM-v1': '{"deliverable": "communication sent", "deliverable_type": "report"}',
|
|
239
|
-
'ACH-AUTH-v1': '{"deliverable": "auth action completed", "deliverable_type": "report"}',
|
|
240
|
-
'ACH-INFRA-v1': '{"deliverable": "infrastructure change", "deliverable_type": "report"}',
|
|
241
|
-
'ACH-DEL-v1': '{"deliverable": "deletion completed", "deliverable_type": "report"}',
|
|
242
|
-
'ACH-ORCH-v1': '{"deliverable": "orchestration result", "deliverable_type": "report"}',
|
|
243
|
-
};
|
|
244
|
-
const ct = (mandate as any).contractType as string;
|
|
245
|
-
const template =
|
|
246
|
-
evidenceTemplates[ct] || '{"deliverable": "work result", "deliverable_type": "report"}';
|
|
247
|
-
|
|
248
|
-
return {
|
|
249
|
-
content: [
|
|
250
|
-
{
|
|
251
|
-
type: 'text',
|
|
252
|
-
text: `Mandate ${mandate.id} accepted and activated (${ct}). Status: ${mandate.status}.\n\nNEXT STEP: Do the work, then call submit_receipt with mandateId="${mandate.id}" and evidence=${template}\n\nThis is REQUIRED — do NOT skip the receipt.`,
|
|
253
|
-
},
|
|
254
|
-
],
|
|
255
|
-
structuredContent: mandate as unknown as Record<string, unknown>,
|
|
256
|
-
};
|
|
157
|
+
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
257
158
|
} catch (err) {
|
|
258
159
|
return apiErrorResult(err);
|
|
259
160
|
}
|
|
@@ -268,7 +169,6 @@ export function registerA2aTools(
|
|
|
268
169
|
inputSchema: {
|
|
269
170
|
agentId: z.string().optional().describe('Your agent ID'),
|
|
270
171
|
},
|
|
271
|
-
outputSchema: ProposalsOutputSchema,
|
|
272
172
|
annotations: {
|
|
273
173
|
readOnlyHint: true,
|
|
274
174
|
destructiveHint: false,
|
|
@@ -279,71 +179,34 @@ export function registerA2aTools(
|
|
|
279
179
|
},
|
|
280
180
|
async (args) => {
|
|
281
181
|
try {
|
|
282
|
-
// Agent keys automatically scope to their mandates — don't pass enterpriseId
|
|
283
|
-
// Enterprise keys need enterpriseId for scoping
|
|
284
182
|
const enterpriseId = getEnterpriseId(config);
|
|
285
183
|
|
|
286
|
-
// Search mandates — agent key auto-scopes, enterprise key needs enterpriseId
|
|
287
184
|
const searchParams: Record<string, unknown> = { limit: 100 };
|
|
288
185
|
if (enterpriseId) searchParams.enterpriseId = enterpriseId;
|
|
289
186
|
|
|
290
187
|
const results = await client.mandates.search(searchParams as any);
|
|
291
|
-
|
|
292
188
|
const allMandates = results.data || [];
|
|
293
189
|
|
|
294
190
|
// Client-side status filtering (backend status param unreliable)
|
|
295
|
-
let
|
|
296
|
-
let
|
|
297
|
-
let
|
|
191
|
+
let proposals = allMandates.filter((m: any) => m.status === 'PROPOSED');
|
|
192
|
+
let active = allMandates.filter((m: any) => m.status === 'ACTIVE');
|
|
193
|
+
let verified = allMandates.filter((m: any) => m.status === 'PROCESSING');
|
|
298
194
|
|
|
299
195
|
// Filter to this agent if ID provided
|
|
300
196
|
if (args.agentId) {
|
|
301
197
|
const id = args.agentId;
|
|
302
|
-
|
|
198
|
+
proposals = proposals.filter(
|
|
303
199
|
(m: any) => m.agentId === id || m.principalAgentId === id,
|
|
304
200
|
);
|
|
305
|
-
|
|
306
|
-
|
|
201
|
+
active = active.filter((m: any) => m.agentId === id || m.principalAgentId === id);
|
|
202
|
+
verified = verified.filter(
|
|
307
203
|
(m: any) => m.agentId === id || m.principalAgentId === id,
|
|
308
204
|
);
|
|
309
205
|
}
|
|
310
206
|
|
|
311
|
-
let text = ` ${allProposals.length} pending proposal(s)`;
|
|
312
|
-
if (allProposals.length > 0) {
|
|
313
|
-
text +=
|
|
314
|
-
':\n' +
|
|
315
|
-
allProposals
|
|
316
|
-
.map(
|
|
317
|
-
(m: any) =>
|
|
318
|
-
` • ${m.id} (${m.contractType}) from ${m.principalAgentId?.slice(0, 8)}... — ${JSON.stringify(m.criteria).slice(0, 100)}`,
|
|
319
|
-
)
|
|
320
|
-
.join('\n');
|
|
321
|
-
text += '\n\n→ Call accept_mandate with the mandate ID to accept.';
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
if (allActive.length > 0) {
|
|
325
|
-
text += `\n\n ${allActive.length} ACTIVE mandate(s) need receipts:`;
|
|
326
|
-
for (const m of allActive.slice(0, 5)) {
|
|
327
|
-
text += `\n • ${m.id} (${(m as any).contractType})`;
|
|
328
|
-
}
|
|
329
|
-
text += '\n→ Call submit_receipt with evidence of completed work!';
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
if (allVerified.length > 0) {
|
|
333
|
-
text += `\n\n ${allVerified.length} mandate(s) ready to settle:`;
|
|
334
|
-
for (const m of allVerified.slice(0, 5)) {
|
|
335
|
-
text += `\n • ${m.id} (${(m as any).contractType})`;
|
|
336
|
-
}
|
|
337
|
-
text += '\n→ These should auto-settle soon, or call settle_mandate to close manually.';
|
|
338
|
-
}
|
|
339
|
-
|
|
340
207
|
return {
|
|
341
|
-
content: [
|
|
342
|
-
structuredContent: {
|
|
343
|
-
proposals: allProposals,
|
|
344
|
-
active: allActive,
|
|
345
|
-
verified: allVerified,
|
|
346
|
-
} as unknown as Record<string, unknown>,
|
|
208
|
+
content: [],
|
|
209
|
+
structuredContent: toStructuredContent({ proposals, active, verified }),
|
|
347
210
|
};
|
|
348
211
|
} catch (err) {
|
|
349
212
|
return apiErrorResult(err);
|
|
@@ -356,12 +219,11 @@ export function registerA2aTools(
|
|
|
356
219
|
{
|
|
357
220
|
title: 'Submit Receipt',
|
|
358
221
|
description:
|
|
359
|
-
'Submit evidence of completed work. REQUIRED to close the accountability loop. Evidence: {"deliverable": "result", "deliverable_type": "report"}
|
|
222
|
+
'Submit evidence of completed work. REQUIRED to close the accountability loop. Evidence documents WHAT WAS DONE (not what was asked — that goes in mandate criteria). Common evidence: {"deliverable": "result", "deliverable_type": "report"}. PROC evidence: {"item_description": "...", "quantity": N, "total_cost": N, "supplier": "...", "confirmation_ref": "..."}.',
|
|
360
223
|
inputSchema: {
|
|
361
224
|
mandateId: z.string().describe('Mandate ID'),
|
|
362
225
|
evidence: z.record(z.string(), z.unknown()).describe('Evidence of completion'),
|
|
363
226
|
},
|
|
364
|
-
outputSchema: ReceiptResultOutputSchema,
|
|
365
227
|
annotations: {
|
|
366
228
|
readOnlyHint: false,
|
|
367
229
|
destructiveHint: false,
|
|
@@ -374,31 +236,7 @@ export function registerA2aTools(
|
|
|
374
236
|
try {
|
|
375
237
|
const { mandateId, ...submitParams } = args;
|
|
376
238
|
const receipt = await client.receipts.submit(mandateId, submitParams);
|
|
377
|
-
|
|
378
|
-
let mandateStatus = '';
|
|
379
|
-
try {
|
|
380
|
-
const mandate = await client.mandates.get(mandateId);
|
|
381
|
-
mandateStatus = mandate.status;
|
|
382
|
-
} catch {
|
|
383
|
-
/* best effort */
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
let text = `Receipt ${receipt.id} submitted for mandate ${mandateId}. Validation: ${receipt.structuralValidation}.`;
|
|
387
|
-
if (mandateStatus) {
|
|
388
|
-
text += `Mandate is now: ${mandateStatus}.`;
|
|
389
|
-
}
|
|
390
|
-
if (mandateStatus === 'FULFILLED') {
|
|
391
|
-
text += `\n\nMandate auto-settled to FULFILLED! Accountability loop closed.`;
|
|
392
|
-
} else if (mandateStatus === 'PROCESSING' || mandateStatus === 'PROCESSING') {
|
|
393
|
-
text += `\n\nCall settle_mandate("${mandateId}") to close this mandate (or wait for auto-settle).`;
|
|
394
|
-
} else if (mandateStatus === 'ACTIVE') {
|
|
395
|
-
text += `Evidence is being verified.`;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
return {
|
|
399
|
-
content: [{ type: 'text', text }],
|
|
400
|
-
structuredContent: { receipt, mandateStatus } as unknown as Record<string, unknown>,
|
|
401
|
-
};
|
|
239
|
+
return { content: [], structuredContent: toStructuredContent(receipt) };
|
|
402
240
|
} catch (err) {
|
|
403
241
|
return apiErrorResult(err);
|
|
404
242
|
}
|
|
@@ -415,7 +253,6 @@ export function registerA2aTools(
|
|
|
415
253
|
mandateId: z.string().describe('Mandate ID'),
|
|
416
254
|
reason: z.string().optional().describe('Settlement reason'),
|
|
417
255
|
},
|
|
418
|
-
outputSchema: A2aMandateOutputSchema,
|
|
419
256
|
annotations: {
|
|
420
257
|
readOnlyHint: false,
|
|
421
258
|
destructiveHint: false,
|
|
@@ -427,15 +264,7 @@ export function registerA2aTools(
|
|
|
427
264
|
async (args) => {
|
|
428
265
|
try {
|
|
429
266
|
const mandate = await client.mandates.transition(args.mandateId, 'settle', args.reason);
|
|
430
|
-
return {
|
|
431
|
-
content: [
|
|
432
|
-
{
|
|
433
|
-
type: 'text',
|
|
434
|
-
text: `Mandate ${mandate.id} settled. Status: ${mandate.status}. Accountability loop closed.`,
|
|
435
|
-
},
|
|
436
|
-
],
|
|
437
|
-
structuredContent: mandate as unknown as Record<string, unknown>,
|
|
438
|
-
};
|
|
267
|
+
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
439
268
|
} catch (err) {
|
|
440
269
|
return apiErrorResult(err);
|
|
441
270
|
}
|
|
@@ -450,7 +279,6 @@ export function registerA2aTools(
|
|
|
450
279
|
inputSchema: {
|
|
451
280
|
mandateId: z.string().describe('Mandate ID'),
|
|
452
281
|
},
|
|
453
|
-
outputSchema: A2aMandateOutputSchema,
|
|
454
282
|
annotations: {
|
|
455
283
|
readOnlyHint: true,
|
|
456
284
|
destructiveHint: false,
|
|
@@ -462,16 +290,7 @@ export function registerA2aTools(
|
|
|
462
290
|
async (args) => {
|
|
463
291
|
try {
|
|
464
292
|
const mandate = await client.mandates.get(args.mandateId);
|
|
465
|
-
|
|
466
|
-
if (mandate.status === 'ACTIVE')
|
|
467
|
-
text += '\n This mandate needs a receipt — call submit_receipt!';
|
|
468
|
-
if (mandate.status === 'PROCESSING')
|
|
469
|
-
text += '\n Should auto-settle to FULFILLED soon. Call settle_mandate if stuck.';
|
|
470
|
-
if (mandate.status === 'FULFILLED') text += '\n Accountability loop closed.';
|
|
471
|
-
return {
|
|
472
|
-
content: [{ type: 'text', text }],
|
|
473
|
-
structuredContent: mandate as unknown as Record<string, unknown>,
|
|
474
|
-
};
|
|
293
|
+
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
475
294
|
} catch (err) {
|
|
476
295
|
return apiErrorResult(err);
|
|
477
296
|
}
|
|
@@ -487,7 +306,6 @@ export function registerA2aTools(
|
|
|
487
306
|
mandateId: z.string().describe('Mandate ID'),
|
|
488
307
|
reason: z.string().describe('Rejection reason'),
|
|
489
308
|
},
|
|
490
|
-
outputSchema: A2aMandateOutputSchema,
|
|
491
309
|
annotations: {
|
|
492
310
|
readOnlyHint: false,
|
|
493
311
|
destructiveHint: true,
|
|
@@ -499,12 +317,7 @@ export function registerA2aTools(
|
|
|
499
317
|
async (args) => {
|
|
500
318
|
try {
|
|
501
319
|
const mandate = await client.mandates.reject(args.mandateId, args.reason);
|
|
502
|
-
return {
|
|
503
|
-
content: [
|
|
504
|
-
{ type: 'text', text: `Mandate ${mandate.id} rejected. Reason: ${args.reason}` },
|
|
505
|
-
],
|
|
506
|
-
structuredContent: mandate as unknown as Record<string, unknown>,
|
|
507
|
-
};
|
|
320
|
+
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
508
321
|
} catch (err) {
|
|
509
322
|
return apiErrorResult(err);
|
|
510
323
|
}
|
|
@@ -519,7 +332,6 @@ export function registerA2aTools(
|
|
|
519
332
|
inputSchema: {
|
|
520
333
|
agentId: z.string().optional().describe('Your agent ID'),
|
|
521
334
|
},
|
|
522
|
-
outputSchema: MandateListOutputSchema,
|
|
523
335
|
annotations: {
|
|
524
336
|
readOnlyHint: true,
|
|
525
337
|
destructiveHint: false,
|
|
@@ -532,7 +344,6 @@ export function registerA2aTools(
|
|
|
532
344
|
try {
|
|
533
345
|
const enterpriseId = getEnterpriseId(config);
|
|
534
346
|
|
|
535
|
-
// Agent keys auto-scope — don't require enterpriseId
|
|
536
347
|
const searchParams: Record<string, unknown> = { limit: 100 };
|
|
537
348
|
if (enterpriseId) searchParams.enterpriseId = enterpriseId;
|
|
538
349
|
|
|
@@ -554,21 +365,9 @@ export function registerA2aTools(
|
|
|
554
365
|
byStatus[s].push(m);
|
|
555
366
|
}
|
|
556
367
|
|
|
557
|
-
let text = ` ${filtered.length} mandate(s) total:`;
|
|
558
|
-
for (const [status, mandates] of Object.entries(byStatus)) {
|
|
559
|
-
text += `\n ${status}: ${mandates.length}`;
|
|
560
|
-
if (status === 'ACTIVE') text += ' need receipts!';
|
|
561
|
-
if (status === 'PROCESSING') text += ' ready to settle!';
|
|
562
|
-
if (status === 'PROPOSED') text += ' — awaiting response';
|
|
563
|
-
for (const m of mandates.slice(0, 3)) {
|
|
564
|
-
text += `\n • ${m.id.slice(0, 8)}... (${m.contractType})`;
|
|
565
|
-
}
|
|
566
|
-
if (mandates.length > 3) text += `\n ... and ${mandates.length - 3} more`;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
368
|
return {
|
|
570
|
-
content: [
|
|
571
|
-
structuredContent: { mandates: filtered, byStatus }
|
|
369
|
+
content: [],
|
|
370
|
+
structuredContent: toStructuredContent({ mandates: filtered, byStatus }),
|
|
572
371
|
};
|
|
573
372
|
} catch (err) {
|
|
574
373
|
return apiErrorResult(err);
|
|
@@ -585,7 +384,6 @@ export function registerA2aTools(
|
|
|
585
384
|
mandateId: z.string().describe('Mandate ID'),
|
|
586
385
|
reason: z.string().describe('Cancellation reason'),
|
|
587
386
|
},
|
|
588
|
-
outputSchema: A2aMandateOutputSchema,
|
|
589
387
|
annotations: {
|
|
590
388
|
readOnlyHint: false,
|
|
591
389
|
destructiveHint: true,
|
|
@@ -597,12 +395,7 @@ export function registerA2aTools(
|
|
|
597
395
|
async (args) => {
|
|
598
396
|
try {
|
|
599
397
|
const mandate = await client.mandates.cancel(args.mandateId, args.reason);
|
|
600
|
-
return {
|
|
601
|
-
content: [
|
|
602
|
-
{ type: 'text', text: `Mandate ${mandate.id} cancelled. Reason: ${args.reason}` },
|
|
603
|
-
],
|
|
604
|
-
structuredContent: mandate as unknown as Record<string, unknown>,
|
|
605
|
-
};
|
|
398
|
+
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
606
399
|
} catch (err) {
|
|
607
400
|
return apiErrorResult(err);
|
|
608
401
|
}
|
|
@@ -617,7 +410,6 @@ export function registerA2aTools(
|
|
|
617
410
|
inputSchema: {
|
|
618
411
|
agentId: z.string().describe('Agent ID'),
|
|
619
412
|
},
|
|
620
|
-
outputSchema: ReputationOutputSchema,
|
|
621
413
|
annotations: {
|
|
622
414
|
readOnlyHint: true,
|
|
623
415
|
destructiveHint: false,
|
|
@@ -629,12 +421,7 @@ export function registerA2aTools(
|
|
|
629
421
|
async (args) => {
|
|
630
422
|
try {
|
|
631
423
|
const rep = await client.reputation.getAgent(args.agentId);
|
|
632
|
-
return {
|
|
633
|
-
content: [
|
|
634
|
-
{ type: 'text', text: `Agent ${args.agentId} reputation: ${JSON.stringify(rep)}` },
|
|
635
|
-
],
|
|
636
|
-
structuredContent: rep as unknown as Record<string, unknown>,
|
|
637
|
-
};
|
|
424
|
+
return { content: [], structuredContent: toStructuredContent(rep) };
|
|
638
425
|
} catch (err) {
|
|
639
426
|
return apiErrorResult(err);
|
|
640
427
|
}
|
|
@@ -1,37 +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';
|
|
4
|
+
import { apiErrorResult, toStructuredContent } from '../errors.js';
|
|
5
5
|
import { toolMeta } from '../tool-scopes.js';
|
|
6
|
-
import { ContractTypeEnum
|
|
7
|
-
|
|
8
|
-
const MandateOutputSchema = z.object({
|
|
9
|
-
id: z.string(),
|
|
10
|
-
enterpriseId: z.string(),
|
|
11
|
-
agentId: z.string().nullable().optional(),
|
|
12
|
-
contractType: ContractTypeEnum,
|
|
13
|
-
contractVersion: z.string(),
|
|
14
|
-
platform: z.string(),
|
|
15
|
-
status: z.string(),
|
|
16
|
-
criteria: z.record(z.string(), z.unknown()),
|
|
17
|
-
tolerance: z.record(z.string(), z.unknown()).nullable().optional(),
|
|
18
|
-
deadline: z.string().nullable().optional(),
|
|
19
|
-
commissionPct: z.number().nullable().optional(),
|
|
20
|
-
parentMandateId: z.string().nullable().optional(),
|
|
21
|
-
rootMandateId: z.string().nullable().optional(),
|
|
22
|
-
chainDepth: z.number().nullable().optional(),
|
|
23
|
-
version: z.number(),
|
|
24
|
-
createdAt: z.string(),
|
|
25
|
-
updatedAt: z.string(),
|
|
26
|
-
nextSteps: NextStepsField,
|
|
27
|
-
}).passthrough().describe('AGLedger mandate object');
|
|
28
|
-
|
|
29
|
-
const PageOutputSchema = z.object({
|
|
30
|
-
data: z.array(MandateOutputSchema),
|
|
31
|
-
hasMore: z.boolean(),
|
|
32
|
-
nextCursor: z.string().nullable().optional(),
|
|
33
|
-
total: z.number().optional(),
|
|
34
|
-
}).describe('Paginated mandate results');
|
|
6
|
+
import { ContractTypeEnum } from '../enums.js';
|
|
35
7
|
|
|
36
8
|
export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient): void {
|
|
37
9
|
mcp.registerTool(
|
|
@@ -51,7 +23,6 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
|
|
|
51
23
|
commissionPct: z.number().optional().describe('Commission percentage (0-100)'),
|
|
52
24
|
deadline: z.string().optional().describe('ISO 8601 deadline'),
|
|
53
25
|
},
|
|
54
|
-
outputSchema: MandateOutputSchema,
|
|
55
26
|
annotations: {
|
|
56
27
|
readOnlyHint: false,
|
|
57
28
|
destructiveHint: false,
|
|
@@ -63,10 +34,7 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
|
|
|
63
34
|
async (args) => {
|
|
64
35
|
try {
|
|
65
36
|
const mandate = await client.mandates.createAgent(args);
|
|
66
|
-
return {
|
|
67
|
-
content: [{ type: 'text', text: `Mandate ${mandate.id} proposed (${mandate.status}).` }],
|
|
68
|
-
structuredContent: mandate as unknown as Record<string, unknown>,
|
|
69
|
-
};
|
|
37
|
+
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
70
38
|
} catch (err) {
|
|
71
39
|
return apiErrorResult(err);
|
|
72
40
|
}
|
|
@@ -81,7 +49,6 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
|
|
|
81
49
|
inputSchema: {
|
|
82
50
|
mandateId: z.string().describe('UUID of the proposed mandate'),
|
|
83
51
|
},
|
|
84
|
-
outputSchema: MandateOutputSchema,
|
|
85
52
|
annotations: {
|
|
86
53
|
readOnlyHint: false,
|
|
87
54
|
destructiveHint: false,
|
|
@@ -93,10 +60,7 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
|
|
|
93
60
|
async (args) => {
|
|
94
61
|
try {
|
|
95
62
|
const mandate = await client.mandates.accept(args.mandateId);
|
|
96
|
-
return {
|
|
97
|
-
content: [{ type: 'text', text: `Mandate ${mandate.id} accepted (${mandate.status}).` }],
|
|
98
|
-
structuredContent: mandate as unknown as Record<string, unknown>,
|
|
99
|
-
};
|
|
63
|
+
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
100
64
|
} catch (err) {
|
|
101
65
|
return apiErrorResult(err);
|
|
102
66
|
}
|
|
@@ -112,7 +76,6 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
|
|
|
112
76
|
mandateId: z.string().describe('UUID of the proposed mandate'),
|
|
113
77
|
reason: z.string().optional().describe('Reason for rejection'),
|
|
114
78
|
},
|
|
115
|
-
outputSchema: MandateOutputSchema,
|
|
116
79
|
annotations: {
|
|
117
80
|
readOnlyHint: false,
|
|
118
81
|
destructiveHint: true,
|
|
@@ -124,10 +87,7 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
|
|
|
124
87
|
async (args) => {
|
|
125
88
|
try {
|
|
126
89
|
const mandate = await client.mandates.reject(args.mandateId, args.reason);
|
|
127
|
-
return {
|
|
128
|
-
content: [{ type: 'text', text: `Mandate ${mandate.id} rejected (${mandate.status}).` }],
|
|
129
|
-
structuredContent: mandate as unknown as Record<string, unknown>,
|
|
130
|
-
};
|
|
90
|
+
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
131
91
|
} catch (err) {
|
|
132
92
|
return apiErrorResult(err);
|
|
133
93
|
}
|
|
@@ -147,7 +107,6 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
|
|
|
147
107
|
counterCommissionPct: z.number().optional().describe('Modified commission percentage'),
|
|
148
108
|
message: z.string().optional().describe('Message explaining the counter-proposal'),
|
|
149
109
|
},
|
|
150
|
-
outputSchema: MandateOutputSchema,
|
|
151
110
|
annotations: {
|
|
152
111
|
readOnlyHint: false,
|
|
153
112
|
destructiveHint: false,
|
|
@@ -165,10 +124,7 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
|
|
|
165
124
|
counterDeadline: args.counterDeadline,
|
|
166
125
|
counterCommissionPct: args.counterCommissionPct ?? undefined,
|
|
167
126
|
});
|
|
168
|
-
return {
|
|
169
|
-
content: [{ type: 'text', text: `Mandate ${mandate.id} counter-proposed (${mandate.status}).` }],
|
|
170
|
-
structuredContent: mandate as unknown as Record<string, unknown>,
|
|
171
|
-
};
|
|
127
|
+
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
172
128
|
} catch (err) {
|
|
173
129
|
return apiErrorResult(err);
|
|
174
130
|
}
|
|
@@ -183,7 +139,6 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
|
|
|
183
139
|
inputSchema: {
|
|
184
140
|
mandateId: z.string().describe('UUID of the counter-proposed mandate'),
|
|
185
141
|
},
|
|
186
|
-
outputSchema: MandateOutputSchema,
|
|
187
142
|
annotations: {
|
|
188
143
|
readOnlyHint: false,
|
|
189
144
|
destructiveHint: false,
|
|
@@ -195,10 +150,7 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
|
|
|
195
150
|
async (args) => {
|
|
196
151
|
try {
|
|
197
152
|
const mandate = await client.mandates.acceptCounter(args.mandateId);
|
|
198
|
-
return {
|
|
199
|
-
content: [{ type: 'text', text: `Counter-proposal on ${mandate.id} accepted (${mandate.status}).` }],
|
|
200
|
-
structuredContent: mandate as unknown as Record<string, unknown>,
|
|
201
|
-
};
|
|
153
|
+
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
202
154
|
} catch (err) {
|
|
203
155
|
return apiErrorResult(err);
|
|
204
156
|
}
|
|
@@ -211,7 +163,6 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
|
|
|
211
163
|
title: 'List My Proposals',
|
|
212
164
|
description: 'List mandate proposals awaiting my response as performer.',
|
|
213
165
|
inputSchema: {},
|
|
214
|
-
outputSchema: PageOutputSchema,
|
|
215
166
|
annotations: {
|
|
216
167
|
readOnlyHint: true,
|
|
217
168
|
destructiveHint: false,
|
|
@@ -223,10 +174,7 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
|
|
|
223
174
|
async () => {
|
|
224
175
|
try {
|
|
225
176
|
const result = await client.mandates.listProposals();
|
|
226
|
-
return {
|
|
227
|
-
content: [{ type: 'text', text: `Found ${result.data.length} proposals.` }],
|
|
228
|
-
structuredContent: result as unknown as Record<string, unknown>,
|
|
229
|
-
};
|
|
177
|
+
return { content: [], structuredContent: toStructuredContent(result) };
|
|
230
178
|
} catch (err) {
|
|
231
179
|
return apiErrorResult(err);
|
|
232
180
|
}
|
|
@@ -239,7 +187,6 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
|
|
|
239
187
|
title: 'List Principal Mandates',
|
|
240
188
|
description: 'List mandates where I am the principal (the one who proposed/created them).',
|
|
241
189
|
inputSchema: {},
|
|
242
|
-
outputSchema: PageOutputSchema,
|
|
243
190
|
annotations: {
|
|
244
191
|
readOnlyHint: true,
|
|
245
192
|
destructiveHint: false,
|
|
@@ -251,10 +198,7 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
|
|
|
251
198
|
async () => {
|
|
252
199
|
try {
|
|
253
200
|
const result = await client.mandates.listAsPrincipal();
|
|
254
|
-
return {
|
|
255
|
-
content: [{ type: 'text', text: `Found ${result.data.length} mandates as principal.` }],
|
|
256
|
-
structuredContent: result as unknown as Record<string, unknown>,
|
|
257
|
-
};
|
|
201
|
+
return { content: [], structuredContent: toStructuredContent(result) };
|
|
258
202
|
} catch (err) {
|
|
259
203
|
return apiErrorResult(err);
|
|
260
204
|
}
|
|
@@ -269,9 +213,6 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
|
|
|
269
213
|
inputSchema: {
|
|
270
214
|
mandateId: z.string().describe('UUID of any mandate in the chain'),
|
|
271
215
|
},
|
|
272
|
-
outputSchema: z.object({
|
|
273
|
-
chain: z.array(MandateOutputSchema),
|
|
274
|
-
}),
|
|
275
216
|
annotations: {
|
|
276
217
|
readOnlyHint: true,
|
|
277
218
|
destructiveHint: false,
|
|
@@ -283,10 +224,7 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
|
|
|
283
224
|
async (args) => {
|
|
284
225
|
try {
|
|
285
226
|
const chain = await client.mandates.getChain(args.mandateId);
|
|
286
|
-
return {
|
|
287
|
-
content: [{ type: 'text', text: `Delegation chain has ${chain.length} mandates.` }],
|
|
288
|
-
structuredContent: { chain } as unknown as Record<string, unknown>,
|
|
289
|
-
};
|
|
227
|
+
return { content: [], structuredContent: toStructuredContent({ chain }) };
|
|
290
228
|
} catch (err) {
|
|
291
229
|
return apiErrorResult(err);
|
|
292
230
|
}
|
|
@@ -301,7 +239,6 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
|
|
|
301
239
|
inputSchema: {
|
|
302
240
|
mandateId: z.string().describe('UUID of the parent mandate'),
|
|
303
241
|
},
|
|
304
|
-
outputSchema: PageOutputSchema,
|
|
305
242
|
annotations: {
|
|
306
243
|
readOnlyHint: true,
|
|
307
244
|
destructiveHint: false,
|
|
@@ -313,10 +250,7 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
|
|
|
313
250
|
async (args) => {
|
|
314
251
|
try {
|
|
315
252
|
const result = await client.mandates.getSubMandates(args.mandateId);
|
|
316
|
-
return {
|
|
317
|
-
content: [{ type: 'text', text: `Found ${result.data.length} sub-mandates.` }],
|
|
318
|
-
structuredContent: result as unknown as Record<string, unknown>,
|
|
319
|
-
};
|
|
253
|
+
return { content: [], structuredContent: toStructuredContent(result) };
|
|
320
254
|
} catch (err) {
|
|
321
255
|
return apiErrorResult(err);
|
|
322
256
|
}
|