@agledger/mcp-server 1.5.0 → 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 -58
- 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 -109
- package/dist/server.js.map +1 -1
- package/package.json +2 -3
- package/src/api-client.ts +72 -0
- package/src/index.ts +27 -60
- package/src/server.ts +136 -120
- 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 -180
- package/src/tools/a2a.ts +0 -430
- package/src/tools/agent-mandates.ts +0 -259
- package/src/tools/agents-refs.ts +0 -232
- package/src/tools/capabilities.ts +0 -63
- package/src/tools/compliance.ts +0 -70
- package/src/tools/dashboard.ts +0 -64
- package/src/tools/disputes.ts +0 -121
- package/src/tools/enterprises.ts +0 -203
- package/src/tools/events.ts +0 -33
- package/src/tools/federation-admin.ts +0 -665
- package/src/tools/federation.ts +0 -587
- package/src/tools/health.ts +0 -30
- package/src/tools/mandates.ts +0 -264
- package/src/tools/openclaw.ts +0 -122
- package/src/tools/receipts.ts +0 -134
- package/src/tools/reputation.ts +0 -69
- package/src/tools/schemas.ts +0 -535
- package/src/tools/verification-keys.ts +0 -33
- package/src/tools/verification.ts +0 -59
- package/tests/conformance.test.ts +0 -197
- package/tests/conformance.ts +0 -65
- package/tests/mock-client.ts +0 -71
- package/tests/profiles.test.ts +0 -120
- package/tests/resources/contract-types.test.ts +0 -82
- package/tests/tools/a2a.test.ts +0 -213
- package/tests/tools/agent-mandates.test.ts +0 -196
- package/tests/tools/agents-refs.test.ts +0 -190
- package/tests/tools/capabilities.test.ts +0 -80
- package/tests/tools/compliance.test.ts +0 -123
- package/tests/tools/dashboard.test.ts +0 -111
- package/tests/tools/disputes.test.ts +0 -123
- package/tests/tools/enterprises.test.ts +0 -171
- package/tests/tools/events.test.ts +0 -56
- package/tests/tools/federation-admin.test.ts +0 -468
- package/tests/tools/federation.test.ts +0 -522
- package/tests/tools/health.test.ts +0 -56
- package/tests/tools/mandates.test.ts +0 -143
- package/tests/tools/openclaw.test.ts +0 -148
- package/tests/tools/receipts.test.ts +0 -157
- package/tests/tools/reputation.test.ts +0 -108
- package/tests/tools/schemas.test.ts +0 -374
- package/tests/tools/verification-keys.test.ts +0 -56
- package/tests/tools/verification.test.ts +0 -64
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface ApiResponse {
|
|
2
|
+
status: number;
|
|
3
|
+
body: unknown;
|
|
4
|
+
ok: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare class ApiClient {
|
|
7
|
+
private readonly apiUrl;
|
|
8
|
+
private readonly apiKey;
|
|
9
|
+
private readonly timeoutMs;
|
|
10
|
+
constructor(apiUrl: string, apiKey: string, timeoutMs?: number);
|
|
11
|
+
request(method: string, path: string, options?: {
|
|
12
|
+
query?: Record<string, unknown>;
|
|
13
|
+
body?: unknown;
|
|
14
|
+
}): Promise<ApiResponse>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=api-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;IACd,EAAE,EAAE,OAAO,CAAC;CACb;AAED,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;gBAEvB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,SAAS;IAMxD,OAAO,CACX,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAChC,IAAI,CAAC,EAAE,OAAO,CAAC;KAChB,GACA,OAAO,CAAC,WAAW,CAAC;CA+CxB"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export class ApiClient {
|
|
2
|
+
apiUrl;
|
|
3
|
+
apiKey;
|
|
4
|
+
timeoutMs;
|
|
5
|
+
constructor(apiUrl, apiKey, timeoutMs = 30_000) {
|
|
6
|
+
this.apiUrl = apiUrl.replace(/\/+$/, '');
|
|
7
|
+
this.apiKey = apiKey;
|
|
8
|
+
this.timeoutMs = timeoutMs;
|
|
9
|
+
}
|
|
10
|
+
async request(method, path, options) {
|
|
11
|
+
const url = new URL(path, this.apiUrl);
|
|
12
|
+
if (options?.query) {
|
|
13
|
+
for (const [k, v] of Object.entries(options.query)) {
|
|
14
|
+
if (v !== undefined && v !== null) {
|
|
15
|
+
url.searchParams.set(k, String(v));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const headers = {
|
|
20
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
21
|
+
Accept: 'application/json',
|
|
22
|
+
'User-Agent': 'agledger-mcp-server/2.0.0',
|
|
23
|
+
};
|
|
24
|
+
if (options?.body !== undefined) {
|
|
25
|
+
headers['Content-Type'] = 'application/json';
|
|
26
|
+
}
|
|
27
|
+
const controller = new AbortController();
|
|
28
|
+
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
29
|
+
try {
|
|
30
|
+
const res = await fetch(url.toString(), {
|
|
31
|
+
method,
|
|
32
|
+
headers,
|
|
33
|
+
body: options?.body !== undefined ? JSON.stringify(options.body) : undefined,
|
|
34
|
+
signal: controller.signal,
|
|
35
|
+
});
|
|
36
|
+
const contentType = res.headers.get('content-type') ?? '';
|
|
37
|
+
let body;
|
|
38
|
+
if (contentType.includes('json')) {
|
|
39
|
+
body = await res.json();
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const text = await res.text();
|
|
43
|
+
body = { _raw: text, _contentType: contentType };
|
|
44
|
+
}
|
|
45
|
+
return { status: res.status, body, ok: res.ok };
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
clearTimeout(timeout);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=api-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,SAAS;IACH,MAAM,CAAS;IACf,MAAM,CAAS;IACf,SAAS,CAAS;IAEnC,YAAY,MAAc,EAAE,MAAc,EAAE,SAAS,GAAG,MAAM;QAC5D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACzC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,OAAO,CACX,MAAc,EACd,IAAY,EACZ,OAGC;QAED,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAEvC,IAAI,OAAO,EAAE,KAAK,EAAE,CAAC;YACnB,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBACnD,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,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EAAE,YAAY,EAAE,WAAW,EAAE,CAAC;YACnD,CAAC;YAED,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC;QAClD,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,OAAO,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;CACF"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAmEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,YAAY,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,85 +2,44 @@
|
|
|
2
2
|
import { parseArgs } from 'node:util';
|
|
3
3
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
4
|
import { AgledgerMcpServer } from './server.js';
|
|
5
|
+
process.on('uncaughtException', (err) => {
|
|
6
|
+
process.stderr.write(`Uncaught exception: ${err.message}\n`);
|
|
7
|
+
});
|
|
8
|
+
process.on('unhandledRejection', (reason) => {
|
|
9
|
+
process.stderr.write(`Unhandled rejection: ${reason instanceof Error ? reason.message : String(reason)}\n`);
|
|
10
|
+
});
|
|
5
11
|
function main() {
|
|
6
12
|
const { values } = parseArgs({
|
|
7
13
|
options: {
|
|
8
|
-
'api-key': {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
},
|
|
12
|
-
'api-url': {
|
|
13
|
-
type: 'string',
|
|
14
|
-
short: 'u',
|
|
15
|
-
},
|
|
16
|
-
profile: {
|
|
17
|
-
type: 'string',
|
|
18
|
-
short: 'p',
|
|
19
|
-
},
|
|
20
|
-
'enterprise-id': {
|
|
21
|
-
type: 'string',
|
|
22
|
-
short: 'e',
|
|
23
|
-
},
|
|
24
|
-
help: {
|
|
25
|
-
type: 'boolean',
|
|
26
|
-
short: 'h',
|
|
27
|
-
},
|
|
14
|
+
'api-key': { type: 'string', short: 'k' },
|
|
15
|
+
'api-url': { type: 'string', short: 'u' },
|
|
16
|
+
help: { type: 'boolean', short: 'h' },
|
|
28
17
|
},
|
|
29
18
|
strict: true,
|
|
30
19
|
});
|
|
31
20
|
if (values.help) {
|
|
32
|
-
process.stderr.write(`AGLedger
|
|
21
|
+
process.stderr.write(`AGLedger MCP Server v2.0.0
|
|
33
22
|
|
|
34
|
-
Usage: agledger-mcp --api-key <key> [--api-url <url>]
|
|
23
|
+
Usage: agledger-mcp --api-key <key> [--api-url <url>]
|
|
35
24
|
|
|
36
25
|
Options:
|
|
37
|
-
--api-key, -k AGLedger API key (
|
|
38
|
-
--api-url, -u AGLedger API base URL (
|
|
39
|
-
--profile, -p Tool profile (required, see below)
|
|
26
|
+
--api-key, -k AGLedger API key (or AGLEDGER_API_KEY env var)
|
|
27
|
+
--api-url, -u AGLedger API base URL (or AGLEDGER_API_URL env var)
|
|
40
28
|
--help, -h Show this help message
|
|
41
29
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
audit Compliance monitoring: mandates, receipts, events, verification, disputes, dashboard
|
|
46
|
-
schema-dev Custom contract type authoring with workflow guidance
|
|
47
|
-
openclaw Lightweight notarization for agent-to-agent agreements (5 tools)
|
|
48
|
-
federation Federation gateway operations + admin
|
|
49
|
-
full All tools (development/debugging only)
|
|
50
|
-
|
|
51
|
-
Environment:
|
|
52
|
-
AGLEDGER_API_KEY API key (overridden by --api-key)
|
|
53
|
-
AGLEDGER_API_URL API URL (overridden by --api-url)
|
|
54
|
-
AGLEDGER_PROFILE Tool profile (overridden by --profile)
|
|
30
|
+
Tools:
|
|
31
|
+
agledger_discover Returns API health, your identity, and available scopes
|
|
32
|
+
agledger_api Make any AGLedger API call — the API guides you via nextSteps
|
|
55
33
|
`);
|
|
56
34
|
process.exit(0);
|
|
57
35
|
}
|
|
58
36
|
const apiKey = values['api-key'] ?? process.env.AGLEDGER_API_KEY;
|
|
59
37
|
const apiUrl = values['api-url'] ?? process.env.AGLEDGER_API_URL;
|
|
60
|
-
const profileRaw = values.profile ?? process.env.AGLEDGER_PROFILE;
|
|
61
|
-
if (!profileRaw) {
|
|
62
|
-
process.stderr.write(`Error: --profile or AGLEDGER_PROFILE is required.
|
|
63
|
-
|
|
64
|
-
Choose a profile to control which tools are available:
|
|
65
|
-
agent Standard agent workflow — create mandates, submit receipts, verdicts
|
|
66
|
-
admin Enterprise management — mandates, receipts, agents, capabilities, reputation
|
|
67
|
-
audit Compliance monitoring — mandates, events, verification, disputes, dashboard
|
|
68
|
-
schema-dev Custom contract type authoring
|
|
69
|
-
openclaw Lightweight notarization (5 tools)
|
|
70
|
-
federation Federation gateway operations + admin
|
|
71
|
-
full All tools (development/debugging only)
|
|
72
|
-
|
|
73
|
-
Example: agledger-mcp --api-key <key> --profile agent
|
|
74
|
-
`);
|
|
75
|
-
process.exit(1);
|
|
76
|
-
}
|
|
77
|
-
const profile = profileRaw;
|
|
78
|
-
const enterpriseId = values['enterprise-id'] ?? process.env.AGLEDGER_ENTERPRISE_ID;
|
|
79
38
|
if (!apiKey) {
|
|
80
39
|
process.stderr.write('Error: --api-key or AGLEDGER_API_KEY environment variable is required.\n');
|
|
81
40
|
process.exit(1);
|
|
82
41
|
}
|
|
83
|
-
const server = new AgledgerMcpServer({ apiKey, apiUrl
|
|
42
|
+
const server = new AgledgerMcpServer({ apiKey, apiUrl });
|
|
84
43
|
const transport = new StdioServerTransport();
|
|
85
44
|
server.mcp.connect(transport).catch((err) => {
|
|
86
45
|
process.stderr.write(`Fatal: failed to start MCP server: ${err instanceof Error ? err.message : String(err)}\n`);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":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AC,MAAM,CAAC,KAAK,CAClB;;;;;;;;;;;;CAYL,CACI,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;IACjE,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;IAEjE,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,0EAA0E,CAC3E,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACzD,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAE7C,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;QACnD,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,sCAAsC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAC3F,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,IAAI,EAAE,CAAC;AAEP,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/server.d.ts
CHANGED
|
@@ -1,24 +1,13 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
import {
|
|
3
|
-
export type ToolProfile = 'full' | 'agent' | 'openclaw' | 'schema-dev' | 'admin' | 'audit' | 'federation';
|
|
2
|
+
import { ApiClient } from './api-client.js';
|
|
4
3
|
export interface AgledgerMcpServerOptions {
|
|
5
4
|
apiKey: string;
|
|
6
5
|
apiUrl?: string;
|
|
7
|
-
/** Tool profile: "agent", "openclaw", "schema-dev", "admin", "audit", "federation", or "full" (legacy, all individual tools). */
|
|
8
|
-
profile?: ToolProfile;
|
|
9
|
-
/** Enterprise ID for A2A search queries. Falls back to AGLEDGER_ENTERPRISE_ID env var. */
|
|
10
|
-
enterpriseId?: string;
|
|
11
6
|
}
|
|
12
|
-
type RegisterFn = (mcp: McpServer, client: AgledgerClient) => void;
|
|
13
|
-
/** Exported for testing — returns the profile registry for a given enterpriseId. */
|
|
14
|
-
export declare function getProfileRegistry(enterpriseId?: string): Record<ToolProfile, RegisterFn[]>;
|
|
15
7
|
export declare class AgledgerMcpServer {
|
|
16
8
|
readonly mcp: McpServer;
|
|
17
|
-
readonly client:
|
|
18
|
-
readonly profile: ToolProfile;
|
|
19
|
-
private readonly enterpriseId?;
|
|
9
|
+
readonly client: ApiClient;
|
|
20
10
|
constructor(options: AgledgerMcpServerOptions);
|
|
21
11
|
private registerTools;
|
|
22
12
|
}
|
|
23
|
-
export {};
|
|
24
13
|
//# sourceMappingURL=server.d.ts.map
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAMD,qBAAa,iBAAiB;IAC5B,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;gBAEf,OAAO,EAAE,wBAAwB;IAa7C,OAAO,CAAC,aAAa;CAiItB"}
|
package/dist/server.js
CHANGED
|
@@ -1,121 +1,125 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { registerReceiptTools } from './tools/receipts.js';
|
|
6
|
-
import { registerVerificationTools } from './tools/verification.js';
|
|
7
|
-
import { registerDisputeTools } from './tools/disputes.js';
|
|
8
|
-
import { registerReputationTools } from './tools/reputation.js';
|
|
9
|
-
import { registerEventTools } from './tools/events.js';
|
|
10
|
-
import { registerSchemaTools } from './tools/schemas.js';
|
|
11
|
-
import { registerHealthTools } from './tools/health.js';
|
|
12
|
-
import { registerCapabilityTools } from './tools/capabilities.js';
|
|
13
|
-
import { registerA2aTools } from './tools/a2a.js';
|
|
14
|
-
import { registerOpenClawTools } from './tools/openclaw.js';
|
|
15
|
-
import { registerEnterpriseTools } from './tools/enterprises.js';
|
|
16
|
-
import { registerDashboardTools } from './tools/dashboard.js';
|
|
17
|
-
import { registerComplianceTools } from './tools/compliance.js';
|
|
18
|
-
import { registerFederationTools } from './tools/federation.js';
|
|
19
|
-
import { registerFederationAdminTools } from './tools/federation-admin.js';
|
|
20
|
-
import { registerAgentsRefsTools } from './tools/agents-refs.js';
|
|
21
|
-
import { registerVerificationKeysTools } from './tools/verification-keys.js';
|
|
22
|
-
import { registerContractTypeResources } from './resources/contract-types.js';
|
|
23
|
-
function buildProfileRegistry(enterpriseId) {
|
|
24
|
-
return {
|
|
25
|
-
openclaw: [registerOpenClawTools],
|
|
26
|
-
agent: [
|
|
27
|
-
(mcp, client) => registerA2aTools(mcp, client, { enterpriseId }),
|
|
28
|
-
(mcp, client) => registerReceiptTools(mcp, client, { skipSubmit: true }),
|
|
29
|
-
registerVerificationTools,
|
|
30
|
-
registerAgentsRefsTools,
|
|
31
|
-
registerHealthTools,
|
|
32
|
-
],
|
|
33
|
-
'schema-dev': [registerSchemaTools, registerHealthTools],
|
|
34
|
-
admin: [
|
|
35
|
-
registerMandateTools,
|
|
36
|
-
registerReceiptTools,
|
|
37
|
-
registerEnterpriseTools,
|
|
38
|
-
registerCapabilityTools,
|
|
39
|
-
registerReputationTools,
|
|
40
|
-
registerAgentsRefsTools,
|
|
41
|
-
registerFederationAdminTools,
|
|
42
|
-
registerHealthTools,
|
|
43
|
-
registerVerificationKeysTools,
|
|
44
|
-
],
|
|
45
|
-
federation: [
|
|
46
|
-
registerFederationTools,
|
|
47
|
-
registerFederationAdminTools,
|
|
48
|
-
registerAgentsRefsTools,
|
|
49
|
-
registerHealthTools,
|
|
50
|
-
],
|
|
51
|
-
audit: [
|
|
52
|
-
registerMandateTools,
|
|
53
|
-
registerReceiptTools,
|
|
54
|
-
registerEventTools,
|
|
55
|
-
registerVerificationTools,
|
|
56
|
-
registerDisputeTools,
|
|
57
|
-
registerReputationTools,
|
|
58
|
-
registerDashboardTools,
|
|
59
|
-
registerComplianceTools,
|
|
60
|
-
registerAgentsRefsTools,
|
|
61
|
-
registerHealthTools,
|
|
62
|
-
registerVerificationKeysTools,
|
|
63
|
-
],
|
|
64
|
-
full: [
|
|
65
|
-
registerMandateTools,
|
|
66
|
-
registerAgentMandateTools,
|
|
67
|
-
registerReceiptTools,
|
|
68
|
-
registerVerificationTools,
|
|
69
|
-
registerDisputeTools,
|
|
70
|
-
registerReputationTools,
|
|
71
|
-
registerEventTools,
|
|
72
|
-
registerSchemaTools,
|
|
73
|
-
registerHealthTools,
|
|
74
|
-
registerCapabilityTools,
|
|
75
|
-
registerEnterpriseTools,
|
|
76
|
-
registerDashboardTools,
|
|
77
|
-
registerComplianceTools,
|
|
78
|
-
registerFederationTools,
|
|
79
|
-
registerFederationAdminTools,
|
|
80
|
-
registerAgentsRefsTools,
|
|
81
|
-
registerVerificationKeysTools,
|
|
82
|
-
],
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
/** Exported for testing — returns the profile registry for a given enterpriseId. */
|
|
86
|
-
export function getProfileRegistry(enterpriseId) {
|
|
87
|
-
return buildProfileRegistry(enterpriseId);
|
|
3
|
+
import { ApiClient } from './api-client.js';
|
|
4
|
+
function errorResult(message) {
|
|
5
|
+
return { content: [{ type: 'text', text: `Error: ${message}` }], isError: true };
|
|
88
6
|
}
|
|
89
7
|
export class AgledgerMcpServer {
|
|
90
8
|
mcp;
|
|
91
9
|
client;
|
|
92
|
-
profile;
|
|
93
|
-
enterpriseId;
|
|
94
10
|
constructor(options) {
|
|
95
|
-
|
|
96
|
-
this.
|
|
97
|
-
this.mcp = new McpServer({
|
|
98
|
-
name: 'agledger-mcp-server',
|
|
99
|
-
version: '1.5.0',
|
|
100
|
-
}, {
|
|
101
|
-
capabilities: {
|
|
102
|
-
tools: {},
|
|
103
|
-
resources: {},
|
|
104
|
-
},
|
|
105
|
-
});
|
|
106
|
-
this.client = new AgledgerClient({
|
|
107
|
-
apiKey: options.apiKey,
|
|
108
|
-
baseUrl: options.apiUrl ?? 'https://agledger.example.com',
|
|
109
|
-
});
|
|
11
|
+
const apiUrl = options.apiUrl ?? 'https://agledger.example.com';
|
|
12
|
+
this.client = new ApiClient(apiUrl, options.apiKey);
|
|
13
|
+
this.mcp = new McpServer({ name: 'agledger-mcp-server', version: '2.0.0' }, { capabilities: { tools: {} } });
|
|
110
14
|
this.registerTools();
|
|
111
15
|
}
|
|
112
16
|
registerTools() {
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
17
|
+
const client = this.client;
|
|
18
|
+
this.mcp.registerTool('agledger_discover', {
|
|
19
|
+
title: 'Discover AGLedger API',
|
|
20
|
+
description: 'Returns API health, your identity, and available scopes. ' +
|
|
21
|
+
'Call this first to understand what you can do. ' +
|
|
22
|
+
'The response includes nextSteps guiding you to available endpoints.',
|
|
23
|
+
inputSchema: {},
|
|
24
|
+
annotations: {
|
|
25
|
+
readOnlyHint: true,
|
|
26
|
+
destructiveHint: false,
|
|
27
|
+
idempotentHint: true,
|
|
28
|
+
openWorldHint: true,
|
|
29
|
+
},
|
|
30
|
+
}, async () => {
|
|
31
|
+
try {
|
|
32
|
+
const [health, identity] = await Promise.allSettled([
|
|
33
|
+
client.request('GET', '/health'),
|
|
34
|
+
client.request('GET', '/v1/auth/me'),
|
|
35
|
+
]);
|
|
36
|
+
const result = {};
|
|
37
|
+
if (health.status === 'fulfilled') {
|
|
38
|
+
result.health = health.value.body;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
result.health = {
|
|
42
|
+
error: health.reason instanceof Error ? health.reason.message : String(health.reason),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (identity.status === 'fulfilled') {
|
|
46
|
+
result.identity = identity.value.body;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
result.identity = {
|
|
50
|
+
error: identity.reason instanceof Error
|
|
51
|
+
? identity.reason.message
|
|
52
|
+
: String(identity.reason),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return { content: [], structuredContent: result };
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
return errorResult(err instanceof Error ? err.message : String(err));
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
this.mcp.registerTool('agledger_api', {
|
|
62
|
+
title: 'AGLedger API',
|
|
63
|
+
description: 'Make any AGLedger API call. The API returns nextSteps on every response to guide you. ' +
|
|
64
|
+
'Start with agledger_discover to see available endpoints, then follow nextSteps. ' +
|
|
65
|
+
'Common entry points: /mandates, /schemas, /health, /auth/me, /agents/{agentId}/reputation. ' +
|
|
66
|
+
'For GET/DELETE, params become query parameters. For POST/PUT/PATCH, params become the JSON body.',
|
|
67
|
+
inputSchema: {
|
|
68
|
+
method: z.enum(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']).describe('HTTP method'),
|
|
69
|
+
path: z.string().describe('API path (e.g. /mandates, /schemas, /mandates/{id}/receipts)'),
|
|
70
|
+
params: z
|
|
71
|
+
.record(z.string(), z.unknown())
|
|
72
|
+
.optional()
|
|
73
|
+
.describe('Request parameters. For GET/DELETE: query params. For POST/PUT/PATCH: JSON body.'),
|
|
74
|
+
},
|
|
75
|
+
annotations: {
|
|
76
|
+
readOnlyHint: false,
|
|
77
|
+
destructiveHint: false,
|
|
78
|
+
idempotentHint: false,
|
|
79
|
+
openWorldHint: true,
|
|
80
|
+
},
|
|
81
|
+
}, async (args) => {
|
|
82
|
+
try {
|
|
83
|
+
const { method, path, params } = args;
|
|
84
|
+
if (!path.startsWith('/')) {
|
|
85
|
+
return errorResult('Path must start with /');
|
|
86
|
+
}
|
|
87
|
+
const options = {};
|
|
88
|
+
if (params) {
|
|
89
|
+
if (method === 'GET' || method === 'DELETE') {
|
|
90
|
+
options.query = params;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
options.body = params;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const response = await client.request(method, path, options);
|
|
97
|
+
if (response.ok) {
|
|
98
|
+
return {
|
|
99
|
+
content: [],
|
|
100
|
+
structuredContent: response.body,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const errorBody = (response.body ?? {});
|
|
104
|
+
const message = (errorBody.message ??
|
|
105
|
+
errorBody.error ??
|
|
106
|
+
`API returned ${response.status}`);
|
|
107
|
+
return {
|
|
108
|
+
content: [{ type: 'text', text: `Error: ${message}` }],
|
|
109
|
+
structuredContent: errorBody,
|
|
110
|
+
isError: true,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
if (err instanceof DOMException && err.name === 'AbortError') {
|
|
115
|
+
return errorResult('Request timed out. The API did not respond within 30 seconds.');
|
|
116
|
+
}
|
|
117
|
+
if (err instanceof TypeError && err.message.includes('fetch')) {
|
|
118
|
+
return errorResult(`Network error: ${err.message}. Check API URL and connectivity.`);
|
|
119
|
+
}
|
|
120
|
+
return errorResult(err instanceof Error ? err.message : String(err));
|
|
121
|
+
}
|
|
122
|
+
});
|
|
119
123
|
}
|
|
120
124
|
}
|
|
121
125
|
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAO5C,SAAS,WAAW,CAAC,OAAe;IAClC,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,OAAO,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AACnF,CAAC;AAED,MAAM,OAAO,iBAAiB;IACnB,GAAG,CAAY;IACf,MAAM,CAAY;IAE3B,YAAY,OAAiC;QAC3C,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,8BAA8B,CAAC;QAEhE,IAAI,CAAC,MAAM,GAAG,IAAI,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QAEpD,IAAI,CAAC,GAAG,GAAG,IAAI,SAAS,CACtB,EAAE,IAAI,EAAE,qBAAqB,EAAE,OAAO,EAAE,OAAO,EAAE,EACjD,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAChC,CAAC;QAEF,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC;IAEO,aAAa;QACnB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAE3B,IAAI,CAAC,GAAG,CAAC,Y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C,kBAAkB,GAAG,CAAC,OAAO,mCAAmC,CAAC,CAAC;gBACvF,CAAC;gBACD,OAAO,WAAW,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YACvE,CAAC;QACH,CAAC,CACF,CAAC;IACJ,CAAC;CACF"}
|
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
|
+
}
|