@agledger/mcp-server 1.4.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) 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/index.d.ts.map +1 -1
  6. package/dist/index.js +0 -2
  7. package/dist/index.js.map +1 -1
  8. package/dist/server.d.ts +6 -2
  9. package/dist/server.d.ts.map +1 -1
  10. package/dist/server.js +71 -76
  11. package/dist/server.js.map +1 -1
  12. package/dist/tool-scopes.js +3 -2
  13. package/dist/tool-scopes.js.map +1 -1
  14. package/dist/tools/a2a.d.ts.map +1 -1
  15. package/dist/tools/a2a.js +22 -222
  16. package/dist/tools/a2a.js.map +1 -1
  17. package/dist/tools/agent-mandates.d.ts.map +1 -1
  18. package/dist/tools/agent-mandates.js +11 -75
  19. package/dist/tools/agent-mandates.js.map +1 -1
  20. package/dist/tools/agents-refs.d.ts.map +1 -1
  21. package/dist/tools/agents-refs.js +10 -61
  22. package/dist/tools/agents-refs.js.map +1 -1
  23. package/dist/tools/capabilities.d.ts.map +1 -1
  24. package/dist/tools/capabilities.js +3 -15
  25. package/dist/tools/capabilities.js.map +1 -1
  26. package/dist/tools/code-mode.d.ts.map +1 -1
  27. package/dist/tools/code-mode.js +4 -35
  28. package/dist/tools/code-mode.js.map +1 -1
  29. package/dist/tools/compliance.d.ts.map +1 -1
  30. package/dist/tools/compliance.js +4 -13
  31. package/dist/tools/compliance.js.map +1 -1
  32. package/dist/tools/dashboard.d.ts.map +1 -1
  33. package/dist/tools/dashboard.js +4 -13
  34. package/dist/tools/dashboard.js.map +1 -1
  35. package/dist/tools/disputes.d.ts.map +1 -1
  36. package/dist/tools/disputes.js +5 -37
  37. package/dist/tools/disputes.js.map +1 -1
  38. package/dist/tools/enterprises.d.ts.map +1 -1
  39. package/dist/tools/enterprises.js +7 -39
  40. package/dist/tools/enterprises.js.map +1 -1
  41. package/dist/tools/events.d.ts.map +1 -1
  42. package/dist/tools/events.js +2 -20
  43. package/dist/tools/events.js.map +1 -1
  44. package/dist/tools/federation-admin.d.ts.map +1 -1
  45. package/dist/tools/federation-admin.js +25 -257
  46. package/dist/tools/federation-admin.js.map +1 -1
  47. package/dist/tools/federation.d.ts.map +1 -1
  48. package/dist/tools/federation.js +21 -198
  49. package/dist/tools/federation.js.map +1 -1
  50. package/dist/tools/health.d.ts.map +1 -1
  51. package/dist/tools/health.js +2 -14
  52. package/dist/tools/health.js.map +1 -1
  53. package/dist/tools/mandates.d.ts.map +1 -1
  54. package/dist/tools/mandates.js +11 -83
  55. package/dist/tools/mandates.js.map +1 -1
  56. package/dist/tools/openclaw.d.ts.map +1 -1
  57. package/dist/tools/openclaw.js +6 -33
  58. package/dist/tools/openclaw.js.map +1 -1
  59. package/dist/tools/receipts.d.ts.map +1 -1
  60. package/dist/tools/receipts.js +5 -96
  61. package/dist/tools/receipts.js.map +1 -1
  62. package/dist/tools/reputation.d.ts.map +1 -1
  63. package/dist/tools/reputation.js +4 -13
  64. package/dist/tools/reputation.js.map +1 -1
  65. package/dist/tools/schemas.d.ts.map +1 -1
  66. package/dist/tools/schemas.js +34 -159
  67. package/dist/tools/schemas.js.map +1 -1
  68. package/dist/tools/verification-keys.d.ts.map +1 -1
  69. package/dist/tools/verification-keys.js +2 -23
  70. package/dist/tools/verification-keys.js.map +1 -1
  71. package/dist/tools/verification.d.ts.map +1 -1
  72. package/dist/tools/verification.js +3 -28
  73. package/dist/tools/verification.js.map +1 -1
  74. package/package.json +1 -1
  75. package/src/errors.ts +9 -0
  76. package/src/index.ts +1 -3
  77. package/src/server.ts +77 -71
  78. package/src/tool-scopes.ts +3 -3
  79. package/src/tools/a2a.ts +22 -235
  80. package/src/tools/agent-mandates.ts +11 -77
  81. package/src/tools/agents-refs.ts +10 -65
  82. package/src/tools/capabilities.ts +3 -16
  83. package/src/tools/compliance.ts +4 -13
  84. package/src/tools/dashboard.ts +4 -13
  85. package/src/tools/disputes.ts +5 -38
  86. package/src/tools/enterprises.ts +7 -39
  87. package/src/tools/events.ts +2 -21
  88. package/src/tools/federation-admin.ts +25 -282
  89. package/src/tools/federation.ts +21 -218
  90. package/src/tools/health.ts +2 -15
  91. package/src/tools/mandates.ts +11 -85
  92. package/src/tools/openclaw.ts +6 -52
  93. package/src/tools/receipts.ts +5 -97
  94. package/src/tools/reputation.ts +4 -13
  95. package/src/tools/schemas.ts +34 -166
  96. package/src/tools/verification-keys.ts +2 -25
  97. package/src/tools/verification.ts +3 -30
  98. package/tests/conformance.test.ts +197 -0
  99. package/tests/conformance.ts +65 -0
  100. package/tests/harness.ts +55 -0
  101. package/tests/mock-client.ts +71 -0
  102. package/tests/profiles.test.ts +120 -0
  103. package/tests/resources/contract-types.test.ts +82 -0
  104. package/tests/tools/a2a.test.ts +213 -0
  105. package/tests/tools/agent-mandates.test.ts +196 -0
  106. package/tests/tools/agents-refs.test.ts +190 -0
  107. package/tests/tools/capabilities.test.ts +80 -0
  108. package/tests/tools/compliance.test.ts +123 -0
  109. package/tests/tools/dashboard.test.ts +111 -0
  110. package/tests/tools/disputes.test.ts +123 -0
  111. package/tests/tools/enterprises.test.ts +171 -0
  112. package/tests/tools/events.test.ts +56 -0
  113. package/tests/tools/federation-admin.test.ts +468 -0
  114. package/tests/tools/federation.test.ts +522 -0
  115. package/tests/tools/health.test.ts +56 -0
  116. package/tests/tools/mandates.test.ts +143 -0
  117. package/tests/tools/openclaw.test.ts +148 -0
  118. package/tests/tools/receipts.test.ts +157 -0
  119. package/tests/tools/reputation.test.ts +108 -0
  120. package/tests/tools/schemas.test.ts +374 -0
  121. package/tests/tools/verification-keys.test.ts +56 -0
  122. package/tests/tools/verification.test.ts +64 -0
  123. package/src/tools/code-mode.ts +0 -461
  124. package/tests/code-mode-manifest.test.ts +0 -144
  125. package/tests/enterprises.test.ts +0 -96
  126. package/tests/schemas.test.ts +0 -531
