@agledger/mcp-server 2.0.0 → 2.0.2

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 (107) hide show
  1. package/README.md +18 -20
  2. package/dist/api-client.js +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/server.d.ts.map +1 -1
  5. package/dist/server.js +68 -11
  6. package/dist/server.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/api-client.ts +1 -1
  9. package/src/index.ts +1 -1
  10. package/src/server.ts +79 -11
  11. package/tests/server.test.ts +76 -6
  12. package/dist/enums.d.ts +0 -110
  13. package/dist/enums.d.ts.map +0 -1
  14. package/dist/enums.js +0 -42
  15. package/dist/enums.js.map +0 -1
  16. package/dist/errors.d.ts +0 -10
  17. package/dist/errors.d.ts.map +0 -1
  18. package/dist/errors.js +0 -49
  19. package/dist/errors.js.map +0 -1
  20. package/dist/resources/contract-types.d.ts +0 -4
  21. package/dist/resources/contract-types.d.ts.map +0 -1
  22. package/dist/resources/contract-types.js +0 -104
  23. package/dist/resources/contract-types.js.map +0 -1
  24. package/dist/tool-scopes.d.ts +0 -11
  25. package/dist/tool-scopes.d.ts.map +0 -1
  26. package/dist/tool-scopes.js +0 -164
  27. package/dist/tool-scopes.js.map +0 -1
  28. package/dist/tools/a2a.d.ts +0 -8
  29. package/dist/tools/a2a.d.ts.map +0 -1
  30. package/dist/tools/a2a.js +0 -360
  31. package/dist/tools/a2a.js.map +0 -1
  32. package/dist/tools/agent-mandates.d.ts +0 -4
  33. package/dist/tools/agent-mandates.d.ts.map +0 -1
  34. package/dist/tools/agent-mandates.js +0 -222
  35. package/dist/tools/agent-mandates.js.map +0 -1
  36. package/dist/tools/agents-refs.d.ts +0 -4
  37. package/dist/tools/agents-refs.d.ts.map +0 -1
  38. package/dist/tools/agents-refs.js +0 -196
  39. package/dist/tools/agents-refs.js.map +0 -1
  40. package/dist/tools/capabilities.d.ts +0 -4
  41. package/dist/tools/capabilities.d.ts.map +0 -1
  42. package/dist/tools/capabilities.js +0 -54
  43. package/dist/tools/capabilities.js.map +0 -1
  44. package/dist/tools/code-mode.d.ts +0 -4
  45. package/dist/tools/code-mode.d.ts.map +0 -1
  46. package/dist/tools/code-mode.js +0 -389
  47. package/dist/tools/code-mode.js.map +0 -1
  48. package/dist/tools/compliance.d.ts +0 -4
  49. package/dist/tools/compliance.d.ts.map +0 -1
  50. package/dist/tools/compliance.js +0 -63
  51. package/dist/tools/compliance.js.map +0 -1
  52. package/dist/tools/dashboard.d.ts +0 -4
  53. package/dist/tools/dashboard.d.ts.map +0 -1
  54. package/dist/tools/dashboard.js +0 -57
  55. package/dist/tools/dashboard.js.map +0 -1
  56. package/dist/tools/disputes.d.ts +0 -4
  57. package/dist/tools/disputes.d.ts.map +0 -1
  58. package/dist/tools/disputes.js +0 -103
  59. package/dist/tools/disputes.js.map +0 -1
  60. package/dist/tools/enterprises.d.ts +0 -4
  61. package/dist/tools/enterprises.d.ts.map +0 -1
  62. package/dist/tools/enterprises.js +0 -173
  63. package/dist/tools/enterprises.js.map +0 -1
  64. package/dist/tools/events.d.ts +0 -4
  65. package/dist/tools/events.d.ts.map +0 -1
  66. package/dist/tools/events.js +0 -28
  67. package/dist/tools/events.js.map +0 -1
  68. package/dist/tools/federation-admin.d.ts +0 -4
  69. package/dist/tools/federation-admin.d.ts.map +0 -1
  70. package/dist/tools/federation-admin.js +0 -567
  71. package/dist/tools/federation-admin.js.map +0 -1
  72. package/dist/tools/federation.d.ts +0 -4
  73. package/dist/tools/federation.d.ts.map +0 -1
  74. package/dist/tools/federation.js +0 -505
  75. package/dist/tools/federation.js.map +0 -1
  76. package/dist/tools/health.d.ts +0 -4
  77. package/dist/tools/health.d.ts.map +0 -1
  78. package/dist/tools/health.js +0 -25
  79. package/dist/tools/health.js.map +0 -1
  80. package/dist/tools/mandates.d.ts +0 -4
  81. package/dist/tools/mandates.d.ts.map +0 -1
  82. package/dist/tools/mandates.js +0 -227
  83. package/dist/tools/mandates.js.map +0 -1
  84. package/dist/tools/openclaw.d.ts +0 -4
  85. package/dist/tools/openclaw.d.ts.map +0 -1
  86. package/dist/tools/openclaw.js +0 -110
  87. package/dist/tools/openclaw.js.map +0 -1
  88. package/dist/tools/receipts.d.ts +0 -8
  89. package/dist/tools/receipts.d.ts.map +0 -1
  90. package/dist/tools/receipts.js +0 -111
  91. package/dist/tools/receipts.js.map +0 -1
  92. package/dist/tools/reputation.d.ts +0 -4
  93. package/dist/tools/reputation.d.ts.map +0 -1
  94. package/dist/tools/reputation.js +0 -62
  95. package/dist/tools/reputation.js.map +0 -1
  96. package/dist/tools/schemas.d.ts +0 -4
  97. package/dist/tools/schemas.d.ts.map +0 -1
  98. package/dist/tools/schemas.js +0 -453
  99. package/dist/tools/schemas.js.map +0 -1
  100. package/dist/tools/verification-keys.d.ts +0 -4
  101. package/dist/tools/verification-keys.d.ts.map +0 -1
  102. package/dist/tools/verification-keys.js +0 -27
  103. package/dist/tools/verification-keys.js.map +0 -1
  104. package/dist/tools/verification.d.ts +0 -4
  105. package/dist/tools/verification.d.ts.map +0 -1
  106. package/dist/tools/verification.js +0 -50
  107. package/dist/tools/verification.js.map +0 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The official [MCP](https://modelcontextprotocol.io) server for the [AGLedger](https://agledger.ai) API -- accountability and audit infrastructure for agentic systems.
4
4
 
5
- Connects any MCP-compatible AI agent (Claude, Cursor, Windsurf, etc.) to the AGLedger API with profile-based tool selection. No SDK code required -- just point your agent at this server.
5
+ Connects any MCP-compatible AI agent (Claude, Cursor, Windsurf, etc.) to the AGLedger API with just 2 universal tools. No SDK code required -- just point your agent at this server.
6
6
 
7
7
  ## Install
8
8
 
@@ -19,10 +19,7 @@ Add to your MCP client configuration (e.g. `claude_desktop_config.json`):
19
19
  "mcpServers": {
20
20
  "agledger": {
21
21
  "command": "agledger-mcp",
22
- "args": ["--profile", "agent"],
23
- "env": {
24
- "AGLEDGER_API_KEY": "your-api-key"
25
- }
22
+ "args": ["--api-key", "your-api-key"]
26
23
  }
27
24
  }
28
25
  }
