@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.
Files changed (133) hide show
  1. package/dist/api-client.d.ts +16 -0
  2. package/dist/api-client.d.ts.map +1 -0
  3. package/dist/api-client.js +52 -0
  4. package/dist/api-client.js.map +1 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +17 -60
  7. package/dist/index.js.map +1 -1
  8. package/dist/server.d.ts +2 -13
  9. package/dist/server.d.ts.map +1 -1
  10. package/dist/server.js +113 -111
  11. package/dist/server.js.map +1 -1
  12. package/dist/tool-scopes.d.ts.map +1 -1
  13. package/dist/tool-scopes.js +0 -3
  14. package/dist/tool-scopes.js.map +1 -1
  15. package/dist/tools/a2a.d.ts.map +1 -1
  16. package/dist/tools/a2a.js +20 -220
  17. package/dist/tools/a2a.js.map +1 -1
  18. package/dist/tools/agent-mandates.d.ts.map +1 -1
  19. package/dist/tools/agent-mandates.js +10 -74
  20. package/dist/tools/agent-mandates.js.map +1 -1
  21. package/dist/tools/agents-refs.d.ts.map +1 -1
  22. package/dist/tools/agents-refs.js +9 -61
  23. package/dist/tools/agents-refs.js.map +1 -1
  24. package/dist/tools/capabilities.d.ts.map +1 -1
  25. package/dist/tools/capabilities.js +2 -14
  26. package/dist/tools/capabilities.js.map +1 -1
  27. package/dist/tools/code-mode.d.ts.map +1 -1
  28. package/dist/tools/code-mode.js +4 -35
  29. package/dist/tools/code-mode.js.map +1 -1
  30. package/dist/tools/compliance.d.ts.map +1 -1
  31. package/dist/tools/compliance.js +3 -37
  32. package/dist/tools/compliance.js.map +1 -1
  33. package/dist/tools/dashboard.d.ts.map +1 -1
  34. package/dist/tools/dashboard.js +3 -37
  35. package/dist/tools/dashboard.js.map +1 -1
  36. package/dist/tools/disputes.d.ts.map +1 -1
  37. package/dist/tools/disputes.js +4 -41
  38. package/dist/tools/disputes.js.map +1 -1
  39. package/dist/tools/enterprises.d.ts.map +1 -1
  40. package/dist/tools/enterprises.js +6 -62
  41. package/dist/tools/enterprises.js.map +1 -1
  42. package/dist/tools/events.d.ts.map +1 -1
  43. package/dist/tools/events.js +1 -19
  44. package/dist/tools/events.js.map +1 -1
  45. package/dist/tools/federation-admin.d.ts.map +1 -1
  46. package/dist/tools/federation-admin.js +24 -256
  47. package/dist/tools/federation-admin.js.map +1 -1
  48. package/dist/tools/federation.d.ts.map +1 -1
  49. package/dist/tools/federation.js +20 -197
  50. package/dist/tools/federation.js.map +1 -1
  51. package/dist/tools/health.d.ts.map +1 -1
  52. package/dist/tools/health.js +1 -13
  53. package/dist/tools/health.js.map +1 -1
  54. package/dist/tools/mandates.d.ts.map +1 -1
  55. package/dist/tools/mandates.js +10 -93
  56. package/dist/tools/mandates.js.map +1 -1
  57. package/dist/tools/openclaw.d.ts.map +1 -1
  58. package/dist/tools/openclaw.js +5 -32
  59. package/dist/tools/openclaw.js.map +1 -1
  60. package/dist/tools/receipts.d.ts.map +1 -1
  61. package/dist/tools/receipts.js +4 -94
  62. package/dist/tools/receipts.js.map +1 -1
  63. package/dist/tools/reputation.d.ts.map +1 -1
  64. package/dist/tools/reputation.js +3 -33
  65. package/dist/tools/reputation.js.map +1 -1
  66. package/dist/tools/schemas.d.ts.map +1 -1
  67. package/dist/tools/schemas.js +16 -186
  68. package/dist/tools/schemas.js.map +1 -1
  69. package/dist/tools/verification-keys.d.ts.map +1 -1
  70. package/dist/tools/verification-keys.js +1 -22
  71. package/dist/tools/verification-keys.js.map +1 -1
  72. package/dist/tools/verification.d.ts.map +1 -1
  73. package/dist/tools/verification.js +2 -27
  74. package/dist/tools/verification.js.map +1 -1
  75. package/package.json +2 -3
  76. package/src/api-client.ts +72 -0
  77. package/src/index.ts +27 -62
  78. package/src/server.ts +136 -122
  79. package/tests/api-client.test.ts +147 -0
  80. package/tests/harness.ts +8 -35
  81. package/tests/integration.test.ts +373 -0
  82. package/tests/server.test.ts +286 -0
  83. package/src/enums.ts +0 -47
  84. package/src/errors.ts +0 -44
  85. package/src/resources/contract-types.ts +0 -130
  86. package/src/tool-scopes.ts +0 -184
  87. package/src/tools/a2a.ts +0 -643
  88. package/src/tools/agent-mandates.ts +0 -325
  89. package/src/tools/agents-refs.ts +0 -288
  90. package/src/tools/capabilities.ts +0 -76
  91. package/src/tools/code-mode.ts +0 -461
  92. package/src/tools/compliance.ts +0 -104
  93. package/src/tools/dashboard.ts +0 -98
  94. package/src/tools/disputes.ts +0 -159
  95. package/src/tools/enterprises.ts +0 -259
  96. package/src/tools/events.ts +0 -52
  97. package/src/tools/federation-admin.ts +0 -922
  98. package/src/tools/federation.ts +0 -784
  99. package/src/tools/health.ts +0 -43
  100. package/src/tools/mandates.ts +0 -349
  101. package/src/tools/openclaw.ts +0 -168
  102. package/src/tools/receipts.ts +0 -225
  103. package/src/tools/reputation.ts +0 -100
  104. package/src/tools/schemas.ts +0 -713
  105. package/src/tools/verification-keys.ts +0 -56
  106. package/src/tools/verification.ts +0 -86
  107. package/tests/conformance.test.ts +0 -219
  108. package/tests/conformance.ts +0 -75
  109. package/tests/drift/code-mode-manifest.test.ts +0 -144
  110. package/tests/integration/output-schema-validation.test.ts +0 -167
  111. package/tests/mock-client.ts +0 -71
  112. package/tests/profiles.test.ts +0 -135
  113. package/tests/resources/contract-types.test.ts +0 -82
  114. package/tests/tools/a2a.test.ts +0 -241
  115. package/tests/tools/agent-mandates.test.ts +0 -206
  116. package/tests/tools/agents-refs.test.ts +0 -199
  117. package/tests/tools/capabilities.test.ts +0 -86
  118. package/tests/tools/code-mode.test.ts +0 -168
  119. package/tests/tools/compliance.test.ts +0 -131
  120. package/tests/tools/dashboard.test.ts +0 -120
  121. package/tests/tools/disputes.test.ts +0 -131
  122. package/tests/tools/enterprises.test.ts +0 -181
  123. package/tests/tools/events.test.ts +0 -61
  124. package/tests/tools/federation-admin.test.ts +0 -509
  125. package/tests/tools/federation.test.ts +0 -556
  126. package/tests/tools/health.test.ts +0 -67
  127. package/tests/tools/mandates.test.ts +0 -155
  128. package/tests/tools/openclaw.test.ts +0 -160
  129. package/tests/tools/receipts.test.ts +0 -170
  130. package/tests/tools/reputation.test.ts +0 -117
  131. package/tests/tools/schemas.test.ts +0 -397
  132. package/tests/tools/verification-keys.test.ts +0 -62
  133. 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,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,MAAM,8BAA8B,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,gCAAgC,CAAC;IAChE,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,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AAgB,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": "1.4.3",