@@ -1,36 +1,9 @@
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 AgentProfileOutputSchema = z.object({
8
- agentId: z.string().describe('Unique agent identifier'),
9
- agentClass: z.string().optional().describe('Agent classification (e.g. "data-processor", "orchestrator")'),
10
- ownerRef: z.string().optional().describe('Owner or team reference'),
11
- orgUnit: z.string().optional().describe('Organizational unit'),
12
- description: z.string().optional().describe('Human-readable agent description'),
13
- }).describe('Agent profile');
14
-
15
- const ReferenceSchema = z.object({
16
- system: z.string().describe('External system name (e.g. "jira", "salesforce", "github")'),
17
- refType: z.string().describe('Reference type within the system (e.g. "ticket", "case", "issue")'),
18
- refId: z.string().describe('Identifier in the external system'),
19
- metadata: z.record(z.string(), z.unknown()).optional().describe('Additional metadata about the reference'),
20
- }).describe('External reference linking an AGLedger entity to an external system');
21
-
22
- const ReferencesOutputSchema = z.object({
23
- references: z.array(ReferenceSchema).describe('List of external references'),
24
- }).describe('External references for an entity');
25
-
26
- const LookupOutputSchema = z.object({
27
- entityType: z.string().optional().describe('Type of entity found (e.g. "agent", "mandate")'),
28
- entityId: z.string().optional().describe('AGLedger ID of the matched entity'),
29
- system: z.string().describe('External system name'),
30
- refType: z.string().describe('Reference type'),
31
- refId: z.string().describe('External reference ID'),
32
- }).describe('Reverse lookup result mapping an external reference to an AGLedger entity');
33
-
34
7
  export function registerAgentsRefsTools(mcp: McpServer, client: AgledgerClient): void {
35
8
  mcp.registerTool(
36
9
  'get_agent',
@@ -42,7 +15,6 @@ export function registerAgentsRefsTools(mcp: McpServer, client: AgledgerClient):
42
15
  inputSchema: {
43
16
  agentId: z.string().describe('Agent ID to retrieve'),
44
17
  },
45
- outputSchema: AgentProfileOutputSchema,
46
18
  annotations: {
47
19
  readOnlyHint: true,
48
20
  destructiveHint: false,
@@ -54,10 +26,7 @@ export function registerAgentsRefsTools(mcp: McpServer, client: AgledgerClient):
54
26
  async (args) => {
55
27
  try {
56
28
  const result = await client.agents.get(args.agentId);
57
- return {
58
- content: [{ type: 'text', text: `Agent ${result.id}: class=${result.agentClass ?? 'unset'}, owner=${result.ownerRef ?? 'unset'}.` }],
59
- structuredContent: result as unknown as Record<string, unknown>,
60
- };
29
+ return { content: [], structuredContent: toStructuredContent(result) };
61
30
  } catch (err) {
62
31
  return apiErrorResult(err);
63
32
  }
@@ -79,7 +48,6 @@ export function registerAgentsRefsTools(mcp: McpServer, client: AgledgerClient):
79
48
  orgUnit: z.string().optional().describe('Organizational unit'),
80
49
  description: z.string().optional().describe('Human-readable agent description'),
81
50
  },
82
- outputSchema: AgentProfileOutputSchema,
83
51
  annotations: {
84
52
  readOnlyHint: false,
85
53
  destructiveHint: false,
@@ -96,10 +64,7 @@ export function registerAgentsRefsTools(mcp: McpServer, client: AgledgerClient):
96
64
  orgUnit: args.orgUnit,
97
65
  description: args.description,
98
66
  });
99
- return {
100
- content: [{ type: 'text', text: `Agent ${result.id} updated.` }],
101
- structuredContent: result as unknown as Record<string, unknown>,
102
- };
67
+ return { content: [], structuredContent: toStructuredContent(result) };
103
68
  } catch (err) {
104
69
  return apiErrorResult(err);
105
70
  }
@@ -123,7 +88,6 @@ export function registerAgentsRefsTools(mcp: McpServer, client: AgledgerClient):
123
88
  metadata: z.record(z.string(), z.unknown()).optional().describe('Additional metadata about the reference'),
124
89
  })).describe('References to add'),
