@agledger/mcp-server 1.4.1 → 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
  import { FederationSignalEnum, FederationOutcomeEnum, RevocationReasonEnum } from '../enums.js';
7
7
 
@@ -155,7 +155,7 @@ export function registerFederationTools(mcp: McpServer, client: AgledgerClient):
155
155
  const result = await client.federation.register(args);
156
156
  return {
157
157
  content: [{ type: 'text', text: `Gateway ${result.gatewayId} registered. Token expires at ${result.bearerTokenExpiresAt}. Use federation_heartbeat to refresh your token before it expires.` }],
158
- structuredContent: result as unknown as Record<string, unknown>,
158
+ structuredContent: toStructuredContent(result),
159
159
  };
160
160
  } catch (err) {
161
161
  return apiErrorResult(err);
@@ -188,7 +188,7 @@ export function registerFederationTools(mcp: McpServer, client: AgledgerClient):
188
188
  const result = await client.federation.heartbeat(args);
189
189
  return {
190
190
  content: [{ type: 'text', text: `Heartbeat accepted for gateway ${args.gatewayId}. Token expires at ${result.bearerTokenExpiresAt}. ${result.revocations.length > 0 ? `${result.revocations.length} revocation(s) received.` : ''}` }],
191
- structuredContent: result as unknown as Record<string, unknown>,
191
+ structuredContent: toStructuredContent(result),
192
192
  };
193
193
  } catch (err) {
194
194
  return apiErrorResult(err);
@@ -220,7 +220,7 @@ export function registerFederationTools(mcp: McpServer, client: AgledgerClient):
220
220
  const result = await client.federation.registerAgent(args);
221
221
  return {
222
222
  content: [{ type: 'text', text: `Agent ${args.agentId} registered: ${result.registered}.` }],
223
- structuredContent: result as unknown as Record<string, unknown>,
223
+ structuredContent: toStructuredContent(result),
224
224
  };
225
225
  } catch (err) {
226
226
  return apiErrorResult(err);
@@ -252,7 +252,7 @@ export function registerFederationTools(mcp: McpServer, client: AgledgerClient):
252
252
  const result = await client.federation.listAgents(args);
253
253
  return {
254
254
  content: [{ type: 'text', text: `Found ${result.data.length} federated agent(s).${result.hasMore ? ' More results available — pass cursor to paginate.' : ''}` }],
255
- structuredContent: result as unknown as Record<string, unknown>,
255
+ structuredContent: toStructuredContent(result),
256
256
  };
257
257
  } catch (err) {
258
258
  return apiErrorResult(err);
@@ -293,7 +293,7 @@ export function registerFederationTools(mcp: McpServer, client: AgledgerClient):
293
293
  const result = await client.federation.submitStateTransition(args);
294
294
  return {
295
295
  content: [{ type: 'text', text: `Transition accepted. Hub state: ${result.hubState}. Sub-status: ${result.subStatus}. Hub timestamp: ${result.hubTimestamp}.` }],
296
- structuredContent: result as unknown as Record<string, unknown>,
296
+ structuredContent: toStructuredContent(result),
297
297
  };
298
298
  } catch (err) {
299
299
  return apiErrorResult(err);
@@ -332,7 +332,7 @@ export function registerFederationTools(mcp: McpServer, client: AgledgerClient):
332
332
  const result = await client.federation.relaySignal(args);
333
333
  return {
334
334
  content: [{ type: 'text', text: `Signal relayed: ${result.relayed}. Target gateway: ${result.targetGatewayId}. Hub timestamp: ${result.hubTimestamp}.` }],
335
- structuredContent: result as unknown as Record<string, unknown>,
335
+ structuredContent: toStructuredContent(result),
336
336
  };
337
337
  } catch (err) {
338
338
  return apiErrorResult(err);
@@ -369,7 +369,7 @@ export function registerFederationTools(mcp: McpServer, client: AgledgerClient):
369
369
  const result = await client.federation.rotateKey(gatewayId, rotateParams);
370
370
  return {
371
371
  content: [{ type: 'text', text: `Keys rotated for gateway ${gatewayId}: ${result.rotated ? 'success' : 'failed'}.` }],
372
- structuredContent: result as unknown as Record<string, unknown>,
372
+ structuredContent: toStructuredContent(result),
373
373
  };
374
374
  } catch (err) {
375
375
  return apiErrorResult(err);
@@ -402,7 +402,7 @@ export function registerFederationTools(mcp: McpServer, client: AgledgerClient):
402
402
  const result = await client.federation.revoke(gatewayId, revokeParams);
403
403
  return {
404
404
  content: [{ type: 'text', text: `Gateway ${gatewayId} revoked: ${result.revoked}. Revoked at: ${result.revokedAt}. This action is permanent.` }],
405
- structuredContent: result as unknown as Record<string, unknown>,
405
+ structuredContent: toStructuredContent(result),
406
406
  };
407
407
  } catch (err) {
408
408
  return apiErrorResult(err);
@@ -433,7 +433,7 @@ export function registerFederationTools(mcp: McpServer, client: AgledgerClient):
433
433
  const result = await client.federation.catchUp(args);
434
434
  return {
435
435
  content: [{ type: 'text', text: `Caught up ${result.data.length} entry(ies) since position ${args.sincePosition}.${result.hasMore ? ' More entries available.' : ' Fully caught up.'}` }],
436
- structuredContent: result as unknown as Record<string, unknown>,
436
+ structuredContent: toStructuredContent(result),
437
437
  };
438
438
  } catch (err) {
439
439
  return apiErrorResult(err);
@@ -464,7 +464,7 @@ export function registerFederationTools(mcp: McpServer, client: AgledgerClient):
464
464
  const events = Array.isArray(result['events']) ? result['events'] as unknown[] : [];
465
465
  return {
466
466
  content: [{ type: 'text', text: `Streamed ${events.length} federation event(s).${args.since ? ` Since: ${args.since}.` : ''}` }],
467
- structuredContent: result as unknown as Record<string, unknown>,
467
+ structuredContent: toStructuredContent(result),
468
468
  };
469
469
  } catch (err) {
470
470
  return apiErrorResult(err);
@@ -496,7 +496,7 @@ export function registerFederationTools(mcp: McpServer, client: AgledgerClient):
496
496
  const result = await client.federation.publishSchema(args.contractType, { schema: args.schema, visibility: args.visibility });
497
497
  return {
498
498
  content: [{ type: 'text', text: `Schema publication initiated for ${args.contractType}. Status: ${result.status ?? 'pending'}. Use federation_confirm_schema_publish with the confirmation token to finalize.` }],
499
- structuredContent: result as unknown as Record<string, unknown>,
499
+ structuredContent: toStructuredContent(result),
500
500
  };
501
501
  } catch (err) {
502
502
  return apiErrorResult(err);
@@ -527,7 +527,7 @@ export function registerFederationTools(mcp: McpServer, client: AgledgerClient):
527
527
  const result = await client.federation.confirmSchemaPublish(args.contractType, { confirmationToken: args.confirmationToken });
528
528
  return {
529
529
  content: [{ type: 'text', text: `Schema publication confirmed for ${args.contractType}. The schema is now available to federated gateways.` }],
530
- structuredContent: result as unknown as Record<string, unknown>,
530
+ structuredContent: toStructuredContent(result),
531
531
  };
532
532
  } catch (err) {
533
533
  return apiErrorResult(err);
@@ -555,7 +555,7 @@ export function registerFederationTools(mcp: McpServer, client: AgledgerClient):
555
555
  const result = await client.federation.listContractTypes();
556
556
  return {
557
557
  content: [{ type: 'text', text: `Found ${result.length} federated contract type(s). Use federation_get_contract_type for details on a specific type.` }],
558
- structuredContent: { contractTypes: result } as unknown as Record<string, unknown>,
558
+ structuredContent: toStructuredContent({ contractTypes: result }),
559
559
  };
560
560
  } catch (err) {
561
561
  return apiErrorResult(err);
@@ -585,7 +585,7 @@ export function registerFederationTools(mcp: McpServer, client: AgledgerClient):
585
585
  const result = await client.federation.getContractType(args.contractType);
586
586
  return {
587
587
  content: [{ type: 'text', text: `Contract type ${args.contractType}: ${result.status ?? 'unknown status'}. Schema version: ${result.version ?? 'n/a'}.` }],
588
- structuredContent: result as unknown as Record<string, unknown>,
588
+ structuredContent: toStructuredContent(result),
589
589
  };
590
590
  } catch (err) {
591
591
  return apiErrorResult(err);
@@ -615,7 +615,7 @@ export function registerFederationTools(mcp: McpServer, client: AgledgerClient):
615
615
  const result = await client.federation.getMandateCriteria(args.mandateId);
616
616
  return {
617
617
  content: [{ type: 'text', text: `Criteria retrieved for mandate ${result.mandateId}. Submitted by: ${result.submittedBy}.` }],
618
- structuredContent: result as unknown as Record<string, unknown>,
618
+ structuredContent: toStructuredContent(result),
619
619
  };
620
620
  } catch (err) {
621
621
  return apiErrorResult(err);
@@ -646,7 +646,7 @@ export function registerFederationTools(mcp: McpServer, client: AgledgerClient):
646
646
  const result = await client.federation.submitMandateCriteria(args.mandateId, { criteria: args.criteria });
647
647
  return {
648
648
  content: [{ type: 'text', text: `Criteria submitted for mandate ${result.mandateId}. Submitted by: ${result.submittedBy} at ${result.submittedAt}.` }],
649
- structuredContent: result as unknown as Record<string, unknown>,
649
+ structuredContent: toStructuredContent(result),
650
650
  };
651
651
  } catch (err) {
652
652
  return apiErrorResult(err);
@@ -679,7 +679,7 @@ export function registerFederationTools(mcp: McpServer, client: AgledgerClient):
679
679
  const result = await client.federation.contributeReputation(args);
680
680
  return {
681
681
  content: [{ type: 'text', text: `Reputation contribution recorded for agent ${args.agentId}. Outcome: ${args.outcome}. Contract type: ${args.contractType}.` }],
682
- structuredContent: result as unknown as Record<string, unknown>,
682
+ structuredContent: toStructuredContent(result),
683
683
  };
684
684
  } catch (err) {
685
685
  return apiErrorResult(err);
@@ -709,7 +709,7 @@ export function registerFederationTools(mcp: McpServer, client: AgledgerClient):
709
709
  const result = await client.federation.getAgentReputation(args.agentId);
710
710
  return {
711
711
  content: [{ type: 'text', text: `Reputation for agent ${args.agentId}: score ${result.overallScore}, contributions: ${result.contributions}.` }],
712
- structuredContent: result as unknown as Record<string, unknown>,
712
+ structuredContent: toStructuredContent(result),
713
713
  };
714
714
  } catch (err) {
715
715
  return apiErrorResult(err);
@@ -741,7 +741,7 @@ export function registerFederationTools(mcp: McpServer, client: AgledgerClient):
741
741
  const result = await client.federation.broadcastRevocations(args);
742
742
  return {
743
743
  content: [{ type: 'text', text: `Revocation broadcast sent for gateway ${args.gatewayId}. Broadcast: ${result.broadcast}.` }],
744
- structuredContent: result as unknown as Record<string, unknown>,
744
+ structuredContent: toStructuredContent(result),
745
745
  };
746
746
  } catch (err) {
747
747
  return apiErrorResult(err);
@@ -774,7 +774,7 @@ export function registerFederationTools(mcp: McpServer, client: AgledgerClient):
774
774
  const result = await client.federation.syncAgentDirectory(args);
775
775
  return {
776
776
  content: [{ type: 'text', text: `Agent directory synced: ${args.agents.length} agent(s) pushed. Synced: ${result.synced ?? 0}.` }],
777
- structuredContent: result as unknown as Record<string, unknown>,
777
+ structuredContent: toStructuredContent(result),
778
778
  };
779
779
  } catch (err) {
780
780
  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 HealthOutputSchema = z.object({
@@ -33,7 +33,7 @@ export function registerHealthTools(mcp: McpServer, client: AgledgerClient): voi
33
33
  const health = await client.health.check();
34
34
  return {
35
35
  content: [{ type: 'text', text: `API health: status=${health.status}${health.version ? `, version=${health.version}` : ''}${health.database ? `, db=${health.database}` : ''}.` }],
36
- structuredContent: health as unknown as Record<string, unknown>,
36
+ structuredContent: toStructuredContent(health),
37
37
  };
38
38
  } catch (err) {
39
39
  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 { ContractTypeEnum, MandateStatusEnum, NextStepsField, OperatingModeEnum, RiskClassificationEnum } from '../enums.js';
6
6
  import { toolMeta } from '../tool-scopes.js';
7
7
 
@@ -38,10 +38,10 @@ const MandateOutputSchema = z.object({
38
38
 
39
39
  const SearchResultOutputSchema = z.object({
40
40
  data: z.array(MandateOutputSchema).describe('Array of matching mandates'),
41
- total: z.number().describe('Total count of matching mandates'),
42
- limit: z.number().describe('Page size'),
43
- offset: z.number().describe('Page offset'),
44
- }).describe('Paginated mandate search results');
41
+ total: z.number().optional().describe('Total count of matching mandates'),
42
+ limit: z.number().optional().describe('Page size'),
43
+ offset: z.number().optional().describe('Page offset'),
44
+ }).passthrough().describe('Paginated mandate search results');
45
45
 
46
46
  export function registerMandateTools(mcp: McpServer, client: AgledgerClient): void {
47
47
  mcp.registerTool(
@@ -66,7 +66,7 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
66
66
  const mandate = await client.mandates.get(args.mandateId);
67
67
  return {
68
68
  content: [{ type: 'text', text: `Mandate ${mandate.id}: status=${mandate.status}, type=${mandate.contractType}.` }],
69
- structuredContent: mandate as unknown as Record<string, unknown>,
69
+ structuredContent: toStructuredContent(mandate),
70
70
  };
71
71
  } catch (err) {
72
72
  return apiErrorResult(err);
@@ -105,7 +105,7 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
105
105
  const result = await client.mandates.search(args);
106
106
  return {
107
107
  content: [{ type: 'text', text: `Found ${result.total} mandates (showing ${result.data.length}).` }],
108
- structuredContent: result as unknown as Record<string, unknown>,
108
+ structuredContent: toStructuredContent(result),
109
109
  };
110
110
  } catch (err) {
111
111
  return apiErrorResult(err);
@@ -135,7 +135,7 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
135
135
  const mandate = await client.mandates.transition(args.mandateId, 'activate');
136
136
  return {
137
137
  content: [{ type: 'text', text: `Mandate ${mandate.id} activated. Status is now ${mandate.status}.` }],
138
- structuredContent: mandate as unknown as Record<string, unknown>,
138
+ structuredContent: toStructuredContent(mandate),
139
139
  };
140
140
  } catch (err) {
141
141
  return apiErrorResult(err);
@@ -166,7 +166,7 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
166
166
  const mandate = await client.mandates.cancel(args.mandateId, args.reason);
167
167
  return {
168
168
  content: [{ type: 'text', text: `Mandate ${mandate.id} cancelled. Status is now ${mandate.status}.` }],
169
- structuredContent: mandate as unknown as Record<string, unknown>,
169
+ structuredContent: toStructuredContent(mandate),
170
170
  };
171
171
  } catch (err) {
172
172
  return apiErrorResult(err);
@@ -197,7 +197,7 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
197
197
  const mandate = await client.mandates.update(args.mandateId, args.updates);
198
198
  return {
199
199
  content: [{ type: 'text', text: `Mandate ${mandate.id} updated. Status: ${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);
@@ -228,7 +228,7 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
228
228
  const mandate = await client.mandates.requestRevision(args.mandateId, args.reason);
229
229
  return {
230
230
  content: [{ type: 'text', text: `Mandate ${mandate.id} moved to REVISION_REQUESTED. The performer should submit a new receipt.` }],
231
- structuredContent: mandate as unknown as Record<string, unknown>,
231
+ structuredContent: toStructuredContent(mandate),
232
232
  };
233
233
  } catch (err) {
234
234
  return apiErrorResult(err);
@@ -270,7 +270,7 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
270
270
  });
271
271
  return {
272
272
  content: [{ type: 'text', text: `Mandate ${args.mandateId} delegated to agent ${args.agentId}. Child mandate: ${childMandate.id}.` }],
273
- structuredContent: childMandate as unknown as Record<string, unknown>,
273
+ structuredContent: toStructuredContent(childMandate),
274
274
  };
275
275
  } catch (err) {
276
276
  return apiErrorResult(err);
@@ -286,6 +286,10 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
286
286
  inputSchema: {
287
287
  mandateId: z.string().describe('UUID of the mandate to get the delegation graph for'),
288
288
  },
289
+ outputSchema: z.object({
290
+ nodes: z.array(z.record(z.string(), z.unknown())).describe('Graph nodes (mandates)'),
291
+ edges: z.array(z.record(z.string(), z.unknown())).describe('Graph edges (delegation links)'),
292
+ }).passthrough().describe('Mandate delegation graph'),
289
293
  annotations: {
290
294
  readOnlyHint: true,
291
295
  destructiveHint: false,
@@ -301,7 +305,7 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
301
305
  const edges = (graph as any).edges?.length ?? 0;
302
306
  return {
303
307
  content: [{ type: 'text', text: `Delegation graph for mandate ${args.mandateId}: ${nodes} node(s), ${edges} edge(s).` }],
304
- structuredContent: graph as unknown as Record<string, unknown>,
308
+ structuredContent: toStructuredContent(graph),
305
309
  };
306
310
  } catch (err) {
307
311
  return apiErrorResult(err);
@@ -315,6 +319,13 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
315
319
  title: 'Get Mandate Summary',
316
320
  description: 'Get mandate counts grouped by status. Use for dashboard-level visibility.',
317
321
  inputSchema: {},
322
+ outputSchema: z.object({
323
+ CREATED: z.number().optional().describe('Count of CREATED mandates'),
324
+ ACTIVE: z.number().optional().describe('Count of ACTIVE mandates'),
325
+ PROCESSING: z.number().optional().describe('Count of PROCESSING mandates'),
326
+ FULFILLED: z.number().optional().describe('Count of FULFILLED mandates'),
327
+ FAILED: z.number().optional().describe('Count of FAILED mandates'),
328
+ }).passthrough().describe('Mandate counts grouped by status'),
318
329
  annotations: {
319
330
  readOnlyHint: true,
320
331
  destructiveHint: false,
@@ -328,7 +339,7 @@ export function registerMandateTools(mcp: McpServer, client: AgledgerClient): vo
328
339
  const summary = await client.mandates.getSummary();
329
340
  return {
330
341
  content: [{ type: 'text', text: `Mandate summary: ${JSON.stringify(summary)}.` }],
331
- structuredContent: summary as unknown as Record<string, unknown>,
342
+ structuredContent: toStructuredContent(summary),
332
343
  };
333
344
  } catch (err) {
334
345
  return apiErrorResult(err);
@@ -2,7 +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 type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
5
- import { apiErrorResult } from '../errors.js';
5
+ import { apiErrorResult, toStructuredContent } from '../errors.js';
6
6
  import { toolMeta } from '../tool-scopes.js';
7
7
 
8
8
  const NotarizeOutputSchema = z.object({
@@ -55,7 +55,7 @@ export function registerOpenClawTools(mcp: McpServer, client: AgledgerClient): v
55
55
  });
56
56
  return ok(
57
57
  `Agreement ${result.id} notarized (${args.contractType}). Hash: ${result.payloadHash}. Send mandate ID + payload to performer, then call agledger_verdict after delivery.`,
58
- result as unknown as Record<string, unknown>,
58
+ toStructuredContent(result),
59
59
  );
60
60
  } catch (e) { return apiErrorResult(e); }
61
61
  },
@@ -79,7 +79,7 @@ export function registerOpenClawTools(mcp: McpServer, client: AgledgerClient): v
79
79
  const mandate = await client.notarize.acceptMandate(args.mandateId);
80
80
  return ok(
81
81
  `Agreement ${mandate.id} accepted. Do the work, then call agledger_receipt.`,
82
- mandate as unknown as Record<string, unknown>,
82
+ toStructuredContent(mandate),
83
83
  );
84
84
  } catch (e) { return apiErrorResult(e); }
85
85
  },
@@ -106,7 +106,7 @@ export function registerOpenClawTools(mcp: McpServer, client: AgledgerClient): v
106
106
  });
107
107
  return ok(
108
108
  `Receipt ${result.id} submitted for ${args.mandateId}. Hash: ${result.payloadHash}. Principal should call agledger_verdict.`,
109
- result as unknown as Record<string, unknown>,
109
+ toStructuredContent(result),
110
110
  );
111
111
  } catch (e) { return apiErrorResult(e); }
112
112
  },
@@ -136,7 +136,7 @@ export function registerOpenClawTools(mcp: McpServer, client: AgledgerClient): v
136
136
  const verb = args.verdict === 'PASS' ? 'accepted' : 'rejected';
137
137
  return ok(
138
138
  `Agreement ${mandate.id} ${verb}. Status: ${mandate.status}.`,
139
- mandate as unknown as Record<string, unknown>,
139
+ toStructuredContent(mandate),
140
140
  );
141
141
  } catch (e) { return apiErrorResult(e); }
142
142
  },
@@ -160,7 +160,7 @@ export function registerOpenClawTools(mcp: McpServer, client: AgledgerClient): v
160
160
  const mandate = await client.notarize.getMandate(args.mandateId);
161
161
  return ok(
162
162
  `Agreement ${mandate.id}: ${mandate.status} (${mandate.contractType})`,
163
- mandate as unknown as Record<string, unknown>,
163
+ toStructuredContent(mandate),
164
164
  );
165
165
  } catch (e) { return apiErrorResult(e); }
166
166
  },
@@ -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 { NextStepsField, StructuralValidationEnum } from '../enums.js';
6
6
  import { toolMeta } from '../tool-scopes.js';
7
7
 
@@ -61,7 +61,6 @@ export function registerReceiptTools(mcp: McpServer, client: AgledgerClient, opt
61
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
62
  inputSchema: {
63
63
  mandateId: z.string().describe('UUID of the mandate this receipt is for'),
64
- agentId: z.string().describe('Agent ID submitting the receipt'),
65
64
  evidence: z
66
65
  .record(z.string(), z.unknown())
67
66
  .describe('Evidence JSON object proving task completion'),
@@ -90,7 +89,7 @@ export function registerReceiptTools(mcp: McpServer, client: AgledgerClient, opt
90
89
  }
91
90
  return {
92
91
  content: [{ type: 'text', text }],
93
- structuredContent: receipt as unknown as Record<string, unknown>,
92
+ structuredContent: toStructuredContent(receipt),
94
93
  };
95
94
  } catch (err) {
96
95
  return apiErrorResult(err);
@@ -142,7 +141,7 @@ export function registerReceiptTools(mcp: McpServer, client: AgledgerClient, opt
142
141
  content: [
143
142
  { type: 'text', text: `Receipt ${args.receiptId} ${verb}. Signal: ${result.signal}.` },
144
143
  ],
145
- structuredContent: result as unknown as Record<string, unknown>,
144
+ structuredContent: toStructuredContent(result),
146
145
  };
147
146
  } catch (err) {
148
147
  return apiErrorResult(err);
@@ -178,7 +177,7 @@ export function registerReceiptTools(mcp: McpServer, client: AgledgerClient, opt
178
177
  text: `Receipt ${receipt.id}: status=${receipt.structuralValidation}, mandate=${receipt.mandateId}.`,
179
178
  },
180
179
  ],
181
- structuredContent: receipt as unknown as Record<string, unknown>,
180
+ structuredContent: toStructuredContent(receipt),
182
181
  };
183
182
  } catch (err) {
184
183
  return apiErrorResult(err);
@@ -216,7 +215,7 @@ export function registerReceiptTools(mcp: McpServer, client: AgledgerClient, opt
216
215
  text: `Found ${result.data.length} receipts for mandate ${mandateId}.`,
217
216
  },
218
217
  ],
219
- structuredContent: result as unknown as Record<string, unknown>,
218
+ structuredContent: toStructuredContent(result),
220
219
  };
221
220
  } catch (err) {
222
221
  return apiErrorResult(err);
@@ -1,9 +1,17 @@
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
+ const ReputationScoreSchema = z.object({
8
+ contractType: z.string().optional().describe('Contract type identifier'),
9
+ compositeScore: z.number().optional().describe('Overall composite reputation score'),
10
+ reliabilityScore: z.number().optional().describe('Reliability score'),
11
+ accuracyScore: z.number().optional().describe('Accuracy score'),
12
+ efficiencyScore: z.number().optional().describe('Efficiency score'),
13
+ }).passthrough();
14
+
7
15
  export function registerReputationTools(mcp: McpServer, client: AgledgerClient): void {
8
16
  mcp.registerTool(
9
17
  'get_agent_reputation',
@@ -13,6 +21,10 @@ export function registerReputationTools(mcp: McpServer, client: AgledgerClient):
13
21
  inputSchema: {
14
22
  agentId: z.string().describe('UUID of the agent'),
15
23
  },
24
+ outputSchema: z.object({
25
+ data: z.array(ReputationScoreSchema).describe('Per-contract-type reputation scores'),
26
+ total: z.number().nullable().optional().describe('Total count'),
27
+ }).passthrough().describe('Agent reputation scores by contract type'),
16
28
  annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
17
29
  _meta: toolMeta('get_agent_reputation'),
18
30
  },
@@ -21,7 +33,7 @@ export function registerReputationTools(mcp: McpServer, client: AgledgerClient):
21
33
  const page = await client.reputation.getAgent(args.agentId);
22
34
  return {
23
35
  content: [{ type: 'text', text: `Agent ${args.agentId}: ${page.data.length} contract type score(s).` }],
24
- structuredContent: page as unknown as Record<string, unknown>,
36
+ structuredContent: toStructuredContent(page),
25
37
  };
26
38
  } catch (err) { return apiErrorResult(err); }
27
39
  },
@@ -36,6 +48,7 @@ export function registerReputationTools(mcp: McpServer, client: AgledgerClient):
36
48
  agentId: z.string().describe('UUID of the agent'),
37
49
  contractType: z.string().describe('Contract type (e.g., ACH-PROC-v1)'),
38
50
  },
51
+ outputSchema: ReputationScoreSchema.describe('Agent reputation score for a specific contract type'),
39
52
  annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
40
53
  _meta: toolMeta('get_reputation_by_type'),
41
54
  },
@@ -44,7 +57,7 @@ export function registerReputationTools(mcp: McpServer, client: AgledgerClient):
44
57
  const score = await client.reputation.getByContractType(args.agentId, args.contractType);
45
58
  return {
46
59
  content: [{ type: 'text', text: `Agent ${args.agentId} [${args.contractType}]: composite=${score.compositeScore}, reliability=${score.reliabilityScore}, accuracy=${score.accuracyScore}, efficiency=${score.efficiencyScore}.` }],
47
- structuredContent: score as unknown as Record<string, unknown>,
60
+ structuredContent: toStructuredContent(score),
48
61
  };
49
62
  } catch (err) { return apiErrorResult(err); }
50
63
  },
@@ -61,6 +74,15 @@ export function registerReputationTools(mcp: McpServer, client: AgledgerClient):
61
74
  outcome: z.enum(['PASS', 'FAIL']).optional().describe('Filter by verdict outcome'),
62
75
  limit: z.number().optional().describe('Page size'),
63
76
  },
77
+ outputSchema: z.object({
78
+ data: z.array(z.object({
79
+ mandateId: z.string().optional().describe('Mandate UUID'),
80
+ contractType: z.string().optional().describe('Contract type'),
81
+ outcome: z.string().nullable().optional().describe('Verdict outcome (PASS/FAIL)'),
82
+ completedAt: z.string().nullable().optional().describe('ISO 8601 completion timestamp'),
83
+ }).passthrough()).describe('Transaction history entries'),
84
+ total: z.number().nullable().optional().describe('Total count'),
85
+ }).passthrough().describe('Agent transaction history'),
64
86
  annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
65
87
  _meta: toolMeta('get_agent_history'),
66
88
  },
@@ -70,7 +92,7 @@ export function registerReputationTools(mcp: McpServer, client: AgledgerClient):
70
92
  const page = await client.reputation.getHistory(agentId, params);
71
93
  return {
72
94
  content: [{ type: 'text', text: `Agent ${agentId}: ${page.data.length} transaction(s).` }],
73
- structuredContent: page as unknown as Record<string, unknown>,
95
+ structuredContent: toStructuredContent(page),
74
96
  };
75
97
  } catch (err) { return apiErrorResult(err); }
76
98
  },