@@ -31,23 +28,26 @@ Add to your MCP client configuration (e.g. `claude_desktop_config.json`):
31
28
  Or run directly:
32
29
 
33
30
  ```bash
34
- agledger-mcp --api-key <key> --profile agent
31
+ agledger-mcp --api-key <key> [--api-url <url>]
35
32
  ```
36
33
 
37
- ## Profiles
34
+ ## Tools
38
35
 
39
- The `--profile` flag is required. Each profile exposes a curated set of tools optimized for a specific agent persona:
36
+ | Tool | Description |
37
+ |------|-------------|
38
+ | `agledger_discover` | Returns API health, your identity, available scopes, and a quickstart workflow. Call this first. |
39
+ | `agledger_api` | Make any AGLedger API call (method, path, params). The API returns `nextSteps` on every response for self-guided workflow discovery. |
40
40
 
41
- | Profile | Tools | Use Case |
42
- |---------|-------|----------|
43
- | `agent` | ~21 | Standard agent workflow: create mandates, submit receipts, verdicts, verification |
44
- | `admin` | ~41 | Enterprise management: mandates, receipts, agents, capabilities, reputation, federation admin |
45
- | `audit` | ~36 | Compliance monitoring: mandates, receipts, events, verification, disputes, dashboard |
46
- | `schema-dev` | ~17 | Custom contract type authoring with workflow guidance |
47
- | `openclaw` | 5 | Lightweight notarization for agent-to-agent agreements |
48
- | `code` | 2 | Power-user mode: execute SDK code directly via `sdk_execute` |
49
- | `federation` | ~52 | Federation gateway operations + admin |
50
- | `full` | ~124 | All tools (development/debugging only) |
41
+ ### Agent workflow
42
+
43
+ The `agledger_discover` tool returns a quickstart workflow that guides agents through the accountability flow:
44
+
45
+ 1. `GET /v1/schemas` -- list available contract types
46
+ 2. `GET /v1/schemas/{type}` -- get required fields and examples
47
+ 3. `POST /v1/mandates` -- create a mandate
48
+ 4. `POST /v1/mandates/{id}/receipts` -- submit evidence when done
49
+
50
+ Every API error response includes a `suggestion` field with actionable recovery guidance -- agents can self-correct without human intervention.
51
51
 
