@agledger/mcp-server 1.5.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-client.d.ts +16 -0
- package/dist/api-client.d.ts.map +1 -0
- package/dist/api-client.js +52 -0
- package/dist/api-client.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -58
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +2 -13
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +113 -109
- package/dist/server.js.map +1 -1
- package/package.json +2 -3
- package/src/api-client.ts +72 -0
- package/src/index.ts +27 -60
- package/src/server.ts +136 -120
- package/tests/api-client.test.ts +147 -0
- package/tests/harness.ts +8 -35
- package/tests/integration.test.ts +373 -0
- package/tests/server.test.ts +286 -0
- package/src/enums.ts +0 -47
- package/src/errors.ts +0 -44
- package/src/resources/contract-types.ts +0 -130
- package/src/tool-scopes.ts +0 -180
- package/src/tools/a2a.ts +0 -430
- package/src/tools/agent-mandates.ts +0 -259
- package/src/tools/agents-refs.ts +0 -232
- package/src/tools/capabilities.ts +0 -63
- package/src/tools/compliance.ts +0 -70
- package/src/tools/dashboard.ts +0 -64
- package/src/tools/disputes.ts +0 -121
- package/src/tools/enterprises.ts +0 -203
- package/src/tools/events.ts +0 -33
- package/src/tools/federation-admin.ts +0 -665
- package/src/tools/federation.ts +0 -587
- package/src/tools/health.ts +0 -30
- package/src/tools/mandates.ts +0 -264
- package/src/tools/openclaw.ts +0 -122
- package/src/tools/receipts.ts +0 -134
- package/src/tools/reputation.ts +0 -69
- package/src/tools/schemas.ts +0 -535
- package/src/tools/verification-keys.ts +0 -33
- package/src/tools/verification.ts +0 -59
- package/tests/conformance.test.ts +0 -197
- package/tests/conformance.ts +0 -65
- package/tests/mock-client.ts +0 -71
- package/tests/profiles.test.ts +0 -120
- package/tests/resources/contract-types.test.ts +0 -82
- package/tests/tools/a2a.test.ts +0 -213
- package/tests/tools/agent-mandates.test.ts +0 -196
- package/tests/tools/agents-refs.test.ts +0 -190
- package/tests/tools/capabilities.test.ts +0 -80
- package/tests/tools/compliance.test.ts +0 -123
- package/tests/tools/dashboard.test.ts +0 -111
- package/tests/tools/disputes.test.ts +0 -123
- package/tests/tools/enterprises.test.ts +0 -171
- package/tests/tools/events.test.ts +0 -56
- package/tests/tools/federation-admin.test.ts +0 -468
- package/tests/tools/federation.test.ts +0 -522
- package/tests/tools/health.test.ts +0 -56
- package/tests/tools/mandates.test.ts +0 -143
- package/tests/tools/openclaw.test.ts +0 -148
- package/tests/tools/receipts.test.ts +0 -157
- package/tests/tools/reputation.test.ts +0 -108
- package/tests/tools/schemas.test.ts +0 -374
- package/tests/tools/verification-keys.test.ts +0 -56
- package/tests/tools/verification.test.ts +0 -64
package/src/tools/mandates.ts
DELETED
|
@@ -1,264 +0,0 @@
|
|
|
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, toStructuredContent } from '../errors.js';
|
|
5
|
-
import { ContractTypeEnum, MandateStatusEnum } from '../enums.js';
|
|
6
|
-
import { toolMeta } from '../tool-scopes.js';
|
|
7
|
-
|
|
8
|
-
export function registerMandateTools(mcp: McpServer, client: AgledgerClient): void {
|
|
9
|
-
mcp.registerTool(
|
|
10
|
-
'get_mandate',
|
|
11
|
-
{
|
|
12
|
-
title: 'Get Mandate',
|
|
13
|
-
description: 'Retrieve an AGLedger mandate by its ID.',
|
|
14
|
-
inputSchema: {
|
|
15
|
-
mandateId: z.string().describe('UUID of the mandate to retrieve'),
|
|
16
|
-
},
|
|
17
|
-
annotations: {
|
|
18
|
-
readOnlyHint: true,
|
|
19
|
-
destructiveHint: false,
|
|
20
|
-
idempotentHint: true,
|
|
21
|
-
openWorldHint: true,
|
|
22
|
-
},
|
|
23
|
-
_meta: toolMeta('get_mandate'),
|
|
24
|
-
},
|
|
25
|
-
async (args) => {
|
|
26
|
-
try {
|
|
27
|
-
const mandate = await client.mandates.get(args.mandateId);
|
|
28
|
-
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
29
|
-
} catch (err) {
|
|
30
|
-
return apiErrorResult(err);
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
mcp.registerTool(
|
|
36
|
-
'search_mandates',
|
|
37
|
-
{
|
|
38
|
-
title: 'Search Mandates',
|
|
39
|
-
description: 'Search AGLedger mandates with filters (status, contract type, agent, date range).',
|
|
40
|
-
inputSchema: {
|
|
41
|
-
enterpriseId: z.string().describe('Enterprise ID to search within (required)'),
|
|
42
|
-
status: MandateStatusEnum.optional().describe('Filter by mandate status'),
|
|
43
|
-
contractType: ContractTypeEnum.optional().describe('Filter by contract type'),
|
|
44
|
-
agentId: z.string().optional().describe('Filter by assigned agent ID'),
|
|
45
|
-
from: z.string().optional().describe('ISO 8601 start date filter'),
|
|
46
|
-
to: z.string().optional().describe('ISO 8601 end date filter'),
|
|
47
|
-
sort: z.string().optional().describe('Sort field (e.g. "createdAt")'),
|
|
48
|
-
order: z.enum(['asc', 'desc']).optional().describe('Sort order'),
|
|
49
|
-
limit: z.number().optional().describe('Page size (default: 20)'),
|
|
50
|
-
offset: z.number().optional().describe('Page offset (default: 0)'),
|
|
51
|
-
},
|
|
52
|
-
annotations: {
|
|
53
|
-
readOnlyHint: true,
|
|
54
|
-
destructiveHint: false,
|
|
55
|
-
idempotentHint: true,
|
|
56
|
-
openWorldHint: true,
|
|
57
|
-
},
|
|
58
|
-
_meta: toolMeta('search_mandates'),
|
|
59
|
-
},
|
|
60
|
-
async (args) => {
|
|
61
|
-
try {
|
|
62
|
-
const result = await client.mandates.search(args);
|
|
63
|
-
return { content: [], structuredContent: toStructuredContent(result) };
|
|
64
|
-
} catch (err) {
|
|
65
|
-
return apiErrorResult(err);
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
mcp.registerTool(
|
|
71
|
-
'activate_mandate',
|
|
72
|
-
{
|
|
73
|
-
title: 'Activate Mandate',
|
|
74
|
-
description: 'Transition a mandate to ACTIVE status. The mandate must be in CREATED status.',
|
|
75
|
-
inputSchema: {
|
|
76
|
-
mandateId: z.string().describe('UUID of the mandate to activate'),
|
|
77
|
-
},
|
|
78
|
-
annotations: {
|
|
79
|
-
readOnlyHint: false,
|
|
80
|
-
destructiveHint: false,
|
|
81
|
-
idempotentHint: true,
|
|
82
|
-
openWorldHint: true,
|
|
83
|
-
},
|
|
84
|
-
_meta: toolMeta('activate_mandate'),
|
|
85
|
-
},
|
|
86
|
-
async (args) => {
|
|
87
|
-
try {
|
|
88
|
-
const mandate = await client.mandates.transition(args.mandateId, 'activate');
|
|
89
|
-
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
90
|
-
} catch (err) {
|
|
91
|
-
return apiErrorResult(err);
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
mcp.registerTool(
|
|
97
|
-
'cancel_mandate',
|
|
98
|
-
{
|
|
99
|
-
title: 'Cancel Mandate',
|
|
100
|
-
description: 'Cancel an AGLedger mandate. This is a destructive operation.',
|
|
101
|
-
inputSchema: {
|
|
102
|
-
mandateId: z.string().describe('UUID of the mandate to cancel'),
|
|
103
|
-
reason: z.string().optional().describe('Reason for cancellation'),
|
|
104
|
-
},
|
|
105
|
-
annotations: {
|
|
106
|
-
readOnlyHint: false,
|
|
107
|
-
destructiveHint: true,
|
|
108
|
-
idempotentHint: false,
|
|
109
|
-
openWorldHint: true,
|
|
110
|
-
},
|
|
111
|
-
_meta: toolMeta('cancel_mandate'),
|
|
112
|
-
},
|
|
113
|
-
async (args) => {
|
|
114
|
-
try {
|
|
115
|
-
const mandate = await client.mandates.cancel(args.mandateId, args.reason);
|
|
116
|
-
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
117
|
-
} catch (err) {
|
|
118
|
-
return apiErrorResult(err);
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
mcp.registerTool(
|
|
124
|
-
'update_mandate',
|
|
125
|
-
{
|
|
126
|
-
title: 'Update Mandate',
|
|
127
|
-
description: 'Update mutable fields on a CREATED mandate (criteria, deadline, commission). Cannot update after activation.',
|
|
128
|
-
inputSchema: {
|
|
129
|
-
mandateId: z.string().describe('UUID of the mandate to update'),
|
|
130
|
-
updates: z.record(z.string(), z.unknown()).describe('Fields to update (criteria, deadline, etc.)'),
|
|
131
|
-
},
|
|
132
|
-
annotations: {
|
|
133
|
-
readOnlyHint: false,
|
|
134
|
-
destructiveHint: false,
|
|
135
|
-
idempotentHint: true,
|
|
136
|
-
openWorldHint: true,
|
|
137
|
-
},
|
|
138
|
-
_meta: toolMeta('update_mandate'),
|
|
139
|
-
},
|
|
140
|
-
async (args) => {
|
|
141
|
-
try {
|
|
142
|
-
const mandate = await client.mandates.update(args.mandateId, args.updates);
|
|
143
|
-
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
144
|
-
} catch (err) {
|
|
145
|
-
return apiErrorResult(err);
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
mcp.registerTool(
|
|
151
|
-
'request_revision',
|
|
152
|
-
{
|
|
153
|
-
title: 'Request Revision',
|
|
154
|
-
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.',
|
|
155
|
-
inputSchema: {
|
|
156
|
-
mandateId: z.string().describe('UUID of the mandate to request revision for'),
|
|
157
|
-
reason: z.string().optional().describe('Why revision is needed'),
|
|
158
|
-
},
|
|
159
|
-
annotations: {
|
|
160
|
-
readOnlyHint: false,
|
|
161
|
-
destructiveHint: false,
|
|
162
|
-
idempotentHint: false,
|
|
163
|
-
openWorldHint: true,
|
|
164
|
-
},
|
|
165
|
-
_meta: toolMeta('request_revision'),
|
|
166
|
-
},
|
|
167
|
-
async (args) => {
|
|
168
|
-
try {
|
|
169
|
-
const mandate = await client.mandates.requestRevision(args.mandateId, args.reason);
|
|
170
|
-
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
171
|
-
} catch (err) {
|
|
172
|
-
return apiErrorResult(err);
|
|
173
|
-
}
|
|
174
|
-
},
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
mcp.registerTool(
|
|
178
|
-
'delegate_mandate',
|
|
179
|
-
{
|
|
180
|
-
title: 'Delegate Mandate',
|
|
181
|
-
description: 'Delegate a mandate to another agent by creating a child mandate in the delegation chain.',
|
|
182
|
-
inputSchema: {
|
|
183
|
-
mandateId: z.string().describe('UUID of the parent mandate to delegate from'),
|
|
184
|
-
agentId: z.string().describe('Agent ID of the performer to delegate to'),
|
|
185
|
-
commissionPct: z.number().optional().describe('Commission percentage for the delegated agent'),
|
|
186
|
-
},
|
|
187
|
-
annotations: {
|
|
188
|
-
readOnlyHint: false,
|
|
189
|
-
destructiveHint: false,
|
|
190
|
-
idempotentHint: false,
|
|
191
|
-
openWorldHint: true,
|
|
192
|
-
},
|
|
193
|
-
_meta: toolMeta('delegate_mandate'),
|
|
194
|
-
},
|
|
195
|
-
async (args) => {
|
|
196
|
-
try {
|
|
197
|
-
// Fetch the parent mandate to get contract details for delegation
|
|
198
|
-
const parent = await client.mandates.get(args.mandateId);
|
|
199
|
-
const childMandate = await client.mandates.delegate(args.mandateId, {
|
|
200
|
-
principalAgentId: parent.agentId ?? '',
|
|
201
|
-
performerAgentId: args.agentId,
|
|
202
|
-
contractType: parent.contractType,
|
|
203
|
-
contractVersion: parent.contractVersion,
|
|
204
|
-
platform: parent.platform,
|
|
205
|
-
criteria: parent.criteria,
|
|
206
|
-
commissionPct: args.commissionPct,
|
|
207
|
-
});
|
|
208
|
-
return { content: [], structuredContent: toStructuredContent(childMandate) };
|
|
209
|
-
} catch (err) {
|
|
210
|
-
return apiErrorResult(err);
|
|
211
|
-
}
|
|
212
|
-
},
|
|
213
|
-
);
|
|
214
|
-
|
|
215
|
-
mcp.registerTool(
|
|
216
|
-
'get_mandate_graph',
|
|
217
|
-
{
|
|
218
|
-
title: 'Get Mandate Graph',
|
|
219
|
-
description: 'Get the delegation graph for a mandate. Returns nodes and edges representing the full delegation tree.',
|
|
220
|
-
inputSchema: {
|
|
221
|
-
mandateId: z.string().describe('UUID of the mandate to get the delegation graph for'),
|
|
222
|
-
},
|
|
223
|
-
annotations: {
|
|
224
|
-
readOnlyHint: true,
|
|
225
|
-
destructiveHint: false,
|
|
226
|
-
idempotentHint: true,
|
|
227
|
-
openWorldHint: true,
|
|
228
|
-
},
|
|
229
|
-
_meta: toolMeta('get_mandate_graph'),
|
|
230
|
-
},
|
|
231
|
-
async (args) => {
|
|
232
|
-
try {
|
|
233
|
-
const graph = await client.mandates.getGraph(args.mandateId);
|
|
234
|
-
return { content: [], structuredContent: toStructuredContent(graph) };
|
|
235
|
-
} catch (err) {
|
|
236
|
-
return apiErrorResult(err);
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
);
|
|
240
|
-
|
|
241
|
-
mcp.registerTool(
|
|
242
|
-
'get_mandate_summary',
|
|
243
|
-
{
|
|
244
|
-
title: 'Get Mandate Summary',
|
|
245
|
-
description: 'Get mandate counts grouped by status. Use for dashboard-level visibility.',
|
|
246
|
-
inputSchema: {},
|
|
247
|
-
annotations: {
|
|
248
|
-
readOnlyHint: true,
|
|
249
|
-
destructiveHint: false,
|
|
250
|
-
idempotentHint: true,
|
|
251
|
-
openWorldHint: true,
|
|
252
|
-
},
|
|
253
|
-
_meta: toolMeta('get_mandate_summary'),
|
|
254
|
-
},
|
|
255
|
-
async () => {
|
|
256
|
-
try {
|
|
257
|
-
const summary = await client.mandates.getSummary();
|
|
258
|
-
return { content: [], structuredContent: toStructuredContent(summary) };
|
|
259
|
-
} catch (err) {
|
|
260
|
-
return apiErrorResult(err);
|
|
261
|
-
}
|
|
262
|
-
},
|
|
263
|
-
);
|
|
264
|
-
}
|
package/src/tools/openclaw.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
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, toStructuredContent } from '../errors.js';
|
|
5
|
-
import { toolMeta } from '../tool-scopes.js';
|
|
6
|
-
|
|
7
|
-
export function registerOpenClawTools(mcp: McpServer, client: AgledgerClient): void {
|
|
8
|
-
|
|
9
|
-
// 1. Notarize — create an agreement
|
|
10
|
-
mcp.registerTool(
|
|
11
|
-
'agledger_notarize',
|
|
12
|
-
{
|
|
13
|
-
title: 'Notarize Agreement',
|
|
14
|
-
description: 'Create a notarized agreement. Returns mandate ID + hash. You keep the payload.',
|
|
15
|
-
inputSchema: {
|
|
16
|
-
contractType: z.string().describe('e.g. ACH-DLVR-v1, ACH-DATA-v1, ACH-ORCH-v1'),
|
|
17
|
-
payload: z.record(z.string(), z.unknown()).describe('Agreement criteria'),
|
|
18
|
-
performerHint: z.string().optional().describe('Who should do the work'),
|
|
19
|
-
},
|
|
20
|
-
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
|
|
21
|
-
_meta: toolMeta('agledger_notarize'),
|
|
22
|
-
},
|
|
23
|
-
async (args) => {
|
|
24
|
-
try {
|
|
25
|
-
const result = await client.notarize.createMandate({
|
|
26
|
-
contractType: args.contractType as any,
|
|
27
|
-
payload: args.payload,
|
|
28
|
-
performerHint: args.performerHint,
|
|
29
|
-
});
|
|
30
|
-
return { content: [], structuredContent: toStructuredContent(result) };
|
|
31
|
-
} catch (e) { return apiErrorResult(e); }
|
|
32
|
-
},
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
// 2. Accept — performer commits to the agreement
|
|
36
|
-
mcp.registerTool(
|
|
37
|
-
'agledger_accept',
|
|
38
|
-
{
|
|
39
|
-
title: 'Accept Agreement',
|
|
40
|
-
description: 'Accept a notarized agreement. Signals commitment to deliver.',
|
|
41
|
-
inputSchema: {
|
|
42
|
-
mandateId: z.string().describe('Mandate ID to accept'),
|
|
43
|
-
},
|
|
44
|
-
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
45
|
-
_meta: toolMeta('agledger_accept'),
|
|
46
|
-
},
|
|
47
|
-
async (args) => {
|
|
48
|
-
try {
|
|
49
|
-
const mandate = await client.notarize.acceptMandate(args.mandateId);
|
|
50
|
-
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
51
|
-
} catch (e) { return apiErrorResult(e); }
|
|
52
|
-
},
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
// 3. Receipt — performer submits evidence of completion
|
|
56
|
-
mcp.registerTool(
|
|
57
|
-
'agledger_receipt',
|
|
58
|
-
{
|
|
59
|
-
title: 'Submit Receipt',
|
|
60
|
-
description: 'Submit evidence of completed work. Returns receipt hash.',
|
|
61
|
-
inputSchema: {
|
|
62
|
-
mandateId: z.string().describe('Mandate ID this receipt is for'),
|
|
63
|
-
payload: z.record(z.string(), z.unknown()).describe('Evidence of completion'),
|
|
64
|
-
},
|
|
65
|
-
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
|
|
66
|
-
_meta: toolMeta('agledger_receipt'),
|
|
67
|
-
},
|
|
68
|
-
async (args) => {
|
|
69
|
-
try {
|
|
70
|
-
const result = await client.notarize.submitReceipt(args.mandateId, {
|
|
71
|
-
payload: args.payload,
|
|
72
|
-
});
|
|
73
|
-
return { content: [], structuredContent: toStructuredContent(result) };
|
|
74
|
-
} catch (e) { return apiErrorResult(e); }
|
|
75
|
-
},
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
// 4. Verdict — principal accepts or rejects delivery
|
|
79
|
-
mcp.registerTool(
|
|
80
|
-
'agledger_verdict',
|
|
81
|
-
{
|
|
82
|
-
title: 'Render Verdict',
|
|
83
|
-
description: 'Accept or reject delivered work. Closes the agreement.',
|
|
84
|
-
inputSchema: {
|
|
85
|
-
mandateId: z.string().describe('Mandate ID'),
|
|
86
|
-
verdict: z.enum(['PASS', 'FAIL']).describe('PASS to accept, FAIL to reject'),
|
|
87
|
-
reason: z.string().optional().describe('Why'),
|
|
88
|
-
},
|
|
89
|
-
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
90
|
-
_meta: toolMeta('agledger_verdict'),
|
|
91
|
-
},
|
|
92
|
-
async (args) => {
|
|
93
|
-
try {
|
|
94
|
-
const mandate = await client.notarize.renderVerdict(args.mandateId, {
|
|
95
|
-
verdict: args.verdict,
|
|
96
|
-
reason: args.reason,
|
|
97
|
-
});
|
|
98
|
-
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
99
|
-
} catch (e) { return apiErrorResult(e); }
|
|
100
|
-
},
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
// 5. Status — check agreement state
|
|
104
|
-
mcp.registerTool(
|
|
105
|
-
'agledger_status',
|
|
106
|
-
{
|
|
107
|
-
title: 'Agreement Status',
|
|
108
|
-
description: 'Check current state of an agreement.',
|
|
109
|
-
inputSchema: {
|
|
110
|
-
mandateId: z.string().describe('Mandate ID'),
|
|
111
|
-
},
|
|
112
|
-
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
113
|
-
_meta: toolMeta('agledger_status'),
|
|
114
|
-
},
|
|
115
|
-
async (args) => {
|
|
116
|
-
try {
|
|
117
|
-
const mandate = await client.notarize.getMandate(args.mandateId);
|
|
118
|
-
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
119
|
-
} catch (e) { return apiErrorResult(e); }
|
|
120
|
-
},
|
|
121
|
-
);
|
|
122
|
-
}
|
package/src/tools/receipts.ts
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
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, toStructuredContent } from '../errors.js';
|
|
5
|
-
import { toolMeta } from '../tool-scopes.js';
|
|
6
|
-
|
|
7
|
-
export interface ReceiptToolsOptions {
|
|
8
|
-
/** Skip submit_receipt (e.g. when a2a tools already provide it). */
|
|
9
|
-
skipSubmit?: boolean;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function registerReceiptTools(mcp: McpServer, client: AgledgerClient, options?: ReceiptToolsOptions): void {
|
|
13
|
-
if (!options?.skipSubmit) mcp.registerTool(
|
|
14
|
-
'submit_receipt',
|
|
15
|
-
{
|
|
16
|
-
title: 'Submit Receipt',
|
|
17
|
-
description:
|
|
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.',
|
|
19
|
-
inputSchema: {
|
|
20
|
-
mandateId: z.string().describe('UUID of the mandate this receipt is for'),
|
|
21
|
-
evidence: z
|
|
22
|
-
.record(z.string(), z.unknown())
|
|
23
|
-
.describe('Evidence JSON object proving task completion'),
|
|
24
|
-
notes: z.string().optional().describe('Human-readable notes about the submission'),
|
|
25
|
-
},
|
|
26
|
-
annotations: {
|
|
27
|
-
readOnlyHint: false,
|
|
28
|
-
destructiveHint: false,
|
|
29
|
-
idempotentHint: false,
|
|
30
|
-
openWorldHint: true,
|
|
31
|
-
},
|
|
32
|
-
_meta: toolMeta('submit_receipt'),
|
|
33
|
-
},
|
|
34
|
-
async (args) => {
|
|
35
|
-
try {
|
|
36
|
-
const { mandateId, ...submitParams } = args;
|
|
37
|
-
const receipt = await client.receipts.submit(mandateId, submitParams);
|
|
38
|
-
return { content: [], structuredContent: toStructuredContent(receipt) };
|
|
39
|
-
} catch (err) {
|
|
40
|
-
return apiErrorResult(err);
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
mcp.registerTool(
|
|
46
|
-
'report_outcome',
|
|
47
|
-
{
|
|
48
|
-
title: 'Report Outcome',
|
|
49
|
-
description:
|
|
50
|
-
'Report the principal verdict (PASS or FAIL) on a receipt. PASS accepts the receipt; FAIL rejects it. This is the standard way to close the accountability loop.',
|
|
51
|
-
inputSchema: {
|
|
52
|
-
mandateId: z.string().describe('UUID of the mandate'),
|
|
53
|
-
receiptId: z.string().describe('UUID of the receipt to judge'),
|
|
54
|
-
outcome: z.enum(['PASS', 'FAIL']).describe('Verdict: PASS (accept) or FAIL (reject)'),
|
|
55
|
-
checks: z
|
|
56
|
-
.record(z.string(), z.unknown())
|
|
57
|
-
.optional()
|
|
58
|
-
.describe('Optional per-field check results'),
|
|
59
|
-
},
|
|
60
|
-
annotations: {
|
|
61
|
-
readOnlyHint: false,
|
|
62
|
-
destructiveHint: false,
|
|
63
|
-
idempotentHint: true,
|
|
64
|
-
openWorldHint: true,
|
|
65
|
-
},
|
|
66
|
-
_meta: toolMeta('report_outcome'),
|
|
67
|
-
},
|
|
68
|
-
async (args) => {
|
|
69
|
-
try {
|
|
70
|
-
const { mandateId, ...outcomeParams } = args;
|
|
71
|
-
const result = await client.mandates.reportOutcome(mandateId, outcomeParams);
|
|
72
|
-
return { content: [], structuredContent: toStructuredContent(result) };
|
|
73
|
-
} catch (err) {
|
|
74
|
-
return apiErrorResult(err);
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
mcp.registerTool(
|
|
80
|
-
'get_receipt',
|
|
81
|
-
{
|
|
82
|
-
title: 'Get Receipt',
|
|
83
|
-
description: 'Get a specific receipt by ID. Use list_receipts to find receipt IDs first.',
|
|
84
|
-
inputSchema: {
|
|
85
|
-
mandateId: z.string().describe('UUID of the associated mandate'),
|
|
86
|
-
receiptId: z.string().describe('UUID of the receipt to retrieve'),
|
|
87
|
-
},
|
|
88
|
-
annotations: {
|
|
89
|
-
readOnlyHint: true,
|
|
90
|
-
destructiveHint: false,
|
|
91
|
-
idempotentHint: true,
|
|
92
|
-
openWorldHint: true,
|
|
93
|
-
},
|
|
94
|
-
_meta: toolMeta('get_receipt'),
|
|
95
|
-
},
|
|
96
|
-
async (args) => {
|
|
97
|
-
try {
|
|
98
|
-
const receipt = await client.receipts.get(args.mandateId, args.receiptId);
|
|
99
|
-
return { content: [], structuredContent: toStructuredContent(receipt) };
|
|
100
|
-
} catch (err) {
|
|
101
|
-
return apiErrorResult(err);
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
mcp.registerTool(
|
|
107
|
-
'list_receipts',
|
|
108
|
-
{
|
|
109
|
-
title: 'List Receipts',
|
|
110
|
-
description: 'List all receipts (task attestations) submitted against a mandate.',
|
|
111
|
-
inputSchema: {
|
|
112
|
-
mandateId: z.string().describe('UUID of the mandate to list receipts for'),
|
|
113
|
-
limit: z.number().optional().describe('Page size (default: 20)'),
|
|
114
|
-
offset: z.number().optional().describe('Page offset (default: 0)'),
|
|
115
|
-
},
|
|
116
|
-
annotations: {
|
|
117
|
-
readOnlyHint: true,
|
|
118
|
-
destructiveHint: false,
|
|
119
|
-
idempotentHint: true,
|
|
120
|
-
openWorldHint: true,
|
|
121
|
-
},
|
|
122
|
-
_meta: toolMeta('list_receipts'),
|
|
123
|
-
},
|
|
124
|
-
async (args) => {
|
|
125
|
-
try {
|
|
126
|
-
const { mandateId, ...paginationParams } = args;
|
|
127
|
-
const result = await client.receipts.list(mandateId, paginationParams);
|
|
128
|
-
return { content: [], structuredContent: toStructuredContent(result) };
|
|
129
|
-
} catch (err) {
|
|
130
|
-
return apiErrorResult(err);
|
|
131
|
-
}
|
|
132
|
-
},
|
|
133
|
-
);
|
|
134
|
-
}
|
package/src/tools/reputation.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
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, toStructuredContent } from '../errors.js';
|
|
5
|
-
import { toolMeta } from '../tool-scopes.js';
|
|
6
|
-
|
|
7
|
-
export function registerReputationTools(mcp: McpServer, client: AgledgerClient): void {
|
|
8
|
-
mcp.registerTool(
|
|
9
|
-
'get_agent_reputation',
|
|
10
|
-
{
|
|
11
|
-
title: 'Get Agent Reputation',
|
|
12
|
-
description: 'Get per-contract-type reputation scores for an agent. Returns paginated list with reliability, accuracy, efficiency, and composite scores for each contract type.',
|
|
13
|
-
inputSchema: {
|
|
14
|
-
agentId: z.string().describe('UUID of the agent'),
|
|
15
|
-
},
|
|
16
|
-
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
17
|
-
_meta: toolMeta('get_agent_reputation'),
|
|
18
|
-
},
|
|
19
|
-
async (args) => {
|
|
20
|
-
try {
|
|
21
|
-
const page = await client.reputation.getAgent(args.agentId);
|
|
22
|
-
return { content: [], structuredContent: toStructuredContent(page) };
|
|
23
|
-
} catch (err) { return apiErrorResult(err); }
|
|
24
|
-
},
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
mcp.registerTool(
|
|
28
|
-
'get_reputation_by_type',
|
|
29
|
-
{
|
|
30
|
-
title: 'Get Reputation by Contract Type',
|
|
31
|
-
description: 'Get an agent\'s reputation score for a specific contract type. Returns reliability, accuracy, efficiency, and composite scores.',
|
|
32
|
-
inputSchema: {
|
|
33
|
-
agentId: z.string().describe('UUID of the agent'),
|
|
34
|
-
contractType: z.string().describe('Contract type (e.g., ACH-PROC-v1)'),
|
|
35
|
-
},
|
|
36
|
-
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
37
|
-
_meta: toolMeta('get_reputation_by_type'),
|
|
38
|
-
},
|
|
39
|
-
async (args) => {
|
|
40
|
-
try {
|
|
41
|
-
const score = await client.reputation.getByContractType(args.agentId, args.contractType);
|
|
42
|
-
return { content: [], structuredContent: toStructuredContent(score) };
|
|
43
|
-
} catch (err) { return apiErrorResult(err); }
|
|
44
|
-
},
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
mcp.registerTool(
|
|
48
|
-
'get_agent_history',
|
|
49
|
-
{
|
|
50
|
-
title: 'Get Agent Transaction History',
|
|
51
|
-
description: 'Get an agent\'s mandate transaction history. Filter by contract type, outcome, and date range.',
|
|
52
|
-
inputSchema: {
|
|
53
|
-
agentId: z.string().describe('UUID of the agent'),
|
|
54
|
-
contractType: z.string().optional().describe('Filter by contract type'),
|
|
55
|
-
outcome: z.enum(['PASS', 'FAIL']).optional().describe('Filter by verdict outcome'),
|
|
56
|
-
limit: z.number().optional().describe('Page size'),
|
|
57
|
-
},
|
|
58
|
-
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
59
|
-
_meta: toolMeta('get_agent_history'),
|
|
60
|
-
},
|
|
61
|
-
async (args) => {
|
|
62
|
-
try {
|
|
63
|
-
const { agentId, ...params } = args;
|
|
64
|
-
const page = await client.reputation.getHistory(agentId, params);
|
|
65
|
-
return { content: [], structuredContent: toStructuredContent(page) };
|
|
66
|
-
} catch (err) { return apiErrorResult(err); }
|
|
67
|
-
},
|
|
68
|
-
);
|
|
69
|
-
}
|