@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 { ContractTypeEnum } from '../enums.js';
6
6
  import { toolMeta } from '../tool-scopes.js';
7
7
 
@@ -90,9 +90,9 @@ const SchemaVersionOutputSchema = z.object({
90
90
  contractType: ContractTypeString,
91
91
  version: z.number().describe('Version number'),
92
92
  enterpriseId: z.string().nullable().describe('Enterprise ID if enterprise-scoped, null for global'),
93
- displayName: z.string().describe('Human-readable name'),
94
- description: z.string().describe('Schema description'),
95
- category: z.string().describe('Schema category'),
93
+ displayName: z.string().nullable().optional().describe('Human-readable name'),
94
+ description: z.string().nullable().optional().describe('Schema description'),
95
+ category: z.string().nullable().optional().describe('Schema category'),
96
96
  compatibilityMode: z.string().describe('Compatibility mode: FULL, BACKWARD, FORWARD, or NONE'),
97
97
  status: z.string().describe('Version status: ACTIVE, DEPRECATED, or DRAFT'),
98
98
  isBuiltin: z.boolean().describe('Whether this is a built-in AGLedger schema'),
@@ -151,7 +151,7 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
151
151
  const result = await client.schemas.list();
152
152
  return {
153
153
  content: [{ type: 'text', text: `${result.data.length} contract types available: ${result.data.join(', ')}.` }],
154
- structuredContent: { contractTypes: result.data } as unknown as Record<string, unknown>,
154
+ structuredContent: toStructuredContent({ contractTypes: result.data }),
155
155
  };
156
156
  } catch (err) {
157
157
  return apiErrorResult(err);
@@ -181,7 +181,7 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
181
181
  const schema = await client.schemas.get(args.contractType);
182
182
  return {
183
183
  content: [{ type: 'text', text: `Schema for ${schema.contractType}: mandate schema has ${Object.keys(schema.mandateSchema).length} fields, receipt schema has ${Object.keys(schema.receiptSchema).length} fields.${(schema as any).quickStart ? ' Includes quickStart examples with copy-pasteable payloads.' : ''}` }],
184
- structuredContent: schema as unknown as Record<string, unknown>,
184
+ structuredContent: toStructuredContent(schema),
185
185
  };
186
186
  } catch (err) {
187
187
  return apiErrorResult(err);
@@ -209,7 +209,7 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
209
209
  const metaSchema = await client.schemas.getMetaSchema();
210
210
  return {
211
211
  content: [{ type: 'text', text: `Meta-schema: max depth ${metaSchema.constraints.maxDepth}, max nodes ${metaSchema.constraints.maxNodes}, max size ${metaSchema.constraints.maxSizeBytes} bytes. ${metaSchema.allowedFormats.length} allowed formats, max ${metaSchema.limits.maxFieldMappings} field mappings, ${metaSchema.fieldMappingValueTypes.length} value types (${metaSchema.fieldMappingValueTypes.join(', ')}). Next: call get_schema_template or get_blank_schema_template to start building.` }],
212
- structuredContent: metaSchema as unknown as Record<string, unknown>,
212
+ structuredContent: toStructuredContent(metaSchema),
213
213
  };
214
214
  } catch (err) {
215
215
  return apiErrorResult(err);
@@ -258,7 +258,7 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
258
258
  : `invalid (${result.errors?.length ?? 0} errors). Fix the errors above, then call preview_schema again.`;
259
259
  return {
260
260
  content: [{ type: 'text', text: `Schema preview for ${args.contractType}: ${status}` }],
261
- structuredContent: result as unknown as Record<string, unknown>,
261
+ structuredContent: toStructuredContent(result),
262
262
  };
263
263
  } catch (err) {
264
264
  return apiErrorResult(err);
@@ -304,7 +304,7 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
304
304
  });
305
305
  return {
306
306
  content: [{ type: 'text', text: `Registered ${result.contractType} v${result.version} (${result.status}). Schema registered. Use get_schema_versions to see all versions.` }],
307
- structuredContent: result as unknown as Record<string, unknown>,
307
+ structuredContent: toStructuredContent(result),
308
308
  };
