@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
@@ -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 registerDashboardTools(mcp: McpServer, client: AgledgerClient): void {
@@ -11,6 +11,13 @@ export function registerDashboardTools(mcp: McpServer, client: AgledgerClient):
11
11
  title: 'Dashboard Summary',
12
12
  description: 'Get a high-level dashboard summary: mandate counts, active agents, fulfillment rates, settlement signals. Start here for situational awareness.',
13
13
  inputSchema: {},
14
+ outputSchema: z.object({
15
+ totalMandates: z.number().describe('Total number of mandates'),
16
+ activeCount: z.number().describe('Count of active mandates'),
17
+ fulfilledCount: z.number().describe('Count of fulfilled mandates'),
18
+ failedCount: z.number().nullable().optional().describe('Count of failed mandates'),
19
+ disputeCount: z.number().nullable().optional().describe('Count of open disputes'),
20
+ }).passthrough().describe('High-level dashboard summary with mandate counts and rates'),
14
21
  annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
15
22
  _meta: toolMeta('get_dashboard_summary'),
16
23
  },
@@ -19,7 +26,7 @@ export function registerDashboardTools(mcp: McpServer, client: AgledgerClient):
19
26
  const summary = await client.dashboard.getSummary();
20
27
  return {
21
28
  content: [{ type: 'text', text: `Dashboard: ${summary.totalMandates} mandates, ${summary.activeCount} active, ${summary.fulfilledCount} fulfilled.` }],
22
- structuredContent: summary as unknown as Record<string, unknown>,
29
+ structuredContent: toStructuredContent(summary),
23
30
  };
24
31
  } catch (err) { return apiErrorResult(err); }
25
32
  },
@@ -35,6 +42,14 @@ export function registerDashboardTools(mcp: McpServer, client: AgledgerClient):
35
42
  to: z.string().optional().describe('End date (ISO 8601)'),
36
43
  granularity: z.enum(['daily', 'weekly', 'monthly']).optional().describe('Time bucket size'),
37
44
  },
45
+ outputSchema: z.object({
46
+ series: z.array(z.object({
47
+ date: z.string().describe('ISO 8601 date for this data point'),
48
+ mandates: z.number().nullable().optional().describe('Mandate count for this period'),
49
+ receipts: z.number().nullable().optional().describe('Receipt count for this period'),
50
+ disputes: z.number().nullable().optional().describe('Dispute count for this period'),
51
+ }).passthrough()).nullable().optional().describe('Time-series data points'),
52
+ }).passthrough().describe('Dashboard time-series metrics'),
38
53
  annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
39
54
  _meta: toolMeta('get_dashboard_metrics'),
40
55
  },
@@ -43,7 +58,7 @@ export function registerDashboardTools(mcp: McpServer, client: AgledgerClient):
43
58
  const metrics = await client.dashboard.getMetrics(args);
44
59
  return {
45
60
  content: [{ type: 'text', text: `Metrics: ${metrics.series?.length ?? 0} data points.` }],
46
- structuredContent: metrics as unknown as Record<string, unknown>,
61
+ structuredContent: toStructuredContent(metrics),
47
62
  };
48
63
  } catch (err) { return apiErrorResult(err); }
49
64
  },
@@ -57,6 +72,16 @@ export function registerDashboardTools(mcp: McpServer, client: AgledgerClient):
57
72
  inputSchema: {
58
73
  limit: z.number().optional().describe('Page size'),
59
74
  },
75
+ outputSchema: z.object({
76
+ data: z.array(z.object({
77
+ id: z.string().optional().describe('Alert ID'),
78
+ type: z.string().optional().describe('Alert type (e.g. overdue, failed_verification)'),
79
+ message: z.string().optional().describe('Human-readable alert message'),
80
+ severity: z.string().nullable().optional().describe('Alert severity level'),
81
+ createdAt: z.string().nullable().optional().describe('ISO 8601 creation timestamp'),
82
+ }).passthrough()).describe('Array of active alerts'),
83
+ total: z.number().nullable().optional().describe('Total count of alerts'),
84
+ }).passthrough().describe('Dashboard alerts requiring attention'),
60
85
  annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
61
86
  _meta: toolMeta('get_dashboard_alerts'),
62
87
  },
@@ -65,7 +90,7 @@ export function registerDashboardTools(mcp: McpServer, client: AgledgerClient):
65
90
  const result = await client.dashboard.getAlerts(args);
