@agledger/mcp-server 1.4.0 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/dist/errors.d.ts +6 -0
  2. package/dist/errors.d.ts.map +1 -1
  3. package/dist/errors.js +8 -0
  4. package/dist/errors.js.map +1 -1
  5. package/dist/server.d.ts +4 -0
  6. package/dist/server.d.ts.map +1 -1
  7. package/dist/server.js +72 -75
  8. package/dist/server.js.map +1 -1
  9. package/dist/tool-scopes.d.ts.map +1 -1
  10. package/dist/tool-scopes.js +6 -2
  11. package/dist/tool-scopes.js.map +1 -1
  12. package/dist/tools/a2a.js +15 -15
  13. package/dist/tools/a2a.js.map +1 -1
  14. package/dist/tools/agent-mandates.js +10 -10
  15. package/dist/tools/agent-mandates.js.map +1 -1
  16. package/dist/tools/agents-refs.d.ts.map +1 -1
  17. package/dist/tools/agents-refs.js +10 -9
  18. package/dist/tools/agents-refs.js.map +1 -1
  19. package/dist/tools/capabilities.js +3 -3
  20. package/dist/tools/capabilities.js.map +1 -1
  21. package/dist/tools/compliance.d.ts.map +1 -1
  22. package/dist/tools/compliance.js +29 -4
  23. package/dist/tools/compliance.js.map +1 -1
  24. package/dist/tools/dashboard.d.ts.map +1 -1
  25. package/dist/tools/dashboard.js +29 -4
  26. package/dist/tools/dashboard.js.map +1 -1
  27. package/dist/tools/disputes.d.ts.map +1 -1
  28. package/dist/tools/disputes.js +10 -5
  29. package/dist/tools/disputes.js.map +1 -1
  30. package/dist/tools/enterprises.d.ts.map +1 -1
  31. package/dist/tools/enterprises.js +30 -6
  32. package/dist/tools/enterprises.js.map +1 -1
  33. package/dist/tools/events.js +2 -2
  34. package/dist/tools/events.js.map +1 -1
  35. package/dist/tools/federation-admin.js +25 -25
  36. package/dist/tools/federation-admin.js.map +1 -1
  37. package/dist/tools/federation.js +21 -21
  38. package/dist/tools/federation.js.map +1 -1
  39. package/dist/tools/health.js +2 -2
  40. package/dist/tools/health.js.map +1 -1
  41. package/dist/tools/mandates.d.ts.map +1 -1
  42. package/dist/tools/mandates.js +25 -14
  43. package/dist/tools/mandates.js.map +1 -1
  44. package/dist/tools/openclaw.js +6 -6
  45. package/dist/tools/openclaw.js.map +1 -1
  46. package/dist/tools/receipts.d.ts.map +1 -1
  47. package/dist/tools/receipts.js +5 -6
  48. package/dist/tools/receipts.js.map +1 -1
  49. package/dist/tools/reputation.d.ts.map +1 -1
  50. package/dist/tools/reputation.js +25 -4
  51. package/dist/tools/reputation.js.map +1 -1
  52. package/dist/tools/schemas.d.ts.map +1 -1
  53. package/dist/tools/schemas.js +71 -26
  54. package/dist/tools/schemas.js.map +1 -1
  55. package/dist/tools/verification-keys.js +2 -2
  56. package/dist/tools/verification-keys.js.map +1 -1
  57. package/dist/tools/verification.js +3 -3
  58. package/dist/tools/verification.js.map +1 -1
  59. package/package.json +1 -1
  60. package/src/errors.ts +9 -0
  61. package/src/server.ts +76 -68
  62. package/src/tool-scopes.ts +7 -3
  63. package/src/tools/a2a.ts +15 -15
  64. package/src/tools/agent-mandates.ts +10 -10
  65. package/src/tools/agents-refs.ts +10 -9
  66. package/src/tools/capabilities.ts +3 -3
  67. package/src/tools/compliance.ts +29 -4
  68. package/src/tools/dashboard.ts +29 -4
  69. package/src/tools/disputes.ts +10 -5
  70. package/src/tools/enterprises.ts +30 -6
  71. package/src/tools/events.ts +2 -2
  72. package/src/tools/federation-admin.ts +25 -25
  73. package/src/tools/federation.ts +21 -21
  74. package/src/tools/health.ts +2 -2
  75. package/src/tools/mandates.ts +25 -14
  76. package/src/tools/openclaw.ts +6 -6
  77. package/src/tools/receipts.ts +5 -6
  78. package/src/tools/reputation.ts +26 -4
  79. package/src/tools/schemas.ts +72 -26
  80. package/src/tools/verification-keys.ts +2 -2
  81. package/src/tools/verification.ts +3 -3
  82. package/tests/conformance.test.ts +219 -0
  83. package/tests/conformance.ts +75 -0
  84. package/tests/{code-mode-manifest.test.ts → drift/code-mode-manifest.test.ts} +2 -2
  85. package/tests/harness.ts +55 -0
  86. package/tests/integration/output-schema-validation.test.ts +167 -0
  87. package/tests/mock-client.ts +71 -0
  88. package/tests/profiles.test.ts +135 -0
  89. package/tests/resources/contract-types.test.ts +82 -0
  90. package/tests/tools/a2a.test.ts +241 -0
  91. package/tests/tools/agent-mandates.test.ts +206 -0
  92. package/tests/tools/agents-refs.test.ts +199 -0
  93. package/tests/tools/capabilities.test.ts +86 -0
  94. package/tests/tools/code-mode.test.ts +168 -0
  95. package/tests/tools/compliance.test.ts +131 -0
  96. package/tests/tools/dashboard.test.ts +120 -0
  97. package/tests/tools/disputes.test.ts +131 -0
  98. package/tests/tools/enterprises.test.ts +181 -0
  99. package/tests/tools/events.test.ts +61 -0
  100. package/tests/tools/federation-admin.test.ts +509 -0
  101. package/tests/tools/federation.test.ts +556 -0
  102. package/tests/tools/health.test.ts +67 -0
  103. package/tests/tools/mandates.test.ts +155 -0
  104. package/tests/tools/openclaw.test.ts +160 -0
  105. package/tests/tools/receipts.test.ts +170 -0
  106. package/tests/tools/reputation.test.ts +117 -0
  107. package/tests/tools/schemas.test.ts +397 -0
  108. package/tests/tools/verification-keys.test.ts +62 -0
  109. package/tests/tools/verification.test.ts +74 -0
  110. package/tests/enterprises.test.ts +0 -96
  111. package/tests/schemas.test.ts +0 -531