309
309
  } catch (err) {
310
310
  return apiErrorResult(err);
@@ -321,9 +321,9 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
321
321
  contractType: ContractTypeString.describe('Contract type to list versions for'),
322
322
  },
323
323
  outputSchema: z.object({
324
- contractType: ContractTypeString,
325
- versions: z.array(SchemaVersionOutputSchema),
326
- }).describe('All versions of a contract type schema'),
324
+ contractType: z.string().describe('Contract type'),
325
+ versions: z.array(SchemaVersionOutputSchema).describe('Version list'),
326
+ }).passthrough().describe('All versions of a contract type schema'),
327
327
  annotations: {
328
328
  readOnlyHint: true,
329
329
  destructiveHint: false,
@@ -334,10 +334,11 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
334
334
  },
335
335
  async (args) => {
336
336
  try {
337
- const versions = await client.schemas.getVersions(args.contractType as Parameters<typeof client.schemas.getVersions>[0]);
337
+ const page = await client.schemas.getVersions(args.contractType as Parameters<typeof client.schemas.getVersions>[0]);
338
+ const latest = page.data.length > 0 ? page.data[page.data.length - 1].version : 'none';
338
339
  return {
339
- content: [{ type: 'text', text: `${args.contractType}: ${versions.length} version(s). Latest: v${versions.length > 0 ? versions[versions.length - 1].version : 'none'}. Use get_schema_version to inspect a specific version, or diff_schema_versions to compare two.` }],
340
- structuredContent: { contractType: args.contractType, versions } as unknown as Record<string, unknown>,
340
+ content: [{ type: 'text', text: `${args.contractType}: ${page.data.length} version(s). Latest: v${latest}. Use get_schema_version to inspect a specific version, or diff_schema_versions to compare two.` }],
341
+ structuredContent: toStructuredContent({ contractType: args.contractType, versions: page.data }),
341
342
  };
342
343
  } catch (err) {
343
344
  return apiErrorResult(err);
@@ -375,7 +376,7 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
375
376
  const receiptChanges = diff.receipt.changes.length;
376
377
  return {
377
378
  content: [{ type: 'text', text: `Diff ${args.contractType} v${args.from} → v${args.to}: ${mandateChanges} mandate change(s), ${receiptChanges} receipt change(s).` }],
378
- structuredContent: diff as unknown as Record<string, unknown>,
379
+ structuredContent: toStructuredContent(diff),
379
380
  };
380
381
  } catch (err) {
381
382
  return apiErrorResult(err);
@@ -383,6 +384,14 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
383
384
  },
384
385
  );
385
386
 