52
52
  ## Configuration
53
53
 
@@ -55,8 +55,6 @@ The `--profile` flag is required. Each profile exposes a curated set of tools op
55
55
  |------|---------|-------------|
56
56
  | `--api-key` | `AGLEDGER_API_KEY` | AGLedger API key (required) |
57
57
  | `--api-url` | `AGLEDGER_API_URL` | API base URL (default: `https://agledger.example.com`) |
58
- | `--profile` | `AGLEDGER_PROFILE` | Tool profile (required) |
59
- | `--enterprise-id` | `AGLEDGER_ENTERPRISE_ID` | Enterprise ID for admin/enterprise tools |
60
58
 
61
59
  ## What is AGLedger?
62
60
 
@@ -19,7 +19,7 @@ export class ApiClient {
19
19
  const headers = {
20
20
  Authorization: `Bearer ${this.apiKey}`,
21
21
  Accept: 'application/json',
22
- 'User-Agent': 'agledger-mcp-server/2.0.0',
22
+ 'User-Agent': 'agledger-mcp-server/2.0.2',
23
23
  };
24
24
  if (options?.body !== undefined) {
25
25
  headers['Content-Type'] = 'application/json';
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@ function main() {
18
18
  strict: true,
19
19
  });
20
20
  if (values.help) {
21
- process.stderr.write(`AGLedger MCP Server v2.0.0
21
+ process.stderr.write(`AGLedger MCP Server v2.0.2
22
22
 
23
23
  Usage: agledger-mcp --api-key <key> [--api-url <url>]
24
24
 
@@ -1 +1 @@
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"}
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;AAoDD,qBAAa,iBAAiB;IAC5B,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;gBAEf,OAAO,EAAE,wBAAwB;IAa7C,OAAO,CAAC,aAAa;CAuJtB"}
package/dist/server.js CHANGED
@@ -1,25 +1,67 @@
1
1
  import { z } from 'zod';
2
2
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
  import { ApiClient } from './api-client.js';
4
+ const QUICKSTART = {
5
+ description: 'To track accountability for your work, follow these steps in order:',
6
+ steps: [
7
+ { step: 1, action: 'List available contract types', method: 'GET', path: '/v1/schemas' },
8
+ { step: 2, action: 'Get schema for your contract type', method: 'GET', path: '/v1/schemas/{contractType}' },
9
+ { step: 3, action: 'Create a mandate', method: 'POST', path: '/v1/mandates' },
10
+ { step: 4, action: 'Do your work, then submit a receipt', method: 'POST', path: '/v1/mandates/{id}/receipts' },
11
+ ],
12
+ };
13
+ const DOCS = {
14
+ quickReference: '/llms-agent.txt',
15
+ fullReference: '/llms.txt',
16
+ };
4
17
  function errorResult(message) {
5
18
  return { content: [{ type: 'text', text: `Error: ${message}` }], isError: true };
6
19
  }
20
+ function recoveryHint(status, method, path) {
21
+ if (status === 400) {
22
+ return `Check required fields. Call GET /v1/schemas to see valid contract types, or GET /v1/schemas/{type} for the exact schema.`;
23
+ }
24
+ if (status === 401) {
25
+ return 'API key is invalid or expired. Call agledger_discover to verify your identity.';
26
+ }
27
+ if (status === 403) {
28
+ return 'Your API key lacks the required scope. Check the missingScopes field above.';
29
+ }
30
+ if (status === 404) {
31
+ if (path.includes('/mandates/') && method === 'POST' && path.includes('/receipts')) {
32
+ return 'Mandate not found. Call GET /v1/mandates to list your mandates and verify the ID.';
33
+ }
34
+ return `Resource not found at ${path}. All routes start with /v1/. Call GET /llms-agent.txt for the full API reference.`;
35
+ }
36
+ if (status === 409) {
37
+ return 'Conflict — the resource state does not allow this action. Check the mandate status with GET /v1/mandates/{id}.';
38
+ }
39
+ if (status === 422) {
40
+ return 'Validation failed. Check the validationErrors field above for specific field issues. Call GET /v1/schemas/{type} for the expected format.';
41
+ }
42
+ if (status === 429) {
43
+ return 'Rate limited. Wait a moment, then retry the same request.';
44
+ }
45
+ if (status >= 500) {
46
+ return 'Server error. Retry the same request. If it persists, try GET /health to check API status.';
47
+ }
48
+ return `Unexpected status ${status}. Try GET /health to verify API status.`;
49
+ }
7
50
  export class AgledgerMcpServer {
8
51
  mcp;
9
52
  client;
10
53
  constructor(options) {
11
54
  const apiUrl = options.apiUrl ?? 'https://agledger.example.com';
12
55
  this.client = new ApiClient(apiUrl, options.apiKey);
13
- this.mcp = new McpServer({ name: 'agledger-mcp-server', version: '2.0.0' }, { capabilities: { tools: {} } });
56
+ this.mcp = new McpServer({ name: 'agledger-mcp-server', version: '2.0.2' }, { capabilities: { tools: {} } });
14
57
  this.registerTools();
15
58
  }
16
59
  registerTools() {
17
60
  const client = this.client;
18
61
  this.mcp.registerTool('agledger_discover', {
19
62
  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.',
63
+ description: 'Returns API health, your identity, available scopes, and a quickstart workflow. ' +
64
+ 'Call this first. The response tells you who you are and what to do next.',
23
65
  inputSchema: {},
24
66
  annotations: {
25
67
  readOnlyHint: true,
@@ -52,6 +94,8 @@ export class AgledgerMcpServer {
52
94
  : String(identity.reason),
53
95
  };
54
96
  }
97
+ result.quickstart = QUICKSTART;
98
+ result.docs = DOCS;
55
99
  return { content: [], structuredContent: result };
56
100
  }
57
101
  catch (err) {
@@ -60,13 +104,20 @@ export class AgledgerMcpServer {
60
104
  });
61
105
  this.mcp.registerTool('agledger_api', {
62
106
  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. ' +
107
+ description: 'Make any AGLedger API call. All paths start with /v1/. ' +
108
+ 'The API returns nextSteps on every response — follow them. Workflow: ' +
109
+ '1. GET /v1/schemas — list contract types. ' +
110
+ '2. GET /v1/schemas/{type} — get required fields and examples. ' +
111
+ '3. POST /v1/mandates — create a mandate. ' +
112
+ '4. POST /v1/mandates/{id}/receipts — submit evidence when done. ' +
113
+ 'If a call fails, read the suggestion field in the error response. ' +
114
+ 'For full API docs: GET /llms-agent.txt. ' +
66
115
  'For GET/DELETE, params become query parameters. For POST/PUT/PATCH, params become the JSON body.',
67
116
  inputSchema: {
68
117
  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)'),
118
+ path: z
119
+ .string()
120
+ .describe('API path starting with / (e.g. /v1/mandates, /v1/schemas, /v1/mandates/{id}/receipts)'),
70
121
  params: z
71
122
  .record(z.string(), z.unknown())
72
123
  .optional()
@@ -82,7 +133,8 @@ export class AgledgerMcpServer {
82
133
  try {
83
134
  const { method, path, params } = args;
84
135
  if (!path.startsWith('/')) {
85
- return errorResult('Path must start with /');
136
+ return errorResult('PATH_INVALID: Path must start with /. All API routes use /v1/ prefix. ' +
137
+ 'Example: /v1/mandates, /v1/schemas. Call agledger_discover for the full workflow.');
86
138
  }
87
139
  const options = {};
88
140
  if (params) {
@@ -104,6 +156,9 @@ export class AgledgerMcpServer {
104
156
  const message = (errorBody.message ??
105
157
  errorBody.error ??
106
158
  `API returned ${response.status}`);
159
+ if (!errorBody.suggestion) {
160
+ errorBody.suggestion = recoveryHint(response.status, method, path);
161
+ }
107
162
  return {
108
163
  content: [{ type: 'text', text: `Error: ${message}` }],
109
164
  structuredContent: errorBody,
@@ -112,10 +167,12 @@ export class AgledgerMcpServer {
112
167
  }
113
168
  catch (err) {
114
169
  if (err instanceof DOMException && err.name === 'AbortError') {
115
- return errorResult('Request timed out. The API did not respond within 30 seconds.');
170
+ return errorResult('TIMEOUT: The API did not respond within 30 seconds. ' +
171
+ 'Retry the same request. If it fails again, try GET /health to check API status.');
116
172
  }
117
173
  if (err instanceof TypeError && err.message.includes('fetch')) {
118
- return errorResult(`Network error: ${err.message}. Check API URL and connectivity.`);
174
+ return errorResult(`NETWORK_ERROR: ${err.message}. ` +
175
+ 'Check that the API URL is correct. Try GET /health to verify connectivity.');
119
176
  }
120
177
  return errorResult(err instanceof Error ? err.message : String(err));
121
178
  }
@@ -1 +1 @@
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,E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2.0.2",
4
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",
package/src/api-client.ts CHANGED
@@ -36,7 +36,7 @@ export class ApiClient {
36
36
  const headers: Record<string, string> = {
37
37
  Authorization: `Bearer ${this.apiKey}`,
38
38
  Accept: 'application/json',
39
- 'User-Agent': 'agledger-mcp-server/2.0.0',
39
+ 'User-Agent': 'agledger-mcp-server/2.0.2',
40
40
  };
41
41
 
42
42
  if (options?.body !== undefined) {
package/src/index.ts CHANGED
@@ -25,7 +25,7 @@ function main(): void {
25
25
 
26
26
  if (values.help) {
27
27
  process.stderr.write(
28
- `AGLedger MCP Server v2.0.0
28
+ `AGLedger MCP Server v2.0.2
29
29
 
30
30
  Usage: agledger-mcp --api-key <key> [--api-url <url>]
31
31
 
package/src/server.ts CHANGED
@@ -8,10 +8,56 @@ export interface AgledgerMcpServerOptions {
8
8
  apiUrl?: string;
9
9
  }
10
10
 
11
+ const QUICKSTART = {
12
+ description: 'To track accountability for your work, follow these steps in order:',
13
+ steps: [
14
+ { step: 1, action: 'List available contract types', method: 'GET', path: '/v1/schemas' },
15
+ { step: 2, action: 'Get schema for your contract type', method: 'GET', path: '/v1/schemas/{contractType}' },
16
+ { step: 3, action: 'Create a mandate', method: 'POST', path: '/v1/mandates' },
17
+ { step: 4, action: 'Do your work, then submit a receipt', method: 'POST', path: '/v1/mandates/{id}/receipts' },
18
+ ],
19
+ } as const;
20
+
21
+ const DOCS = {
22
+ quickReference: '/llms-agent.txt',
23
+ fullReference: '/llms.txt',
24
+ } as const;
25
+
11
26
  function errorResult(message: string): CallToolResult {
12
27
  return { content: [{ type: 'text', text: `Error: ${message}` }], isError: true };
13
28
  }
14
29
 
30
+ function recoveryHint(status: number, method: string, path: string): string {
31
+ if (status === 400) {
32
+ return `Check required fields. Call GET /v1/schemas to see valid contract types, or GET /v1/schemas/{type} for the exact schema.`;
33
+ }
34
+ if (status === 401) {
35
+ return 'API key is invalid or expired. Call agledger_discover to verify your identity.';
36
+ }
37
+ if (status === 403) {
38
+ return 'Your API key lacks the required scope. Check the missingScopes field above.';
39
+ }
40
+ if (status === 404) {
41
+ if (path.includes('/mandates/') && method === 'POST' && path.includes('/receipts')) {
42
+ return 'Mandate not found. Call GET /v1/mandates to list your mandates and verify the ID.';
43
+ }
44
+ return `Resource not found at ${path}. All routes start with /v1/. Call GET /llms-agent.txt for the full API reference.`;
45
+ }
46
+ if (status === 409) {
47
+ return 'Conflict — the resource state does not allow this action. Check the mandate status with GET /v1/mandates/{id}.';
48
+ }
49
+ if (status === 422) {
50
+ return 'Validation failed. Check the validationErrors field above for specific field issues. Call GET /v1/schemas/{type} for the expected format.';
51
+ }
52
+ if (status === 429) {
53
+ return 'Rate limited. Wait a moment, then retry the same request.';
54
+ }
55
+ if (status >= 500) {
56
+ return 'Server error. Retry the same request. If it persists, try GET /health to check API status.';
57
+ }
58
+ return `Unexpected status ${status}. Try GET /health to verify API status.`;
59
+ }
60
+
15
61
  export class AgledgerMcpServer {
16
62
  readonly mcp: McpServer;
17
63
  readonly client: ApiClient;
@@ -22,7 +68,7 @@ export class AgledgerMcpServer {
22
68
  this.client = new ApiClient(apiUrl, options.apiKey);
23
69
 
24
70
  this.mcp = new McpServer(
25
- { name: 'agledger-mcp-server', version: '2.0.0' },
71
+ { name: 'agledger-mcp-server', version: '2.0.2' },
26
72
  { capabilities: { tools: {} } },
27
73
  );
28
74
 
@@ -37,9 +83,8 @@ export class AgledgerMcpServer {
37
83
  {
38
84
  title: 'Discover AGLedger API',
39
85
  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.',
86
+ 'Returns API health, your identity, available scopes, and a quickstart workflow. ' +
87
+ 'Call this first. The response tells you who you are and what to do next.',
43
88
  inputSchema: {},
44
89
  annotations: {
45
90
  readOnlyHint: true,
@@ -76,6 +121,9 @@ export class AgledgerMcpServer {
76
121
  };
77
122
  }
78
123
 
124
+ result.quickstart = QUICKSTART;
125
+ result.docs = DOCS;
126
+
79
127
  return { content: [], structuredContent: result };
80
128
  } catch (err) {
81
129
  return errorResult(err instanceof Error ? err.message : String(err));
@@ -88,13 +136,20 @@ export class AgledgerMcpServer {
88
136
  {
89
137
  title: 'AGLedger API',
90
138
  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. ' +
139
+ 'Make any AGLedger API call. All paths start with /v1/. ' +
140
+ 'The API returns nextSteps on every response — follow them. Workflow: ' +
141
+ '1. GET /v1/schemas — list contract types. ' +
142
+ '2. GET /v1/schemas/{type} — get required fields and examples. ' +
143
+ '3. POST /v1/mandates — create a mandate. ' +
144
+ '4. POST /v1/mandates/{id}/receipts — submit evidence when done. ' +
145
+ 'If a call fails, read the suggestion field in the error response. ' +
146
+ 'For full API docs: GET /llms-agent.txt. ' +
94
147
  'For GET/DELETE, params become query parameters. For POST/PUT/PATCH, params become the JSON body.',
95
148
  inputSchema: {
96
149
  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)'),
150
+ path: z
151
+ .string()
152
+ .describe('API path starting with / (e.g. /v1/mandates, /v1/schemas, /v1/mandates/{id}/receipts)'),
98
153
  params: z
99
154
  .record(z.string(), z.unknown())
100
155
  .optional()
@@ -114,7 +169,10 @@ export class AgledgerMcpServer {
114
169
  const { method, path, params } = args;
115
170
 
116
171
  if (!path.startsWith('/')) {
117
- return errorResult('Path must start with /');
172
+ return errorResult(
173
+ 'PATH_INVALID: Path must start with /. All API routes use /v1/ prefix. ' +
174
+ 'Example: /v1/mandates, /v1/schemas. Call agledger_discover for the full workflow.',
175
+ );
118
176
  }
119
177
 
120
178
  const options: { query?: Record<string, unknown>; body?: unknown } = {};
@@ -141,6 +199,10 @@ export class AgledgerMcpServer {
141
199
  errorBody.error ??
142
200
  `API returned ${response.status}`) as string;
143
201
 
202
+ if (!errorBody.suggestion) {
203
+ errorBody.suggestion = recoveryHint(response.status, method, path);
204
+ }
205
+
144
206
  return {
145
207
  content: [{ type: 'text', text: `Error: ${message}` }],
146
208
  structuredContent: errorBody,
@@ -148,10 +210,16 @@ export class AgledgerMcpServer {
148
210
  };
149
211
  } catch (err) {
150
212
  if (err instanceof DOMException && err.name === 'AbortError') {
151
- return errorResult('Request timed out. The API did not respond within 30 seconds.');
213
+ return errorResult(
214
+ 'TIMEOUT: The API did not respond within 30 seconds. ' +
215
+ 'Retry the same request. If it fails again, try GET /health to check API status.',
216
+ );
152
217
  }
153
218
  if (err instanceof TypeError && err.message.includes('fetch')) {
154
- return errorResult(`Network error: ${err.message}. Check API URL and connectivity.`);
219
+ return errorResult(
220
+ `NETWORK_ERROR: ${err.message}. ` +
221
+ 'Check that the API URL is correct. Try GET /health to verify connectivity.',
222
+ );
155
223
  }
156
224
  return errorResult(err instanceof Error ? err.message : String(err));
157
225
  }
@@ -28,12 +28,16 @@ describe('tool registration', () => {
28
28
  expect(tool).toBeDefined();
29
29
  expect(tool!.description).toContain('health');
30
30
  expect(tool!.description).toContain('identity');
31
+ expect(tool!.description).toContain('quickstart');
31
32
  });
32
33
 
33
34
  it('registers agledger_api', () => {
34
35
  const tool = tools.find((t) => t.name === 'agledger_api');
35
36
  expect(tool).toBeDefined();
36
37
  expect(tool!.description).toContain('nextSteps');
38
+ expect(tool!.description).toContain('/v1/');
39
+ expect(tool!.description).toContain('/v1/schemas');
40
+ expect(tool!.description).toContain('/v1/mandates');
37
41
  });
38
42
  });
39
43
 
@@ -61,6 +65,17 @@ describe('agledger_discover', () => {
61
65
  const content = result.structuredContent as Record<string, unknown>;
62
66
  expect(content.health).toEqual({ status: 'ok', version: '1.0.0' });
63
67
  expect(content.identity).toEqual({ agentId: 'agent-1', scopes: ['mandates:read'] });
68
+
69
+ // Quickstart workflow is always present
70
+ const quickstart = content.quickstart as { steps: Array<{ step: number; path: string }> };
71
+ expect(quickstart.steps).toHaveLength(4);
72
+ expect(quickstart.steps[0].path).toBe('/v1/schemas');
73
+ expect(quickstart.steps[2].path).toBe('/v1/mandates');
74
+
75
+ // Docs links are always present
76
+ const docs = content.docs as { quickReference: string; fullReference: string };
77
+ expect(docs.quickReference).toBe('/llms-agent.txt');
78
+ expect(docs.fullReference).toBe('/llms.txt');
64
79
  });
65
80
 
66
81
  it('returns partial results when one call fails', async () => {
@@ -192,7 +207,7 @@ describe('agledger_api', () => {
192
207
  expect(content.missingScopes).toEqual(['mandates:write']);
193
208
  });
194
209
 
195
- it('rejects path not starting with /', async () => {
210
+ it('rejects path not starting with / with recovery directive', async () => {
196
211
  const result = await harness.client.callTool({
197
212
  name: 'agledger_api',
198
213
  arguments: { method: 'GET', path: 'mandates' },
@@ -200,10 +215,63 @@ describe('agledger_api', () => {
200
215
 
201
216
  expect(result.isError).toBe(true);
202
217
  const text = (result.content as Array<{ type: string; text: string }>)[0].text;
203
- expect(text).toContain('Path must start with /');
218
+ expect(text).toContain('PATH_INVALID');
219
+ expect(text).toContain('/v1/');
220
+ expect(text).toContain('agledger_discover');
221
+ });
222
+
223
+ it('enriches API errors with recovery hint when suggestion is missing', async () => {
224
+ const errorBody = {
225
+ message: 'Invalid contract type',
226
+ code: 'BAD_REQUEST',
227
+ };
228
+ vi.stubGlobal(
229
+ 'fetch',
230
+ vi.fn().mockResolvedValueOnce(
231
+ new Response(JSON.stringify(errorBody), {
232
+ status: 400,
233
+ headers: { 'content-type': 'application/json' },
234
+ }),
235
+ ),
236
+ );
237
+
238
+ const result = await harness.client.callTool({
239
+ name: 'agledger_api',
240
+ arguments: { method: 'POST', path: '/v1/mandates', params: { contractType: 'INVALID' } },
241
+ });
242
+
243
+ expect(result.isError).toBe(true);
244
+ const content = result.structuredContent as Record<string, unknown>;
245
+ expect(content.suggestion).toContain('/v1/schemas');
246
+ });
247
+
248
+ it('preserves existing API suggestion without overwriting', async () => {
249
+ const errorBody = {
250
+ message: 'Mandate not found',
251
+ code: 'NOT_FOUND',
252
+ suggestion: 'The mandate may have been deleted.',
253
+ };
254
+ vi.stubGlobal(
255
+ 'fetch',
256
+ vi.fn().mockResolvedValueOnce(
257
+ new Response(JSON.stringify(errorBody), {
258
+ status: 404,
259
+ headers: { 'content-type': 'application/json' },
260
+ }),
261
+ ),
262
+ );
263
+
264
+ const result = await harness.client.callTool({
265
+ name: 'agledger_api',
266
+ arguments: { method: 'GET', path: '/v1/mandates/bad-id' },
267
+ });
268
+
269
+ expect(result.isError).toBe(true);
270
+ const content = result.structuredContent as Record<string, unknown>;
271
+ expect(content.suggestion).toBe('The mandate may have been deleted.');
204
272
  });
205
273
 
206
- it('handles network errors without crashing', async () => {
274
+ it('handles network errors with recovery directive', async () => {
207
275
  vi.stubGlobal(
208
276
  'fetch',
209
277
  vi.fn().mockRejectedValueOnce(new TypeError('fetch failed: DNS resolution failed')),
@@ -216,10 +284,11 @@ describe('agledger_api', () => {
216
284
 
217
285
  expect(result.isError).toBe(true);
218
286
  const text = (result.content as Array<{ type: string; text: string }>)[0].text;
219
- expect(text).toContain('Network error');
287
+ expect(text).toContain('NETWORK_ERROR');
288
+ expect(text).toContain('/health');
220
289
  });
221
290
 
222
- it('handles timeout without crashing', async () => {
291
+ it('handles timeout with recovery directive', async () => {
223
292
  vi.stubGlobal(
224
293
  'fetch',
225
294
  vi
@@ -236,7 +305,8 @@ describe('agledger_api', () => {
236
305
 
237
306
  expect(result.isError).toBe(true);
238
307
  const text = (result.content as Array<{ type: string; text: string }>)[0].text;
239
- expect(text).toContain('timed out');
308
+ expect(text).toContain('TIMEOUT');
309
+ expect(text).toContain('Retry');
240
310
  });
241
311
 
242
312
  it('handles non-JSON responses', async () => {