66
91
  return {
67
92
  content: [{ type: 'text', text: `Found ${result.data.length} alerts.` }],
68
- structuredContent: result as unknown as Record<string, unknown>,
93
+ structuredContent: toStructuredContent(result),
69
94
  };
70
95
  } catch (err) { return apiErrorResult(err); }
71
96
  },
@@ -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 { DisputeStatusEnum, NextStepsField } from '../enums.js';
7
7
 
@@ -48,7 +48,7 @@ export function registerDisputeTools(mcp: McpServer, client: AgledgerClient): vo
48
48
  const dispute = await client.disputes.create(mandateId, disputeParams);
49
49
  return {
50
50
  content: [{ type: 'text', text: `Dispute ${dispute.id} opened on mandate ${mandateId}. Status: ${dispute.status}, tier: ${dispute.currentTier}.` }],
51
- structuredContent: dispute as unknown as Record<string, unknown>,
51
+ structuredContent: toStructuredContent(dispute),
52
52
  };
53
53
  } catch (err) {
54
54
  return apiErrorResult(err);
@@ -79,7 +79,7 @@ export function registerDisputeTools(mcp: McpServer, client: AgledgerClient): vo
79
79
  const dispute = result.dispute;
80
80
  return {
81
81
  content: [{ type: 'text', text: `Dispute ${dispute.id}: status=${dispute.status}, tier=${dispute.currentTier}, grounds="${dispute.grounds}". ${result.evidence?.length ?? 0} evidence item(s).` }],
82
- structuredContent: result as unknown as Record<string, unknown>,
82
+ structuredContent: toStructuredContent(dispute),
83
83
  };
84
84
  } catch (err) {
85
85
  return apiErrorResult(err);
@@ -109,7 +109,7 @@ export function registerDisputeTools(mcp: McpServer, client: AgledgerClient): vo
109
109
  const dispute = await client.disputes.escalate(args.mandateId);
110
110
  return {
111
111
  content: [{ type: 'text', text: `Dispute on mandate ${args.mandateId} escalated to tier ${dispute.currentTier}. Status: ${dispute.status}.` }],
112
- structuredContent: dispute as unknown as Record<string, unknown>,
112
+ structuredContent: toStructuredContent(dispute),
113
113
  };
114
114
  } catch (err) {
115
115
  return apiErrorResult(err);
@@ -127,6 +127,11 @@ export function registerDisputeTools(mcp: McpServer, client: AgledgerClient): vo
127
127
  evidenceType: z.enum(['screenshot', 'external_lookup', 'document', 'communication', 'other']).describe('Type of evidence being submitted'),
128
128
  payload: z.record(z.string(), z.unknown()).describe('Evidence payload object'),
129
129
  },
130
+ outputSchema: z.object({
131
+ id: z.string().describe('Evidence record ID'),
132
+ evidenceType: z.string().describe('Type of evidence submitted'),
133
+ createdAt: z.string().nullable().optional().describe('ISO 8601 creation timestamp'),
134
+ }).passthrough().describe('Submitted dispute evidence confirmation'),
130
135
  annotations: {
131
136
  readOnlyHint: false,
132
137
  destructiveHint: false,
@@ -143,7 +148,7 @@ export function registerDisputeTools(mcp: McpServer, client: AgledgerClient): vo
143
148
  });
144
149
  return {
145
150
  content: [{ type: 'text', text: `Evidence submitted for dispute on mandate ${args.mandateId}. Type: ${args.evidenceType}.` }],
146
- structuredContent: result as unknown as Record<string, unknown>,
151
+ structuredContent: toStructuredContent(result),
147
152
  };
148
153
  } catch (err) {
149
154
  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 registerEnterpriseTools(mcp: McpServer, client: AgledgerClient): void {
@@ -15,6 +15,12 @@ export function registerEnterpriseTools(mcp: McpServer, client: AgledgerClient):
15
15
  agentId: z.string().describe('Agent ID to approve'),
16
16
  reason: z.string().optional().describe('Reason for approval'),
17
17
  },
18
+ outputSchema: z.object({
19
+ agentId: z.string().describe('Approved agent ID'),
20
+ enterpriseId: z.string().describe('Enterprise ID'),
21
+ status: z.string().describe('Agent approval status'),
22
+ approvedAt: z.string().nullable().optional().describe('ISO 8601 approval timestamp'),
23
+ }).passthrough().describe('Enterprise agent approval result'),
18
24
  annotations: {
19
25
  readOnlyHint: false,
20
26
  destructiveHint: false,
@@ -30,7 +36,7 @@ export function registerEnterpriseTools(mcp: McpServer, client: AgledgerClient):
30
36
  });