125
90
  },
126
- outputSchema: ReferencesOutputSchema,
127
91
  annotations: {
128
92
  readOnlyHint: false,
129
93
  destructiveHint: false,
@@ -135,10 +99,7 @@ export function registerAgentsRefsTools(mcp: McpServer, client: AgledgerClient):
135
99
  async (args) => {
136
100
  try {
137
101
  const result = await client.agents.addReferences(args.agentId, args.references);
138
- return {
139
- content: [{ type: 'text', text: `Added ${args.references.length} reference(s) to agent ${args.agentId}.` }],
140
- structuredContent: result as unknown as Record<string, unknown>,
141
- };
102
+ return { content: [], structuredContent: toStructuredContent(result) };
142
103
  } catch (err) {
143
104
  return apiErrorResult(err);
144
105
  }
@@ -155,7 +116,6 @@ export function registerAgentsRefsTools(mcp: McpServer, client: AgledgerClient):
155
116
  inputSchema: {
156
117
  agentId: z.string().describe('Agent ID to get references for'),
157
118
  },
158
- outputSchema: ReferencesOutputSchema,
159
119
  annotations: {
160
120
  readOnlyHint: true,
161
121
  destructiveHint: false,
@@ -167,11 +127,8 @@ export function registerAgentsRefsTools(mcp: McpServer, client: AgledgerClient):
167
127
  async (args) => {
168
128
  try {
169
129
  const result = await client.agents.getReferences(args.agentId);
170
- const refs = Array.isArray(result) ? result : (result as Record<string, unknown>).references ?? [];
171
- return {
172
- content: [{ type: 'text', text: `Agent ${args.agentId} has ${(refs as unknown[]).length} reference(s).` }],
173
- structuredContent: (Array.isArray(result) ? { references: result } : result) as unknown as Record<string, unknown>,
174
- };
130
+ const structured = Array.isArray(result) ? { references: result } : result;
131
+ return { content: [], structuredContent: toStructuredContent(structured) };
175
132
  } catch (err) {
176
133
  return apiErrorResult(err);
177
134
  }
@@ -191,7 +148,6 @@ export function registerAgentsRefsTools(mcp: McpServer, client: AgledgerClient):
191
148
  refType: z.string().describe('Reference type within the system (e.g. "ticket", "case", "issue")'),
192
149
  refId: z.string().describe('Identifier in the external system'),
193
150
  },
194
- outputSchema: LookupOutputSchema,
195
151
  annotations: {
196
152
  readOnlyHint: true,
197
153
  destructiveHint: false,
@@ -203,10 +159,7 @@ export function registerAgentsRefsTools(mcp: McpServer, client: AgledgerClient):
203
159
  async (args) => {
204
160
  try {
205
161
  const result = await client.references.lookup(args);
206
- return {
207
- content: [{ type: 'text', text: `Found ${(result as unknown as Record<string, unknown>).entityType ?? 'entity'} ${(result as unknown as Record<string, unknown>).entityId ?? 'unknown'} for ${args.system}/${args.refType}/${args.refId}.` }],
208
- structuredContent: result as unknown as Record<string, unknown>,
209
- };
162
+ return { content: [], structuredContent: toStructuredContent(result) };
210
163
  } catch (err) {
211
164
  return apiErrorResult(err);
212
165
  }
@@ -230,7 +183,6 @@ export function registerAgentsRefsTools(mcp: McpServer, client: AgledgerClient):
230
183
  metadata: z.record(z.string(), z.unknown()).optional().describe('Additional metadata about the reference'),
231
184
  })).describe('References to add'),
232
185
  },
233
- outputSchema: ReferencesOutputSchema,
234
186
  annotations: {
235
187
  readOnlyHint: false,
236
188
  destructiveHint: false,
@@ -242,10 +194,7 @@ export function registerAgentsRefsTools(mcp: McpServer, client: AgledgerClient):
242
194
  async (args) => {
243
195
  try {
244
196
  const result = await client.references.addMandateReferences(args.mandateId, args.references);
245
- return {
246
- content: [{ type: 'text', text: `Added ${args.references.length} reference(s) to mandate ${args.mandateId}.` }],
247
- structuredContent: result as unknown as Record<string, unknown>,
248
- };
197
+ return { content: [], structuredContent: toStructuredContent(result) };
249
198
  } catch (err) {
250
199
  return apiErrorResult(err);
251
200
  }
@@ -262,7 +211,6 @@ export function registerAgentsRefsTools(mcp: McpServer, client: AgledgerClient):
262
211
  inputSchema: {
263
212
  mandateId: z.string().describe('Mandate ID to get references for'),
264
213
  },
265
- outputSchema: ReferencesOutputSchema,
266
214
  annotations: {
267
215
  readOnlyHint: true,
268
216
  destructiveHint: false,
@@ -274,11 +222,8 @@ export function registerAgentsRefsTools(mcp: McpServer, client: AgledgerClient):
274
222
  async (args) => {
275
223
  try {
276
224
  const result = await client.references.getMandateReferences(args.mandateId);
277
- const refs = Array.isArray(result) ? result : (result as Record<string, unknown>).references ?? [];
278
- return {
279
- content: [{ type: 'text', text: `Mandate ${args.mandateId} has ${(refs as unknown[]).length} reference(s).` }],
280
- structuredContent: (Array.isArray(result) ? { references: result } : result) as unknown as Record<string, unknown>,
281
- };
225
+ const structured = Array.isArray(result) ? { references: result } : result;
226
+ return { content: [], structuredContent: toStructuredContent(structured) };
282
227
  } catch (err) {
283
228
  return apiErrorResult(err);
284
229
  }
@@ -1,15 +1,10 @@
1
1
  import { z } from 'zod';
2
2
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
  import type { AgledgerClient } from '@agledger/sdk';
4
- import { apiErrorResult } from '../errors.js';
4
+ import { apiErrorResult, toStructuredContent } from '../errors.js';
5
5
  import { toolMeta } from '../tool-scopes.js';
6
6
  import { ContractTypeEnum } from '../enums.js';
7
7
 
8
- const CapabilitiesOutputSchema = z.object({
9
- agentId: z.string().describe('Agent ID'),
10
- capabilities: z.array(ContractTypeEnum).describe('Supported contract types'),
11
- }).describe('Agent capabilities');
12
-
13
8
  export function registerCapabilityTools(mcp: McpServer, client: AgledgerClient): void {
14
9
  mcp.registerTool(
15
10
  'get_agent_capabilities',
@@ -19,7 +14,6 @@ export function registerCapabilityTools(mcp: McpServer, client: AgledgerClient):
19
14
  inputSchema: {
20
15
  agentId: z.string().describe('Agent ID to check capabilities for'),
21
16
  },
22
- outputSchema: CapabilitiesOutputSchema,
23
17
  annotations: {
24
18
  readOnlyHint: true,
25
19
  destructiveHint: false,
@@ -31,10 +25,7 @@ export function registerCapabilityTools(mcp: McpServer, client: AgledgerClient):
31
25
  async (args) => {
32
26
  try {
33
27
  const result = await client.capabilities.get(args.agentId);
34
- return {
35
- content: [{ type: 'text', text: `Agent ${result.agentId} supports ${result.capabilities.length} contract types.` }],
36
- structuredContent: result as unknown as Record<string, unknown>,
37
- };
28
+ return { content: [], structuredContent: toStructuredContent(result) };
38
29
  } catch (err) {
39
30
  return apiErrorResult(err);
40
31
  }
@@ -50,7 +41,6 @@ export function registerCapabilityTools(mcp: McpServer, client: AgledgerClient):
50
41
  agentId: z.string().describe('Agent ID to set capabilities for'),
51
42
  contractTypes: z.array(ContractTypeEnum).describe('Contract types this agent supports'),
52
43
  },
53
- outputSchema: CapabilitiesOutputSchema,
54
44
  annotations: {
55
45
  readOnlyHint: false,
56
46
  destructiveHint: false,
@@ -64,10 +54,7 @@ export function registerCapabilityTools(mcp: McpServer, client: AgledgerClient):
64
54
  const result = await client.capabilities.set(args.agentId, {
65
55
  contractTypes: args.contractTypes,
66
56
  });
67
- return {
68
- content: [{ type: 'text', text: `Capabilities declared for ${result.agentId}: ${result.capabilities.join(', ')}.` }],
69
- structuredContent: result as unknown as Record<string, unknown>,
70
- };
57
+ return { content: [], structuredContent: toStructuredContent(result) };
71
58
  } catch (err) {
72
59
  return apiErrorResult(err);
73
60
  }
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
  import type { AgledgerClient } from '@agledger/sdk';
4
- import { apiErrorResult } from '../errors.js';
4
+ import { apiErrorResult, toStructuredContent } from '../errors.js';
5
5
  import { toolMeta } from '../tool-scopes.js';
6
6
 
7
7
  export function registerComplianceTools(mcp: McpServer, client: AgledgerClient): void {
@@ -26,10 +26,7 @@ export function registerComplianceTools(mcp: McpServer, client: AgledgerClient):
26
26
  attestation: args.attestation,
27
27
  attestedBy: args.attestedBy,
28
28
  });
29
- return {
30
- content: [{ type: 'text', text: `Compliance record created for mandate ${args.mandateId} (type: ${args.recordType}).` }],
31
- structuredContent: record as unknown as Record<string, unknown>,
32
- };
29
+ return { content: [], structuredContent: toStructuredContent(record) };
33
30
  } catch (err) { return apiErrorResult(err); }
34
31
  },
35
32
  );
@@ -49,10 +46,7 @@ export function registerComplianceTools(mcp: McpServer, client: AgledgerClient):
49
46
  async (args) => {
50
47
  try {
51
48
  const result = await client.compliance.listRecords(args.mandateId, { limit: args.limit });
52
- return {
53
- content: [{ type: 'text', text: `Found ${result.data.length} compliance records for mandate ${args.mandateId}.` }],
54
- structuredContent: result as unknown as Record<string, unknown>,
55
- };
49
+ return { content: [], structuredContent: toStructuredContent(result) };
56
50
  } catch (err) { return apiErrorResult(err); }
57
51
  },
58
52
  );
@@ -69,10 +63,7 @@ export function registerComplianceTools(mcp: McpServer, client: AgledgerClient):
69
63
  async () => {
70
64
  try {
71
65
  const report = await client.compliance.getEuAiActReport();
72
- return {
73
- content: [{ type: 'text', text: `EU AI Act report: ${report.summary.highRiskCount} high-risk mandates, ${report.summary.auditedCount} audited.` }],
74
- structuredContent: report as unknown as Record<string, unknown>,
75
- };
66
+ return { content: [], structuredContent: toStructuredContent(report) };
76
67
  } catch (err) { return apiErrorResult(err); }
77
68
  },
78
69
  );
@@ -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 {
@@ -17,10 +17,7 @@ export function registerDashboardTools(mcp: McpServer, client: AgledgerClient):
17
17
  async () => {
18
18
  try {
19
19
  const summary = await client.dashboard.getSummary();
20
- return {
21
- content: [{ type: 'text', text: `Dashboard: ${summary.totalMandates} mandates, ${summary.activeCount} active, ${summary.fulfilledCount} fulfilled.` }],
22
- structuredContent: summary as unknown as Record<string, unknown>,
23
- };
20
+ return { content: [], structuredContent: toStructuredContent(summary) };
24
21
  } catch (err) { return apiErrorResult(err); }
25
22
  },
26
23
  );
@@ -41,10 +38,7 @@ export function registerDashboardTools(mcp: McpServer, client: AgledgerClient):
41
38
  async (args) => {
42
39
  try {
43
40
  const metrics = await client.dashboard.getMetrics(args);
44
- return {
45
- content: [{ type: 'text', text: `Metrics: ${metrics.series?.length ?? 0} data points.` }],
46
- structuredContent: metrics as unknown as Record<string, unknown>,
47
- };
41
+ return { content: [], structuredContent: toStructuredContent(metrics) };
48
42
  } catch (err) { return apiErrorResult(err); }
49
43
  },
50
44
  );
@@ -63,10 +57,7 @@ export function registerDashboardTools(mcp: McpServer, client: AgledgerClient):
63
57
  async (args) => {
64
58
  try {
65
59
  const result = await client.dashboard.getAlerts(args);
66
- return {
67
- content: [{ type: 'text', text: `Found ${result.data.length} alerts.` }],
68
- structuredContent: result as unknown as Record<string, unknown>,
69
- };
60
+ return { content: [], structuredContent: toStructuredContent(result) };
70
61
  } catch (err) { return apiErrorResult(err); }
71
62
  },
72
63
  );
