@agledger/mcp-server 1.3.0 → 1.4.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.
@@ -44,50 +44,6 @@ const SearchResultOutputSchema = z.object({
44
44
  }).describe('Paginated mandate search results');
45
45
 
46
46
  export function registerMandateTools(mcp: McpServer, client: AgledgerClient): void {
47
- mcp.registerTool(
48
- 'create_mandate',
49
- {
50
- title: 'Create Mandate',
51
- description: 'Create a new AGLedger mandate with acceptance criteria, contract type, and optional tolerance bands.',
52
- inputSchema: {
53
- enterpriseId: z.string().describe('Enterprise ID that owns this mandate'),
54
- contractType: ContractTypeEnum,
55
- contractVersion: z.string().describe('Contract version (e.g. "1.0")'),
56
- platform: z.string().describe('Platform identifier (e.g. "openai", "anthropic")'),
57
- platformRef: z.string().optional().describe('Platform-specific reference ID'),
58
- criteria: z.record(z.string(), z.unknown()).describe('Acceptance criteria JSON object'),
59
- tolerance: z.record(z.string(), z.unknown()).optional().describe('Tolerance bands for criteria'),
60
- deadline: z.string().optional().describe('ISO 8601 deadline for mandate fulfillment'),
61
- agentId: z.string().optional().describe('Agent ID to assign the mandate to'),
62
- commissionPct: z.number().optional().describe('Commission percentage (0-100)'),
63
- operatingMode: OperatingModeEnum.optional(),
64
- verificationMode: z.enum(['auto', 'principal', 'gated']).optional().describe('Verification mode: auto (rules auto-settle, default), principal (hold for principal verdict), gated (run rules then hold for principal)'),
65
- riskClassification: RiskClassificationEnum.optional(),
66
- euAiActDomain: z.string().optional().describe('EU AI Act domain classification'),
67
- humanOversight: z.record(z.string(), z.unknown()).optional().describe('Human oversight configuration'),
68
- },
69
- outputSchema: MandateOutputSchema,
70
- annotations: {
71
- readOnlyHint: false,
72
- destructiveHint: false,
73
- idempotentHint: false,
74
- openWorldHint: true,
75
- },
76
- _meta: toolMeta('create_mandate'),
77
- },
78
- async (args) => {
79
- try {
80
- const mandate = await client.mandates.create(args);
81
- return {
82
- content: [{ type: 'text', text: `Mandate ${mandate.id} created with status ${mandate.status}.` }],
83
- structuredContent: mandate as unknown as Record<string, unknown>,
84
- };
85
- } catch (err) {
86
- return apiErrorResult(err);
87
- }
88
- },
89
- );
90
-
91
47
  mcp.registerTool(
92
48
  'get_mandate',
93
49
  {
@@ -2,178 +2,225 @@ import { z } from 'zod';
2
2
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
  import type { AgledgerClient } from '@agledger/sdk';
4
4
  import { apiErrorResult } from '../errors.js';
5
- import { NextStepsField, ReceiptStatusEnum } from '../enums.js';
5
+ import { NextStepsField, StructuralValidationEnum } from '../enums.js';
6
6
  import { toolMeta } from '../tool-scopes.js';
7
7
 
8
- const ReceiptOutputSchema = z.object({
9
- id: z.string().describe('Receipt UUID'),
10
- mandateId: z.string().describe('Associated mandate UUID'),
11
- agentId: z.string().describe('Agent that submitted the receipt'),
12
- status: ReceiptStatusEnum,
13
- evidence: z.record(z.string(), z.unknown()).describe('Evidence payload'),
14
- evidenceHash: z.string().nullable().optional().describe('SHA-256 hash of evidence'),
15
- notes: z.string().nullable().optional().describe('Human-readable notes'),
16
- verificationPhase: z.string().nullable().optional().describe('Current verification phase'),
17
- verificationResult: z.record(z.string(), z.unknown()).nullable().optional().describe('Verification result details'),
18
- validationErrors: z.array(z.string()).nullable().optional().describe('Validation errors if any'),
19
- idempotencyKey: z.string().nullable().optional().describe('Idempotency key for deduplication'),
20
- createdAt: z.string().describe('ISO 8601 creation timestamp'),
21
- updatedAt: z.string().nullable().optional().describe('ISO 8601 last update timestamp'),
22
- nextSteps: NextStepsField,
23
- }).passthrough().describe('AGLedger receipt (task attestation) object');
8
+ const ReceiptOutputSchema = z
9
+ .object({
10
+ id: z.string().describe('Receipt UUID'),
11
+ mandateId: z.string().describe('Associated mandate UUID'),
12
+ agentId: z.string().describe('Agent that submitted the receipt'),
13
+ structuralValidation: StructuralValidationEnum.nullable()
14
+ .optional()
15
+ .describe('Structural validation result'),
16
+ evidence: z.record(z.string(), z.unknown()).describe('Evidence payload'),
17
+ evidenceHash: z.string().nullable().optional().describe('SHA-256 hash of evidence'),
18
+ notes: z.string().nullable().optional().describe('Human-readable notes'),
19
+ verificationPhase: z.string().nullable().optional().describe('Current verification phase'),
20
+ verificationResult: z
21
+ .record(z.string(), z.unknown())
22
+ .nullable()
23
+ .optional()
24
+ .describe('Verification result details'),
25
+ validationErrors: z
26
+ .array(z.string())
27
+ .nullable()
28
+ .optional()
29
+ .describe('Validation errors if any'),
30
+ idempotencyKey: z.string().nullable().optional().describe('Idempotency key for deduplication'),
31
+ createdAt: z.string().describe('ISO 8601 creation timestamp'),
32
+ updatedAt: z.string().nullable().optional().describe('ISO 8601 last update timestamp'),
33
+ nextSteps: NextStepsField,
34
+ })
35
+ .passthrough()
36
+ .describe('AGLedger receipt (task attestation) object');
24
37
 
25
- const ReceiptListOutputSchema = z.object({
26
- data: z.array(ReceiptOutputSchema).describe('Array of receipts for the mandate'),
27
- nextCursor: z.string().nullable().optional().describe('Cursor for the next page (null if no more results)'),
28
- }).passthrough().describe('List of receipts for a mandate');
38
+ const ReceiptListOutputSchema = z
39
+ .object({
40
+ data: z.array(ReceiptOutputSchema).describe('Array of receipts for the mandate'),
41
+ nextCursor: z
42
+ .string()
43
+ .nullable()
44
+ .optional()
45
+ .describe('Cursor for the next page (null if no more results)'),
46
+ })
47
+ .passthrough()
48
+ .describe('List of receipts for a mandate');
29
49
 
30
- export function registerReceiptTools(mcp: McpServer, client: AgledgerClient): void {
31
- mcp.registerTool(
32
- 'submit_receipt',
33
- {
34
- title: 'Submit Receipt',
35
- description: 'Submit a task attestation (receipt) with evidence against a mandate. REQUIRED to close the accountability loop — do NOT skip this step after completing work.',
36
- inputSchema: {
37
- mandateId: z.string().describe('UUID of the mandate this receipt is for'),
38
- agentId: z.string().describe('Agent ID submitting the receipt'),
39
- evidence: z.record(z.string(), z.unknown()).describe('Evidence JSON object proving task completion'),
40
- notes: z.string().optional().describe('Human-readable notes about the submission'),
41
- },
42
- outputSchema: ReceiptOutputSchema,
43
- annotations: {
44
- readOnlyHint: false,
45
- destructiveHint: false,
46
- idempotentHint: false,
47
- openWorldHint: true,
48
- },
49
- _meta: toolMeta('submit_receipt'),
50
- },
51
- async (args) => {
52
- try {
53
- const { mandateId, ...submitParams } = args;
54
- const receipt = await client.receipts.submit(mandateId, submitParams);
55
- let text = ` Receipt ${receipt.id} submitted for mandate ${mandateId}. Status: ${receipt.structuralValidation}.`;
56
- // Use denormalized mandateStatus from receipt response (no extra API call)
57
- const ms = receipt.mandateStatus;
58
- if (ms === 'FULFILLED') {
59
- text += '\n\n Mandate settled to FULFILLED. Accountability loop closed.';
60
- } else if (ms === 'PROCESSING') {
61
- text += '\n\n Evidence is being verified. The principal will accept or reject.';
62
- }
63
- return {
64
- content: [{ type: 'text', text }],
65
- structuredContent: receipt as unknown as Record<string, unknown>,
66
- };
67
- } catch (err) {
68
- return apiErrorResult(err);
69
- }
70
- },
71
- );
50
+ export interface ReceiptToolsOptions {
51
+ /** Skip submit_receipt (e.g. when a2a tools already provide it). */
52
+ skipSubmit?: boolean;
53
+ }
54
+
55
+ export function registerReceiptTools(mcp: McpServer, client: AgledgerClient, options?: ReceiptToolsOptions): void {
56
+ if (!options?.skipSubmit) mcp.registerTool(
57
+ 'submit_receipt',
58
+ {
59
+ title: 'Submit Receipt',
60
+ description:
61
+ 'Submit a task attestation (receipt) with evidence against a mandate. REQUIRED to close the accountability loop — do NOT skip this step after completing work.',
62
+ inputSchema: {
63
+ mandateId: z.string().describe('UUID of the mandate this receipt is for'),
64
+ agentId: z.string().describe('Agent ID submitting the receipt'),
65
+ evidence: z
66
+ .record(z.string(), z.unknown())
67
+ .describe('Evidence JSON object proving task completion'),
68
+ notes: z.string().optional().describe('Human-readable notes about the submission'),
69
+ },
70
+ outputSchema: ReceiptOutputSchema,
71
+ annotations: {
72
+ readOnlyHint: false,
73
+ destructiveHint: false,
74
+ idempotentHint: false,
75
+ openWorldHint: true,
76
+ },
77
+ _meta: toolMeta('submit_receipt'),
78
+ },
79
+ async (args) => {
80
+ try {
81
+ const { mandateId, ...submitParams } = args;
82
+ const receipt = await client.receipts.submit(mandateId, submitParams);
83
+ let text = `Receipt ${receipt.id} submitted for mandate ${mandateId}. Status: ${receipt.structuralValidation}.`;
84
+ // Use denormalized mandateStatus from receipt response (no extra API call)
85
+ const ms = receipt.mandateStatus;
86
+ if (ms === 'FULFILLED') {
87
+ text += '\n\nMandate settled to FULFILLED. Accountability loop closed.';
88
+ } else if (ms === 'PROCESSING') {
89
+ text += '\n\nEvidence is being verified. The principal will accept or reject.';
90
+ }
91
+ return {
92
+ content: [{ type: 'text', text }],
93
+ structuredContent: receipt as unknown as Record<string, unknown>,
94
+ };
95
+ } catch (err) {
96
+ return apiErrorResult(err);
97
+ }
98
+ },
99
+ );
72
100
 
73
- mcp.registerTool(
74
- 'report_outcome',
75
- {
76
- title: 'Report Outcome',
77
- description: '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.',
78
- inputSchema: {
79
- mandateId: z.string().describe('UUID of the mandate'),
80
- receiptId: z.string().describe('UUID of the receipt to judge'),
81
- outcome: z.enum(['PASS', 'FAIL']).describe('Verdict: PASS (accept) or FAIL (reject)'),
82
- checks: z.record(z.string(), z.unknown()).optional().describe('Optional per-field check results'),
83
- },
84
- outputSchema: z.object({
85
- mandateId: z.string().describe('Mandate UUID'),
86
- receiptId: z.string().describe('Receipt UUID'),
87
- outcome: z.enum(['PASS', 'FAIL']).describe('Reported outcome'),
88
- signal: z.string().describe('Settlement signal: SETTLE, HOLD, or RELEASE'),
89
- reporterType: z.string().describe('Who reported: principal'),
90
- reportedAt: z.string().describe('ISO 8601 timestamp'),
91
- nextSteps: NextStepsField,
92
- }).passthrough().describe('Outcome result'),
93
- annotations: {
94
- readOnlyHint: false,
95
- destructiveHint: false,
96
- idempotentHint: true,
97
- openWorldHint: true,
98
- },
99
- _meta: toolMeta('report_outcome'),
100
- },
101
- async (args) => {
102
- try {
103
- const { mandateId, ...outcomeParams } = args;
104
- const result = await client.mandates.reportOutcome(mandateId, outcomeParams);
105
- const verb = result.outcome === 'PASS' ? 'accepted' : 'rejected';
106
- return {
107
- content: [{ type: 'text', text: `Receipt ${args.receiptId} ${verb}. Signal: ${result.signal}.` }],
108
- structuredContent: result as unknown as Record<string, unknown>,
109
- };
110
- } catch (err) {
111
- return apiErrorResult(err);
112
- }
113
- },
114
- );
101
+ mcp.registerTool(
102
+ 'report_outcome',
103
+ {
104
+ title: 'Report Outcome',
105
+ description:
106
+ '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.',
107
+ inputSchema: {
108
+ mandateId: z.string().describe('UUID of the mandate'),
109
+ receiptId: z.string().describe('UUID of the receipt to judge'),
110
+ outcome: z.enum(['PASS', 'FAIL']).describe('Verdict: PASS (accept) or FAIL (reject)'),
111
+ checks: z
112
+ .record(z.string(), z.unknown())
113
+ .optional()
114
+ .describe('Optional per-field check results'),
115
+ },
116
+ outputSchema: z
117
+ .object({
118
+ mandateId: z.string().describe('Mandate UUID'),
119
+ receiptId: z.string().describe('Receipt UUID'),
120
+ outcome: z.enum(['PASS', 'FAIL']).describe('Reported outcome'),
121
+ signal: z.string().describe('Settlement signal: SETTLE, HOLD, or RELEASE'),
122
+ reporterType: z.string().describe('Who reported: principal'),
123
+ reportedAt: z.string().describe('ISO 8601 timestamp'),
124
+ nextSteps: NextStepsField,
125
+ })
126
+ .passthrough()
127
+ .describe('Outcome result'),
128
+ annotations: {
129
+ readOnlyHint: false,
130
+ destructiveHint: false,
131
+ idempotentHint: true,
132
+ openWorldHint: true,
133
+ },
134
+ _meta: toolMeta('report_outcome'),
135
+ },
136
+ async (args) => {
137
+ try {
138
+ const { mandateId, ...outcomeParams } = args;
139
+ const result = await client.mandates.reportOutcome(mandateId, outcomeParams);
140
+ const verb = result.outcome === 'PASS' ? 'accepted' : 'rejected';
141
+ return {
142
+ content: [
143
+ { type: 'text', text: `Receipt ${args.receiptId} ${verb}. Signal: ${result.signal}.` },
144
+ ],
145
+ structuredContent: result as unknown as Record<string, unknown>,
146
+ };
147
+ } catch (err) {
148
+ return apiErrorResult(err);
149
+ }
150
+ },
151
+ );
115
152
 
116
- mcp.registerTool(
117
- 'get_receipt',
118
- {
119
- title: 'Get Receipt',
120
- description: 'Get a specific receipt by ID. Use list_receipts to find receipt IDs first.',
121
- inputSchema: {
122
- mandateId: z.string().describe('UUID of the associated mandate'),
123
- receiptId: z.string().describe('UUID of the receipt to retrieve'),
124
- },
125
- outputSchema: ReceiptOutputSchema,
126
- annotations: {
127
- readOnlyHint: true,
128
- destructiveHint: false,
129
- idempotentHint: true,
130
- openWorldHint: true,
131
- },
132
- _meta: toolMeta('get_receipt'),
133
- },
134
- async (args) => {
135
- try {
136
- const receipt = await client.receipts.get(args.mandateId, args.receiptId);
137
- return {
138
- content: [{ type: 'text', text: `Receipt ${receipt.id}: status=${receipt.structuralValidation}, mandate=${receipt.mandateId}.` }],
139
- structuredContent: receipt as unknown as Record<string, unknown>,
140
- };
141
- } catch (err) {
142
- return apiErrorResult(err);
143
- }
144
- },
145
- );
153
+ mcp.registerTool(
154
+ 'get_receipt',
155
+ {
156
+ title: 'Get Receipt',
157
+ description: 'Get a specific receipt by ID. Use list_receipts to find receipt IDs first.',
158
+ inputSchema: {
159
+ mandateId: z.string().describe('UUID of the associated mandate'),
160
+ receiptId: z.string().describe('UUID of the receipt to retrieve'),
161
+ },
162
+ outputSchema: ReceiptOutputSchema,
163
+ annotations: {
164
+ readOnlyHint: true,
165
+ destructiveHint: false,
166
+ idempotentHint: true,
167
+ openWorldHint: true,
168
+ },
169
+ _meta: toolMeta('get_receipt'),
170
+ },
171
+ async (args) => {
172
+ try {
173
+ const receipt = await client.receipts.get(args.mandateId, args.receiptId);
174
+ return {
175
+ content: [
176
+ {
177
+ type: 'text',
178
+ text: `Receipt ${receipt.id}: status=${receipt.structuralValidation}, mandate=${receipt.mandateId}.`,
179
+ },
180
+ ],
181
+ structuredContent: receipt as unknown as Record<string, unknown>,
182
+ };
183
+ } catch (err) {
184
+ return apiErrorResult(err);
185
+ }
186
+ },
187
+ );
146
188
 
147
- mcp.registerTool(
148
- 'list_receipts',
149
- {
150
- title: 'List Receipts',
151
- description: 'List all receipts (task attestations) submitted against a mandate.',
152
- inputSchema: {
153
- mandateId: z.string().describe('UUID of the mandate to list receipts for'),
154
- limit: z.number().optional().describe('Page size (default: 20)'),
155
- offset: z.number().optional().describe('Page offset (default: 0)'),
156
- },
157
- outputSchema: ReceiptListOutputSchema,
158
- annotations: {
159
- readOnlyHint: true,
160
- destructiveHint: false,
161
- idempotentHint: true,
162
- openWorldHint: true,
163
- },
164
- _meta: toolMeta('list_receipts'),
165
- },
166
- async (args) => {
167
- try {
168
- const { mandateId, ...paginationParams } = args;
169
- const result = await client.receipts.list(mandateId, paginationParams);
170
- return {
171
- content: [{ type: 'text', text: `Found ${result.data.length} receipts for mandate ${mandateId}.` }],
172
- structuredContent: result as unknown as Record<string, unknown>,
173
- };
174
- } catch (err) {
175
- return apiErrorResult(err);
176
- }
177
- },
178
- );
189
+ mcp.registerTool(
190
+ 'list_receipts',
191
+ {
192
+ title: 'List Receipts',
193
+ description: 'List all receipts (task attestations) submitted against a mandate.',
194
+ inputSchema: {
195
+ mandateId: z.string().describe('UUID of the mandate to list receipts for'),
196
+ limit: z.number().optional().describe('Page size (default: 20)'),
197
+ offset: z.number().optional().describe('Page offset (default: 0)'),
198
+ },
199
+ outputSchema: ReceiptListOutputSchema,
200
+ annotations: {
201
+ readOnlyHint: true,
202
+ destructiveHint: false,
203
+ idempotentHint: true,
204
+ openWorldHint: true,
205
+ },
206
+ _meta: toolMeta('list_receipts'),
207
+ },
208
+ async (args) => {
209
+ try {
210
+ const { mandateId, ...paginationParams } = args;
211
+ const result = await client.receipts.list(mandateId, paginationParams);
212
+ return {
213
+ content: [
214
+ {
215
+ type: 'text',
216
+ text: `Found ${result.data.length} receipts for mandate ${mandateId}.`,
217
+ },
218
+ ],
219
+ structuredContent: result as unknown as Record<string, unknown>,
220
+ };
221
+ } catch (err) {
222
+ return apiErrorResult(err);
223
+ }
224
+ },
225
+ );
179
226
  }
@@ -2,6 +2,7 @@ import { z } from 'zod';
2
2
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
  import type { AgledgerClient } from '@agledger/sdk';
4
4
  import { apiErrorResult } from '../errors.js';
5
+ import { VerificationOutcomeEnum } from '../enums.js';
5
6
  import { toolMeta } from '../tool-scopes.js';
6
7
 
7
8
  const VerificationResultOutputSchema = z.object({
@@ -11,7 +12,7 @@ const VerificationResultOutputSchema = z.object({
11
12
  phase1Result: z.record(z.string(), z.unknown()).optional().describe('Phase 1 (sync) verification result'),
12
13
  phase2Result: z.record(z.string(), z.unknown()).optional().describe('Phase 2 (async) verification result'),
13
14
  })).describe('Per-receipt verification results'),
14
- overallStatus: z.string().describe('Overall verification outcome'),
15
+ overallStatus: VerificationOutcomeEnum.describe('Overall verification outcome: PASS, FAIL, or REVIEW_REQUIRED'),
15
16
  }).passthrough().describe('Mandate verification result');
16
17
 
17
18
  const VerificationStatusOutputSchema = z.object({