31
37
  return {
32
38
  content: [{ type: 'text', text: `Agent ${args.agentId} approved for enterprise ${args.enterpriseId}.` }],
33
- structuredContent: record as unknown as Record<string, unknown>,
39
+ structuredContent: toStructuredContent(record),
34
40
  };
35
41
  } catch (err) {
36
42
  return apiErrorResult(err);
@@ -48,6 +54,11 @@ export function registerEnterpriseTools(mcp: McpServer, client: AgledgerClient):
48
54
  agentId: z.string().describe('Agent ID to revoke'),
49
55
  reason: z.string().optional().describe('Reason for revocation'),
50
56
  },
57
+ outputSchema: z.object({
58
+ enterpriseId: z.string().describe('Enterprise ID'),
59
+ agentId: z.string().describe('Revoked agent ID'),
60
+ status: z.string().describe('Agent status after revocation'),
61
+ }).passthrough().describe('Enterprise agent revocation result'),
51
62
  annotations: {
52
63
  readOnlyHint: false,
53
64
  destructiveHint: true,
@@ -82,6 +93,15 @@ export function registerEnterpriseTools(mcp: McpServer, client: AgledgerClient):
82
93
  limit: z.number().optional().describe('Page size'),
83
94
  offset: z.number().optional().describe('Page offset'),
84
95
  },
96
+ outputSchema: z.object({
97
+ data: z.array(z.object({
98
+ agentId: z.string().describe('Agent ID'),
99
+ status: z.string().describe('Agent approval status'),
100
+ }).passthrough()).describe('Array of enterprise agents'),
101
+ total: z.number().nullable().optional().describe('Total count of matching agents'),
102
+ limit: z.number().nullable().optional().describe('Page size'),
103
+ offset: z.number().nullable().optional().describe('Page offset'),
104
+ }).passthrough().describe('Paginated list of enterprise agents'),
85
105
  annotations: {
86
106
  readOnlyHint: true,
87
107
  destructiveHint: false,
@@ -99,7 +119,7 @@ export function registerEnterpriseTools(mcp: McpServer, client: AgledgerClient):
99
119
  });
100
120
  return {
101
121
  content: [{ type: 'text', text: `Found ${result.data.length} agents for enterprise ${args.enterpriseId}.` }],
102
- structuredContent: result as unknown as Record<string, unknown>,
122
+ structuredContent: toStructuredContent(result),
103
123
  };
104
124
  } catch (err) {
105
125
  return apiErrorResult(err);
@@ -141,7 +161,7 @@ export function registerEnterpriseTools(mcp: McpServer, client: AgledgerClient):
141
161
  const enterprise = await client.admin.createEnterprise({ name: args.name, slug: args.slug });
142
162
  return {
143
163
  content: [{ type: 'text', text: `Enterprise "${enterprise.name}" created (${enterprise.id}, slug: ${enterprise.slug}). Next: create an API key with POST /v1/admin/api-keys, then register agents.` }],
144
- structuredContent: enterprise as unknown as Record<string, unknown>,
164
+ structuredContent: toStructuredContent(enterprise),
145
165
  };
146
166
  } catch (err) {
147
167
  return apiErrorResult(err);
@@ -189,7 +209,7 @@ export function registerEnterpriseTools(mcp: McpServer, client: AgledgerClient):
189
209
  });
190
210
  return {
191
211
  content: [{ type: 'text', text: `Agent "${agent.displayName}" created (${agent.id}, slug: ${agent.slug}). Next: create an API key with POST /v1/admin/api-keys, then set capabilities.` }],
192
- structuredContent: agent as unknown as Record<string, unknown>,
212
+ structuredContent: toStructuredContent(agent),
193
213
  };
194
214
  } catch (err) {
195
215
  return apiErrorResult(err);
@@ -212,6 +232,10 @@ export function registerEnterpriseTools(mcp: McpServer, client: AgledgerClient):
212
232
  'allowSelfApproval (boolean), defaultScopes (string[])',
213
233
  ),
214
234
  },
