@agledger/mcp-server 1.2.0 → 1.3.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.
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/dist/enums.d.ts +0 -1
- package/dist/enums.d.ts.map +1 -1
- package/dist/enums.js +0 -1
- package/dist/enums.js.map +1 -1
- package/dist/errors.d.ts +0 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +0 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/resources/contract-types.d.ts +0 -1
- package/dist/resources/contract-types.d.ts.map +1 -1
- package/dist/resources/contract-types.js +0 -3
- package/dist/resources/contract-types.js.map +1 -1
- package/dist/server.d.ts +0 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +6 -3
- package/dist/server.js.map +1 -1
- package/dist/tool-scopes.d.ts +0 -12
- package/dist/tool-scopes.d.ts.map +1 -1
- package/dist/tool-scopes.js +20 -30
- package/dist/tool-scopes.js.map +1 -1
- package/dist/tools/a2a.d.ts +0 -1
- package/dist/tools/a2a.d.ts.map +1 -1
- package/dist/tools/a2a.js +21 -52
- package/dist/tools/a2a.js.map +1 -1
- package/dist/tools/agent-mandates.d.ts +0 -1
- package/dist/tools/agent-mandates.d.ts.map +1 -1
- package/dist/tools/agent-mandates.js +0 -10
- package/dist/tools/agent-mandates.js.map +1 -1
- package/dist/tools/agents-refs.d.ts +0 -1
- package/dist/tools/agents-refs.d.ts.map +1 -1
- package/dist/tools/agents-refs.js +0 -8
- package/dist/tools/agents-refs.js.map +1 -1
- package/dist/tools/capabilities.d.ts +0 -1
- package/dist/tools/capabilities.d.ts.map +1 -1
- package/dist/tools/capabilities.js +0 -3
- package/dist/tools/capabilities.js.map +1 -1
- package/dist/tools/code-mode.d.ts +0 -1
- package/dist/tools/code-mode.d.ts.map +1 -1
- package/dist/tools/code-mode.js +4 -10
- package/dist/tools/code-mode.js.map +1 -1
- package/dist/tools/compliance.d.ts +0 -1
- package/dist/tools/compliance.d.ts.map +1 -1
- package/dist/tools/compliance.js +0 -1
- package/dist/tools/compliance.js.map +1 -1
- package/dist/tools/dashboard.d.ts +0 -1
- package/dist/tools/dashboard.d.ts.map +1 -1
- package/dist/tools/dashboard.js +0 -1
- package/dist/tools/dashboard.js.map +1 -1
- package/dist/tools/disputes.d.ts +0 -1
- package/dist/tools/disputes.d.ts.map +1 -1
- package/dist/tools/disputes.js +0 -5
- package/dist/tools/disputes.js.map +1 -1
- package/dist/tools/enterprises.d.ts +0 -1
- package/dist/tools/enterprises.d.ts.map +1 -1
- package/dist/tools/enterprises.js +0 -7
- package/dist/tools/enterprises.js.map +1 -1
- package/dist/tools/events.d.ts +0 -1
- package/dist/tools/events.d.ts.map +1 -1
- package/dist/tools/events.js +0 -2
- package/dist/tools/events.js.map +1 -1
- package/dist/tools/federation-admin.d.ts +0 -1
- package/dist/tools/federation-admin.d.ts.map +1 -1
- package/dist/tools/federation-admin.js +0 -25
- package/dist/tools/federation-admin.js.map +1 -1
- package/dist/tools/federation.d.ts +0 -1
- package/dist/tools/federation.d.ts.map +1 -1
- package/dist/tools/federation.js +0 -21
- package/dist/tools/federation.js.map +1 -1
- package/dist/tools/health.d.ts +0 -1
- package/dist/tools/health.d.ts.map +1 -1
- package/dist/tools/health.js +0 -2
- package/dist/tools/health.js.map +1 -1
- package/dist/tools/mandates.d.ts +0 -1
- package/dist/tools/mandates.d.ts.map +1 -1
- package/dist/tools/mandates.js +0 -11
- package/dist/tools/mandates.js.map +1 -1
- package/dist/tools/openclaw.d.ts +0 -5
- package/dist/tools/openclaw.d.ts.map +1 -1
- package/dist/tools/openclaw.js +0 -5
- package/dist/tools/openclaw.js.map +1 -1
- package/dist/tools/receipts.d.ts +0 -1
- package/dist/tools/receipts.d.ts.map +1 -1
- package/dist/tools/receipts.js +3 -8
- package/dist/tools/receipts.js.map +1 -1
- package/dist/tools/reputation.d.ts +0 -1
- package/dist/tools/reputation.d.ts.map +1 -1
- package/dist/tools/reputation.js +0 -1
- package/dist/tools/reputation.js.map +1 -1
- package/dist/tools/schemas.d.ts +0 -1
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/schemas.js +0 -17
- package/dist/tools/schemas.js.map +1 -1
- package/dist/tools/verification-keys.d.ts +4 -0
- package/dist/tools/verification-keys.d.ts.map +1 -0
- package/dist/tools/verification-keys.js +48 -0
- package/dist/tools/verification-keys.js.map +1 -0
- package/dist/tools/verification.d.ts +0 -1
- package/dist/tools/verification.d.ts.map +1 -1
- package/dist/tools/verification.js +0 -3
- package/dist/tools/verification.js.map +1 -1
- package/package.json +2 -7
- package/src/enums.ts +46 -0
- package/src/errors.ts +35 -0
- package/src/index.ts +100 -0
- package/src/resources/contract-types.ts +130 -0
- package/src/server.ts +132 -0
- package/src/tool-scopes.ts +180 -0
- package/src/tools/a2a.ts +519 -0
- package/src/tools/agent-mandates.ts +325 -0
- package/src/tools/agents-refs.ts +287 -0
- package/src/tools/capabilities.ts +76 -0
- package/src/tools/code-mode.ts +461 -0
- package/src/tools/compliance.ts +79 -0
- package/src/tools/dashboard.ts +73 -0
- package/src/tools/disputes.ts +154 -0
- package/src/tools/enterprises.ts +235 -0
- package/src/tools/events.ts +52 -0
- package/src/tools/federation-admin.ts +922 -0
- package/src/tools/federation.ts +784 -0
- package/src/tools/health.ts +43 -0
- package/src/tools/mandates.ts +382 -0
- package/src/tools/openclaw.ts +168 -0
- package/src/tools/receipts.ts +179 -0
- package/src/tools/reputation.ts +78 -0
- package/src/tools/schemas.ts +667 -0
- package/src/tools/verification-keys.ts +56 -0
- package/src/tools/verification.ts +85 -0
- package/tests/code-mode-manifest.test.ts +144 -0
- package/tests/enterprises.test.ts +96 -0
- package/tests/schemas.test.ts +531 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
+
import type { AgledgerClient } from '@agledger/sdk';
|
|
4
|
+
import { apiErrorResult } from '../errors.js';
|
|
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
|
+
|
|
25
|
+
export function registerDisputeTools(mcp: McpServer, client: AgledgerClient): void {
|
|
26
|
+
mcp.registerTool(
|
|
27
|
+
'create_dispute',
|
|
28
|
+
{
|
|
29
|
+
title: 'Create Dispute',
|
|
30
|
+
description: 'Open a dispute on a mandate. Grounds examples: "pricing_dispute", "mandate_ambiguity", "quality_issue".',
|
|
31
|
+
inputSchema: {
|
|
32
|
+
mandateId: z.string().describe('UUID of the mandate to dispute'),
|
|
33
|
+
grounds: z.string().describe('Dispute grounds (e.g. "pricing_dispute", "mandate_ambiguity")'),
|
|
34
|
+
context: z.string().optional().describe('Additional context for the dispute'),
|
|
35
|
+
},
|
|
36
|
+
outputSchema: DisputeOutputSchema,
|
|
37
|
+
annotations: {
|
|
38
|
+
readOnlyHint: false,
|
|
39
|
+
destructiveHint: false,
|
|
40
|
+
idempotentHint: false,
|
|
41
|
+
openWorldHint: true,
|
|
42
|
+
},
|
|
43
|
+
_meta: toolMeta('create_dispute'),
|
|
44
|
+
},
|
|
45
|
+
async (args) => {
|
|
46
|
+
try {
|
|
47
|
+
const { mandateId, ...disputeParams } = args;
|
|
48
|
+
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
|
+
};
|
|
53
|
+
} catch (err) {
|
|
54
|
+
return apiErrorResult(err);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
mcp.registerTool(
|
|
60
|
+
'get_dispute',
|
|
61
|
+
{
|
|
62
|
+
title: 'Get Dispute',
|
|
63
|
+
description: 'Get the dispute details for a mandate.',
|
|
64
|
+
inputSchema: {
|
|
65
|
+
mandateId: z.string().describe('UUID of the mandate with the dispute'),
|
|
66
|
+
},
|
|
67
|
+
outputSchema: DisputeOutputSchema,
|
|
68
|
+
annotations: {
|
|
69
|
+
readOnlyHint: true,
|
|
70
|
+
destructiveHint: false,
|
|
71
|
+
idempotentHint: true,
|
|
72
|
+
openWorldHint: true,
|
|
73
|
+
},
|
|
74
|
+
_meta: toolMeta('get_dispute'),
|
|
75
|
+
},
|
|
76
|
+
async (args) => {
|
|
77
|
+
try {
|
|
78
|
+
const result = await client.disputes.get(args.mandateId);
|
|
79
|
+
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
|
+
};
|
|
84
|
+
} catch (err) {
|
|
85
|
+
return apiErrorResult(err);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
mcp.registerTool(
|
|
91
|
+
'escalate_dispute',
|
|
92
|
+
{
|
|
93
|
+
title: 'Escalate Dispute',
|
|
94
|
+
description: 'Escalate a dispute to the next review tier. Use when tier-1 auto-resolution was insufficient.',
|
|
95
|
+
inputSchema: {
|
|
96
|
+
mandateId: z.string().describe('UUID of the mandate whose dispute to escalate'),
|
|
97
|
+
},
|
|
98
|
+
outputSchema: DisputeOutputSchema,
|
|
99
|
+
annotations: {
|
|
100
|
+
readOnlyHint: false,
|
|
101
|
+
destructiveHint: false,
|
|
102
|
+
idempotentHint: false,
|
|
103
|
+
openWorldHint: true,
|
|
104
|
+
},
|
|
105
|
+
_meta: toolMeta('escalate_dispute'),
|
|
106
|
+
},
|
|
107
|
+
async (args) => {
|
|
108
|
+
try {
|
|
109
|
+
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
|
+
};
|
|
114
|
+
} catch (err) {
|
|
115
|
+
return apiErrorResult(err);
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
mcp.registerTool(
|
|
121
|
+
'submit_dispute_evidence',
|
|
122
|
+
{
|
|
123
|
+
title: 'Submit Dispute Evidence',
|
|
124
|
+
description: 'Submit additional evidence for an open dispute. Evidence types: screenshot, external_lookup, document, communication, other.',
|
|
125
|
+
inputSchema: {
|
|
126
|
+
mandateId: z.string().describe('UUID of the mandate whose dispute to submit evidence for'),
|
|
127
|
+
evidenceType: z.enum(['screenshot', 'external_lookup', 'document', 'communication', 'other']).describe('Type of evidence being submitted'),
|
|
128
|
+
payload: z.record(z.string(), z.unknown()).describe('Evidence payload object'),
|
|
129
|
+
},
|
|
130
|
+
annotations: {
|
|
131
|
+
readOnlyHint: false,
|
|
132
|
+
destructiveHint: false,
|
|
133
|
+
idempotentHint: false,
|
|
134
|
+
openWorldHint: true,
|
|
135
|
+
},
|
|
136
|
+
_meta: toolMeta('submit_dispute_evidence'),
|
|
137
|
+
},
|
|
138
|
+
async (args) => {
|
|
139
|
+
try {
|
|
140
|
+
const result = await client.disputes.submitEvidence(args.mandateId, {
|
|
141
|
+
evidenceType: args.evidenceType,
|
|
142
|
+
payload: args.payload,
|
|
143
|
+
});
|
|
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
|
+
};
|
|
148
|
+
} catch (err) {
|
|
149
|
+
return apiErrorResult(err);
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
+
import type { AgledgerClient } from '@agledger/sdk';
|
|
4
|
+
import { apiErrorResult } from '../errors.js';
|
|
5
|
+
import { toolMeta } from '../tool-scopes.js';
|
|
6
|
+
|
|
7
|
+
export function registerEnterpriseTools(mcp: McpServer, client: AgledgerClient): void {
|
|
8
|
+
mcp.registerTool(
|
|
9
|
+
'approve_enterprise_agent',
|
|
10
|
+
{
|
|
11
|
+
title: 'Approve Enterprise Agent',
|
|
12
|
+
description: 'Approve an agent for use within an enterprise. The agent will be allowed to create mandates and submit receipts.',
|
|
13
|
+
inputSchema: {
|
|
14
|
+
enterpriseId: z.string().describe('Enterprise ID'),
|
|
15
|
+
agentId: z.string().describe('Agent ID to approve'),
|
|
16
|
+
reason: z.string().optional().describe('Reason for approval'),
|
|
17
|
+
},
|
|
18
|
+
annotations: {
|
|
19
|
+
readOnlyHint: false,
|
|
20
|
+
destructiveHint: false,
|
|
21
|
+
idempotentHint: true,
|
|
22
|
+
openWorldHint: true,
|
|
23
|
+
},
|
|
24
|
+
_meta: toolMeta('approve_enterprise_agent'),
|
|
25
|
+
},
|
|
26
|
+
async (args) => {
|
|
27
|
+
try {
|
|
28
|
+
const record = await client.enterprises.approveAgent(args.enterpriseId, args.agentId, {
|
|
29
|
+
reason: args.reason,
|
|
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
|
+
};
|
|
35
|
+
} catch (err) {
|
|
36
|
+
return apiErrorResult(err);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
mcp.registerTool(
|
|
42
|
+
'revoke_enterprise_agent',
|
|
43
|
+
{
|
|
44
|
+
title: 'Revoke Enterprise Agent',
|
|
45
|
+
description: 'Revoke an agent\'s access to an enterprise. The agent will no longer be able to create mandates or submit receipts.',
|
|
46
|
+
inputSchema: {
|
|
47
|
+
enterpriseId: z.string().describe('Enterprise ID'),
|
|
48
|
+
agentId: z.string().describe('Agent ID to revoke'),
|
|
49
|
+
reason: z.string().optional().describe('Reason for revocation'),
|
|
50
|
+
},
|
|
51
|
+
annotations: {
|
|
52
|
+
readOnlyHint: false,
|
|
53
|
+
destructiveHint: true,
|
|
54
|
+
idempotentHint: false,
|
|
55
|
+
openWorldHint: true,
|
|
56
|
+
},
|
|
57
|
+
_meta: toolMeta('revoke_enterprise_agent'),
|
|
58
|
+
},
|
|
59
|
+
async (args) => {
|
|
60
|
+
try {
|
|
61
|
+
await client.enterprises.revokeAgent(args.enterpriseId, args.agentId, {
|
|
62
|
+
reason: args.reason,
|
|
63
|
+
});
|
|
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
|
+
};
|
|
68
|
+
} catch (err) {
|
|
69
|
+
return apiErrorResult(err);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
mcp.registerTool(
|
|
75
|
+
'list_enterprise_agents',
|
|
76
|
+
{
|
|
77
|
+
title: 'List Enterprise Agents',
|
|
78
|
+
description: 'List agents registered with an enterprise, optionally filtered by status.',
|
|
79
|
+
inputSchema: {
|
|
80
|
+
enterpriseId: z.string().describe('Enterprise ID'),
|
|
81
|
+
status: z.enum(['approved', 'suspended', 'revoked']).optional().describe('Filter by agent status'),
|
|
82
|
+
limit: z.number().optional().describe('Page size'),
|
|
83
|
+
offset: z.number().optional().describe('Page offset'),
|
|
84
|
+
},
|
|
85
|
+
annotations: {
|
|
86
|
+
readOnlyHint: true,
|
|
87
|
+
destructiveHint: false,
|
|
88
|
+
idempotentHint: true,
|
|
89
|
+
openWorldHint: true,
|
|
90
|
+
},
|
|
91
|
+
_meta: toolMeta('list_enterprise_agents'),
|
|
92
|
+
},
|
|
93
|
+
async (args) => {
|
|
94
|
+
try {
|
|
95
|
+
const result = await client.enterprises.listAgents(args.enterpriseId, {
|
|
96
|
+
status: args.status,
|
|
97
|
+
limit: args.limit,
|
|
98
|
+
offset: args.offset,
|
|
99
|
+
});
|
|
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
|
+
};
|
|
104
|
+
} catch (err) {
|
|
105
|
+
return apiErrorResult(err);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
mcp.registerTool(
|
|
111
|
+
'create_enterprise',
|
|
112
|
+
{
|
|
113
|
+
title: 'Create Enterprise',
|
|
114
|
+
description:
|
|
115
|
+
'Provision a new enterprise on the platform. Returns a flat enterprise resource. ' +
|
|
116
|
+
'Slug is auto-generated from name if omitted. ' +
|
|
117
|
+
'Workflow: create_enterprise → create API key → create_agent → approve agent → set capabilities.',
|
|
118
|
+
inputSchema: {
|
|
119
|
+
name: z.string().describe('Legal or display name for the enterprise'),
|
|
120
|
+
slug: z.string().optional().describe('URL-safe slug (auto-generated if omitted)'),
|
|
121
|
+
email: z.string().optional().describe('Contact email'),
|
|
122
|
+
trustLevel: z.enum(['sandbox', 'active', 'verified']).optional().describe('Initial trust level (default: sandbox)'),
|
|
123
|
+
},
|
|
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
|
+
annotations: {
|
|
132
|
+
readOnlyHint: false,
|
|
133
|
+
destructiveHint: false,
|
|
134
|
+
idempotentHint: false,
|
|
135
|
+
openWorldHint: true,
|
|
136
|
+
},
|
|
137
|
+
_meta: toolMeta('create_enterprise'),
|
|
138
|
+
},
|
|
139
|
+
async (args) => {
|
|
140
|
+
try {
|
|
141
|
+
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
|
+
};
|
|
146
|
+
} catch (err) {
|
|
147
|
+
return apiErrorResult(err);
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
mcp.registerTool(
|
|
153
|
+
'create_agent',
|
|
154
|
+
{
|
|
155
|
+
title: 'Create Agent',
|
|
156
|
+
description:
|
|
157
|
+
'Provision a new agent on the platform. Returns the agent resource and a nextSteps array ' +
|
|
158
|
+
'Slug is auto-generated from name if omitted. ' +
|
|
159
|
+
'Prerequisites: enterprise must exist. ' +
|
|
160
|
+
'Workflow: create_enterprise → create_agent → create API key → set capabilities → approve agent.',
|
|
161
|
+
inputSchema: {
|
|
162
|
+
name: z.string().describe('Display name for the agent'),
|
|
163
|
+
slug: z.string().optional().describe('URL-safe slug (auto-generated if omitted)'),
|
|
164
|
+
enterpriseId: z.string().optional().describe('Enterprise ID the agent belongs to'),
|
|
165
|
+
email: z.string().optional().describe('Contact email'),
|
|
166
|
+
trustLevel: z.enum(['sandbox', 'active', 'verified']).optional().describe('Initial trust level (default: sandbox)'),
|
|
167
|
+
},
|
|
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
|
+
annotations: {
|
|
176
|
+
readOnlyHint: false,
|
|
177
|
+
destructiveHint: false,
|
|
178
|
+
idempotentHint: false,
|
|
179
|
+
openWorldHint: true,
|
|
180
|
+
},
|
|
181
|
+
_meta: toolMeta('create_agent'),
|
|
182
|
+
},
|
|
183
|
+
async (args) => {
|
|
184
|
+
try {
|
|
185
|
+
const agent = await client.admin.createAgent({
|
|
186
|
+
name: args.name,
|
|
187
|
+
slug: args.slug,
|
|
188
|
+
enterpriseId: args.enterpriseId,
|
|
189
|
+
});
|
|
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
|
+
};
|
|
194
|
+
} catch (err) {
|
|
195
|
+
return apiErrorResult(err);
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
mcp.registerTool(
|
|
201
|
+
'set_enterprise_config',
|
|
202
|
+
{
|
|
203
|
+
title: 'Set Enterprise Config',
|
|
204
|
+
description:
|
|
205
|
+
'Replace an enterprise\'s configuration using desired-state semantics (PUT). ' +
|
|
206
|
+
'The entire config object is replaced — omitted fields are removed. ' +
|
|
207
|
+
'Use this after create_enterprise to configure approval policies, default scopes, and operational settings.',
|
|
208
|
+
inputSchema: {
|
|
209
|
+
enterpriseId: z.string().describe('Enterprise ID to configure'),
|
|
210
|
+
config: z.record(z.string(), z.unknown()).describe(
|
|
211
|
+
'Full configuration object. Common fields: agentApprovalRequired (boolean), ' +
|
|
212
|
+
'allowSelfApproval (boolean), defaultScopes (string[])',
|
|
213
|
+
),
|
|
214
|
+
},
|
|
215
|
+
annotations: {
|
|
216
|
+
readOnlyHint: false,
|
|
217
|
+
destructiveHint: false,
|
|
218
|
+
idempotentHint: true,
|
|
219
|
+
openWorldHint: true,
|
|
220
|
+
},
|
|
221
|
+
_meta: toolMeta('set_enterprise_config'),
|
|
222
|
+
},
|
|
223
|
+
async (args) => {
|
|
224
|
+
try {
|
|
225
|
+
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
|
+
};
|
|
230
|
+
} catch (err) {
|
|
231
|
+
return apiErrorResult(err);
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
);
|
|
235
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
+
import type { AgledgerClient } from '@agledger/sdk';
|
|
4
|
+
import { apiErrorResult } from '../errors.js';
|
|
5
|
+
import { toolMeta } from '../tool-scopes.js';
|
|
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
|
+
export function registerEventTools(mcp: McpServer, client: AgledgerClient): void {
|
|
23
|
+
mcp.registerTool(
|
|
24
|
+
'get_audit_trail',
|
|
25
|
+
{
|
|
26
|
+
title: 'Get Audit Trail',
|
|
27
|
+
description: 'Get the hash-chained audit trail for a mandate. Returns an ordered, tamper-evident chain of all events.',
|
|
28
|
+
inputSchema: {
|
|
29
|
+
mandateId: z.string().describe('UUID of the mandate to get the audit trail for'),
|
|
30
|
+
},
|
|
31
|
+
outputSchema: AuditChainOutputSchema,
|
|
32
|
+
annotations: {
|
|
33
|
+
readOnlyHint: true,
|
|
34
|
+
destructiveHint: false,
|
|
35
|
+
idempotentHint: true,
|
|
36
|
+
openWorldHint: true,
|
|
37
|
+
},
|
|
38
|
+
_meta: toolMeta('get_audit_trail'),
|
|
39
|
+
},
|
|
40
|
+
async (args) => {
|
|
41
|
+
try {
|
|
42
|
+
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
|
+
};
|
|
47
|
+
} catch (err) {
|
|
48
|
+
return apiErrorResult(err);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
);
|
|
52
|
+
}
|