package/src/server.ts CHANGED
@@ -34,6 +34,77 @@ export interface AgledgerMcpServerOptions {
34
34
  enterpriseId?: string;
35
35
  }
36
36
 
37
+ type RegisterFn = (mcp: McpServer, client: AgledgerClient) => void;
38
+
39
+ function buildProfileRegistry(enterpriseId?: string): Record<ToolProfile, RegisterFn[]> {
40
+ return {
41
+ code: [registerCodeModeTools],
42
+ openclaw: [registerOpenClawTools],
43
+ agent: [
44
+ (mcp, client) => registerA2aTools(mcp, client, { enterpriseId }),
45
+ (mcp, client) => registerReceiptTools(mcp, client, { skipSubmit: true }),
46
+ registerVerificationTools,
47
+ registerAgentsRefsTools,
48
+ registerHealthTools,
49
+ ],
50
+ 'schema-dev': [registerSchemaTools, registerHealthTools],
51
+ admin: [
52
+ registerMandateTools,
53
+ registerReceiptTools,
54
+ registerEnterpriseTools,
55
+ registerCapabilityTools,
56
+ registerReputationTools,
57
+ registerAgentsRefsTools,
58
+ registerFederationAdminTools,
59
+ registerHealthTools,
60
+ registerVerificationKeysTools,
61
+ ],
62
+ federation: [
63
+ registerFederationTools,
64
+ registerFederationAdminTools,
65
+ registerAgentsRefsTools,
66
+ registerHealthTools,
67
+ ],
68
+ audit: [
69
+ registerMandateTools,
70
+ registerReceiptTools,
71
+ registerEventTools,
72
+ registerVerificationTools,
73
+ registerDisputeTools,
74
+ registerReputationTools,
75
+ registerDashboardTools,
76
+ registerComplianceTools,
77
+ registerAgentsRefsTools,
78
+ registerHealthTools,
79
+ registerVerificationKeysTools,
80
+ ],
81
+ full: [
82
+ registerMandateTools,
83
+ registerAgentMandateTools,
84
+ registerReceiptTools,
85
+ registerVerificationTools,
86
+ registerDisputeTools,
87
+ registerReputationTools,
88
+ registerEventTools,
89
+ registerSchemaTools,
90
+ registerHealthTools,
91
+ registerCapabilityTools,
92
+ registerEnterpriseTools,
93
+ registerDashboardTools,
94
+ registerComplianceTools,
95
+ registerFederationTools,
96
+ registerFederationAdminTools,
97
+ registerAgentsRefsTools,
98
+ registerVerificationKeysTools,
99
+ ],
100
+ };
101
+ }
102
+
103
+ /** Exported for testing — returns the profile registry for a given enterpriseId. */
104
+ export function getProfileRegistry(enterpriseId?: string): Record<ToolProfile, RegisterFn[]> {
105
+ return buildProfileRegistry(enterpriseId);
106
+ }
107
+
37
108
  export class AgledgerMcpServer {
38
109
  readonly mcp: McpServer;
39
110
  readonly client: AgledgerClient;
@@ -47,7 +118,7 @@ export class AgledgerMcpServer {
47
118
  this.mcp = new McpServer(
48
119
  {
49
120
  name: 'agledger-mcp-server',
50
- version: '1.4.0',
121
+ version: '1.4.3',
51
122
  },
52
123
  {
53
124
  capabilities: {
@@ -66,74 +137,11 @@ export class AgledgerMcpServer {
66
137
  }
67
138
 
68
139
  private registerTools(): void {
69
- if (this.profile === 'code') {
70
- // Code mode: 2 tools — SDK code execution + documentation (replaces full)
71
- registerCodeModeTools(this.mcp, this.client);
72
- } else if (this.profile === 'openclaw') {
73
- // OpenClaw profile: 5 thin notarization tools (<500 tokens total schema)
74
- registerOpenClawTools(this.mcp, this.client);
75
- } else if (this.profile === 'agent') {
76
- // Standard agent profile: create mandates, submit receipts, get verdicts, verify, check status
77
- registerA2aTools(this.mcp, this.client, { enterpriseId: this.enterpriseId });
78
- registerReceiptTools(this.mcp, this.client, { skipSubmit: true }); // a2a tools include submit_receipt with workflow guidance
79
- registerVerificationTools(this.mcp, this.client);
80
- registerAgentsRefsTools(this.mcp, this.client);
81
- registerHealthTools(this.mcp, this.client);
82
- } else if (this.profile === 'schema-dev') {
83
- // Schema development profile: schema tools + health check
84
- registerSchemaTools(this.mcp, this.client);
85
- registerHealthTools(this.mcp, this.client);
86
- } else if (this.profile === 'admin') {
87
- // Admin profile: enterprise + agent management + mandate visibility + references + federation admin
88
- registerMandateTools(this.mcp, this.client);
89
- registerReceiptTools(this.mcp, this.client);
90
- registerEnterpriseTools(this.mcp, this.client);
91
- registerCapabilityTools(this.mcp, this.client);
92
- registerReputationTools(this.mcp, this.client);
93
- registerAgentsRefsTools(this.mcp, this.client);
94
- registerFederationAdminTools(this.mcp, this.client);
95
- registerHealthTools(this.mcp, this.client);
96
- registerVerificationKeysTools(this.mcp, this.client);
97
- } else if (this.profile === 'federation') {
98
- // Federation profile: gateway ops + admin ops + agent identity + health
99
- registerFederationTools(this.mcp, this.client);
100
- registerFederationAdminTools(this.mcp, this.client);
101
- registerAgentsRefsTools(this.mcp, this.client);
102
- registerHealthTools(this.mcp, this.client);
103
- } else if (this.profile === 'audit') {
104
- // Audit profile: read-only compliance monitoring + mandate visibility + dashboard + agent lookup
105
- registerMandateTools(this.mcp, this.client);
106
- registerReceiptTools(this.mcp, this.client);
107
- registerEventTools(this.mcp, this.client);
108
- registerVerificationTools(this.mcp, this.client);
109
- registerDisputeTools(this.mcp, this.client);
110
- registerReputationTools(this.mcp, this.client);
111
- registerDashboardTools(this.mcp, this.client);
112
- registerComplianceTools(this.mcp, this.client);
113
- registerAgentsRefsTools(this.mcp, this.client);
114
- registerHealthTools(this.mcp, this.client);
115
- registerVerificationKeysTools(this.mcp, this.client);
116
- } else {
117
- // Full profile (legacy): all individual tools
118
- registerMandateTools(this.mcp, this.client);
119
- registerAgentMandateTools(this.mcp, this.client);
120
- registerReceiptTools(this.mcp, this.client);
121
- registerVerificationTools(this.mcp, this.client);
122
- registerDisputeTools(this.mcp, this.client);
123
- registerReputationTools(this.mcp, this.client);
124
- registerEventTools(this.mcp, this.client);
125
- registerSchemaTools(this.mcp, this.client);
126
- registerHealthTools(this.mcp, this.client);
127
- registerCapabilityTools(this.mcp, this.client);
128
- registerEnterpriseTools(this.mcp, this.client);
129
- registerDashboardTools(this.mcp, this.client);
130
- registerComplianceTools(this.mcp, this.client);
131
- registerFederationTools(this.mcp, this.client);
132
- registerFederationAdminTools(this.mcp, this.client);
133
- registerAgentsRefsTools(this.mcp, this.client);
134
- registerVerificationKeysTools(this.mcp, this.client);
140
+ const registry = buildProfileRegistry(this.enterpriseId);
141
+ const fns = registry[this.profile];
142
+ for (const fn of fns) {
143
+ fn(this.mcp, this.client);
135
144
  }
136
- // Resources are always available
137
145
  registerContractTypeResources(this.mcp, this.client);
138
146
  }
139
147
  }
@@ -31,14 +31,14 @@ export const TOOL_SCOPES: Record<string, string[]> = {
31
31
 
32
32
  // A2A
33
33
  accept_mandate: ['mandates:write'],
34
+ reject_mandate: ['mandates:write'],
35
+ accept_counter_proposal: ['mandates:write'],
34
36
  my_mandates: ['mandates:read'],
35
37
 
36
38
  // Receipts
37
39
  submit_receipt: ['receipts:write'],
38
40
  get_receipt: ['receipts:read'],
39
41
  list_receipts: ['receipts:read'],
40
- validate_receipt_schema: ['receipts:read', 'schemas:read'],
41
-
42
42
  // Verification
43
43
  verify_mandate: ['mandates:write'],
44
44
  get_verification_status: ['mandates:read'],
@@ -68,7 +68,7 @@ export const TOOL_SCOPES: Record<string, string[]> = {
68
68
  delete_schema: ['schemas:write'],
69
69
  export_schema: ['schemas:read'],
70
70
  import_schema: ['schemas:write'],
71
- validate_receipt_against_schema: ['schemas:read'],
71
+ validate_receipt_schema: ['schemas:read'],
72
72
 
73
73
  // Enterprise management
74
74
  approve_enterprise_agent: ['agents:manage'],
@@ -161,6 +161,10 @@ export const TOOL_SCOPES: Record<string, string[]> = {
161
161
  federation_reset_reputation: ['admin:system'],
162
162
  federation_get_mandate_criteria_status: ['admin:system'],
163
163
 
164
+ // Code mode
165
+ sdk_execute: [],
166
+ sdk_describe: [],
167
+
164
168
  // OpenClaw
165
169
  agledger_notarize: ['mandates:write', 'receipts:write'],
166
170
  agledger_receipt: ['receipts:write'],
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
 
@@ -122,7 +122,7 @@ export function registerA2aTools(
122
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
123
  },
124
124
  ],
125
- structuredContent: mandate as unknown as Record<string, unknown>,
125
+ structuredContent: toStructuredContent(mandate),
126
126
  };
127
127
  } catch (err) {
128
128
  return apiErrorResult(err);
@@ -184,7 +184,7 @@ export function registerA2aTools(
184
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
185
  },
186
186
  ],
187
- structuredContent: mandate as unknown as Record<string, unknown>,
187
+ structuredContent: toStructuredContent(mandate),
188
188
  };
189
189
  } catch (err) {
190
190
  return apiErrorResult(err);
@@ -232,7 +232,7 @@ export function registerA2aTools(
232
232
  'ACH-DATA-v1': '{"deliverable": "data results", "deliverable_type": "report"}',
233
233
  'ACH-DLVR-v1': '{"deliverable": "artifact content", "deliverable_type": "document"}',
234
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"}',
235
+ '{"item_description": "item name", "quantity": 1, "total_cost": {"amount": 100, "currency": "USD"}, "supplier": {"id": "S1", "name": "Supplier"}, "confirmation_ref": "REF-1"}',
236
236
  'ACH-TXN-v1':
237
237
  '{"confirmations": [{"ref": "T1", "type": "payment", "provider": "provider", "cost": {"amount": 100, "currency": "USD"}}]}',
238
238
  'ACH-COMM-v1': '{"deliverable": "communication sent", "deliverable_type": "report"}',
@@ -252,7 +252,7 @@ export function registerA2aTools(
252
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
253
  },
254
254
  ],
255
- structuredContent: mandate as unknown as Record<string, unknown>,
255
+ structuredContent: toStructuredContent(mandate),
256
256
  };
257
257
  } catch (err) {
258
258
  return apiErrorResult(err);
@@ -339,11 +339,11 @@ export function registerA2aTools(
339
339
 
340
340
  return {
341
341
  content: [{ type: 'text', text }],
342
- structuredContent: {
342
+ structuredContent: toStructuredContent({
343
343
  proposals: allProposals,
344
344
  active: allActive,
345
345
  verified: allVerified,
346
- } as unknown as Record<string, unknown>,
346
+ }),
347
347
  };
348
348
  } catch (err) {
349
349
  return apiErrorResult(err);
@@ -356,7 +356,7 @@ export function registerA2aTools(
356
356
  {
357
357
  title: 'Submit Receipt',
358
358
  description:
359
- 'Submit evidence of completed work. REQUIRED to close the accountability loop. Evidence: {"deliverable": "result", "deliverable_type": "report"} for most types. PROC needs item_secured/quantity/total_cost/supplier/confirmation_ref.',
359
+ 'Submit evidence of completed work. REQUIRED to close the accountability loop. Evidence: {"deliverable": "result", "deliverable_type": "report"} for most types. PROC needs item_description/quantity/total_cost/supplier/confirmation_ref.',
360
360
  inputSchema: {
361
361
  mandateId: z.string().describe('Mandate ID'),
362
362
  evidence: z.record(z.string(), z.unknown()).describe('Evidence of completion'),
@@ -397,7 +397,7 @@ export function registerA2aTools(
397
397
 
398
398
  return {
399
399
  content: [{ type: 'text', text }],
400
- structuredContent: { receipt, mandateStatus } as unknown as Record<string, unknown>,
400
+ structuredContent: toStructuredContent({ receipt, mandateStatus }),
401
401
  };
402
402
  } catch (err) {
403
403
  return apiErrorResult(err);
@@ -434,7 +434,7 @@ export function registerA2aTools(
434
434
  text: `Mandate ${mandate.id} settled. Status: ${mandate.status}. Accountability loop closed.`,
435
435
  },
436
436
  ],
437
- structuredContent: mandate as unknown as Record<string, unknown>,
437
+ structuredContent: toStructuredContent(mandate),
438
438
  };
439
439
  } catch (err) {
440
440
  return apiErrorResult(err);
@@ -470,7 +470,7 @@ export function registerA2aTools(
470
470
  if (mandate.status === 'FULFILLED') text += '\n Accountability loop closed.';
471
471
  return {
472
472
  content: [{ type: 'text', text }],
473
- structuredContent: mandate as unknown as Record<string, unknown>,
473
+ structuredContent: toStructuredContent(mandate),
474
474
  };
475
475
  } catch (err) {
476
476
  return apiErrorResult(err);
@@ -503,7 +503,7 @@ export function registerA2aTools(
503
503
  content: [
504
504
  { type: 'text', text: `Mandate ${mandate.id} rejected. Reason: ${args.reason}` },
505
505
  ],
506
- structuredContent: mandate as unknown as Record<string, unknown>,
506
+ structuredContent: toStructuredContent(mandate),
507
507
  };
508
508
  } catch (err) {
509
509
  return apiErrorResult(err);
@@ -568,7 +568,7 @@ export function registerA2aTools(
568
568
 
569
569
  return {
570
570
  content: [{ type: 'text', text }],
571
- structuredContent: { mandates: filtered, byStatus } as unknown as Record<string, unknown>,
571
+ structuredContent: toStructuredContent({ mandates: filtered, byStatus }),
572
572
  };
573
573
  } catch (err) {
574
574
  return apiErrorResult(err);
@@ -601,7 +601,7 @@ export function registerA2aTools(
601
601
  content: [
602
602
  { type: 'text', text: `Mandate ${mandate.id} cancelled. Reason: ${args.reason}` },
603
603
  ],
604
- structuredContent: mandate as unknown as Record<string, unknown>,
604
+ structuredContent: toStructuredContent(mandate),
605
605
  };
606
606
  } catch (err) {
607
607
  return apiErrorResult(err);
@@ -633,7 +633,7 @@ export function registerA2aTools(
633
633
  content: [
634
634
  { type: 'text', text: `Agent ${args.agentId} reputation: ${JSON.stringify(rep)}` },
635
635
  ],
636
- structuredContent: rep as unknown as Record<string, unknown>,
636
+ structuredContent: toStructuredContent(rep),
637
637
  };
638
638
  } catch (err) {
639
639
  return apiErrorResult(err);
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
  import type { AgledgerClient } from '@agledger/sdk';
4
- import { apiErrorResult } from '../errors.js';
4
+ import { apiErrorResult, toStructuredContent } from '../errors.js';
5
5
  import { toolMeta } from '../tool-scopes.js';
6
6
  import { ContractTypeEnum, NextStepsField } from '../enums.js';
7
7
 
@@ -65,7 +65,7 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
65
65
  const mandate = await client.mandates.createAgent(args);
66
66
  return {
67
67
  content: [{ type: 'text', text: `Mandate ${mandate.id} proposed (${mandate.status}).` }],
68
- structuredContent: mandate as unknown as Record<string, unknown>,
68
+ structuredContent: toStructuredContent(mandate),
69
69
  };
70
70
  } catch (err) {
71
71
  return apiErrorResult(err);
@@ -95,7 +95,7 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
95
95
  const mandate = await client.mandates.accept(args.mandateId);
96
96
  return {
97
97
  content: [{ type: 'text', text: `Mandate ${mandate.id} accepted (${mandate.status}).` }],
98
- structuredContent: mandate as unknown as Record<string, unknown>,
98
+ structuredContent: toStructuredContent(mandate),
99
99
  };
100
100
  } catch (err) {
101
101
  return apiErrorResult(err);
@@ -126,7 +126,7 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
126
126
  const mandate = await client.mandates.reject(args.mandateId, args.reason);
127
127
  return {
128
128
  content: [{ type: 'text', text: `Mandate ${mandate.id} rejected (${mandate.status}).` }],
129
- structuredContent: mandate as unknown as Record<string, unknown>,
129
+ structuredContent: toStructuredContent(mandate),
130
130
  };
131
131
  } catch (err) {
132
132
  return apiErrorResult(err);
@@ -167,7 +167,7 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
167
167
  });
168
168
  return {
169
169
  content: [{ type: 'text', text: `Mandate ${mandate.id} counter-proposed (${mandate.status}).` }],
170
- structuredContent: mandate as unknown as Record<string, unknown>,
170
+ structuredContent: toStructuredContent(mandate),
171
171
  };
172
172
  } catch (err) {
173
173
  return apiErrorResult(err);
@@ -197,7 +197,7 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
197
197
  const mandate = await client.mandates.acceptCounter(args.mandateId);
198
198
  return {
199
199
  content: [{ type: 'text', text: `Counter-proposal on ${mandate.id} accepted (${mandate.status}).` }],
200
- structuredContent: mandate as unknown as Record<string, unknown>,
200
+ structuredContent: toStructuredContent(mandate),
201
201
  };
202
202
  } catch (err) {
203
203
  return apiErrorResult(err);
@@ -225,7 +225,7 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
225
225
  const result = await client.mandates.listProposals();
226
226
  return {
227
227
  content: [{ type: 'text', text: `Found ${result.data.length} proposals.` }],
228
- structuredContent: result as unknown as Record<string, unknown>,
228
+ structuredContent: toStructuredContent(result),
229
229
  };
230
230
  } catch (err) {
231
231
  return apiErrorResult(err);
@@ -253,7 +253,7 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
253
253
  const result = await client.mandates.listAsPrincipal();
254
254
  return {
255
255
  content: [{ type: 'text', text: `Found ${result.data.length} mandates as principal.` }],
256
- structuredContent: result as unknown as Record<string, unknown>,
256
+ structuredContent: toStructuredContent(result),
257
257
  };
258
258
  } catch (err) {
259
259
  return apiErrorResult(err);
@@ -285,7 +285,7 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
285
285
  const chain = await client.mandates.getChain(args.mandateId);
286
286
  return {
287
287
  content: [{ type: 'text', text: `Delegation chain has ${chain.length} mandates.` }],
288
- structuredContent: { chain } as unknown as Record<string, unknown>,
288
+ structuredContent: toStructuredContent({ chain }),
289
289
  };
290
290
  } catch (err) {
291
291
  return apiErrorResult(err);
@@ -315,7 +315,7 @@ export function registerAgentMandateTools(mcp: McpServer, client: AgledgerClient
315
315
  const result = await client.mandates.getSubMandates(args.mandateId);
316
316
  return {
317
317
  content: [{ type: 'text', text: `Found ${result.data.length} sub-mandates.` }],
318
- structuredContent: result as unknown as Record<string, unknown>,
318
+ structuredContent: toStructuredContent(result),
319
319
  };
320
320
  } catch (err) {
321
321
  return apiErrorResult(err);
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
  import type { AgledgerClient } from '@agledger/sdk';
4
- import { apiErrorResult } from '../errors.js';
4
+ import { apiErrorResult, toStructuredContent } from '../errors.js';
5
5
  import { toolMeta } from '../tool-scopes.js';
6
6
 
7
7
  const AgentProfileOutputSchema = z.object({
@@ -56,7 +56,7 @@ export function registerAgentsRefsTools(mcp: McpServer, client: AgledgerClient):
56
56
  const result = await client.agents.get(args.agentId);
57
57
  return {
58
58
  content: [{ type: 'text', text: `Agent ${result.id}: class=${result.agentClass ?? 'unset'}, owner=${result.ownerRef ?? 'unset'}.` }],
59
- structuredContent: result as unknown as Record<string, unknown>,
59
+ structuredContent: toStructuredContent(result),
60
60
  };
61
61
  } catch (err) {
62
62
  return apiErrorResult(err);
@@ -98,7 +98,7 @@ export function registerAgentsRefsTools(mcp: McpServer, client: AgledgerClient):
98
98
  });
99
99
  return {
100
100
  content: [{ type: 'text', text: `Agent ${result.id} updated.` }],
101
- structuredContent: result as unknown as Record<string, unknown>,
101
+ structuredContent: toStructuredContent(result),
102
102
  };
103
103
  } catch (err) {
104
104
  return apiErrorResult(err);
@@ -137,7 +137,7 @@ export function registerAgentsRefsTools(mcp: McpServer, client: AgledgerClient):
137
137
  const result = await client.agents.addReferences(args.agentId, args.references);
138
138
  return {
139
139
  content: [{ type: 'text', text: `Added ${args.references.length} reference(s) to agent ${args.agentId}.` }],
140
- structuredContent: result as unknown as Record<string, unknown>,
140
+ structuredContent: toStructuredContent(result),
141
141
  };
142
142
  } catch (err) {
143
143
  return apiErrorResult(err);
@@ -170,7 +170,7 @@ export function registerAgentsRefsTools(mcp: McpServer, client: AgledgerClient):
170
170
  const refs = Array.isArray(result) ? result : (result as Record<string, unknown>).references ?? [];
171
171
  return {
172
172
  content: [{ type: 'text', text: `Agent ${args.agentId} has ${(refs as unknown[]).length} reference(s).` }],
173
- structuredContent: (Array.isArray(result) ? { references: result } : result) as unknown as Record<string, unknown>,
173
+ structuredContent: toStructuredContent(Array.isArray(result) ? { references: result } : result),
174
174
  };
175
175
  } catch (err) {
176
176
  return apiErrorResult(err);
@@ -203,9 +203,10 @@ export function registerAgentsRefsTools(mcp: McpServer, client: AgledgerClient):
203
203
  async (args) => {
204
204
  try {
205
205
  const result = await client.references.lookup(args);
206
+ const structured = toStructuredContent(result);
206
207
  return {
207
- content: [{ type: 'text', text: `Found ${(result as unknown as Record<string, unknown>).entityType ?? 'entity'} ${(result as unknown as Record<string, unknown>).entityId ?? 'unknown'} for ${args.system}/${args.refType}/${args.refId}.` }],
208
- structuredContent: result as unknown as Record<string, unknown>,
208
+ content: [{ type: 'text', text: `Found ${structured.entityType ?? 'entity'} ${structured.entityId ?? 'unknown'} for ${args.system}/${args.refType}/${args.refId}.` }],
209
+ structuredContent: structured,
209
210
  };
210
211
  } catch (err) {
211
212
  return apiErrorResult(err);
@@ -244,7 +245,7 @@ export function registerAgentsRefsTools(mcp: McpServer, client: AgledgerClient):
244
245
  const result = await client.references.addMandateReferences(args.mandateId, args.references);
245
246
  return {
246
247
  content: [{ type: 'text', text: `Added ${args.references.length} reference(s) to mandate ${args.mandateId}.` }],
247
- structuredContent: result as unknown as Record<string, unknown>,
248
+ structuredContent: toStructuredContent(result),
248
249
  };
249
250
  } catch (err) {
250
251
  return apiErrorResult(err);
@@ -277,7 +278,7 @@ export function registerAgentsRefsTools(mcp: McpServer, client: AgledgerClient):
277
278
  const refs = Array.isArray(result) ? result : (result as Record<string, unknown>).references ?? [];
278
279
  return {
279
280
  content: [{ type: 'text', text: `Mandate ${args.mandateId} has ${(refs as unknown[]).length} reference(s).` }],
280
- structuredContent: (Array.isArray(result) ? { references: result } : result) as unknown as Record<string, unknown>,
281
+ structuredContent: toStructuredContent(Array.isArray(result) ? { references: result } : result),
281
282
  };
282
283
  } catch (err) {
283
284
  return apiErrorResult(err);
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
  import type { AgledgerClient } from '@agledger/sdk';
4
- import { apiErrorResult } from '../errors.js';
4
+ import { apiErrorResult, toStructuredContent } from '../errors.js';
5
5
  import { toolMeta } from '../tool-scopes.js';
6
6
  import { ContractTypeEnum } from '../enums.js';
7
7
 
@@ -33,7 +33,7 @@ export function registerCapabilityTools(mcp: McpServer, client: AgledgerClient):
33
33
  const result = await client.capabilities.get(args.agentId);
34
34
  return {
35
35
  content: [{ type: 'text', text: `Agent ${result.agentId} supports ${result.capabilities.length} contract types.` }],
36
- structuredContent: result as unknown as Record<string, unknown>,
36
+ structuredContent: toStructuredContent(result),
37
37
  };
38
38
  } catch (err) {
39
39
  return apiErrorResult(err);
@@ -66,7 +66,7 @@ export function registerCapabilityTools(mcp: McpServer, client: AgledgerClient):
66
66
  });
67
67
  return {
68
68
  content: [{ type: 'text', text: `Capabilities declared for ${result.agentId}: ${result.capabilities.join(', ')}.` }],
69
- structuredContent: result as unknown as Record<string, unknown>,
69
+ structuredContent: toStructuredContent(result),
70
70
  };
71
71
  } catch (err) {
72
72
  return apiErrorResult(err);
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
  import type { AgledgerClient } from '@agledger/sdk';
4
- import { apiErrorResult } from '../errors.js';
4
+ import { apiErrorResult, toStructuredContent } from '../errors.js';
5
5
  import { toolMeta } from '../tool-scopes.js';
6
6
 
7
7
  export function registerComplianceTools(mcp: McpServer, client: AgledgerClient): void {
@@ -16,6 +16,13 @@ export function registerComplianceTools(mcp: McpServer, client: AgledgerClient):
16
16
  attestation: z.record(z.string(), z.unknown()).describe('Attestation data'),
17
17
  attestedBy: z.string().describe('Who attested (name or ID)'),
18
18
  },
19
+ outputSchema: z.object({
20
+ id: z.string().describe('Compliance record ID'),
21
+ mandateId: z.string().describe('Associated mandate ID'),
22
+ recordType: z.string().describe('Record type'),
23
+ attestedBy: z.string().describe('Who attested'),
24
+ createdAt: z.string().nullable().optional().describe('ISO 8601 creation timestamp'),
25
+ }).passthrough().describe('Created compliance attestation record'),
19
26
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
20
27
  _meta: toolMeta('create_compliance_record'),
21
28
  },
@@ -28,7 +35,7 @@ export function registerComplianceTools(mcp: McpServer, client: AgledgerClient):
28
35
  });
29
36
  return {
30
37
  content: [{ type: 'text', text: `Compliance record created for mandate ${args.mandateId} (type: ${args.recordType}).` }],
31
- structuredContent: record as unknown as Record<string, unknown>,
38
+ structuredContent: toStructuredContent(record),
32
39
  };
33
40
  } catch (err) { return apiErrorResult(err); }
34
41
  },
@@ -43,6 +50,16 @@ export function registerComplianceTools(mcp: McpServer, client: AgledgerClient):
43
50
  mandateId: z.string().describe('Mandate ID'),
44
51
  limit: z.number().optional().describe('Page size'),
45
52
  },
53
+ outputSchema: z.object({
54
+ data: z.array(z.object({
55
+ id: z.string().optional().describe('Compliance record ID'),
56
+ mandateId: z.string().optional().describe('Associated mandate ID'),
57
+ recordType: z.string().optional().describe('Record type'),
58
+ attestedBy: z.string().optional().describe('Who attested'),
59
+ createdAt: z.string().nullable().optional().describe('ISO 8601 creation timestamp'),
60
+ }).passthrough()).describe('Array of compliance records'),
61
+ total: z.number().nullable().optional().describe('Total count'),
62
+ }).passthrough().describe('Paginated list of compliance records for a mandate'),
46
63
  annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
47
64
  _meta: toolMeta('list_compliance_records'),
48
65
  },
