@agledger/mcp-server 1.4.3 → 2.0.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/dist/api-client.d.ts +16 -0
- package/dist/api-client.d.ts.map +1 -0
- package/dist/api-client.js +52 -0
- package/dist/api-client.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -60
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +2 -13
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +113 -111
- package/dist/server.js.map +1 -1
- package/dist/tool-scopes.d.ts.map +1 -1
- package/dist/tool-scopes.js +0 -3
- package/dist/tool-scopes.js.map +1 -1
- package/dist/tools/a2a.d.ts.map +1 -1
- package/dist/tools/a2a.js +20 -220
- package/dist/tools/a2a.js.map +1 -1
- package/dist/tools/agent-mandates.d.ts.map +1 -1
- package/dist/tools/agent-mandates.js +10 -74
- package/dist/tools/agent-mandates.js.map +1 -1
- package/dist/tools/agents-refs.d.ts.map +1 -1
- package/dist/tools/agents-refs.js +9 -61
- package/dist/tools/agents-refs.js.map +1 -1
- package/dist/tools/capabilities.d.ts.map +1 -1
- package/dist/tools/capabilities.js +2 -14
- package/dist/tools/capabilities.js.map +1 -1
- package/dist/tools/code-mode.d.ts.map +1 -1
- package/dist/tools/code-mode.js +4 -35
- package/dist/tools/code-mode.js.map +1 -1
- package/dist/tools/compliance.d.ts.map +1 -1
- package/dist/tools/compliance.js +3 -37
- package/dist/tools/compliance.js.map +1 -1
- package/dist/tools/dashboard.d.ts.map +1 -1
- package/dist/tools/dashboard.js +3 -37
- package/dist/tools/dashboard.js.map +1 -1
- package/dist/tools/disputes.d.ts.map +1 -1
- package/dist/tools/disputes.js +4 -41
- package/dist/tools/disputes.js.map +1 -1
- package/dist/tools/enterprises.d.ts.map +1 -1
- package/dist/tools/enterprises.js +6 -62
- package/dist/tools/enterprises.js.map +1 -1
- package/dist/tools/events.d.ts.map +1 -1
- package/dist/tools/events.js +1 -19
- package/dist/tools/events.js.map +1 -1
- package/dist/tools/federation-admin.d.ts.map +1 -1
- package/dist/tools/federation-admin.js +24 -256
- package/dist/tools/federation-admin.js.map +1 -1
- package/dist/tools/federation.d.ts.map +1 -1
- package/dist/tools/federation.js +20 -197
- package/dist/tools/federation.js.map +1 -1
- package/dist/tools/health.d.ts.map +1 -1
- package/dist/tools/health.js +1 -13
- package/dist/tools/health.js.map +1 -1
- package/dist/tools/mandates.d.ts.map +1 -1
- package/dist/tools/mandates.js +10 -93
- package/dist/tools/mandates.js.map +1 -1
- package/dist/tools/openclaw.d.ts.map +1 -1
- package/dist/tools/openclaw.js +5 -32
- package/dist/tools/openclaw.js.map +1 -1
- package/dist/tools/receipts.d.ts.map +1 -1
- package/dist/tools/receipts.js +4 -94
- package/dist/tools/receipts.js.map +1 -1
- package/dist/tools/reputation.d.ts.map +1 -1
- package/dist/tools/reputation.js +3 -33
- package/dist/tools/reputation.js.map +1 -1
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/schemas.js +16 -186
- package/dist/tools/schemas.js.map +1 -1
- package/dist/tools/verification-keys.d.ts.map +1 -1
- package/dist/tools/verification-keys.js +1 -22
- package/dist/tools/verification-keys.js.map +1 -1
- package/dist/tools/verification.d.ts.map +1 -1
- package/dist/tools/verification.js +2 -27
- package/dist/tools/verification.js.map +1 -1
- package/package.json +2 -3
- package/src/api-client.ts +72 -0
- package/src/index.ts +27 -62
- package/src/server.ts +136 -122
- package/tests/api-client.test.ts +147 -0
- package/tests/harness.ts +8 -35
- package/tests/integration.test.ts +373 -0
- package/tests/server.test.ts +286 -0
- package/src/enums.ts +0 -47
- package/src/errors.ts +0 -44
- package/src/resources/contract-types.ts +0 -130
- package/src/tool-scopes.ts +0 -184
- package/src/tools/a2a.ts +0 -643
- package/src/tools/agent-mandates.ts +0 -325
- package/src/tools/agents-refs.ts +0 -288
- package/src/tools/capabilities.ts +0 -76
- package/src/tools/code-mode.ts +0 -461
- package/src/tools/compliance.ts +0 -104
- package/src/tools/dashboard.ts +0 -98
- package/src/tools/disputes.ts +0 -159
- package/src/tools/enterprises.ts +0 -259
- package/src/tools/events.ts +0 -52
- package/src/tools/federation-admin.ts +0 -922
- package/src/tools/federation.ts +0 -784
- package/src/tools/health.ts +0 -43
- package/src/tools/mandates.ts +0 -349
- package/src/tools/openclaw.ts +0 -168
- package/src/tools/receipts.ts +0 -225
- package/src/tools/reputation.ts +0 -100
- package/src/tools/schemas.ts +0 -713
- package/src/tools/verification-keys.ts +0 -56
- package/src/tools/verification.ts +0 -86
- package/tests/conformance.test.ts +0 -219
- package/tests/conformance.ts +0 -75
- package/tests/drift/code-mode-manifest.test.ts +0 -144
- package/tests/integration/output-schema-validation.test.ts +0 -167
- package/tests/mock-client.ts +0 -71
- package/tests/profiles.test.ts +0 -135
- package/tests/resources/contract-types.test.ts +0 -82
- package/tests/tools/a2a.test.ts +0 -241
- package/tests/tools/agent-mandates.test.ts +0 -206
- package/tests/tools/agents-refs.test.ts +0 -199
- package/tests/tools/capabilities.test.ts +0 -86
- package/tests/tools/code-mode.test.ts +0 -168
- package/tests/tools/compliance.test.ts +0 -131
- package/tests/tools/dashboard.test.ts +0 -120
- package/tests/tools/disputes.test.ts +0 -131
- package/tests/tools/enterprises.test.ts +0 -181
- package/tests/tools/events.test.ts +0 -61
- package/tests/tools/federation-admin.test.ts +0 -509
- package/tests/tools/federation.test.ts +0 -556
- package/tests/tools/health.test.ts +0 -67
- package/tests/tools/mandates.test.ts +0 -155
- package/tests/tools/openclaw.test.ts +0 -160
- package/tests/tools/receipts.test.ts +0 -170
- package/tests/tools/reputation.test.ts +0 -117
- package/tests/tools/schemas.test.ts +0 -397
- package/tests/tools/verification-keys.test.ts +0 -62
- package/tests/tools/verification.test.ts +0 -74
|
@@ -1,23 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { apiErrorResult, toStructuredContent } from '../errors.js';
|
|
3
|
-
import { VerificationOutcomeEnum } from '../enums.js';
|
|
4
3
|
import { toolMeta } from '../tool-scopes.js';
|
|
5
|
-
const VerificationResultOutputSchema = z.object({
|
|
6
|
-
mandateId: z.string().describe('Mandate UUID that was verified'),
|
|
7
|
-
receipts: z.array(z.object({
|
|
8
|
-
receiptId: z.string().describe('Receipt UUID'),
|
|
9
|
-
phase1Result: z.record(z.string(), z.unknown()).optional().describe('Phase 1 (sync) verification result'),
|
|
10
|
-
phase2Result: z.record(z.string(), z.unknown()).optional().describe('Phase 2 (async) verification result'),
|
|
11
|
-
})).describe('Per-receipt verification results'),
|
|
12
|
-
overallStatus: VerificationOutcomeEnum.describe('Overall verification outcome: PASS, FAIL, or REVIEW_REQUIRED'),
|
|
13
|
-
}).passthrough().describe('Mandate verification result');
|
|
14
|
-
const VerificationStatusOutputSchema = z.object({
|
|
15
|
-
mandateId: z.string().describe('Mandate UUID'),
|
|
16
|
-
phase1Status: z.string().describe('Phase 1 (sync rules) verification status'),
|
|
17
|
-
phase2Status: z.string().describe('Phase 2 (async rules) verification status'),
|
|
18
|
-
lastVerifiedAt: z.string().nullable().optional().describe('ISO 8601 timestamp of last verification'),
|
|
19
|
-
pendingRules: z.array(z.string()).nullable().optional().describe('Rule IDs still pending verification'),
|
|
20
|
-
}).passthrough().describe('Current verification status for a mandate');
|
|
21
4
|
export function registerVerificationTools(mcp, client) {
|
|
22
5
|
mcp.registerTool('verify_mandate', {
|
|
23
6
|
title: 'Verify Mandate',
|
|
@@ -25,7 +8,6 @@ export function registerVerificationTools(mcp, client) {
|
|
|
25
8
|
inputSchema: {
|
|
26
9
|
mandateId: z.string().describe('UUID of the mandate to verify'),
|
|
27
10
|
},
|
|
28
|
-
outputSchema: VerificationResultOutputSchema,
|
|
29
11
|
annotations: {
|
|
30
12
|
readOnlyHint: false,
|
|
31
13
|
destructiveHint: false,
|
|
@@ -36,10 +18,7 @@ export function registerVerificationTools(mcp, client) {
|
|
|
36
18
|
}, async (args) => {
|
|
37
19
|
try {
|
|
38
20
|
const result = await client.verification.verify(args.mandateId);
|
|
39
|
-
return {
|
|
40
|
-
content: [{ type: 'text', text: `Verification for mandate ${result.mandateId}: ${result.overallStatus}. ${result.receipts.length} receipt(s) evaluated.` }],
|
|
41
|
-
structuredContent: toStructuredContent(result),
|
|
42
|
-
};
|
|
21
|
+
return { content: [], structuredContent: toStructuredContent(result) };
|
|
43
22
|
}
|
|
44
23
|
catch (err) {
|
|
45
24
|
return apiErrorResult(err);
|
|
@@ -51,7 +30,6 @@ export function registerVerificationTools(mcp, client) {
|
|
|
51
30
|
inputSchema: {
|
|
52
31
|
mandateId: z.string().describe('UUID of the mandate to check verification status for'),
|
|
53
32
|
},
|
|
54
|
-
outputSchema: VerificationStatusOutputSchema,
|
|
55
33
|
annotations: {
|
|
56
34
|
readOnlyHint: true,
|
|
57
35
|
destructiveHint: false,
|
|
@@ -62,10 +40,7 @@ export function registerVerificationTools(mcp, client) {
|
|
|
62
40
|
}, async (args) => {
|
|
63
41
|
try {
|
|
64
42
|
const status = await client.verification.getStatus(args.mandateId);
|
|
65
|
-
return {
|
|
66
|
-
content: [{ type: 'text', text: `Verification status for ${status.mandateId}: phase1=${status.phase1Status}, phase2=${status.phase2Status}.` }],
|
|
67
|
-
structuredContent: toStructuredContent(status),
|
|
68
|
-
};
|
|
43
|
+
return { content: [], structuredContent: toStructuredContent(status) };
|
|
69
44
|
}
|
|
70
45
|
catch (err) {
|
|
71
46
|
return apiErrorResult(err);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verification.js","sourceRoot":"","sources":["../../src/tools/verification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"verification.js","sourceRoot":"","sources":["../../src/tools/verification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,MAAM,UAAU,yBAAyB,CAAC,GAAc,EAAE,MAAsB;IAC9E,GAAG,CAAC,YAAY,CACd,gBAAgB,EAChB;QACE,KAAK,EAAE,gBAAgB;QACvB,WAAW,EAAE,+GAA+G;QAC5H,WAAW,EAAE;YACX,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,+BAA+B,CAAC;SAChE;QACD,WAAW,EAAE;YACX,YAAY,EAAE,KAAK;YACnB,eAAe,EAAE,KAAK;YACtB,cAAc,EAAE,IAAI;YACpB,aAAa,EAAE,IAAI;SACpB;QACD,KAAK,EAAE,QAAQ,CAAC,gBAAgB,CAAC;KAClC,EACD,KAAK,EAAE,IAAI,EAAE,EAAE;QACb,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAChE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,iBAAiB,EAAE,mBAAmB,CAAC,MAAM,CAAC,EAAE,CAAC;QACzE,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC,CACF,CAAC;IAEF,GAAG,CAAC,YAAY,CACd,yBAAyB,EACzB;QACE,KAAK,EAAE,yBAAyB;QAChC,WAAW,EAAE,oGAAoG;QACjH,WAAW,EAAE;YACX,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,sDAAsD,CAAC;SACvF;QACD,WAAW,EAAE;YACX,YAAY,EAAE,IAAI;YAClB,eAAe,EAAE,KAAK;YACtB,cAAc,EAAE,IAAI;YACpB,aAAa,EAAE,IAAI;SACpB;QACD,KAAK,EAAE,QAAQ,CAAC,yBAAyB,CAAC;KAC3C,EACD,KAAK,EAAE,IAAI,EAAE,EAAE;QACb,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACnE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,iBAAiB,EAAE,mBAAmB,CAAC,MAAM,CAAC,EAAE,CAAC;QACzE,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agledger/mcp-server",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "AGLedger
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "AGLedger MCP Server — Thin API pass-through for AI agents via MCP protocol",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "AGLedger LLC",
|
|
7
7
|
"repository": {
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
"lint": "tsc --noEmit"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@agledger/sdk": "^0.4.0",
|
|
43
42
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
44
43
|
"zod": "^4.3.6"
|
|
45
44
|
},
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export interface ApiResponse {
|
|
2
|
+
status: number;
|
|
3
|
+
body: unknown;
|
|
4
|
+
ok: boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export class ApiClient {
|
|
8
|
+
private readonly apiUrl: string;
|
|
9
|
+
private readonly apiKey: string;
|
|
10
|
+
private readonly timeoutMs: number;
|
|
11
|
+
|
|
12
|
+
constructor(apiUrl: string, apiKey: string, timeoutMs = 30_000) {
|
|
13
|
+
this.apiUrl = apiUrl.replace(/\/+$/, '');
|
|
14
|
+
this.apiKey = apiKey;
|
|
15
|
+
this.timeoutMs = timeoutMs;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async request(
|
|
19
|
+
method: string,
|
|
20
|
+
path: string,
|
|
21
|
+
options?: {
|
|
22
|
+
query?: Record<string, unknown>;
|
|
23
|
+
body?: unknown;
|
|
24
|
+
},
|
|
25
|
+
): Promise<ApiResponse> {
|
|
26
|
+
const url = new URL(path, this.apiUrl);
|
|
27
|
+
|
|
28
|
+
if (options?.query) {
|
|
29
|
+
for (const [k, v] of Object.entries(options.query)) {
|
|
30
|
+
if (v !== undefined && v !== null) {
|
|
31
|
+
url.searchParams.set(k, String(v));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const headers: Record<string, string> = {
|
|
37
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
38
|
+
Accept: 'application/json',
|
|
39
|
+
'User-Agent': 'agledger-mcp-server/2.0.0',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
if (options?.body !== undefined) {
|
|
43
|
+
headers['Content-Type'] = 'application/json';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const controller = new AbortController();
|
|
47
|
+
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const res = await fetch(url.toString(), {
|
|
51
|
+
method,
|
|
52
|
+
headers,
|
|
53
|
+
body: options?.body !== undefined ? JSON.stringify(options.body) : undefined,
|
|
54
|
+
signal: controller.signal,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const contentType = res.headers.get('content-type') ?? '';
|
|
58
|
+
let body: unknown;
|
|
59
|
+
|
|
60
|
+
if (contentType.includes('json')) {
|
|
61
|
+
body = await res.json();
|
|
62
|
+
} else {
|
|
63
|
+
const text = await res.text();
|
|
64
|
+
body = { _raw: text, _contentType: contentType };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return { status: res.status, body, ok: res.ok };
|
|
68
|
+
} finally {
|
|
69
|
+
clearTimeout(timeout);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -3,59 +3,40 @@ import { parseArgs } from 'node:util';
|
|
|
3
3
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
4
|
import { AgledgerMcpServer } from './server.js';
|
|
5
5
|
|
|
6
|
+
process.on('uncaughtException', (err) => {
|
|
7
|
+
process.stderr.write(`Uncaught exception: ${err.message}\n`);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
process.on('unhandledRejection', (reason) => {
|
|
11
|
+
process.stderr.write(
|
|
12
|
+
`Unhandled rejection: ${reason instanceof Error ? reason.message : String(reason)}\n`,
|
|
13
|
+
);
|
|
14
|
+
});
|
|
15
|
+
|
|
6
16
|
function main(): void {
|
|
7
17
|
const { values } = parseArgs({
|
|
8
18
|
options: {
|
|
9
|
-
'api-key': {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
'api-url': {
|
|
14
|
-
type: 'string',
|
|
15
|
-
short: 'u',
|
|
16
|
-
},
|
|
17
|
-
profile: {
|
|
18
|
-
type: 'string',
|
|
19
|
-
short: 'p',
|
|
20
|
-
},
|
|
21
|
-
'enterprise-id': {
|
|
22
|
-
type: 'string',
|
|
23
|
-
short: 'e',
|
|
24
|
-
},
|
|
25
|
-
help: {
|
|
26
|
-
type: 'boolean',
|
|
27
|
-
short: 'h',
|
|
28
|
-
},
|
|
19
|
+
'api-key': { type: 'string', short: 'k' },
|
|
20
|
+
'api-url': { type: 'string', short: 'u' },
|
|
21
|
+
help: { type: 'boolean', short: 'h' },
|
|
29
22
|
},
|
|
30
23
|
strict: true,
|
|
31
24
|
});
|
|
32
25
|
|
|
33
26
|
if (values.help) {
|
|
34
27
|
process.stderr.write(
|
|
35
|
-
`AGLedger
|
|
28
|
+
`AGLedger MCP Server v2.0.0
|
|
36
29
|
|
|
37
|
-
Usage: agledger-mcp --api-key <key> [--api-url <url>]
|
|
30
|
+
Usage: agledger-mcp --api-key <key> [--api-url <url>]
|
|
38
31
|
|
|
39
32
|
Options:
|
|
40
|
-
--api-key, -k AGLedger API key (
|
|
41
|
-
--api-url, -u AGLedger API base URL (
|
|
42
|
-
--profile, -p Tool profile (required, see below)
|
|
33
|
+
--api-key, -k AGLedger API key (or AGLEDGER_API_KEY env var)
|
|
34
|
+
--api-url, -u AGLedger API base URL (or AGLEDGER_API_URL env var)
|
|
43
35
|
--help, -h Show this help message
|
|
44
36
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
audit Compliance monitoring: mandates, receipts, events, verification, disputes, dashboard
|
|
49
|
-
schema-dev Custom contract type authoring with workflow guidance
|
|
50
|
-
openclaw Lightweight notarization for agent-to-agent agreements (5 tools)
|
|
51
|
-
code Power-user mode: execute SDK code directly via sdk_execute (2 tools)
|
|
52
|
-
federation Federation gateway operations + admin
|
|
53
|
-
full All tools (development/debugging only)
|
|
54
|
-
|
|
55
|
-
Environment:
|
|
56
|
-
AGLEDGER_API_KEY API key (overridden by --api-key)
|
|
57
|
-
AGLEDGER_API_URL API URL (overridden by --api-url)
|
|
58
|
-
AGLEDGER_PROFILE Tool profile (overridden by --profile)
|
|
37
|
+
Tools:
|
|
38
|
+
agledger_discover Returns API health, your identity, and available scopes
|
|
39
|
+
agledger_api Make any AGLedger API call — the API guides you via nextSteps
|
|
59
40
|
`,
|
|
60
41
|
);
|
|
61
42
|
process.exit(0);
|
|
@@ -63,37 +44,21 @@ Environment:
|
|
|
63
44
|
|
|
64
45
|
const apiKey = values['api-key'] ?? process.env.AGLEDGER_API_KEY;
|
|
65
46
|
const apiUrl = values['api-url'] ?? process.env.AGLEDGER_API_URL;
|
|
66
|
-
const profileRaw = values.profile ?? process.env.AGLEDGER_PROFILE;
|
|
67
|
-
if (!profileRaw) {
|
|
68
|
-
process.stderr.write(`Error: --profile or AGLEDGER_PROFILE is required.
|
|
69
|
-
|
|
70
|
-
Choose a profile to control which tools are available:
|
|
71
|
-
agent Standard agent workflow — create mandates, submit receipts, verdicts
|
|
72
|
-
admin Enterprise management — mandates, receipts, agents, capabilities, reputation
|
|
73
|
-
audit Compliance monitoring — mandates, events, verification, disputes, dashboard
|
|
74
|
-
schema-dev Custom contract type authoring
|
|
75
|
-
openclaw Lightweight notarization (5 tools)
|
|
76
|
-
code SDK code execution (2 tools)
|
|
77
|
-
federation Federation gateway operations + admin
|
|
78
|
-
full All tools (development/debugging only)
|
|
79
|
-
|
|
80
|
-
Example: agledger-mcp --api-key <key> --profile agent
|
|
81
|
-
`);
|
|
82
|
-
process.exit(1);
|
|
83
|
-
}
|
|
84
|
-
const profile = profileRaw as 'full' | 'agent' | 'openclaw' | 'schema-dev' | 'admin' | 'audit' | 'code' | 'federation';
|
|
85
|
-
const enterpriseId = values['enterprise-id'] ?? process.env.AGLEDGER_ENTERPRISE_ID;
|
|
86
47
|
|
|
87
48
|
if (!apiKey) {
|
|
88
|
-
process.stderr.write(
|
|
49
|
+
process.stderr.write(
|
|
50
|
+
'Error: --api-key or AGLEDGER_API_KEY environment variable is required.\n',
|
|
51
|
+
);
|
|
89
52
|
process.exit(1);
|
|
90
53
|
}
|
|
91
54
|
|
|
92
|
-
const server = new AgledgerMcpServer({ apiKey, apiUrl
|
|
55
|
+
const server = new AgledgerMcpServer({ apiKey, apiUrl });
|
|
93
56
|
const transport = new StdioServerTransport();
|
|
94
57
|
|
|
95
58
|
server.mcp.connect(transport).catch((err: unknown) => {
|
|
96
|
-
process.stderr.write(
|
|
59
|
+
process.stderr.write(
|
|
60
|
+
`Fatal: failed to start MCP server: ${err instanceof Error ? err.message : String(err)}\n`,
|
|
61
|
+
);
|
|
97
62
|
process.exit(1);
|
|
98
63
|
});
|
|
99
64
|
}
|
package/src/server.ts
CHANGED
|
@@ -1,147 +1,161 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { registerMandateTools } from './tools/mandates.js';
|
|
5
|
-
import { registerAgentMandateTools } from './tools/agent-mandates.js';
|
|
6
|
-
import { registerReceiptTools } from './tools/receipts.js';
|
|
7
|
-
import { registerVerificationTools } from './tools/verification.js';
|
|
8
|
-
import { registerDisputeTools } from './tools/disputes.js';
|
|
9
|
-
import { registerReputationTools } from './tools/reputation.js';
|
|
10
|
-
import { registerEventTools } from './tools/events.js';
|
|
11
|
-
import { registerSchemaTools } from './tools/schemas.js';
|
|
12
|
-
import { registerHealthTools } from './tools/health.js';
|
|
13
|
-
import { registerCapabilityTools } from './tools/capabilities.js';
|
|
14
|
-
import { registerA2aTools } from './tools/a2a.js';
|
|
15
|
-
import { registerOpenClawTools } from './tools/openclaw.js';
|
|
16
|
-
import { registerEnterpriseTools } from './tools/enterprises.js';
|
|
17
|
-
import { registerDashboardTools } from './tools/dashboard.js';
|
|
18
|
-
import { registerComplianceTools } from './tools/compliance.js';
|
|
19
|
-
import { registerFederationTools } from './tools/federation.js';
|
|
20
|
-
import { registerFederationAdminTools } from './tools/federation-admin.js';
|
|
21
|
-
import { registerAgentsRefsTools } from './tools/agents-refs.js';
|
|
22
|
-
import { registerCodeModeTools } from './tools/code-mode.js';
|
|
23
|
-
import { registerVerificationKeysTools } from './tools/verification-keys.js';
|
|
24
|
-
import { registerContractTypeResources } from './resources/contract-types.js';
|
|
25
|
-
|
|
26
|
-
export type ToolProfile = 'full' | 'code' | 'agent' | 'openclaw' | 'schema-dev' | 'admin' | 'audit' | 'federation';
|
|
3
|
+
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
+
import { ApiClient } from './api-client.js';
|
|
27
5
|
|
|
28
6
|
export interface AgledgerMcpServerOptions {
|
|
29
7
|
apiKey: string;
|
|
30
8
|
apiUrl?: string;
|
|
31
|
-
/** Tool profile: "code" (2 tools — SDK code execution + docs), "agent", "openclaw", "schema-dev", "admin", "audit", "federation", or "full" (legacy, all individual tools). */
|
|
32
|
-
profile?: ToolProfile;
|
|
33
|
-
/** Enterprise ID for A2A search queries. Falls back to AGLEDGER_ENTERPRISE_ID env var. */
|
|
34
|
-
enterpriseId?: string;
|
|
35
9
|
}
|
|
36
10
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
function buildProfileRegistry(enterpriseId?: string): Record<ToolProfile, RegisterFn[]> {
|
|
40
|
-
return {
|
|
41
|
-
code: [registerCodeModeTools],
|
|
42
|
-
openclaw: [registerOpenClawTools],
|
|
43
|
-
agent: [
|
|
44
|
-
(mcp, client) => registerA2aTools(mcp, client, { enterpriseId }),
|
|
45
|
-
(mcp, client) => registerReceiptTools(mcp, client, { skipSubmit: true }),
|
|
46
|
-
registerVerificationTools,
|
|
47
|
-
registerAgentsRefsTools,
|
|
48
|
-
registerHealthTools,
|
|
49
|
-
],
|
|
50
|
-
'schema-dev': [registerSchemaTools, registerHealthTools],
|
|
51
|
-
admin: [
|
|
52
|
-
registerMandateTools,
|
|
53
|
-
registerReceiptTools,
|
|
54
|
-
registerEnterpriseTools,
|
|
55
|
-
registerCapabilityTools,
|
|
56
|
-
registerReputationTools,
|
|
57
|
-
registerAgentsRefsTools,
|
|
58
|
-
registerFederationAdminTools,
|
|
59
|
-
registerHealthTools,
|
|
60
|
-
registerVerificationKeysTools,
|
|
61
|
-
],
|
|
62
|
-
federation: [
|
|
63
|
-
registerFederationTools,
|
|
64
|
-
registerFederationAdminTools,
|
|
65
|
-
registerAgentsRefsTools,
|
|
66
|
-
registerHealthTools,
|
|
67
|
-
],
|
|
68
|
-
audit: [
|
|
69
|
-
registerMandateTools,
|
|
70
|
-
registerReceiptTools,
|
|
71
|
-
registerEventTools,
|
|
72
|
-
registerVerificationTools,
|
|
73
|
-
registerDisputeTools,
|
|
74
|
-
registerReputationTools,
|
|
75
|
-
registerDashboardTools,
|
|
76
|
-
registerComplianceTools,
|
|
77
|
-
registerAgentsRefsTools,
|
|
78
|
-
registerHealthTools,
|
|
79
|
-
registerVerificationKeysTools,
|
|
80
|
-
],
|
|
81
|
-
full: [
|
|
82
|
-
registerMandateTools,
|
|
83
|
-
registerAgentMandateTools,
|
|
84
|
-
registerReceiptTools,
|
|
85
|
-
registerVerificationTools,
|
|
86
|
-
registerDisputeTools,
|
|
87
|
-
registerReputationTools,
|
|
88
|
-
registerEventTools,
|
|
89
|
-
registerSchemaTools,
|
|
90
|
-
registerHealthTools,
|
|
91
|
-
registerCapabilityTools,
|
|
92
|
-
registerEnterpriseTools,
|
|
93
|
-
registerDashboardTools,
|
|
94
|
-
registerComplianceTools,
|
|
95
|
-
registerFederationTools,
|
|
96
|
-
registerFederationAdminTools,
|
|
97
|
-
registerAgentsRefsTools,
|
|
98
|
-
registerVerificationKeysTools,
|
|
99
|
-
],
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** Exported for testing — returns the profile registry for a given enterpriseId. */
|
|
104
|
-
export function getProfileRegistry(enterpriseId?: string): Record<ToolProfile, RegisterFn[]> {
|
|
105
|
-
return buildProfileRegistry(enterpriseId);
|
|
11
|
+
function errorResult(message: string): CallToolResult {
|
|
12
|
+
return { content: [{ type: 'text', text: `Error: ${message}` }], isError: true };
|
|
106
13
|
}
|
|
107
14
|
|
|
108
15
|
export class AgledgerMcpServer {
|
|
109
16
|
readonly mcp: McpServer;
|
|
110
|
-
readonly client:
|
|
111
|
-
readonly profile: ToolProfile;
|
|
112
|
-
private readonly enterpriseId?: string;
|
|
17
|
+
readonly client: ApiClient;
|
|
113
18
|
|
|
114
19
|
constructor(options: AgledgerMcpServerOptions) {
|
|
115
|
-
|
|
116
|
-
|
|
20
|
+
const apiUrl = options.apiUrl ?? 'https://agledger.example.com';
|
|
21
|
+
|
|
22
|
+
this.client = new ApiClient(apiUrl, options.apiKey);
|
|
117
23
|
|
|
118
24
|
this.mcp = new McpServer(
|
|
25
|
+
{ name: 'agledger-mcp-server', version: '2.0.0' },
|
|
26
|
+
{ capabilities: { tools: {} } },
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
this.registerTools();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private registerTools(): void {
|
|
33
|
+
const client = this.client;
|
|
34
|
+
|
|
35
|
+
this.mcp.registerTool(
|
|
36
|
+
'agledger_discover',
|
|
119
37
|
{
|
|
120
|
-
|
|
121
|
-
|
|
38
|
+
title: 'Discover AGLedger API',
|
|
39
|
+
description:
|
|
40
|
+
'Returns API health, your identity, and available scopes. ' +
|
|
41
|
+
'Call this first to understand what you can do. ' +
|
|
42
|
+
'The response includes nextSteps guiding you to available endpoints.',
|
|
43
|
+
inputSchema: {},
|
|
44
|
+
annotations: {
|
|
45
|
+
readOnlyHint: true,
|
|
46
|
+
destructiveHint: false,
|
|
47
|
+
idempotentHint: true,
|
|
48
|
+
openWorldHint: true,
|
|
49
|
+
},
|
|
122
50
|
},
|
|
51
|
+
async () => {
|
|
52
|
+
try {
|
|
53
|
+
const [health, identity] = await Promise.allSettled([
|
|
54
|
+
client.request('GET', '/health'),
|
|
55
|
+
client.request('GET', '/v1/auth/me'),
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
const result: Record<string, unknown> = {};
|
|
59
|
+
|
|
60
|
+
if (health.status === 'fulfilled') {
|
|
61
|
+
result.health = health.value.body;
|
|
62
|
+
} else {
|
|
63
|
+
result.health = {
|
|
64
|
+
error: health.reason instanceof Error ? health.reason.message : String(health.reason),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (identity.status === 'fulfilled') {
|
|
69
|
+
result.identity = identity.value.body;
|
|
70
|
+
} else {
|
|
71
|
+
result.identity = {
|
|
72
|
+
error:
|
|
73
|
+
identity.reason instanceof Error
|
|
74
|
+
? identity.reason.message
|
|
75
|
+
: String(identity.reason),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return { content: [], structuredContent: result };
|
|
80
|
+
} catch (err) {
|
|
81
|
+
return errorResult(err instanceof Error ? err.message : String(err));
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
this.mcp.registerTool(
|
|
87
|
+
'agledger_api',
|
|
123
88
|
{
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
89
|
+
title: 'AGLedger API',
|
|
90
|
+
description:
|
|
91
|
+
'Make any AGLedger API call. The API returns nextSteps on every response to guide you. ' +
|
|
92
|
+
'Start with agledger_discover to see available endpoints, then follow nextSteps. ' +
|
|
93
|
+
'Common entry points: /mandates, /schemas, /health, /auth/me, /agents/{agentId}/reputation. ' +
|
|
94
|
+
'For GET/DELETE, params become query parameters. For POST/PUT/PATCH, params become the JSON body.',
|
|
95
|
+
inputSchema: {
|
|
96
|
+
method: z.enum(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']).describe('HTTP method'),
|
|
97
|
+
path: z.string().describe('API path (e.g. /mandates, /schemas, /mandates/{id}/receipts)'),
|
|
98
|
+
params: z
|
|
99
|
+
.record(z.string(), z.unknown())
|
|
100
|
+
.optional()
|
|
101
|
+
.describe(
|
|
102
|
+
'Request parameters. For GET/DELETE: query params. For POST/PUT/PATCH: JSON body.',
|
|
103
|
+
),
|
|
104
|
+
},
|
|
105
|
+
annotations: {
|
|
106
|
+
readOnlyHint: false,
|
|
107
|
+
destructiveHint: false,
|
|
108
|
+
idempotentHint: false,
|
|
109
|
+
openWorldHint: true,
|
|
127
110
|
},
|
|
128
111
|
},
|
|
129
|
-
|
|
112
|
+
async (args) => {
|
|
113
|
+
try {
|
|
114
|
+
const { method, path, params } = args;
|
|
130
115
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
});
|
|
116
|
+
if (!path.startsWith('/')) {
|
|
117
|
+
return errorResult('Path must start with /');
|
|
118
|
+
}
|
|
135
119
|
|
|
136
|
-
|
|
137
|
-
}
|
|
120
|
+
const options: { query?: Record<string, unknown>; body?: unknown } = {};
|
|
138
121
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
122
|
+
if (params) {
|
|
123
|
+
if (method === 'GET' || method === 'DELETE') {
|
|
124
|
+
options.query = params;
|
|
125
|
+
} else {
|
|
126
|
+
options.body = params;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const response = await client.request(method, path, options);
|
|
131
|
+
|
|
132
|
+
if (response.ok) {
|
|
133
|
+
return {
|
|
134
|
+
content: [],
|
|
135
|
+
structuredContent: response.body as Record<string, unknown>,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const errorBody = (response.body ?? {}) as Record<string, unknown>;
|
|
140
|
+
const message = (errorBody.message ??
|
|
141
|
+
errorBody.error ??
|
|
142
|
+
`API returned ${response.status}`) as string;
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
content: [{ type: 'text', text: `Error: ${message}` }],
|
|
146
|
+
structuredContent: errorBody,
|
|
147
|
+
isError: true,
|
|
148
|
+
};
|
|
149
|
+
} catch (err) {
|
|
150
|
+
if (err instanceof DOMException && err.name === 'AbortError') {
|
|
151
|
+
return errorResult('Request timed out. The API did not respond within 30 seconds.');
|
|
152
|
+
}
|
|
153
|
+
if (err instanceof TypeError && err.message.includes('fetch')) {
|
|
154
|
+
return errorResult(`Network error: ${err.message}. Check API URL and connectivity.`);
|
|
155
|
+
}
|
|
156
|
+
return errorResult(err instanceof Error ? err.message : String(err));
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
);
|
|
146
160
|
}
|
|
147
161
|
}
|