@@ -1,26 +1,8 @@
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
- import { DisputeStatusEnum, NextStepsField } from '../enums.js';
7
-
8
- const DisputeOutputSchema = z.object({
9
- id: z.string().describe('Dispute UUID'),
10
- mandateId: z.string().describe('Associated mandate UUID'),
11
- receiptId: z.string().describe('Associated receipt UUID'),
12
- status: DisputeStatusEnum,
13
- reason: z.string().describe('Dispute reason/grounds'),
14
- evidence: z.record(z.string(), z.unknown()).nullable().optional().describe('Supporting evidence'),
15
- currentTier: z.number().describe('Current dispute resolution tier (1-3)'),
16
- tierHistory: z.array(z.record(z.string(), z.unknown())).nullable().optional().describe('History of tier transitions'),
17
- resolution: z.string().nullable().optional().describe('Resolution description'),
18
- amount: z.number().nullable().optional().describe('Settlement amount if applicable'),
19
- createdAt: z.string().describe('ISO 8601 creation timestamp'),
20
- updatedAt: z.string().nullable().optional().describe('ISO 8601 last update timestamp'),
21
- resolvedAt: z.string().nullable().optional().describe('ISO 8601 resolution timestamp'),
22
- nextSteps: NextStepsField,
23
- }).passthrough().describe('AGLedger dispute object');
24
6
 
