@agledger/mcp-server 1.5.0 → 2.0.1
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/dist/enums.d.ts +0 -110
- package/dist/enums.d.ts.map +0 -1
- package/dist/enums.js +0 -42
- package/dist/enums.js.map +0 -1
- package/dist/errors.d.ts +0 -10
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -49
- package/dist/errors.js.map +0 -1
- package/dist/resources/contract-types.d.ts +0 -4
- package/dist/resources/contract-types.d.ts.map +0 -1
- package/dist/resources/contract-types.js +0 -104
- package/dist/resources/contract-types.js.map +0 -1
- package/dist/tool-scopes.d.ts +0 -11
- package/dist/tool-scopes.d.ts.map +0 -1
- package/dist/tool-scopes.js +0 -164
- package/dist/tool-scopes.js.map +0 -1
- package/dist/tools/a2a.d.ts +0 -8
- package/dist/tools/a2a.d.ts.map +0 -1
- package/dist/tools/a2a.js +0 -360
- package/dist/tools/a2a.js.map +0 -1
- package/dist/tools/agent-mandates.d.ts +0 -4
- package/dist/tools/agent-mandates.d.ts.map +0 -1
- package/dist/tools/agent-mandates.js +0 -222
- package/dist/tools/agent-mandates.js.map +0 -1
- package/dist/tools/agents-refs.d.ts +0 -4
- package/dist/tools/agents-refs.d.ts.map +0 -1
- package/dist/tools/agents-refs.js +0 -196
- package/dist/tools/agents-refs.js.map +0 -1
- package/dist/tools/capabilities.d.ts +0 -4
- package/dist/tools/capabilities.d.ts.map +0 -1
- package/dist/tools/capabilities.js +0 -54
- package/dist/tools/capabilities.js.map +0 -1
- package/dist/tools/code-mode.d.ts +0 -4
- package/dist/tools/code-mode.d.ts.map +0 -1
- package/dist/tools/code-mode.js +0 -389
- package/dist/tools/code-mode.js.map +0 -1
- package/dist/tools/compliance.d.ts +0 -4
- package/dist/tools/compliance.d.ts.map +0 -1
- package/dist/tools/compliance.js +0 -63
- package/dist/tools/compliance.js.map +0 -1
- package/dist/tools/dashboard.d.ts +0 -4
- package/dist/tools/dashboard.d.ts.map +0 -1
- package/dist/tools/dashboard.js +0 -57
- package/dist/tools/dashboard.js.map +0 -1
- package/dist/tools/disputes.d.ts +0 -4
- package/dist/tools/disputes.d.ts.map +0 -1
- package/dist/tools/disputes.js +0 -103
- package/dist/tools/disputes.js.map +0 -1
- package/dist/tools/enterprises.d.ts +0 -4
- package/dist/tools/enterprises.d.ts.map +0 -1
- package/dist/tools/enterprises.js +0 -173
- package/dist/tools/enterprises.js.map +0 -1
- package/dist/tools/events.d.ts +0 -4
- package/dist/tools/events.d.ts.map +0 -1
- package/dist/tools/events.js +0 -28
- package/dist/tools/events.js.map +0 -1
- package/dist/tools/federation-admin.d.ts +0 -4
- package/dist/tools/federation-admin.d.ts.map +0 -1
- package/dist/tools/federation-admin.js +0 -567
- package/dist/tools/federation-admin.js.map +0 -1
- package/dist/tools/federation.d.ts +0 -4
- package/dist/tools/federation.d.ts.map +0 -1
- package/dist/tools/federation.js +0 -505
- package/dist/tools/federation.js.map +0 -1
- package/dist/tools/health.d.ts +0 -4
- package/dist/tools/health.d.ts.map +0 -1
- package/dist/tools/health.js +0 -25
- package/dist/tools/health.js.map +0 -1
- package/dist/tools/mandates.d.ts +0 -4
- package/dist/tools/mandates.d.ts.map +0 -1
- package/dist/tools/mandates.js +0 -227
- package/dist/tools/mandates.js.map +0 -1
- package/dist/tools/openclaw.d.ts +0 -4
- package/dist/tools/openclaw.d.ts.map +0 -1
- package/dist/tools/openclaw.js +0 -110
- package/dist/tools/openclaw.js.map +0 -1
- package/dist/tools/receipts.d.ts +0 -8
- package/dist/tools/receipts.d.ts.map +0 -1
- package/dist/tools/receipts.js +0 -111
- package/dist/tools/receipts.js.map +0 -1
- package/dist/tools/reputation.d.ts +0 -4
- package/dist/tools/reputation.d.ts.map +0 -1
- package/dist/tools/reputation.js +0 -62
- package/dist/tools/reputation.js.map +0 -1
- package/dist/tools/schemas.d.ts +0 -4
- package/dist/tools/schemas.d.ts.map +0 -1
- package/dist/tools/schemas.js +0 -453
- package/dist/tools/schemas.js.map +0 -1
- package/dist/tools/verification-keys.d.ts +0 -4
- package/dist/tools/verification-keys.d.ts.map +0 -1
- package/dist/tools/verification-keys.js +0 -27
- package/dist/tools/verification-keys.js.map +0 -1
- package/dist/tools/verification.d.ts +0 -4
- package/dist/tools/verification.d.ts.map +0 -1
- package/dist/tools/verification.js +0 -50
- package/dist/tools/verification.js.map +0 -1
- 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/a2a.ts
DELETED
|
@@ -1,430 +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 } from '../enums.js';
|
|
6
|
-
import { toolMeta } from '../tool-scopes.js';
|
|
7
|
-
|
|
8
|
-
export interface A2aToolsConfig {
|
|
9
|
-
/** Enterprise ID for search queries. Falls back to AGLEDGER_ENTERPRISE_ID env var. */
|
|
10
|
-
enterpriseId?: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function getEnterpriseId(config: A2aToolsConfig): string {
|
|
14
|
-
return config.enterpriseId ?? process.env.AGLEDGER_ENTERPRISE_ID ?? '';
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function registerA2aTools(
|
|
18
|
-
mcp: McpServer,
|
|
19
|
-
client: AgledgerClient,
|
|
20
|
-
config: A2aToolsConfig = {},
|
|
21
|
-
): void {
|
|
22
|
-
mcp.registerTool(
|
|
23
|
-
'create_mandate',
|
|
24
|
-
{
|
|
25
|
-
title: 'Create Mandate',
|
|
26
|
-
description:
|
|
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.',
|
|
28
|
-
inputSchema: {
|
|
29
|
-
contractType: ContractTypeEnum,
|
|
30
|
-
criteria: z
|
|
31
|
-
.record(z.string(), z.unknown())
|
|
32
|
-
.describe('Acceptance criteria (key-value pairs)'),
|
|
33
|
-
performerAgentId: z.string().optional().describe('Agent to do the work (omit for self-mandate)'),
|
|
34
|
-
projectRef: z.string().optional().describe('Project grouping ID'),
|
|
35
|
-
deadline: z.string().optional().describe('ISO 8601 future deadline'),
|
|
36
|
-
},
|
|
37
|
-
annotations: {
|
|
38
|
-
readOnlyHint: false,
|
|
39
|
-
destructiveHint: false,
|
|
40
|
-
idempotentHint: false,
|
|
41
|
-
openWorldHint: true,
|
|
42
|
-
},
|
|
43
|
-
_meta: toolMeta('create_mandate'),
|
|
44
|
-
},
|
|
45
|
-
async (args) => {
|
|
46
|
-
try {
|
|
47
|
-
let deadline = args.deadline;
|
|
48
|
-
if (deadline) {
|
|
49
|
-
try {
|
|
50
|
-
const d = new Date(deadline);
|
|
51
|
-
if (isNaN(d.getTime()) || d.getTime() <= Date.now()) {
|
|
52
|
-
deadline = undefined;
|
|
53
|
-
}
|
|
54
|
-
} catch {
|
|
55
|
-
deadline = undefined;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
const mandate = await client.mandates.createAgent({
|
|
59
|
-
contractType: args.contractType,
|
|
60
|
-
contractVersion: '1',
|
|
61
|
-
criteria: args.criteria,
|
|
62
|
-
performerAgentId: args.performerAgentId,
|
|
63
|
-
projectRef: args.projectRef,
|
|
64
|
-
deadline,
|
|
65
|
-
autoActivate: true,
|
|
66
|
-
});
|
|
67
|
-
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
68
|
-
} catch (err) {
|
|
69
|
-
return apiErrorResult(err);
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
mcp.registerTool(
|
|
75
|
-
'propose_mandate',
|
|
76
|
-
{
|
|
77
|
-
title: 'Propose Mandate',
|
|
78
|
-
description:
|
|
79
|
-
'Propose accountable work to another agent. Your identity is inferred from your API key. Use create_mandate instead for self-mandates. Criteria: simple key-value pairs (strings, not nested objects).',
|
|
80
|
-
inputSchema: {
|
|
81
|
-
performerAgentId: z.string().describe('Agent to do the work'),
|
|
82
|
-
contractType: ContractTypeEnum,
|
|
83
|
-
criteria: z
|
|
84
|
-
.record(z.string(), z.unknown())
|
|
85
|
-
.describe('Acceptance criteria (key-value pairs)'),
|
|
86
|
-
projectRef: z.string().optional().describe('Project grouping ID'),
|
|
87
|
-
parentMandateId: z.string().optional().describe('Parent mandate if delegating'),
|
|
88
|
-
deadline: z.string().optional().describe('ISO 8601 future deadline'),
|
|
89
|
-
},
|
|
90
|
-
annotations: {
|
|
91
|
-
readOnlyHint: false,
|
|
92
|
-
destructiveHint: false,
|
|
93
|
-
idempotentHint: false,
|
|
94
|
-
openWorldHint: true,
|
|
95
|
-
},
|
|
96
|
-
_meta: toolMeta('propose_mandate'),
|
|
97
|
-
},
|
|
98
|
-
async (args) => {
|
|
99
|
-
try {
|
|
100
|
-
// Validate deadline is in the future, strip if not
|
|
101
|
-
let deadline = args.deadline;
|
|
102
|
-
if (deadline) {
|
|
103
|
-
try {
|
|
104
|
-
const d = new Date(deadline);
|
|
105
|
-
if (isNaN(d.getTime()) || d.getTime() <= Date.now()) {
|
|
106
|
-
deadline = undefined; // silently drop invalid/past deadlines
|
|
107
|
-
}
|
|
108
|
-
} catch {
|
|
109
|
-
deadline = undefined;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
const mandate = await client.mandates.createAgent({
|
|
113
|
-
performerAgentId: args.performerAgentId,
|
|
114
|
-
contractType: args.contractType,
|
|
115
|
-
contractVersion: '1',
|
|
116
|
-
criteria: args.criteria,
|
|
117
|
-
parentMandateId: args.parentMandateId,
|
|
118
|
-
deadline,
|
|
119
|
-
});
|
|
120
|
-
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
121
|
-
} catch (err) {
|
|
122
|
-
return apiErrorResult(err);
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
mcp.registerTool(
|
|
128
|
-
'accept_mandate',
|
|
129
|
-
{
|
|
130
|
-
title: 'Accept Mandate',
|
|
131
|
-
description:
|
|
132
|
-
'Accept a proposed mandate. After accepting, do the work, then call submit_receipt.',
|
|
133
|
-
inputSchema: {
|
|
134
|
-
mandateId: z.string().describe('Mandate ID to accept'),
|
|
135
|
-
},
|
|
136
|
-
annotations: {
|
|
137
|
-
readOnlyHint: false,
|
|
138
|
-
destructiveHint: false,
|
|
139
|
-
idempotentHint: true,
|
|
140
|
-
openWorldHint: true,
|
|
141
|
-
},
|
|
142
|
-
_meta: toolMeta('accept_mandate'),
|
|
143
|
-
},
|
|
144
|
-
async (args) => {
|
|
145
|
-
try {
|
|
146
|
-
let mandate = await client.mandates.accept(args.mandateId);
|
|
147
|
-
|
|
148
|
-
// Auto-activate: CREATED → ACTIVE so receipts can be submitted immediately
|
|
149
|
-
if (mandate.status === 'CREATED') {
|
|
150
|
-
try {
|
|
151
|
-
mandate = await client.mandates.transition(args.mandateId, 'activate');
|
|
152
|
-
} catch {
|
|
153
|
-
/* activation may fail if already active or missing prerequisites */
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
158
|
-
} catch (err) {
|
|
159
|
-
return apiErrorResult(err);
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
mcp.registerTool(
|
|
165
|
-
'check_proposals',
|
|
166
|
-
{
|
|
167
|
-
title: 'Check Proposals',
|
|
168
|
-
description: 'Check pending proposals and open obligations. Call at start of each round.',
|
|
169
|
-
inputSchema: {
|
|
170
|
-
agentId: z.string().optional().describe('Your agent ID'),
|
|
171
|
-
},
|
|
172
|
-
annotations: {
|
|
173
|
-
readOnlyHint: true,
|
|
174
|
-
destructiveHint: false,
|
|
175
|
-
idempotentHint: true,
|
|
176
|
-
openWorldHint: true,
|
|
177
|
-
},
|
|
178
|
-
_meta: toolMeta('check_proposals'),
|
|
179
|
-
},
|
|
180
|
-
async (args) => {
|
|
181
|
-
try {
|
|
182
|
-
const enterpriseId = getEnterpriseId(config);
|
|
183
|
-
|
|
184
|
-
const searchParams: Record<string, unknown> = { limit: 100 };
|
|
185
|
-
if (enterpriseId) searchParams.enterpriseId = enterpriseId;
|
|
186
|
-
|
|
187
|
-
const results = await client.mandates.search(searchParams as any);
|
|
188
|
-
const allMandates = results.data || [];
|
|
189
|
-
|
|
190
|
-
// Client-side status filtering (backend status param unreliable)
|
|
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');
|
|
194
|
-
|
|
195
|
-
// Filter to this agent if ID provided
|
|
196
|
-
if (args.agentId) {
|
|
197
|
-
const id = args.agentId;
|
|
198
|
-
proposals = proposals.filter(
|
|
199
|
-
(m: any) => m.agentId === id || m.principalAgentId === id,
|
|
200
|
-
);
|
|
201
|
-
active = active.filter((m: any) => m.agentId === id || m.principalAgentId === id);
|
|
202
|
-
verified = verified.filter(
|
|
203
|
-
(m: any) => m.agentId === id || m.principalAgentId === id,
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return {
|
|
208
|
-
content: [],
|
|
209
|
-
structuredContent: toStructuredContent({ proposals, active, verified }),
|
|
210
|
-
};
|
|
211
|
-
} catch (err) {
|
|
212
|
-
return apiErrorResult(err);
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
mcp.registerTool(
|
|
218
|
-
'submit_receipt',
|
|
219
|
-
{
|
|
220
|
-
title: 'Submit Receipt',
|
|
221
|
-
description:
|
|
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": "..."}.',
|
|
223
|
-
inputSchema: {
|
|
224
|
-
mandateId: z.string().describe('Mandate ID'),
|
|
225
|
-
evidence: z.record(z.string(), z.unknown()).describe('Evidence of completion'),
|
|
226
|
-
},
|
|
227
|
-
annotations: {
|
|
228
|
-
readOnlyHint: false,
|
|
229
|
-
destructiveHint: false,
|
|
230
|
-
idempotentHint: false,
|
|
231
|
-
openWorldHint: true,
|
|
232
|
-
},
|
|
233
|
-
_meta: toolMeta('submit_receipt'),
|
|
234
|
-
},
|
|
235
|
-
async (args) => {
|
|
236
|
-
try {
|
|
237
|
-
const { mandateId, ...submitParams } = args;
|
|
238
|
-
const receipt = await client.receipts.submit(mandateId, submitParams);
|
|
239
|
-
return { content: [], structuredContent: toStructuredContent(receipt) };
|
|
240
|
-
} catch (err) {
|
|
241
|
-
return apiErrorResult(err);
|
|
242
|
-
}
|
|
243
|
-
},
|
|
244
|
-
);
|
|
245
|
-
|
|
246
|
-
mcp.registerTool(
|
|
247
|
-
'settle_mandate',
|
|
248
|
-
{
|
|
249
|
-
title: 'Settle Mandate',
|
|
250
|
-
description:
|
|
251
|
-
'Settle a mandate manually. Usually auto-settles — use only if stuck in PROCESSING.',
|
|
252
|
-
inputSchema: {
|
|
253
|
-
mandateId: z.string().describe('Mandate ID'),
|
|
254
|
-
reason: z.string().optional().describe('Settlement reason'),
|
|
255
|
-
},
|
|
256
|
-
annotations: {
|
|
257
|
-
readOnlyHint: false,
|
|
258
|
-
destructiveHint: false,
|
|
259
|
-
idempotentHint: true,
|
|
260
|
-
openWorldHint: true,
|
|
261
|
-
},
|
|
262
|
-
_meta: toolMeta('settle_mandate'),
|
|
263
|
-
},
|
|
264
|
-
async (args) => {
|
|
265
|
-
try {
|
|
266
|
-
const mandate = await client.mandates.transition(args.mandateId, 'settle', args.reason);
|
|
267
|
-
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
268
|
-
} catch (err) {
|
|
269
|
-
return apiErrorResult(err);
|
|
270
|
-
}
|
|
271
|
-
},
|
|
272
|
-
);
|
|
273
|
-
|
|
274
|
-
mcp.registerTool(
|
|
275
|
-
'get_mandate',
|
|
276
|
-
{
|
|
277
|
-
title: 'Get Mandate',
|
|
278
|
-
description: 'Get mandate status and details by ID.',
|
|
279
|
-
inputSchema: {
|
|
280
|
-
mandateId: z.string().describe('Mandate ID'),
|
|
281
|
-
},
|
|
282
|
-
annotations: {
|
|
283
|
-
readOnlyHint: true,
|
|
284
|
-
destructiveHint: false,
|
|
285
|
-
idempotentHint: true,
|
|
286
|
-
openWorldHint: true,
|
|
287
|
-
},
|
|
288
|
-
_meta: toolMeta('get_mandate'),
|
|
289
|
-
},
|
|
290
|
-
async (args) => {
|
|
291
|
-
try {
|
|
292
|
-
const mandate = await client.mandates.get(args.mandateId);
|
|
293
|
-
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
294
|
-
} catch (err) {
|
|
295
|
-
return apiErrorResult(err);
|
|
296
|
-
}
|
|
297
|
-
},
|
|
298
|
-
);
|
|
299
|
-
|
|
300
|
-
mcp.registerTool(
|
|
301
|
-
'reject_mandate',
|
|
302
|
-
{
|
|
303
|
-
title: 'Reject Mandate',
|
|
304
|
-
description: 'Reject a proposed mandate with a reason.',
|
|
305
|
-
inputSchema: {
|
|
306
|
-
mandateId: z.string().describe('Mandate ID'),
|
|
307
|
-
reason: z.string().describe('Rejection reason'),
|
|
308
|
-
},
|
|
309
|
-
annotations: {
|
|
310
|
-
readOnlyHint: false,
|
|
311
|
-
destructiveHint: true,
|
|
312
|
-
idempotentHint: false,
|
|
313
|
-
openWorldHint: true,
|
|
314
|
-
},
|
|
315
|
-
_meta: toolMeta('reject_mandate'),
|
|
316
|
-
},
|
|
317
|
-
async (args) => {
|
|
318
|
-
try {
|
|
319
|
-
const mandate = await client.mandates.reject(args.mandateId, args.reason);
|
|
320
|
-
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
321
|
-
} catch (err) {
|
|
322
|
-
return apiErrorResult(err);
|
|
323
|
-
}
|
|
324
|
-
},
|
|
325
|
-
);
|
|
326
|
-
|
|
327
|
-
mcp.registerTool(
|
|
328
|
-
'my_mandates',
|
|
329
|
-
{
|
|
330
|
-
title: 'My Mandates',
|
|
331
|
-
description: 'List your mandates grouped by status. Shows what needs action.',
|
|
332
|
-
inputSchema: {
|
|
333
|
-
agentId: z.string().optional().describe('Your agent ID'),
|
|
334
|
-
},
|
|
335
|
-
annotations: {
|
|
336
|
-
readOnlyHint: true,
|
|
337
|
-
destructiveHint: false,
|
|
338
|
-
idempotentHint: true,
|
|
339
|
-
openWorldHint: true,
|
|
340
|
-
},
|
|
341
|
-
_meta: toolMeta('my_mandates'),
|
|
342
|
-
},
|
|
343
|
-
async (args) => {
|
|
344
|
-
try {
|
|
345
|
-
const enterpriseId = getEnterpriseId(config);
|
|
346
|
-
|
|
347
|
-
const searchParams: Record<string, unknown> = { limit: 100 };
|
|
348
|
-
if (enterpriseId) searchParams.enterpriseId = enterpriseId;
|
|
349
|
-
|
|
350
|
-
const result = await client.mandates.search(searchParams as any);
|
|
351
|
-
const allMandates: any[] = result.data || [];
|
|
352
|
-
|
|
353
|
-
// Filter to this agent
|
|
354
|
-
let filtered = allMandates;
|
|
355
|
-
if (args.agentId) {
|
|
356
|
-
const id = args.agentId;
|
|
357
|
-
filtered = allMandates.filter((m: any) => m.agentId === id || m.principalAgentId === id);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
// Group by status
|
|
361
|
-
const byStatus: Record<string, any[]> = {};
|
|
362
|
-
for (const m of filtered) {
|
|
363
|
-
const s = m.status || 'UNKNOWN';
|
|
364
|
-
if (!byStatus[s]) byStatus[s] = [];
|
|
365
|
-
byStatus[s].push(m);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
return {
|
|
369
|
-
content: [],
|
|
370
|
-
structuredContent: toStructuredContent({ mandates: filtered, byStatus }),
|
|
371
|
-
};
|
|
372
|
-
} catch (err) {
|
|
373
|
-
return apiErrorResult(err);
|
|
374
|
-
}
|
|
375
|
-
},
|
|
376
|
-
);
|
|
377
|
-
|
|
378
|
-
mcp.registerTool(
|
|
379
|
-
'cancel_mandate',
|
|
380
|
-
{
|
|
381
|
-
title: 'Cancel Mandate',
|
|
382
|
-
description: 'Cancel a mandate with a reason.',
|
|
383
|
-
inputSchema: {
|
|
384
|
-
mandateId: z.string().describe('Mandate ID'),
|
|
385
|
-
reason: z.string().describe('Cancellation reason'),
|
|
386
|
-
},
|
|
387
|
-
annotations: {
|
|
388
|
-
readOnlyHint: false,
|
|
389
|
-
destructiveHint: true,
|
|
390
|
-
idempotentHint: false,
|
|
391
|
-
openWorldHint: true,
|
|
392
|
-
},
|
|
393
|
-
_meta: toolMeta('cancel_mandate'),
|
|
394
|
-
},
|
|
395
|
-
async (args) => {
|
|
396
|
-
try {
|
|
397
|
-
const mandate = await client.mandates.cancel(args.mandateId, args.reason);
|
|
398
|
-
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
399
|
-
} catch (err) {
|
|
400
|
-
return apiErrorResult(err);
|
|
401
|
-
}
|
|
402
|
-
},
|
|
403
|
-
);
|
|
404
|
-
|
|
405
|
-
mcp.registerTool(
|
|
406
|
-
'check_reputation',
|
|
407
|
-
{
|
|
408
|
-
title: 'Check Reputation',
|
|
409
|
-
description: "Check an agent's reputation score and fulfillment history.",
|
|
410
|
-
inputSchema: {
|
|
411
|
-
agentId: z.string().describe('Agent ID'),
|
|
412
|
-
},
|
|
413
|
-
annotations: {
|
|
414
|
-
readOnlyHint: true,
|
|
415
|
-
destructiveHint: false,
|
|
416
|
-
idempotentHint: true,
|
|
417
|
-
openWorldHint: true,
|
|
418
|
-
},
|
|
419
|
-
_meta: toolMeta('check_reputation'),
|
|
420
|
-
},
|
|
421
|
-
async (args) => {
|
|
422
|
-
try {
|
|
423
|
-
const rep = await client.reputation.getAgent(args.agentId);
|
|
424
|
-
return { content: [], structuredContent: toStructuredContent(rep) };
|
|
425
|
-
} catch (err) {
|
|
426
|
-
return apiErrorResult(err);
|
|
427
|
-
}
|
|
428
|
-
},
|
|
429
|
-
);
|
|
430
|
-
}
|
|
@@ -1,259 +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
|
-
import { ContractTypeEnum } from '../enums.js';
|
|
7
|
-
|
|
8
|
-
export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient): void {
|
|
9
|
-
mcp.registerTool(
|
|
10
|
-
'propose_agent_mandate',
|
|
11
|
-
{
|
|
12
|
-
title: 'Propose Agent Mandate',
|
|
13
|
-
description: 'Create a mandate proposal from one agent to another. The mandate starts in PROPOSED status.',
|
|
14
|
-
inputSchema: {
|
|
15
|
-
principalAgentId: z.string().describe('Agent ID of the principal (proposer)'),
|
|
16
|
-
performerAgentId: z.string().optional().describe('Agent ID of the performer (recipient)'),
|
|
17
|
-
contractType: ContractTypeEnum,
|
|
18
|
-
contractVersion: z.string().default('1').describe('Contract version'),
|
|
19
|
-
platform: z.string().optional().describe('Platform identifier'),
|
|
20
|
-
criteria: z.record(z.string(), z.unknown()).describe('Acceptance criteria'),
|
|
21
|
-
tolerance: z.record(z.string(), z.unknown()).optional().describe('Tolerance bands'),
|
|
22
|
-
parentMandateId: z.string().optional().describe('Parent mandate ID for delegation'),
|
|
23
|
-
commissionPct: z.number().optional().describe('Commission percentage (0-100)'),
|
|
24
|
-
deadline: z.string().optional().describe('ISO 8601 deadline'),
|
|
25
|
-
},
|
|
26
|
-
annotations: {
|
|
27
|
-
readOnlyHint: false,
|
|
28
|
-
destructiveHint: false,
|
|
29
|
-
idempotentHint: false,
|
|
30
|
-
openWorldHint: true,
|
|
31
|
-
},
|
|
32
|
-
_meta: toolMeta('propose_agent_mandate'),
|
|
33
|
-
},
|
|
34
|
-
async (args) => {
|
|
35
|
-
try {
|
|
36
|
-
const mandate = await client.mandates.createAgent(args);
|
|
37
|
-
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
38
|
-
} catch (err) {
|
|
39
|
-
return apiErrorResult(err);
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
mcp.registerTool(
|
|
45
|
-
'accept_proposal',
|
|
46
|
-
{
|
|
47
|
-
title: 'Accept Proposal',
|
|
48
|
-
description: 'Accept a proposed mandate. Moves status from PROPOSED to ACCEPTED.',
|
|
49
|
-
inputSchema: {
|
|
50
|
-
mandateId: z.string().describe('UUID of the proposed mandate'),
|
|
51
|
-
},
|
|
52
|
-
annotations: {
|
|
53
|
-
readOnlyHint: false,
|
|
54
|
-
destructiveHint: false,
|
|
55
|
-
idempotentHint: true,
|
|
56
|
-
openWorldHint: true,
|
|
57
|
-
},
|
|
58
|
-
_meta: toolMeta('accept_proposal'),
|
|
59
|
-
},
|
|
60
|
-
async (args) => {
|
|
61
|
-
try {
|
|
62
|
-
const mandate = await client.mandates.accept(args.mandateId);
|
|
63
|
-
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
64
|
-
} catch (err) {
|
|
65
|
-
return apiErrorResult(err);
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
mcp.registerTool(
|
|
71
|
-
'reject_proposal',
|
|
72
|
-
{
|
|
73
|
-
title: 'Reject Proposal',
|
|
74
|
-
description: 'Reject a proposed mandate. Moves status to REJECTED.',
|
|
75
|
-
inputSchema: {
|
|
76
|
-
mandateId: z.string().describe('UUID of the proposed mandate'),
|
|
77
|
-
reason: z.string().optional().describe('Reason for rejection'),
|
|
78
|
-
},
|
|
79
|
-
annotations: {
|
|
80
|
-
readOnlyHint: false,
|
|
81
|
-
destructiveHint: true,
|
|
82
|
-
idempotentHint: false,
|
|
83
|
-
openWorldHint: true,
|
|
84
|
-
},
|
|
85
|
-
_meta: toolMeta('reject_proposal'),
|
|
86
|
-
},
|
|
87
|
-
async (args) => {
|
|
88
|
-
try {
|
|
89
|
-
const mandate = await client.mandates.reject(args.mandateId, args.reason);
|
|
90
|
-
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
91
|
-
} catch (err) {
|
|
92
|
-
return apiErrorResult(err);
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
mcp.registerTool(
|
|
98
|
-
'counter_proposal',
|
|
99
|
-
{
|
|
100
|
-
title: 'Counter Proposal',
|
|
101
|
-
description: 'Counter-propose modified terms on a proposed mandate.',
|
|
102
|
-
inputSchema: {
|
|
103
|
-
mandateId: z.string().describe('UUID of the proposed mandate'),
|
|
104
|
-
counterCriteria: z.record(z.string(), z.unknown()).optional().describe('Modified acceptance criteria'),
|
|
105
|
-
counterTolerance: z.record(z.string(), z.unknown()).optional().describe('Modified tolerance bands'),
|
|
106
|
-
counterDeadline: z.string().optional().describe('Modified ISO 8601 deadline'),
|
|
107
|
-
counterCommissionPct: z.number().optional().describe('Modified commission percentage'),
|
|
108
|
-
message: z.string().optional().describe('Message explaining the counter-proposal'),
|
|
109
|
-
},
|
|
110
|
-
annotations: {
|
|
111
|
-
readOnlyHint: false,
|
|
112
|
-
destructiveHint: false,
|
|
113
|
-
idempotentHint: false,
|
|
114
|
-
openWorldHint: true,
|
|
115
|
-
},
|
|
116
|
-
_meta: toolMeta('counter_proposal'),
|
|
117
|
-
},
|
|
118
|
-
async (args) => {
|
|
119
|
-
try {
|
|
120
|
-
const mandate = await client.mandates.counterPropose(args.mandateId, {
|
|
121
|
-
message: args.message,
|
|
122
|
-
counterCriteria: args.counterCriteria,
|
|
123
|
-
counterTolerance: args.counterTolerance,
|
|
124
|
-
counterDeadline: args.counterDeadline,
|
|
125
|
-
counterCommissionPct: args.counterCommissionPct ?? undefined,
|
|
126
|
-
});
|
|
127
|
-
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
128
|
-
} catch (err) {
|
|
129
|
-
return apiErrorResult(err);
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
mcp.registerTool(
|
|
135
|
-
'accept_counter_proposal',
|
|
136
|
-
{
|
|
137
|
-
title: 'Accept Counter Proposal',
|
|
138
|
-
description: 'Accept a counter-proposal on a mandate.',
|
|
139
|
-
inputSchema: {
|
|
140
|
-
mandateId: z.string().describe('UUID of the counter-proposed mandate'),
|
|
141
|
-
},
|
|
142
|
-
annotations: {
|
|
143
|
-
readOnlyHint: false,
|
|
144
|
-
destructiveHint: false,
|
|
145
|
-
idempotentHint: true,
|
|
146
|
-
openWorldHint: true,
|
|
147
|
-
},
|
|
148
|
-
_meta: toolMeta('accept_counter_proposal'),
|
|
149
|
-
},
|
|
150
|
-
async (args) => {
|
|
151
|
-
try {
|
|
152
|
-
const mandate = await client.mandates.acceptCounter(args.mandateId);
|
|
153
|
-
return { content: [], structuredContent: toStructuredContent(mandate) };
|
|
154
|
-
} catch (err) {
|
|
155
|
-
return apiErrorResult(err);
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
mcp.registerTool(
|
|
161
|
-
'list_my_proposals',
|
|
162
|
-
{
|
|
163
|
-
title: 'List My Proposals',
|
|
164
|
-
description: 'List mandate proposals awaiting my response as performer.',
|
|
165
|
-
inputSchema: {},
|
|
166
|
-
annotations: {
|
|
167
|
-
readOnlyHint: true,
|
|
168
|
-
destructiveHint: false,
|
|
169
|
-
idempotentHint: true,
|
|
170
|
-
openWorldHint: true,
|
|
171
|
-
},
|
|
172
|
-
_meta: toolMeta('list_my_proposals'),
|
|
173
|
-
},
|
|
174
|
-
async () => {
|
|
175
|
-
try {
|
|
176
|
-
const result = await client.mandates.listProposals();
|
|
177
|
-
return { content: [], structuredContent: toStructuredContent(result) };
|
|
178
|
-
} catch (err) {
|
|
179
|
-
return apiErrorResult(err);
|
|
180
|
-
}
|
|
181
|
-
},
|
|
182
|
-
);
|
|
183
|
-
|
|
184
|
-
mcp.registerTool(
|
|
185
|
-
'list_principal_mandates',
|
|
186
|
-
{
|
|
187
|
-
title: 'List Principal Mandates',
|
|
188
|
-
description: 'List mandates where I am the principal (the one who proposed/created them).',
|
|
189
|
-
inputSchema: {},
|
|
190
|
-
annotations: {
|
|
191
|
-
readOnlyHint: true,
|
|
192
|
-
destructiveHint: false,
|
|
193
|
-
idempotentHint: true,
|
|
194
|
-
openWorldHint: true,
|
|
195
|
-
},
|
|
196
|
-
_meta: toolMeta('list_principal_mandates'),
|
|
197
|
-
},
|
|
198
|
-
async () => {
|
|
199
|
-
try {
|
|
200
|
-
const result = await client.mandates.listAsPrincipal();
|
|
201
|
-
return { content: [], structuredContent: toStructuredContent(result) };
|
|
202
|
-
} catch (err) {
|
|
203
|
-
return apiErrorResult(err);
|
|
204
|
-
}
|
|
205
|
-
},
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
mcp.registerTool(
|
|
209
|
-
'get_delegation_chain',
|
|
210
|
-
{
|
|
211
|
-
title: 'Get Delegation Chain',
|
|
212
|
-
description: 'Get the full delegation chain for a mandate (root to leaf).',
|
|
213
|
-
inputSchema: {
|
|
214
|
-
mandateId: z.string().describe('UUID of any mandate in the chain'),
|
|
215
|
-
},
|
|
216
|
-
annotations: {
|
|
217
|
-
readOnlyHint: true,
|
|
218
|
-
destructiveHint: false,
|
|
219
|
-
idempotentHint: true,
|
|
220
|
-
openWorldHint: true,
|
|
221
|
-
},
|
|
222
|
-
_meta: toolMeta('get_delegation_chain'),
|
|
223
|
-
},
|
|
224
|
-
async (args) => {
|
|
225
|
-
try {
|
|
226
|
-
const chain = await client.mandates.getChain(args.mandateId);
|
|
227
|
-
return { content: [], structuredContent: toStructuredContent({ chain }) };
|
|
228
|
-
} catch (err) {
|
|
229
|
-
return apiErrorResult(err);
|
|
230
|
-
}
|
|
231
|
-
},
|
|
232
|
-
);
|
|
233
|
-
|
|
234
|
-
mcp.registerTool(
|
|
235
|
-
'get_sub_mandates',
|
|
236
|
-
{
|
|
237
|
-
title: 'Get Sub-Mandates',
|
|
238
|
-
description: 'Get direct sub-mandates (children) of a parent mandate.',
|
|
239
|
-
inputSchema: {
|
|
240
|
-
mandateId: z.string().describe('UUID of the parent mandate'),
|
|
241
|
-
},
|
|
242
|
-
annotations: {
|
|
243
|
-
readOnlyHint: true,
|
|
244
|
-
destructiveHint: false,
|
|
245
|
-
idempotentHint: true,
|
|
246
|
-
openWorldHint: true,
|
|
247
|
-
},
|
|
248
|
-
_meta: toolMeta('get_sub_mandates'),
|
|
249
|
-
},
|
|
250
|
-
async (args) => {
|
|
251
|
-
try {
|
|
252
|
-
const result = await client.mandates.getSubMandates(args.mandateId);
|
|
253
|
-
return { content: [], structuredContent: toStructuredContent(result) };
|
|
254
|
-
} catch (err) {
|
|
255
|
-
return apiErrorResult(err);
|
|
256
|
-
}
|
|
257
|
-
},
|
|
258
|
-
);
|
|
259
|
-
}
|