387
+ const SchemaTemplateOutputSchema = z.object({
388
+ contractType: z.string().optional().describe('Contract type identifier'),
389
+ displayName: z.string().nullable().optional().describe('Human-readable name'),
390
+ mandateSchema: z.record(z.string(), z.unknown()).optional().describe('Mandate criteria JSON Schema'),
391
+ receiptSchema: z.record(z.string(), z.unknown()).optional().describe('Receipt evidence JSON Schema'),
392
+ fieldMappings: z.array(z.record(z.string(), z.unknown())).nullable().optional().describe('Field mappings'),
393
+ }).passthrough();
394
+
386
395
  mcp.registerTool(
387
396
  'get_schema_template',
388
397
  {
@@ -391,6 +400,7 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
391
400
  inputSchema: {
392
401
  contractType: ContractTypeString.describe('Contract type to use as template (e.g. ACH-PROC-v1)'),
393
402
  },
403
+ outputSchema: SchemaTemplateOutputSchema.describe('Schema template derived from an existing contract type'),
394
404
  annotations: {
395
405
  readOnlyHint: true,
396
406
  destructiveHint: false,
@@ -404,7 +414,7 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
404
414
  const template = await client.schemas.getTemplate(args.contractType as Parameters<typeof client.schemas.getTemplate>[0]);
405
415
  return {
406
416
  content: [{ type: 'text', text: `Template from ${args.contractType}. Next: modify the template, then call preview_schema to validate before registration.` }],
407
- structuredContent: template as unknown as Record<string, unknown>,
417
+ structuredContent: toStructuredContent(template),
408
418
  };
409
419
  } catch (err) {
410
420
  return apiErrorResult(err);
@@ -418,6 +428,7 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
418
428
  title: 'Get Blank Schema Template',
419
429
  description: 'Get a blank template for creating a custom contract type from scratch. Returns the minimal valid structure with placeholder fields. After filling in, use preview_schema to validate.',
420
430
  inputSchema: {},
431
+ outputSchema: SchemaTemplateOutputSchema.describe('Blank schema template for building a custom contract type from scratch'),
421
432
  annotations: {
422
433
  readOnlyHint: true,
423
434
  destructiveHint: false,
@@ -431,7 +442,7 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
431
442
  const template = await client.schemas.getBlankTemplate();
432
443
  return {
433
444
  content: [{ type: 'text', text: `Blank schema template ready. Next: fill in contractType, mandateSchema, receiptSchema, then call preview_schema.` }],
434
- structuredContent: template as unknown as Record<string, unknown>,
445
+ structuredContent: toStructuredContent(template),
435
446
  };
436
447
  } catch (err) {
437
448
  return apiErrorResult(err);
@@ -449,6 +460,14 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
449
460
  mandateSchema: z.record(z.string(), z.unknown()).describe('Proposed mandate criteria JSON Schema'),
450
461
  receiptSchema: z.record(z.string(), z.unknown()).describe('Proposed receipt evidence JSON Schema'),
451
462
  },
463
+ outputSchema: z.object({
464
+ compatible: z.boolean().describe('Whether the proposed changes are compatible'),
465
+ mode: z.string().nullable().optional().describe('Compatibility mode checked against'),
466
+ issues: z.array(z.object({
467
+ message: z.string().describe('Compatibility issue description'),
468
+ path: z.string().nullable().optional().describe('JSON path of the incompatible field'),
469
+ })).nullable().optional().describe('List of compatibility issues found'),
470
+ }).passthrough().describe('Schema compatibility check result'),
452
471
  annotations: {
453
472
  readOnlyHint: true,
454
473
  destructiveHint: false,
@@ -465,7 +484,7 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
465
484
  );
466
485
  return {
467
486
  content: [{ type: 'text', text: `Compatibility check for ${args.contractType}: ${JSON.stringify(result)}.` }],
468
- structuredContent: result as unknown as Record<string, unknown>,
487
+ structuredContent: toStructuredContent(result),
469
488
  };
470
489
  } catch (err) {
471
490
  return apiErrorResult(err);
@@ -499,7 +518,7 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
499
518
  );
500
519
  return {
501
520
  content: [{ type: 'text', text: `${result.contractType} v${result.version} (${result.status}), created ${result.createdAt}.` }],
502
- structuredContent: result as unknown as Record<string, unknown>,
521
+ structuredContent: toStructuredContent(result),
503
522
  };
504
523
  } catch (err) {
505
524
  return apiErrorResult(err);
@@ -516,6 +535,13 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
516
535
  contractType: ContractTypeString.describe('Contract type to validate against (e.g., ACH-PROC-v1)'),
517
536
  evidence: z.record(z.string(), z.unknown()).describe('Evidence object to validate'),
518
537
  },
538
+ outputSchema: z.object({
539
+ valid: z.boolean().describe('Whether the evidence is valid for the contract type'),
540
+ errors: z.array(z.object({
541
+ message: z.string().describe('Validation error message'),
542
+ instancePath: z.string().nullable().optional().describe('JSON path of the invalid field'),
543
+ })).nullable().optional().describe('Validation errors if invalid'),
544
+ }).passthrough().describe('Receipt evidence validation result'),
519
545
  annotations: {
520
546
  readOnlyHint: true,
521
547
  destructiveHint: false,
@@ -533,14 +559,14 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
533
559
  if (result.valid) {
534
560
  return {
535
561
  content: [{ type: 'text', text: `Evidence is valid for ${args.contractType}. You can now call submit_receipt.` }],
536
- structuredContent: result as unknown as Record<string, unknown>,
562
+ structuredContent: toStructuredContent(result),
537
563
  };
538
564
  }
539
565
  const errorCount = result.errors?.length ?? 0;
540
566
  const errorDetails = result.errors?.map(e => `- ${e.instancePath ?? '/'}: ${e.message}`).join('\n') ?? '';
541
567
  return {
542
568
  content: [{ type: 'text', text: `Evidence is invalid for ${args.contractType} (${errorCount} error(s)):\n${errorDetails}\n\nFix the errors and try again.` }],
543
- structuredContent: result as unknown as Record<string, unknown>,
569
+ structuredContent: toStructuredContent(result),
544
570
  };
545
571
  } catch (err) {
546
572
  return apiErrorResult(err);
@@ -556,6 +582,10 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
556
582
  inputSchema: {
557
583
  contractType: ContractTypeString.describe('Contract type to get rules for'),
558
584
  },
585
+ outputSchema: z.object({
586
+ syncRuleIds: z.array(z.string()).describe('Synchronous verification rule IDs'),
587
+ asyncRuleIds: z.array(z.string()).describe('Asynchronous verification rule IDs'),
588
+ }).passthrough().describe('Verification rules configured for the contract type'),
559
589
  annotations: {
560
590
  readOnlyHint: true,
561
591
  destructiveHint: false,
@@ -570,7 +600,7 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
570
600
  const total = result.syncRuleIds.length + result.asyncRuleIds.length;
571
601
  return {
572
602
  content: [{ type: 'text', text: `${args.contractType}: ${total} rule(s) — ${result.syncRuleIds.length} sync, ${result.asyncRuleIds.length} async.` }],
573
- structuredContent: result as unknown as Record<string, unknown>,
603
+ structuredContent: toStructuredContent(result),
574
604
  };
575
605
  } catch (err) {
576
606
  return apiErrorResult(err);
@@ -586,6 +616,10 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
586
616
  inputSchema: {
587
617
  contractType: ContractTypeString.describe('Custom contract type identifier to delete'),
588
618
  },
619
+ outputSchema: z.object({
620
+ deleted: z.boolean().nullable().optional().describe('Whether the schema was deleted'),
621
+ contractType: z.string().nullable().optional().describe('Deleted contract type identifier'),
622
+ }).passthrough().describe('Schema deletion confirmation'),
589
623
  annotations: {
590
624
  readOnlyHint: false,
591
625
  destructiveHint: true,
@@ -599,7 +633,7 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
599
633
  const result = await client.schemas.delete(args.contractType);
600
634
  return {
601
635
  content: [{ type: 'text', text: `Schema ${args.contractType} deleted.` }],
602
- structuredContent: result as unknown as Record<string, unknown>,
636
+ structuredContent: toStructuredContent(result),
603
637
  };
604
638
  } catch (err) {
605
639
  return apiErrorResult(err);
@@ -615,6 +649,13 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
615
649
  inputSchema: {
616
650
  contractType: ContractTypeString.describe('Contract type to export'),
617
651
  },
652
+ outputSchema: z.object({
653
+ contractType: z.string().optional().describe('Exported contract type identifier'),
654
+ version: z.number().nullable().optional().describe('Schema version number'),
655
+ mandateSchema: z.record(z.string(), z.unknown()).nullable().optional().describe('Mandate criteria JSON Schema'),
656
+ receiptSchema: z.record(z.string(), z.unknown()).nullable().optional().describe('Receipt evidence JSON Schema'),
657
+ fieldMappings: z.array(z.record(z.string(), z.unknown())).nullable().optional().describe('Field mappings'),
658
+ }).passthrough().describe('Exported schema bundle for cross-environment promotion'),
618
659
  annotations: {
619
660
  readOnlyHint: true,
620
661
  destructiveHint: false,
@@ -628,7 +669,7 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
628
669
  const bundle = await client.schemas.exportSchema(args.contractType);
629
670
  return {
630
671
  content: [{ type: 'text', text: `Exported schema bundle for ${args.contractType}. Use import_schema to import into another environment.` }],
631
- structuredContent: bundle as unknown as Record<string, unknown>,
672
+ structuredContent: toStructuredContent(bundle),
632
673
  };
633
674
  } catch (err) {
634
675
  return apiErrorResult(err);
@@ -644,6 +685,11 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
644
685
  inputSchema: {
645
686
  bundle: z.record(z.string(), z.unknown()).describe('Schema bundle object from export_schema'),
646
687
  },
688
+ outputSchema: z.object({
689
+ contractType: z.string().nullable().optional().describe('Imported contract type identifier'),
690
+ version: z.number().nullable().optional().describe('Imported schema version number'),
691
+ status: z.string().nullable().optional().describe('Import status'),
692
+ }).passthrough().describe('Schema import result'),
647
693
  annotations: {
648
694
  readOnlyHint: false,
649
695
  destructiveHint: false,
@@ -657,7 +703,7 @@ export function registerSchemaTools(mcp: McpServer, client: AgledgerClient): voi
657
703
  const result = await client.schemas.importSchema(args.bundle as any);
658
704
  return {
659
705
  content: [{ type: 'text', text: `Schema imported successfully.` }],
660
- structuredContent: result as unknown as Record<string, unknown>,
706
+ structuredContent: toStructuredContent(result),
661
707
  };
662
708
  } catch (err) {
663
709
  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 VerificationKeySchema = z.object({
@@ -46,7 +46,7 @@ export function registerVerificationKeysTools(mcp: McpServer, client: AgledgerCl
46
46
  const active = result.data.filter((k) => k.status === 'active').length;
47
47
  return {
48
48
  content: [{ type: 'text', text: `${count} verification key(s): ${active} active, ${count - active} retired. Algorithm: ${result.signatureAlgorithm}.` }],
49
- structuredContent: result as unknown as Record<string, unknown>,
49
+ structuredContent: toStructuredContent(result),
50
50
  };
51
51
  } catch (err) {
52
52
  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 { VerificationOutcomeEnum } from '../enums.js';
6
6
  import { toolMeta } from '../tool-scopes.js';
7
7
 
@@ -46,7 +46,7 @@ export function registerVerificationTools(mcp: McpServer, client: AgledgerClient
46
46
  const result = await client.verification.verify(args.mandateId);
47
47
  return {
48
48
  content: [{ type: 'text', text: `Verification for mandate ${result.mandateId}: ${result.overallStatus}. ${result.receipts.length} receipt(s) evaluated.` }],
49
- structuredContent: result as unknown as Record<string, unknown>,
49
+ structuredContent: toStructuredContent(result),
50
50
  };
51
51
  } catch (err) {
52
52
  return apiErrorResult(err);
@@ -76,7 +76,7 @@ export function registerVerificationTools(mcp: McpServer, client: AgledgerClient
76
76
  const status = await client.verification.getStatus(args.mandateId);
77
77
  return {
78
78
  content: [{ type: 'text', text: `Verification status for ${status.mandateId}: phase1=${status.phase1Status}, phase2=${status.phase2Status}.` }],
79
- structuredContent: status as unknown as Record<string, unknown>,
79
+ structuredContent: toStructuredContent(status),
80
80
  };
81
81
  } catch (err) {
82
82
  return apiErrorResult(err);
@@ -0,0 +1,219 @@
1
+ import { describe, it, expect, beforeAll, afterAll } from 'vitest';
2
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
3
+ import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
4
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5
+ import { AgledgerMcpServer } from '../src/server.js';
6
+ import { getProfileRegistry } from '../src/server.js';
7
+ import { TOOL_SCOPES } from '../src/tool-scopes.js';
8
+ import { createMockClient } from './mock-client.js';
9
+
10
+ /**
11
+ * Global conformance tests — validate structural invariants across ALL tools.
12
+ * Uses the full profile to exercise every tool module.
13
+ */
14
+ describe('global conformance', () => {
15
+ let client: Client;
16
+ let cleanup: () => Promise<void>;
17
+ let tools: Array<{
18
+ name: string;
19
+ description?: string;
20
+ inputSchema?: Record<string, unknown>;
21
+ outputSchema?: Record<string, unknown>;
22
+ annotations?: Record<string, unknown>;
23
+ _meta?: Record<string, unknown>;
24
+ }>;
25
+
26
+ beforeAll(async () => {
27
+ const server = new AgledgerMcpServer({
28
+ apiKey: 'test-key',
29
+ apiUrl: 'https://test.example.com',
30
+ profile: 'full',
31
+ });
32
+
33
+ const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
34
+ client = new Client({ name: 'conformance-test', version: '0.0.0' });
35
+
36
+ await Promise.all([
37
+ server.mcp.connect(serverTransport),
38
+ client.connect(clientTransport),
39
+ ]);
40
+
41
+ cleanup = async () => {
42
+ await client.close();
43
+ await server.mcp.close();
44
+ };
45
+
46
+ const result = await client.listTools();
47
+ tools = result.tools as typeof tools;
48
+ });
49
+
50
+ afterAll(async () => {
51
+ await cleanup();
52
+ });
53
+
54
+ it('registers at least 100 tools in full profile', () => {
55
+ expect(tools.length).toBeGreaterThanOrEqual(100);
56
+ });
57
+
58
+ it('no duplicate tool names', () => {
59
+ const names = tools.map(t => t.name);
60
+ const dupes = names.filter((n, i) => names.indexOf(n) !== i);
61
+ expect(dupes, `Duplicate tools: ${dupes.join(', ')}`).toEqual([]);
62
+ });
63
+
64
+ describe('outputSchema', () => {
65
+ it('tools with outputSchema have type:"object" at root', () => {
66
+ const violations: string[] = [];
67
+ for (const tool of tools) {
68
+ if (tool.outputSchema && tool.outputSchema.type !== 'object') {
69
+ violations.push(`${tool.name}: type="${tool.outputSchema.type}"`);
70
+ }
71
+ }
72
+ expect(violations, `outputSchema type violations: ${violations.join(', ')}`).toEqual([]);
73
+ });
74
+
75
+ it('every tool has outputSchema', () => {
76
+ const missing = tools.filter(t => !t.outputSchema).map(t => t.name);
77
+ expect(missing, `Tools missing outputSchema: ${missing.join(', ')}`).toEqual([]);
78
+ });
79
+ });
80
+
81
+ describe('inputSchema', () => {
82
+ it('every tool has an inputSchema', () => {
83
+ const missing = tools.filter(t => !t.inputSchema).map(t => t.name);
84
+ expect(missing, `Tools missing inputSchema: ${missing.join(', ')}`).toEqual([]);
85
+ });
86
+ });
87
+
88
+ describe('descriptions', () => {
89
+ it('every tool has a non-empty description', () => {
90
+ const missing = tools.filter(t => !t.description).map(t => t.name);
91
+ expect(missing, `Tools missing description: ${missing.join(', ')}`).toEqual([]);
92
+ });
93
+ });
94
+
95
+ describe('annotations', () => {
96
+ it('tools with annotations have all 4 hint fields', () => {
97
+ const hints = ['readOnlyHint', 'destructiveHint', 'idempotentHint', 'openWorldHint'];
98
+ const violations: string[] = [];
99
+ for (const tool of tools) {
100
+ if (tool.annotations) {
101
+ for (const hint of hints) {
102
+ if (!(hint in tool.annotations)) {
103
+ violations.push(`${tool.name}: missing ${hint}`);
104
+ }
105
+ }
106
+ }
107
+ }
108
+ expect(violations).toEqual([]);
109
+ });
110
+
111
+ it('every tool has annotations', () => {
112
+ const missing = tools.filter(t => !t.annotations).map(t => t.name);
113
+ expect(missing, `Tools missing annotations: ${missing.join(', ')}`).toEqual([]);
114
+ });
115
+ });
116
+
117
+ describe('scope coverage', () => {
118
+ it('every registered tool has a TOOL_SCOPES entry', () => {
119
+ const missing = tools.filter(t => !(t.name in TOOL_SCOPES)).map(t => t.name);
120
+ expect(missing, `Tools without TOOL_SCOPES entry: ${missing.join(', ')}`).toEqual([]);
121
+ });
122
+
123
+ it('every TOOL_SCOPES entry with non-empty scopes has _meta on its tool', () => {
124
+ const violations: string[] = [];
125
+ for (const tool of tools) {
126
+ const scopes = TOOL_SCOPES[tool.name];
127
+ if (scopes && scopes.length > 0) {
128
+ const meta = tool._meta as Record<string, unknown> | undefined;
129
+ if (!meta || !meta.requiredScopes) {
130
+ violations.push(tool.name);
131
+ }
132
+ }
133
+ }
134
+ expect(violations, `Tools with scopes but no _meta.requiredScopes: ${violations.join(', ')}`).toEqual([]);
135
+ });
136
+ });
137
+ });
138
+
139
+ /**
140
+ * Error + outputSchema interaction test.
141
+ *
142
+ * Known MCP SDK issue: when a tool has outputSchema and returns isError: true,
143
+ * the SDK may validate the error content against the outputSchema and block it.
144
+ * This test verifies every tool can still surface errors correctly.
145
+ *
146
+ * Strategy: create a server where ALL SDK methods throw, then call every tool.
147
+ * Every call should return isError: true with a readable error message (not an
148
+ * outputSchema validation error or a thrown exception).
149
+ */
150
+ describe('error + outputSchema interaction', () => {
151
+ let errorClient: Client;
152
+ let errorCleanup: () => Promise<void>;
153
+ let toolNames: string[];
154
+
155
+ beforeAll(async () => {
156
+ // Create a mock client where every method throws — no overrides
157
+ const mockSdk = createMockClient();
158
+
159
+ const mcp = new McpServer(
160
+ { name: 'error-test', version: '0.0.0' },
161
+ { capabilities: { tools: {}, resources: {} } },
162
+ );
163
+
164
+ // Register all tools from the full profile
165
+ const registry = getProfileRegistry();
166
+ for (const fn of registry.full) {
167
+ fn(mcp, mockSdk);
168
+ }
169
+
170
+ const [ct, st] = InMemoryTransport.createLinkedPair();
171
+ errorClient = new Client({ name: 'error-test-client', version: '0.0.0' });
172
+ await Promise.all([mcp.connect(st), errorClient.connect(ct)]);
173
+
174
+ const { tools } = await errorClient.listTools();
175
+ toolNames = tools.map((t: any) => t.name);
176
+
177
+ errorCleanup = async () => {
178
+ await errorClient.close();
179
+ await mcp.close();
180
+ };
181
+ });
182
+
183
+ afterAll(async () => { await errorCleanup(); });
184
+
185
+ it('every tool with outputSchema can return errors without being blocked', async () => {
186
+ const blocked: string[] = [];
187
+ const thrown: string[] = [];
188
+
189
+ for (const name of toolNames) {
190
+ // Build minimal valid arguments (empty object works for most; SDK error happens before arg validation matters)
191
+ try {
192
+ const result = await errorClient.callTool({ name, arguments: {} });
193
+ const r = result as any;
194
+ if (r.isError) {
195
+ // Good — error came through
196
+ const text = r.content?.[0]?.text ?? '';
197
+ if (text.includes('Output validation error') || text.includes('Invalid structured content')) {
198
+ blocked.push(`${name}: outputSchema blocked error response`);
199
+ }
200
+ }
201
+ // If isError is false, the tool might have succeeded with empty args (e.g., health check with mock).
202
+ // That's fine — the mock throws "not mocked" so most will error.
203
+ } catch (err: any) {
204
+ // MCP client threw instead of returning an error result — this is the bug
205
+ const msg = err?.message ?? String(err);
206
+ if (msg.includes('Output validation') || msg.includes('Invalid structured content')) {
207
+ blocked.push(`${name}: outputSchema validation threw instead of returning error`);
208
+ } else if (msg.includes('Input validation')) {
209
+ // Tool requires specific input args — skip, not an outputSchema issue
210
+ } else {
211
+ thrown.push(`${name}: ${msg.slice(0, 100)}`);
212
+ }
213
+ }
214
+ }
215
+
216
+ expect(blocked, `Tools where outputSchema blocks error responses:\n${blocked.join('\n')}`).toEqual([]);
217
+ // thrown is informational — some tools may throw for input validation, that's expected
218
+ });
219
+ });
@@ -0,0 +1,75 @@
1
+ import { expect } from 'vitest';
2
+ import { TOOL_SCOPES } from '../src/tool-scopes.js';
3
+
4
+ interface ToolDefinition {
5
+ name: string;
6
+ description?: string;
7
+ inputSchema?: Record<string, unknown>;
8
+ outputSchema?: Record<string, unknown>;
9
+ annotations?: Record<string, unknown>;
10
+ _meta?: Record<string, unknown>;
11
+ }
12
+
13
+ interface CallToolResult {
14
+ content: Array<{ type: string; text?: string }>;
15
+ structuredContent?: Record<string, unknown>;
16
+ isError?: boolean;
17
+ }
18
+
19
+ /**
20
+ * Assert a tool's outputSchema is valid:
21
+ * - Has type: "object" at root (required by Claude Desktop and other MCP clients)
22
+ * - Has at least one property or uses passthrough
23
+ */
24
+ export function assertOutputSchemaValid(tool: ToolDefinition): void {
25
+ expect(tool.outputSchema, `${tool.name}: missing outputSchema`).toBeDefined();
26
+ const schema = tool.outputSchema!;
27
+ expect(schema.type, `${tool.name}: outputSchema must have type:"object" at root`).toBe('object');
28
+ }
29
+
30
+ /**
31
+ * Assert tool metadata follows conventions:
32
+ * - Non-empty description
33
+ * - All 4 annotation hints present
34
+ * - _meta.requiredScopes matches TOOL_SCOPES (if tool is in the scope map)
35
+ */
36
+ export function assertToolMetadata(tool: ToolDefinition): void {
37
+ expect(tool.description, `${tool.name}: missing description`).toBeTruthy();
38
+
39
+ if (tool.annotations) {
40
+ const hints = ['readOnlyHint', 'destructiveHint', 'idempotentHint', 'openWorldHint'];
41
+ for (const hint of hints) {
42
+ expect(
43
+ hint in tool.annotations,
44
+ `${tool.name}: missing annotation ${hint}`,
45
+ ).toBe(true);
46
+ }
47
+ }
48
+
49
+ const expectedScopes = TOOL_SCOPES[tool.name];
50
+ if (expectedScopes && tool._meta) {
51
+ const meta = tool._meta as Record<string, unknown>;
52
+ if (meta.requiredScopes) {
53
+ expect(meta.requiredScopes, `${tool.name}: _meta.requiredScopes mismatch`).toEqual(expectedScopes);
54
+ }
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Assert a callTool result is an error result with the expected shape.
60
+ */
61
+ export function assertErrorResult(result: CallToolResult): void {
62
+ expect(result.isError, 'Expected isError to be true').toBe(true);
63
+ expect(result.content.length).toBeGreaterThan(0);
64
+ expect(result.content[0].type).toBe('text');
65
+ expect(result.content[0].text).toMatch(/^Error:/);
66
+ }
67
+
68
+ /**
69
+ * Assert a callTool result is a success result with structured content.
70
+ */
71
+ export function assertSuccessResult(result: CallToolResult): void {
72
+ expect(result.isError).toBeFalsy();
73
+ expect(result.content.length).toBeGreaterThan(0);
74
+ expect(result.content[0].type).toBe('text');
75
+ }
@@ -18,7 +18,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
18
18
  // ---------------------------------------------------------------------------
19
19
 
20
20
  function getClientResourceNames(): string[] {
21
- const clientPath = resolve(__dirname, '../../../agledger-sdk/src/client.ts');
21
+ const clientPath = resolve(__dirname, '../../../../agledger-sdk/src/client.ts');
22
22
  const source = readFileSync(clientPath, 'utf8');
23
23
 
24
24
  // Match "readonly <name>: <Type>Resource" property declarations
@@ -36,7 +36,7 @@ function getClientResourceNames(): string[] {
36
36
  // ---------------------------------------------------------------------------
37
37
 
38
38
  function getManifestResourceNames(): string[] {
39
- const codePath = resolve(__dirname, '../src/tools/code-mode.ts');
39
+ const codePath = resolve(__dirname, '../../src/tools/code-mode.ts');
40
40
  const source = readFileSync(codePath, 'utf8');
41
41
 
42
42
  // The manifest is defined as: const RESOURCE_MANIFEST: Record<string, string> = { key: `...`, ... };