25
7
  export function registerDisputeTools(mcp: McpServer, client: AgledgerClient): void {
26
8
  mcp.registerTool(
@@ -33,7 +15,6 @@ export function registerDisputeTools(mcp: McpServer, client: AgledgerClient): vo
33
15
  grounds: z.string().describe('Dispute grounds (e.g. "pricing_dispute", "mandate_ambiguity")'),
34
16
  context: z.string().optional().describe('Additional context for the dispute'),
35
17
  },
36
- outputSchema: DisputeOutputSchema,
37
18
  annotations: {
38
19
  readOnlyHint: false,
39
20
  destructiveHint: false,
@@ -46,10 +27,7 @@ export function registerDisputeTools(mcp: McpServer, client: AgledgerClient): vo
46
27
  try {
47
28
  const { mandateId, ...disputeParams } = args;
48
29
  const dispute = await client.disputes.create(mandateId, disputeParams);
49
- return {
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>,
52
- };
30
+ return { content: [], structuredContent: toStructuredContent(dispute) };
53
31
  } catch (err) {
54
32
  return apiErrorResult(err);
55
33
  }
@@ -64,7 +42,6 @@ export function registerDisputeTools(mcp: McpServer, client: AgledgerClient): vo
64
42
  inputSchema: {
65
43
  mandateId: z.string().describe('UUID of the mandate with the dispute'),
66
44
  },
67
- outputSchema: DisputeOutputSchema,
68
45
  annotations: {
69
46
  readOnlyHint: true,
70
47
  destructiveHint: false,
@@ -77,10 +54,7 @@ export function registerDisputeTools(mcp: McpServer, client: AgledgerClient): vo
77
54
  try {
78
55
  const result = await client.disputes.get(args.mandateId);
79
56
  const dispute = result.dispute;
80
- return {
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>,
83
- };
57
+ return { content: [], structuredContent: toStructuredContent(dispute) };
84
58
  } catch (err) {
85
59
  return apiErrorResult(err);
86
60
  }
@@ -95,7 +69,6 @@ export function registerDisputeTools(mcp: McpServer, client: AgledgerClient): vo
95
69
  inputSchema: {
96
70
  mandateId: z.string().describe('UUID of the mandate whose dispute to escalate'),
97
71
  },
98
- outputSchema: DisputeOutputSchema,
99
72
  annotations: {
100
73
  readOnlyHint: false,
101
74
  destructiveHint: false,
@@ -107,10 +80,7 @@ export function registerDisputeTools(mcp: McpServer, client: AgledgerClient): vo
107
80
  async (args) => {
108
81
  try {
109
82
  const dispute = await client.disputes.escalate(args.mandateId);
110
- return {
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>,
113
- };
83
+ return { content: [], structuredContent: toStructuredContent(dispute) };
114
84
  } catch (err) {
115
85
  return apiErrorResult(err);
116
86
  }
@@ -141,10 +111,7 @@ export function registerDisputeTools(mcp: McpServer, client: AgledgerClient): vo
141
111
  evidenceType: args.evidenceType,
142
112
  payload: args.payload,
143
113
  });
144
- return {
145
- content: [{ type: 'text', text: `Evidence submitted for dispute on mandate ${args.mandateId}. Type: ${args.evidenceType}.` }],
146
- structuredContent: result as unknown as Record<string, unknown>,
147
- };
114
+ return { content: [], structuredContent: toStructuredContent(result) };
148
115
  } catch (err) {
149
116
  return apiErrorResult(err);
150
117
  }
@@ -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 {
@@ -28,10 +28,7 @@ export function registerEnterpriseTools(mcp: McpServer, client: AgledgerClient):
28
28
  const record = await client.enterprises.approveAgent(args.enterpriseId, args.agentId, {
29
29
  reason: args.reason,
30
30
  });
31
- return {
32
- content: [{ type: 'text', text: `Agent ${args.agentId} approved for enterprise ${args.enterpriseId}.` }],
33
- structuredContent: record as unknown as Record<string, unknown>,
34
- };
31
+ return { content: [], structuredContent: toStructuredContent(record) };
35
32
  } catch (err) {
36
33
  return apiErrorResult(err);
37
34
  }
@@ -61,10 +58,7 @@ export function registerEnterpriseTools(mcp: McpServer, client: AgledgerClient):
61
58
  await client.enterprises.revokeAgent(args.enterpriseId, args.agentId, {
62
59
  reason: args.reason,
63
60
  });
64
- return {
65
- content: [{ type: 'text', text: `Agent ${args.agentId} revoked from enterprise ${args.enterpriseId}.` }],
66
- structuredContent: { enterpriseId: args.enterpriseId, agentId: args.agentId, status: 'revoked' },
67
- };
61
+ return { content: [], structuredContent: { enterpriseId: args.enterpriseId, agentId: args.agentId, status: 'revoked' } };
68
62
  } catch (err) {
69
63
  return apiErrorResult(err);
70
64
  }
@@ -97,10 +91,7 @@ export function registerEnterpriseTools(mcp: McpServer, client: AgledgerClient):
97
91
  limit: args.limit,
98
92
  offset: args.offset,
99
93
  });