235
+ outputSchema: z.object({
236
+ enterpriseId: z.string().nullable().optional().describe('Enterprise ID'),
237
+ config: z.record(z.string(), z.unknown()).nullable().optional().describe('Applied configuration'),
238
+ }).passthrough().describe('Enterprise configuration update result'),
215
239
  annotations: {
216
240
  readOnlyHint: false,
217
241
  destructiveHint: false,
@@ -225,7 +249,7 @@ export function registerEnterpriseTools(mcp: McpServer, client: AgledgerClient):
225
249
  const result = await client.admin.setEnterpriseConfig(args.enterpriseId, args.config);
226
250
  return {
227
251
  content: [{ type: 'text', text: `Configuration replaced for enterprise ${args.enterpriseId}.` }],
228
- structuredContent: result as unknown as Record<string, unknown>,
252
+ structuredContent: toStructuredContent(result),
229
253
  };
230
254
  } catch (err) {
231
255
  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 AuditChainOutputSchema = z.object({
@@ -42,7 +42,7 @@ export function registerEventTools(mcp: McpServer, client: AgledgerClient): void
42
42
  const chain = await client.events.getAuditChain(args.mandateId);
43
43
  return {
44
44
  content: [{ type: 'text', text: `Audit trail for mandate ${chain.mandateId}: ${chain.entries.length} entries, chain valid=${chain.isValid}.` }],
45
- structuredContent: chain as unknown as Record<string, unknown>,
45
+ structuredContent: toStructuredContent(chain),
46
46
  };
47
47
  } catch (err) {
48
48
  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 { HubStateEnum, GatewayStatusEnum } from '../enums.js';
7
7
  import type { FederationAuditEntryType } from '@agledger/sdk';
@@ -196,7 +196,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
196
196
  });
197
197
  return {
198
198
  content: [{ type: 'text', text: `Registration token created. Expires: ${result.expiresAt}.` }],
199
- structuredContent: result as unknown as Record<string, unknown>,
199
+ structuredContent: toStructuredContent(result),
200
200
  };
201
201
  } catch (err) {
202
202
  return apiErrorResult(err);
@@ -232,7 +232,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
232
232
  });
233
233
  return {
234
234
  content: [{ type: 'text', text: `Found ${result.data.length} gateway(s).${result.total != null ? ` Total: ${result.total}.` : ''}` }],
235
- structuredContent: result as unknown as Record<string, unknown>,
235
+ structuredContent: toStructuredContent(result),
236
236
  };
237
237
  } catch (err) {
238
238
  return apiErrorResult(err);
@@ -263,7 +263,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
263
263
  const result = await client.federationAdmin.revokeGateway(args.gatewayId, { reason: args.reason });
264
264
  return {
265
265
  content: [{ type: 'text', text: `Gateway ${args.gatewayId} revoked. Reason: ${args.reason}.` }],
266
- structuredContent: result as unknown as Record<string, unknown>,
266
+ structuredContent: toStructuredContent(result),
267
267
  };
268
268
  } catch (err) {
269
269
  return apiErrorResult(err);
@@ -303,7 +303,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
303
303
  });
304
304
  return {
305
305
  content: [{ type: 'text', text: `Found ${result.data.length} federation mandate(s).${result.total != null ? ` Total: ${result.total}.` : ''}` }],
306
- structuredContent: result as unknown as Record<string, unknown>,
306
+ structuredContent: toStructuredContent(result),
307
307
  };
308
308
  } catch (err) {
309
309
  return apiErrorResult(err);
@@ -343,7 +343,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
343
343
  });
344
344
  return {
345
345
  content: [{ type: 'text', text: `Retrieved ${result.data.length} audit log entry(ies).${result.total != null ? ` Total: ${result.total}.` : ''}` }],
346
- structuredContent: result as unknown as Record<string, unknown>,
346
+ structuredContent: toStructuredContent(result),
347
347
  };
348
348
  } catch (err) {
349
349
  return apiErrorResult(err);
@@ -371,7 +371,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
371
371
  const result = await client.federationAdmin.getHealth();
372
372
  return {
373
373
  content: [{ type: 'text', text: `Federation health: ${result.gateways.active} active gateways, ${result.gateways.suspended} suspended, ${result.gateways.revoked} revoked. Audit chain length: ${result.auditChainLength}.` }],
374
- structuredContent: result as unknown as Record<string, unknown>,
374
+ structuredContent: toStructuredContent(result),
375
375
  };
376
376
  } catch (err) {
377
377
  return apiErrorResult(err);
@@ -402,7 +402,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
402
402
  const result = await client.federationAdmin.resetSequence(args.gatewayId, { newSeq: args.newSeq });
403
403
  return {
404
404
  content: [{ type: 'text', text: `Sequence reset for gateway ${args.gatewayId}: ${result.reset ? 'success' : 'failed'}.` }],
405
- structuredContent: result as unknown as Record<string, unknown>,
405
+ structuredContent: toStructuredContent(result),
406
406
  };
407
407
  } catch (err) {
408
408
  return apiErrorResult(err);
@@ -436,7 +436,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
436
436
  });
