@agledger/mcp-server 2.3.1 → 2.3.3
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/CHANGELOG.md +35 -0
- package/dist/api-client.d.ts.map +1 -1
- package/dist/api-client.js +2 -1
- package/dist/api-client.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +73 -26
- package/dist/server.js.map +1 -1
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/package.json +7 -1
- package/src/api-client.ts +0 -72
- package/src/index.ts +0 -69
- package/src/server.ts +0 -326
- package/src/verify/verify-export.ts +0 -296
- package/tests/api-client.test.ts +0 -147
- package/tests/harness.ts +0 -28
- package/tests/integration.test.ts +0 -373
- package/tests/server.test.ts +0 -500
- package/tsconfig.json +0 -12
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,41 @@ All notable changes to the AGLedger MCP Server will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/), and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [2.3.3] - 2026-05-06
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- **Gemini-MCP integrations no longer break on the first non-trivial call.** The three free-form object fields (`agledger_api.params`, `agledger_verify.export`, `agledger_verify.publicKeys`) were emitting `additionalProperties: {}` on a properties-less OBJECT — both keywords are outside Gemini's strict OpenAPI 3.0 function-call grammar, so any non-trivial body returned `MALFORMED_FUNCTION_CALL`. Each field is now declared as a JSON-encoded `string` on the wire (Gemini-friendly) and parsed server-side. Object-native runtimes (Claude Desktop, ChatGPT MCP) keep working — the server accepts either a stringified-JSON string or a native object via a Zod preprocess. Tool descriptions document the JSON-encoded shape with examples. (testbed F-532 / agledger-agents#67)
|
|
12
|
+
|
|
13
|
+
### Tests
|
|
14
|
+
|
|
15
|
+
- Added Gemini-shape regressions covering all three affected fields: stringified-JSON path, native-object path (back-compat), and malformed-JSON error path. The new `INVALID_JSON` error code surfaces a structured suggestion telling the agent how to retry.
|
|
16
|
+
|
|
17
|
+
## [2.3.2] - 2026-05-06
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- **Tool results are now visible to LLM-driven MCP runtimes.** Previously every tool returned `content: []` with all data in `structuredContent`. Per MCP spec 2025-06-18, structured content SHOULD also be returned as functionally-equivalent unstructured content; LLM clients (Claude Desktop, ChatGPT MCP, Cursor, OpenAI tool-mapped runtimes) only forward `content[]` to the model, so they saw empty results and stopped. All three tools (`agledger_discover`, `agledger_api`, `agledger_verify`) now mirror `structuredContent` into a single TextContent block on every success and error path. (testbed F-531 / agledger-agents#66)
|
|
22
|
+
- **`serverInfo.version`, `User-Agent`, and `--help` banner no longer drift from `package.json`.** All three read the version from `package.json` at runtime via a shared `version.ts` module instead of duplicating the literal. v2.3.1 shipped `serverInfo.version: 2.3.0` and `User-Agent: agledger-mcp-server/2.2.0`; that class of drift is now structurally impossible.
|
|
23
|
+
- **`--help` banner lists all three tools.** `agledger_verify` was missing from the Tools section.
|
|
24
|
+
- **`mirrorContent` no longer pretty-prints.** The text mirror is consumed by an LLM, not a human — dropping the 2-space indent saves ~25% on agent context tokens for large paginated responses.
|
|
25
|
+
|
|
26
|
+
### Build
|
|
27
|
+
|
|
28
|
+
- Added a `files` allowlist to `package.json` so the npm tarball only ships `dist/`, `LICENSE`, `README.md`, `CHANGELOG.md`, and `package.json` (24 files vs. 29 in 2.3.1). No more shipping `tests/` or `tsconfig.json`.
|
|
29
|
+
|
|
30
|
+
### Tests
|
|
31
|
+
|
|
32
|
+
- Added `assertContentMirrorsStructured` helper and a dedicated F-531 regression suite covering success and error paths on all three tools, plus a parity test asserting `SERVER_VERSION` matches `package.json`.
|
|
33
|
+
|
|
34
|
+
## [2.3.1] - 2026-04-30
|
|
35
|
+
|
|
36
|
+
Tracks AGLedger API v0.22.13. The MCP server is a thin pass-through, so all 10 new v0.22.x routes (`/v1/admin/strings/*`, federation gateway status, peer directory, vault checkpoints, dispute withdraw, etc.) are reachable via `agledger_api` with no surface changes.
|
|
37
|
+
|
|
38
|
+
### Changed
|
|
39
|
+
|
|
40
|
+
- Re-published as part of the v0.7.1 SDK/CLI sweep tracking API v0.22.13. No tool-surface changes.
|
|
41
|
+
|
|
7
42
|
## [2.3.0] - 2026-04-27
|
|
8
43
|
|
|
9
44
|
Tracks AGLedger API v0.21.5. Every `/v1/mandates/*` route is now `/v1/records/*`; `Contract Type` is `Type`. The MCP server is a thin pass-through, so this release sweeps tool descriptions, the quickstart returned by `agledger_discover`, and the offline verifier's field names.
|
package/dist/api-client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"AAEA,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"}
|
package/dist/api-client.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SERVER_VERSION } from './version.js';
|
|
1
2
|
export class ApiClient {
|
|
2
3
|
apiUrl;
|
|
3
4
|
apiKey;
|
|
@@ -19,7 +20,7 @@ export class ApiClient {
|
|
|
19
20
|
const headers = {
|
|
20
21
|
Authorization: `Bearer ${this.apiKey}`,
|
|
21
22
|
Accept: 'application/json',
|
|
22
|
-
'User-Agent':
|
|
23
|
+
'User-Agent': `agledger-mcp-server/${SERVER_VERSION}`,
|
|
23
24
|
};
|
|
24
25
|
if (options?.body !== undefined) {
|
|
25
26
|
headers['Content-Type'] = 'application/json';
|
package/dist/api-client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAQ9C,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,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,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;YAC1B,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;gBAC9B,IAAI,GAAG,EAAE,IAAI,EAAE,IAAI,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":";AAoEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,YAAY,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { parseArgs } from 'node:util';
|
|
3
3
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
-
import { AgledgerMcpServer } from './server.js';
|
|
4
|
+
import { AgledgerMcpServer, SERVER_VERSION } from './server.js';
|
|
5
5
|
process.on('uncaughtException', (err) => {
|
|
6
6
|
process.stderr.write(`Uncaught exception: ${err.message}\n`);
|
|
7
7
|
});
|
|
@@ -18,7 +18,7 @@ function main() {
|
|
|
18
18
|
strict: true,
|
|
19
19
|
});
|
|
20
20
|
if (values.help) {
|
|
21
|
-
process.stderr.write(`AGLedger MCP Server
|
|
21
|
+
process.stderr.write(`AGLedger MCP Server v${SERVER_VERSION}
|
|
22
22
|
|
|
23
23
|
Usage: agledger-mcp --api-key <key> [--api-url <url>]
|
|
24
24
|
|
|
@@ -30,6 +30,7 @@ Options:
|
|
|
30
30
|
Tools:
|
|
31
31
|
agledger_discover Returns API health, your identity, and available scopes
|
|
32
32
|
agledger_api Make any AGLedger API call — the API guides you via nextSteps
|
|
33
|
+
agledger_verify Verify an audit export offline (hash chain + Ed25519)
|
|
33
34
|
`);
|
|
34
35
|
process.exit(0);
|
|
35
36
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEhE,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;IACtC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,uBAAuB,GAAG,CAAC,OAAO,IAAI,CAAC,CAAC;AAC/D,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,EAAE;IAC1C,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,wBAAwB,MAAM,YAAY,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CACtF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,SAA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M,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,5 +1,7 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import { ApiClient } from './api-client.js';
|
|
3
|
+
import { SERVER_VERSION } from './version.js';
|
|
4
|
+
export { SERVER_VERSION };
|
|
3
5
|
export interface AgledgerMcpServerOptions {
|
|
4
6
|
apiKey: string;
|
|
5
7
|
apiUrl?: string;
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGpE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGpE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,cAAc,EAAE,CAAC;AAE1B,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAmFD,qBAAa,iBAAiB;IAC5B,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;gBAEf,OAAO,EAAE,wBAAwB;IAc7C,OAAO,CAAC,aAAa;IA+OrB,OAAO,CAAC,iBAAiB;CAkC1B"}
|
package/dist/server.js
CHANGED
|
@@ -2,6 +2,8 @@ import { z } from 'zod';
|
|
|
2
2
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
3
|
import { verifyExport } from './verify/verify-export.js';
|
|
4
4
|
import { ApiClient } from './api-client.js';
|
|
5
|
+
import { SERVER_VERSION } from './version.js';
|
|
6
|
+
export { SERVER_VERSION };
|
|
5
7
|
const QUICKSTART = {
|
|
6
8
|
description: 'To track accountability for your work, follow these steps in order:',
|
|
7
9
|
steps: [
|
|
@@ -17,6 +19,11 @@ const DOCS = {
|
|
|
17
19
|
openapi: '/openapi.json',
|
|
18
20
|
openapiResource: 'agledger://openapi',
|
|
19
21
|
};
|
|
22
|
+
// MCP spec 2025-06-18: structuredContent SHOULD also surface as content[]
|
|
23
|
+
// because most LLM-driven runtimes ignore structuredContent.
|
|
24
|
+
function mirrorContent(structured) {
|
|
25
|
+
return [{ type: 'text', text: JSON.stringify(structured) }];
|
|
26
|
+
}
|
|
20
27
|
/**
|
|
21
28
|
* Structured error for CLI-origin failures (network, timeout, malformed input).
|
|
22
29
|
* API-origin errors are forwarded verbatim without enrichment — if the API
|
|
@@ -29,18 +36,44 @@ function errorResult(message, code, suggestion) {
|
|
|
29
36
|
if (suggestion)
|
|
30
37
|
structuredContent.suggestion = suggestion;
|
|
31
38
|
return {
|
|
32
|
-
content:
|
|
39
|
+
content: mirrorContent(structuredContent),
|
|
33
40
|
structuredContent,
|
|
34
41
|
isError: true,
|
|
35
42
|
};
|
|
36
43
|
}
|
|
44
|
+
// Free-form object fields are declared as `string` on the wire so Gemini's
|
|
45
|
+
// function-call grammar (a strict OpenAPI 3.0 subset that rejects
|
|
46
|
+
// `additionalProperties` and properties-less OBJECT) can emit them. Preprocess
|
|
47
|
+
// keeps the door open for object-native runtimes (Claude Desktop, ChatGPT MCP)
|
|
48
|
+
// that pass a native object — it re-stringifies before validation, then the
|
|
49
|
+
// handler JSON.parses uniformly.
|
|
50
|
+
const jsonStringField = z.preprocess((v) => (v !== null && typeof v === 'object' ? JSON.stringify(v) : v), z.string());
|
|
51
|
+
function parseJsonObject(value, fieldName) {
|
|
52
|
+
let parsed;
|
|
53
|
+
try {
|
|
54
|
+
parsed = JSON.parse(value);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
return {
|
|
58
|
+
ok: false,
|
|
59
|
+
error: errorResult(`Argument \`${fieldName}\` is not valid JSON: ${err instanceof Error ? err.message : String(err)}`, 'INVALID_JSON', `Pass \`${fieldName}\` as a JSON-encoded string (e.g. '{"key":"value"}') or as a native object.`),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
63
|
+
return {
|
|
64
|
+
ok: false,
|
|
65
|
+
error: errorResult(`Argument \`${fieldName}\` must decode to a JSON object.`, 'INVALID_JSON', `Pass \`${fieldName}\` as a JSON object, e.g. '{"key":"value"}'.`),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return { ok: true, value: parsed };
|
|
69
|
+
}
|
|
37
70
|
export class AgledgerMcpServer {
|
|
38
71
|
mcp;
|
|
39
72
|
client;
|
|
40
73
|
constructor(options) {
|
|
41
74
|
const apiUrl = options.apiUrl ?? 'https://agledger.example.com';
|
|
42
75
|
this.client = new ApiClient(apiUrl, options.apiKey, options.timeoutMs);
|
|
43
|
-
this.mcp = new McpServer({ name: 'agledger-mcp-server', version:
|
|
76
|
+
this.mcp = new McpServer({ name: 'agledger-mcp-server', version: SERVER_VERSION }, { capabilities: { tools: {}, resources: {} } });
|
|
44
77
|
this.registerTools();
|
|
45
78
|
this.registerResources();
|
|
46
79
|
}
|
|
@@ -88,7 +121,7 @@ export class AgledgerMcpServer {
|
|
|
88
121
|
}
|
|
89
122
|
result.quickstart = QUICKSTART;
|
|
90
123
|
result.docs = DOCS;
|
|
91
|
-
return { content:
|
|
124
|
+
return { content: mirrorContent(result), structuredContent: result };
|
|
92
125
|
}
|
|
93
126
|
catch (err) {
|
|
94
127
|
return errorResult(err instanceof Error ? err.message : String(err), 'DISCOVER_FAILED');
|
|
@@ -110,10 +143,11 @@ export class AgledgerMcpServer {
|
|
|
110
143
|
path: z
|
|
111
144
|
.string()
|
|
112
145
|
.describe('API path starting with / (e.g. /v1/records, /v1/schemas, /v1/records/{id}/receipts)'),
|
|
113
|
-
params:
|
|
114
|
-
.record(z.string(), z.unknown())
|
|
146
|
+
params: jsonStringField
|
|
115
147
|
.optional()
|
|
116
|
-
.describe('Request parameters
|
|
148
|
+
.describe('Request parameters as a JSON-encoded string, e.g. \'{"type":"ACH-PROC-v1","platform":"my-app"}\'. ' +
|
|
149
|
+
'For GET/DELETE: becomes query parameters. For POST/PUT/PATCH: becomes the JSON body. ' +
|
|
150
|
+
'Native JSON objects are also accepted for compatibility.'),
|
|
117
151
|
},
|
|
118
152
|
annotations: {
|
|
119
153
|
readOnlyHint: false,
|
|
@@ -129,29 +163,30 @@ export class AgledgerMcpServer {
|
|
|
129
163
|
'Example: /v1/records, /v1/schemas. Call agledger_discover for the full workflow.', 'PATH_INVALID', 'Prefix the path with /v1/ (e.g. /v1/records). Call agledger_discover if unsure which path to use.');
|
|
130
164
|
}
|
|
131
165
|
const options = {};
|
|
132
|
-
if (params) {
|
|
166
|
+
if (params !== undefined && params !== '') {
|
|
167
|
+
const decoded = parseJsonObject(params, 'params');
|
|
168
|
+
if (!decoded.ok)
|
|
169
|
+
return decoded.error;
|
|
133
170
|
if (method === 'GET' || method === 'DELETE') {
|
|
134
|
-
options.query =
|
|
171
|
+
options.query = decoded.value;
|
|
135
172
|
}
|
|
136
173
|
else {
|
|
137
|
-
options.body =
|
|
174
|
+
options.body = decoded.value;
|
|
138
175
|
}
|
|
139
176
|
}
|
|
140
177
|
const response = await client.request(method, path, options);
|
|
141
178
|
if (response.ok) {
|
|
179
|
+
const body = response.body;
|
|
142
180
|
return {
|
|
143
|
-
content:
|
|
144
|
-
structuredContent:
|
|
181
|
+
content: mirrorContent(body),
|
|
182
|
+
structuredContent: body,
|
|
145
183
|
};
|
|
146
184
|
}
|
|
147
185
|
// Forward the API error body verbatim. The API owns error guidance;
|
|
148
186
|
// the MCP does not enrich, translate, or inject suggestions.
|
|
149
187
|
const errorBody = (response.body ?? {});
|
|
150
|
-
const message = (errorBody.message ??
|
|
151
|
-
errorBody.error ??
|
|
152
|
-
`API returned ${response.status}`);
|
|
153
188
|
return {
|
|
154
|
-
content:
|
|
189
|
+
content: mirrorContent(errorBody),
|
|
155
190
|
structuredContent: errorBody,
|
|
156
191
|
isError: true,
|
|
157
192
|
};
|
|
@@ -176,14 +211,14 @@ export class AgledgerMcpServer {
|
|
|
176
211
|
'position_gap, malformed_entry, unsupported_algorithm). ' +
|
|
177
212
|
'Obtain the export via agledger_api with method=GET, path=/v1/records/{id}/audit-export.',
|
|
178
213
|
inputSchema: {
|
|
179
|
-
export:
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
publicKeys:
|
|
183
|
-
.record(z.string(), z.string())
|
|
214
|
+
export: jsonStringField.describe('The audit export as a JSON-encoded string (the response body from ' +
|
|
215
|
+
'GET /v1/records/{id}/audit-export, JSON.stringify\'d). Native JSON ' +
|
|
216
|
+
'objects are also accepted for compatibility.'),
|
|
217
|
+
publicKeys: jsonStringField
|
|
184
218
|
.optional()
|
|
185
|
-
.describe('Optional map of signingKeyId → SPKI DER base64 public key
|
|
186
|
-
'
|
|
219
|
+
.describe('Optional map of signingKeyId → SPKI DER base64 public key, as a JSON-encoded ' +
|
|
220
|
+
'string, e.g. \'{"key-1":"MCowBQYDK2VwAyEA..."}\'. Merged over any keys embedded ' +
|
|
221
|
+
'in the export. Native JSON objects are also accepted.'),
|
|
187
222
|
requireKeyId: z
|
|
188
223
|
.string()
|
|
189
224
|
.optional()
|
|
@@ -198,17 +233,29 @@ export class AgledgerMcpServer {
|
|
|
198
233
|
},
|
|
199
234
|
}, async (args) => {
|
|
200
235
|
try {
|
|
201
|
-
const { export:
|
|
202
|
-
|
|
236
|
+
const { export: exportRaw, publicKeys: publicKeysRaw, requireKeyId } = args;
|
|
237
|
+
const decodedExport = parseJsonObject(exportRaw, 'export');
|
|
238
|
+
if (!decodedExport.ok)
|
|
239
|
+
return decodedExport.error;
|
|
240
|
+
const exportData = decodedExport.value;
|
|
241
|
+
if (!('entries' in exportData)) {
|
|
203
242
|
return errorResult('Input is not a valid audit export. Expected an object with exportMetadata and entries.', 'INVALID_EXPORT', 'Call agledger_api with method=GET and path=/v1/records/{id}/audit-export, then pass the response body as the `export` argument.');
|
|
204
243
|
}
|
|
244
|
+
let publicKeys;
|
|
245
|
+
if (publicKeysRaw !== undefined && publicKeysRaw !== '') {
|
|
246
|
+
const decodedKeys = parseJsonObject(publicKeysRaw, 'publicKeys');
|
|
247
|
+
if (!decodedKeys.ok)
|
|
248
|
+
return decodedKeys.error;
|
|
249
|
+
publicKeys = decodedKeys.value;
|
|
250
|
+
}
|
|
205
251
|
const result = verifyExport(exportData, {
|
|
206
252
|
publicKeys,
|
|
207
253
|
requireKeyId,
|
|
208
254
|
});
|
|
255
|
+
const structured = result;
|
|
209
256
|
return {
|
|
210
|
-
content:
|
|
211
|
-
structuredContent:
|
|
257
|
+
content: mirrorContent(structured),
|
|
258
|
+
structuredContent: structured,
|
|
212
259
|
isError: !result.valid,
|
|
213
260
|
};
|
|
214
261
|
}
|
package/dist/server.js.map
CHANGED
|
@@ -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,YAAY,EAA0B,MAAM,2BAA2B,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+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MAAM,CAAC;QAE3B;;;;;WAKG;QACH,IAAI,CAAC,GAAG,CAAC,gBAAgB,CACvB,kBAAkB,EAClB,oBAAoB,EACpB;YACE,WAAW,EACT,iIAAiI;YACnI,QAAQ,EAAE,kBAAkB;SAC7B,EACD,KAAK,IAAI,EAAE;YACT,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC;YAC9D,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,uCAAuC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;YAC5E,CAAC;YACD,OAAO;gBACL,QAAQ,EAAE;oBACR;wBACE,GAAG,EAAE,oBAAoB;wBACzB,QAAQ,EAAE,kBAAkB;wBAC5B,IAAI,EAAE,OAAO,QAAQ,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC;qBACxF;iBACF;aACF,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,QAIlB,CAAC"}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,CAAC,MAAM,cAAc,GACzB,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAG7E,CAAC,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agledger/mcp-server",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.3",
|
|
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",
|
|
@@ -23,6 +23,12 @@
|
|
|
23
23
|
"type": "module",
|
|
24
24
|
"main": "./dist/index.js",
|
|
25
25
|
"types": "./dist/index.d.ts",
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"LICENSE",
|
|
29
|
+
"README.md",
|
|
30
|
+
"CHANGELOG.md"
|
|
31
|
+
],
|
|
26
32
|
"bin": {
|
|
27
33
|
"agledger-mcp": "./dist/index.js"
|
|
28
34
|
},
|
package/src/api-client.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
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.2.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
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { parseArgs } from 'node:util';
|
|
3
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
-
import { AgledgerMcpServer } from './server.js';
|
|
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
|
-
|
|
16
|
-
function main(): void {
|
|
17
|
-
const { values } = parseArgs({
|
|
18
|
-
options: {
|
|
19
|
-
'api-key': { type: 'string', short: 'k' },
|
|
20
|
-
'api-url': { type: 'string', short: 'u' },
|
|
21
|
-
help: { type: 'boolean', short: 'h' },
|
|
22
|
-
},
|
|
23
|
-
strict: true,
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
if (values.help) {
|
|
27
|
-
process.stderr.write(
|
|
28
|
-
`AGLedger MCP Server v2.3.0
|
|
29
|
-
|
|
30
|
-
Usage: agledger-mcp --api-key <key> [--api-url <url>]
|
|
31
|
-
|
|
32
|
-
Options:
|
|
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)
|
|
35
|
-
--help, -h Show this help message
|
|
36
|
-
|
|
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
|
|
40
|
-
`,
|
|
41
|
-
);
|
|
42
|
-
process.exit(0);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const apiKey = values['api-key'] ?? process.env.AGLEDGER_API_KEY;
|
|
46
|
-
const apiUrl = values['api-url'] ?? process.env.AGLEDGER_API_URL;
|
|
47
|
-
|
|
48
|
-
if (!apiKey) {
|
|
49
|
-
process.stderr.write(
|
|
50
|
-
'Error: --api-key or AGLEDGER_API_KEY environment variable is required.\n',
|
|
51
|
-
);
|
|
52
|
-
process.exit(1);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const server = new AgledgerMcpServer({ apiKey, apiUrl });
|
|
56
|
-
const transport = new StdioServerTransport();
|
|
57
|
-
|
|
58
|
-
server.mcp.connect(transport).catch((err: unknown) => {
|
|
59
|
-
process.stderr.write(
|
|
60
|
-
`Fatal: failed to start MCP server: ${err instanceof Error ? err.message : String(err)}\n`,
|
|
61
|
-
);
|
|
62
|
-
process.exit(1);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
main();
|
|
67
|
-
|
|
68
|
-
export { AgledgerMcpServer } from './server.js';
|
|
69
|
-
export type { AgledgerMcpServerOptions } from './server.js';
|