100
- return {
101
- content: [{ type: 'text', text: `Found ${result.data.length} agents for enterprise ${args.enterpriseId}.` }],
102
- structuredContent: result as unknown as Record<string, unknown>,
103
- };
94
+ return { content: [], structuredContent: toStructuredContent(result) };
104
95
  } catch (err) {
105
96
  return apiErrorResult(err);
106
97
  }
@@ -121,13 +112,6 @@ export function registerEnterpriseTools(mcp: McpServer, client: AgledgerClient):
121
112
  email: z.string().optional().describe('Contact email'),
122
113
  trustLevel: z.enum(['sandbox', 'active', 'verified']).optional().describe('Initial trust level (default: sandbox)'),
123
114
  },
124
- outputSchema: {
125
- id: z.string().describe('Enterprise UUID'),
126
- name: z.string().describe('Enterprise display name'),
127
- slug: z.string().describe('URL-safe identifier'),
128
- trustLevel: z.string(),
129
- createdAt: z.string().describe('ISO 8601 creation timestamp'),
130
- },
131
115
  annotations: {
132
116
  readOnlyHint: false,
133
117
  destructiveHint: false,
@@ -139,10 +123,7 @@ export function registerEnterpriseTools(mcp: McpServer, client: AgledgerClient):
139
123
  async (args) => {
140
124
  try {
141
125
  const enterprise = await client.admin.createEnterprise({ name: args.name, slug: args.slug });
142
- return {
143
- 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>,
145
- };
126
+ return { content: [], structuredContent: toStructuredContent(enterprise) };
146
127
  } catch (err) {
147
128
  return apiErrorResult(err);
148
129
  }
@@ -165,13 +146,6 @@ export function registerEnterpriseTools(mcp: McpServer, client: AgledgerClient):
165
146
  email: z.string().optional().describe('Contact email'),
166
147
  trustLevel: z.enum(['sandbox', 'active', 'verified']).optional().describe('Initial trust level (default: sandbox)'),
167
148
  },
168
- outputSchema: {
169
- id: z.string().describe('Agent UUID'),
170
- displayName: z.string().nullable().describe('Agent display name'),
171
- slug: z.string().describe('URL-safe identifier'),
172
- trustLevel: z.string(),
173
- createdAt: z.string().describe('ISO 8601 creation timestamp'),
174
- },
175
149
  annotations: {
176
150
  readOnlyHint: false,
177
151
  destructiveHint: false,
@@ -187,10 +161,7 @@ export function registerEnterpriseTools(mcp: McpServer, client: AgledgerClient):
187
161
  slug: args.slug,
188
162
  enterpriseId: args.enterpriseId,
189
163
  });