437
437
  return {
438
438
  content: [{ type: 'text', text: `Found ${result.data.length} DLQ entry(ies).${result.hasMore ? ' More available.' : ''}` }],
439
- structuredContent: result as unknown as Record<string, unknown>,
439
+ structuredContent: toStructuredContent(result),
440
440
  };
441
441
  } catch (err) {
442
442
  return apiErrorResult(err);
@@ -466,7 +466,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
466
466
  const result = await client.federationAdmin.retryDlq(args.dlqId);
467
467
  return {
468
468
  content: [{ type: 'text', text: `DLQ entry ${args.dlqId} retried: ${result.retried ? 'success' : 'failed'}.` }],
469
- structuredContent: result as unknown as Record<string, unknown>,
469
+ structuredContent: toStructuredContent(result),
470
470
  };
471
471
  } catch (err) {
472
472
  return apiErrorResult(err);
@@ -496,7 +496,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
496
496
  const result = await client.federationAdmin.deleteDlq(args.dlqId);
497
497
  return {
498
498
  content: [{ type: 'text', text: `DLQ entry ${args.dlqId} deleted.` }],
499
- structuredContent: result as unknown as Record<string, unknown>,
499
+ structuredContent: toStructuredContent(result),
500
500
  };
501
501
  } catch (err) {
502
502
  return apiErrorResult(err);
@@ -524,7 +524,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
524
524
  const result = await client.federationAdmin.rotateHubKey();
525
525
  return {
526
526
  content: [{ type: 'text', text: `Hub key rotated. New key ID: ${result.id}. Use federation_activate_hub_key to make it active.` }],
527
- structuredContent: result as unknown as Record<string, unknown>,
527
+ structuredContent: toStructuredContent(result),
528
528
  };
529
529
  } catch (err) {
530
530
  return apiErrorResult(err);
@@ -552,7 +552,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
552
552
  const result = await client.federationAdmin.listHubKeys();
553
553
  return {
554
554
  content: [{ type: 'text', text: `Found ${Array.isArray(result) ? result.length : 0} hub signing key(s).` }],
555
- structuredContent: { keys: result } as unknown as Record<string, unknown>,
555
+ structuredContent: toStructuredContent({ keys: result }),
556
556
  };
557
557
  } catch (err) {
558
558
  return apiErrorResult(err);
@@ -582,7 +582,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
582
582
  const result = await client.federationAdmin.activateHubKey(args.keyId);
583
583
  return {
584
584
  content: [{ type: 'text', text: `Hub key ${args.keyId} activated. All gateways will now use this key for signature verification.` }],
585
- structuredContent: result as unknown as Record<string, unknown>,
585
+ structuredContent: toStructuredContent(result),
586
586
  };
587
587
  } catch (err) {
588
588
  return apiErrorResult(err);
@@ -612,7 +612,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
612
612
  const result = await client.federationAdmin.expireHubKey(args.keyId);
613
613
  return {
614
614
  content: [{ type: 'text', text: `Hub key ${args.keyId} expired. It will no longer be accepted for signature verification.` }],
615
- structuredContent: result as unknown as Record<string, unknown>,
615
+ structuredContent: toStructuredContent(result),
616
616
  };
617
617
  } catch (err) {
618
618
  return apiErrorResult(err);
@@ -645,7 +645,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
645
645
  const result = await client.federationAdmin.registerPeer(args);
646
646
  return {
647
647
  content: [{ type: 'text', text: `Peer hub "${args.name}" registered. Hub ID: ${result.hubId ?? 'n/a'}. Use federation_resync_peer to synchronize state.` }],
648
- structuredContent: result as unknown as Record<string, unknown>,
648
+ structuredContent: toStructuredContent(result),
649
649
  };
650
650
  } catch (err) {
651
651
  return apiErrorResult(err);
@@ -673,7 +673,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
673
673
  const result = await client.federationAdmin.listPeers();
674
674
  return {
675
675
  content: [{ type: 'text', text: `Found ${result.data.length} peer hub(s).` }],
676
- structuredContent: result as unknown as Record<string, unknown>,
676
+ structuredContent: toStructuredContent(result),
677
677
  };
678
678
  } catch (err) {
679
679
  return apiErrorResult(err);
@@ -703,7 +703,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
703
703
  const result = await client.federationAdmin.getPeer(args.hubId);
704
704
  return {
705
705
  content: [{ type: 'text', text: `Peer hub ${args.hubId}: ${result.name ?? 'unnamed'}. Status: ${result.status ?? 'unknown'}.` }],
706
- structuredContent: result as unknown as Record<string, unknown>,
706
+ structuredContent: toStructuredContent(result),
707
707
  };
708
708
  } catch (err) {
709
709
  return apiErrorResult(err);
@@ -733,7 +733,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
733
733
  const result = await client.federationAdmin.revokePeer(args.hubId);
734
734
  return {
735
735
  content: [{ type: 'text', text: `Peer hub ${args.hubId} revoked. It can no longer communicate with this federation hub.` }],
736
- structuredContent: result as unknown as Record<string, unknown>,
736
+ structuredContent: toStructuredContent(result),
737
737
  };
738
738
  } catch (err) {
739
739
  return apiErrorResult(err);
@@ -763,7 +763,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
763
763
  const result = await client.federationAdmin.resyncPeer(args.hubId);
764
764
  return {
765
765
  content: [{ type: 'text', text: `Resync initiated for peer hub ${args.hubId}. Synced: ${result.synced}.` }],
766
- structuredContent: result as unknown as Record<string, unknown>,
766
+ structuredContent: toStructuredContent(result),
767
767
  };
768
768
  } catch (err) {
769
769
  return apiErrorResult(err);
@@ -791,7 +791,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
791
791
  const result = await client.federationAdmin.createPeeringToken();
792
792
  return {
793
793
  content: [{ type: 'text', text: `Peering token created. Expires: ${result.expiresAt ?? 'n/a'}. Share securely with the remote hub administrator.` }],
794
- structuredContent: result as unknown as Record<string, unknown>,
794
+ structuredContent: toStructuredContent(result),
795
795
  };
796
796
  } catch (err) {
797
797
  return apiErrorResult(err);
@@ -822,7 +822,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
822
822
  const result = await client.federationAdmin.deleteSchemaVersion(args.contractType, args.version);
823
823
  return {
824
824
  content: [{ type: 'text', text: `Schema version ${args.version} deleted for ${args.contractType}. Gateways using this version must upgrade.` }],
825
- structuredContent: result as unknown as Record<string, unknown>,
825
+ structuredContent: toStructuredContent(result),
826
826
  };
827
827
  } catch (err) {
828
828
  return apiErrorResult(err);
@@ -852,7 +852,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
852
852
  const result = await client.federationAdmin.listReputationContributions(args.agentId);
853
853
  return {
854
854
  content: [{ type: 'text', text: `Found ${result.length} reputation contribution(s) for agent ${args.agentId}.` }],
855
- structuredContent: { contributions: result } as unknown as Record<string, unknown>,
855
+ structuredContent: toStructuredContent({ contributions: result }),
856
856
  };
857
857
  } catch (err) {
858
858
  return apiErrorResult(err);
@@ -882,7 +882,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
882
882
  const result = await client.federationAdmin.resetReputation(args.agentId);
883
883
  return {
884
884
  content: [{ type: 'text', text: `Reputation reset for agent ${args.agentId}. All historical data cleared.` }],
885
- structuredContent: result as unknown as Record<string, unknown>,
885
+ structuredContent: toStructuredContent(result),
886
886
  };
887
887
  } catch (err) {
888
888
  return apiErrorResult(err);
@@ -912,7 +912,7 @@ export function registerFederationAdminTools(mcp: McpServer, client: AgledgerCli
912
912
  const result = await client.federationAdmin.getMandateCriteriaStatus(args.mandateId);
913
913
  return {
914
914
  content: [{ type: 'text', text: `Criteria status for mandate ${result.mandateId}: principal submitted: ${result.principalSubmitted}, performer submitted: ${result.performerSubmitted}, agreement reached: ${result.agreementReached}.` }],
915
- structuredContent: result as unknown as Record<string, unknown>,
915
+ structuredContent: toStructuredContent(result),
916
916
  };
917
917
  } catch (err) {
918
918
  return apiErrorResult(err);