4
- "description": "AGLedger™ MCP Server — Agent-facing AGLedger API tools via MCP protocol",
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
- type: 'string',
11
- short: 'k',
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™ MCP Server v1.4.0
28
+ `AGLedger MCP Server v2.0.0
36
29
 
37
- Usage: agledger-mcp --api-key <key> [--api-url <url>] [--profile <profile>]
30
+ Usage: agledger-mcp --api-key <key> [--api-url <url>]
38
31
 
39
32
  Options:
40
- --api-key, -k AGLedger API key (required)
41
- --api-url, -u AGLedger API base URL (default: https://agledger.example.com)
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
- Profiles:
46
- agent Standard agent workflow: create mandates, submit receipts, verdicts, verification
47
- admin Enterprise management: mandates, receipts, agents, capabilities, reputation, federation admin
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('Error: --api-key or AGLEDGER_API_KEY environment variable is required.\n');
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, profile, enterpriseId });
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(`Fatal: failed to start MCP server: ${err instanceof Error ? err.message : String(err)}\n`);
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 { AgledgerClient } from '@agledger/sdk';
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
- type RegisterFn = (mcp: McpServer, client: AgledgerClient) => void;
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: AgledgerClient;
111
- readonly profile: ToolProfile;
112
- private readonly enterpriseId?: string;
17
+ readonly client: ApiClient;
113
18
 
114
19
  constructor(options: AgledgerMcpServerOptions) {
115
- this.profile = options.profile ?? 'full';
116
- this.enterpriseId = options.enterpriseId;
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
- name: 'agledger-mcp-server',
121
- version: '1.4.3',
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
- capabilities: {
125
- tools: {},
126
- resources: {},
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
- this.client = new AgledgerClient({
132
- apiKey: options.apiKey,
133
- baseUrl: options.apiUrl ?? 'https://agledger.example.com',
134
- });
116
+ if (!path.startsWith('/')) {
117
+ return errorResult('Path must start with /');
118
+ }
135
119
 
136
- this.registerTools();
137
- }
120
+ const options: { query?: Record<string, unknown>; body?: unknown } = {};
138
121
 
139
- private registerTools(): void {
140
- const registry = buildProfileRegistry(this.enterpriseId);
141
- const fns = registry[this.profile];
142
- for (const fn of fns) {
143
- fn(this.mcp, this.client);
144
- }
145
- registerContractTypeResources(this.mcp, this.client);
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
  }