@@ -51,7 +68,7 @@ export function registerComplianceTools(mcp: McpServer, client: AgledgerClient):
51
68
  const result = await client.compliance.listRecords(args.mandateId, { limit: args.limit });
52
69
  return {
53
70
  content: [{ type: 'text', text: `Found ${result.data.length} compliance records for mandate ${args.mandateId}.` }],
54
- structuredContent: result as unknown as Record<string, unknown>,
71
+ structuredContent: toStructuredContent(result),
55
72
  };
56
73
  } catch (err) { return apiErrorResult(err); }
57
74
  },
@@ -63,6 +80,14 @@ export function registerComplianceTools(mcp: McpServer, client: AgledgerClient):
63
80
  title: 'EU AI Act Report',
64
81
  description: 'Get EU AI Act compliance report showing risk classifications, human oversight designations, and audit status across all mandates.',
65
82
  inputSchema: {},
83
+ outputSchema: z.object({
84
+ summary: z.object({
85
+ highRiskCount: z.number().describe('Count of high-risk mandates'),
86
+ auditedCount: z.number().describe('Count of audited mandates'),
87
+ totalCount: z.number().nullable().optional().describe('Total mandate count'),
88
+ }).passthrough().describe('Report summary counts'),
89
+ mandates: z.array(z.record(z.string(), z.unknown())).nullable().optional().describe('Detailed mandate-level compliance data'),
90
+ }).passthrough().describe('EU AI Act compliance report'),
66
91
  annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
67
92
  _meta: toolMeta('get_eu_ai_act_report'),
68
93
  },
@@ -71,7 +96,7 @@ export function registerComplianceTools(mcp: McpServer, client: AgledgerClient):
71
96
  const report = await client.compliance.getEuAiActReport();
72
97
  return {
73
98
  content: [{ type: 'text', text: `EU AI Act report: ${report.summary.highRiskCount} high-risk mandates, ${report.summary.auditedCount} audited.` }],
74
- structuredContent: report as unknown as Record<string, unknown>,
99
+ structuredContent: toStructuredContent(report),
75
100
  };
76
101
  } catch (err) { return apiErrorResult(err); }
77
102
  },