190
- return {
191
- 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>,
193
- };
164
+ return { content: [], structuredContent: toStructuredContent(agent) };
194
165
  } catch (err) {
195
166
  return apiErrorResult(err);
196
167
  }
@@ -223,10 +194,7 @@ export function registerEnterpriseTools(mcp: McpServer, client: AgledgerClient):
223
194
  async (args) => {
224
195
  try {
225
196
  const result = await client.admin.setEnterpriseConfig(args.enterpriseId, args.config);
226
- return {
227
- content: [{ type: 'text', text: `Configuration replaced for enterprise ${args.enterpriseId}.` }],
228
- structuredContent: result as unknown as Record<string, unknown>,
229
- };
197
+ return { content: [], structuredContent: toStructuredContent(result) };
230
198
  } catch (err) {
231
199
  return apiErrorResult(err);
232
200
  }
@@ -1,24 +1,9 @@
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 AuditChainOutputSchema = z.object({
8
- mandateId: z.string().describe('Mandate UUID'),
9
- chainStart: z.string().describe('ISO 8601 timestamp of the first audit entry'),
10
- entries: z.array(z.object({
11
- index: z.number().describe('Entry index in the chain'),
12
- hash: z.string().describe('SHA-256 hash of this entry'),
13
- previousHash: z.string().nullable().describe('Hash of the previous entry (null for first)'),
14
- event: z.string().describe('Event type'),
15
- actor: z.string().describe('Actor who triggered the event'),
16
- timestamp: z.string().describe('ISO 8601 timestamp'),
17
- signature: z.string().optional().describe('Optional cryptographic signature'),
18
- })).describe('Ordered chain of audit entries'),
19
- isValid: z.boolean().describe('Whether the hash chain is valid (tamper-proof check)'),
20
- }).passthrough().describe('Hash-chained audit trail for a mandate');
21
-
22
7
  export function registerEventTools(mcp: McpServer, client: AgledgerClient): void {
23
8
  mcp.registerTool(
24
9
  'get_audit_trail',
@@ -28,7 +13,6 @@ export function registerEventTools(mcp: McpServer, client: AgledgerClient): void
28
13
  inputSchema: {
29
14
  mandateId: z.string().describe('UUID of the mandate to get the audit trail for'),
30
15
  },
31
- outputSchema: AuditChainOutputSchema,
32
16
  annotations: {
33
17
  readOnlyHint: true,
34
18
  destructiveHint: false,
@@ -40,10 +24,7 @@ export function registerEventTools(mcp: McpServer, client: AgledgerClient): void
40
24
  async (args) => {
41
25
  try {
42
26
  const chain = await client.events.getAuditChain(args.mandateId);
43
- return {
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>,
46
- };
27
+ return { content: [], structuredContent: toStructuredContent(chain) };
47
28
  } catch (err) {
48
29
  return apiErrorResult(err);
49
30
  }