@agledger/mcp-server 2.9.0 → 2.10.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/CHANGELOG.md +24 -0
- package/README.md +1 -1
- package/dist/api-client.d.ts +1 -0
- package/dist/api-client.js +43 -1
- package/dist/index.js +10 -0
- package/dist/server.js +72 -20
- package/dist/zod-integrity.d.ts +37 -0
- package/dist/zod-integrity.js +33 -0
- package/package.json +6 -3
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,30 @@ 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.10.0] - 2026-08-21
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- **An `idempotencyKey` argument on `agledger_api`, and a generated key on every POST.** The server could not send an `Idempotency-Key` at all, so an agent retrying a tool call after a timeout notarized the same work twice. Every POST now carries a generated key, which makes a single call replay-safe on its own. An agent retrying a call that may already have reached the Server passes the key it used the first time, and the Server returns the original result instead of creating a second record. The key binds to method, route and body, so a retry that changes the body is rejected rather than silently replaying the old response. Scoped to POST because that is what the engine arms: all 18 routes that opt into idempotency are POST, and the header is ignored elsewhere.
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- **A host tree holding zod 3 stripped every argument description out of the published tool contract.** `@modelcontextprotocol/sdk` declares zod as a non-optional peer across `^3.25 || ^4.0` and renders tool schemas with the copy it resolves. This package declared `zod: ^4.3.6`, so an application already holding zod 3 satisfied the SDK at the top level while npm nested a second copy of zod 4 for us. `.describe()` and `.meta()` write into zod's registry rather than onto the schema, and a registry belongs to one module instance, so the SDK looked our schemas up somewhere they had never been recorded: every argument description disappeared and `export`, `publicKeys` and `params` lost `type: string`. Nothing threw. The server started, connected and answered calls, and agents received the contract with its guidance removed. Present in published 2.9.0 and every release before it.
|
|
16
|
+
|
|
17
|
+
The fix is to stop forcing a second copy: this package now declares the same `^3.25.0 || ^4.0.0` range the SDK does, adds `zod` as a peer dependency, and imports the version-specific `zod/v4` subpath, which zod 3.25 also ships. One copy now serves both on either major. Verified end to end on three host trees (no zod, zod 4, zod 3): all resolve a single copy and publish the full contract, where the zod 3 tree previously degraded silently. Declaring the peer alone was **not** sufficient, and is worth knowing if this recurs: npm simply nested the copy to satisfy the peer. `src/zod-integrity.ts` warns on stderr at startup if a tree still resolves two different zod VERSIONS, because the failure is otherwise silent. It compares versions rather than copies deliberately: a host pinned below the `zod/v4` floor nests a private copy for each side, and with both on the same release the published contract is complete, so warning there would be a false alarm on a working install. Reported by agledger-testbed while reviewing the round-5 candidate.
|
|
18
|
+
|
|
19
|
+
- **`agledger_verify` published its one mandatory argument as optional.** The tool advertised no `required` array at all, so every client read `export` as something it could omit. `jsonStringField` was built with `z.preprocess`, whose input is typed `unknown`; `unknown` subsumes `undefined`, so zod marked the field `optin: 'optional'` and the MCP SDK left it out of `required` when rendering the schema with `io: 'input'`. The field is now an explicit `unknown` piped through the transform, which reports required-ness correctly while still publishing as `type: string` and still accepting a native object from object-native runtimes. `agledger_api`, whose fields are plain `z.string()`, was never affected. Reported by agledger-testbed against the 2.10.0 candidate (F-982). A new `tests/tool-schema.test.ts` asserts the published `required` array of every tool, read back over a real client connection rather than from the zod, since that is where the two came apart.
|
|
20
|
+
|
|
21
|
+
- **Object query parameters reached the wire as `[object Object]`.** The client ran every query value through `String(value)`, so `agledger_api` with `GET /v1/records/search` and a `criteria` or `metadata` filter returned 400 rather than filtering. Objects now expand into the API's bracket notation (`metadata[state]=blocked`), and a `Date` serializes as ISO-8601 rather than the JS locale form the date-time params reject. Found by driving the server against a live API.
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- **The `params` description says the body is not type-coerced.** The Server stopped coercing the fields of a JSON body, and `params` is a JSON string the model writes, so the type discipline of the body is now the model's responsibility. Identifier fields (`externalTaskId`, `correlationId`, `platformRef`, `projectRef`, `publisher`) are declared `string` and frequently hold all-digit values, which is exactly the case a model is most likely to write as a bare number. The Server's 400 carries `received`, `expected`, `constraint` and `instancePath`, so the cost was a wasted turn rather than a dead end; the description now heads it off. Raised by agledger-api ahead of the engine tag (agents#123).
|
|
26
|
+
|
|
27
|
+
- **The `agledger_api` description now covers supersession.** The ledger is append-only, so every past state keeps matching a filter forever, and an agent tracking ongoing work needs to know that `supersedesRecordId` plus `?superseded=false` is how "what is the state of my work right now" stays answerable. It also explains that `supersededByCount` above 1 is a fork with several current heads, and the difference between filtering on signed `criteria` and unsigned `metadata`.
|
|
28
|
+
|
|
29
|
+
- `@agledger/verify-core` moves to `^1.4.0`. The declared range was `^1.3.0` while the lockfile pinned 1.3.0, so CI tested against a build without the ES256 verification floor while a fresh install resolved 1.4.0. Lockfile refreshed, which also clears a high-severity `nanoid` advisory in the dev tree (vitest -> vite -> postcss; never shipped in the tarball).
|
|
30
|
+
|
|
7
31
|
## [2.9.0] - 2026-08-07
|
|
8
32
|
|
|
9
33
|
### Fixed
|
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ crash.
|
|
|
53
53
|
| Tool | Description |
|
|
54
54
|
|------|-------------|
|
|
55
55
|
| `agledger_discover` | Returns API health, your identity, available scopes, and a quickstart workflow. Call this first. |
|
|
56
|
-
| `agledger_api` | Make any AGLedger API call (method, path, params). The API returns `nextSteps` on every response for self-guided workflow discovery. |
|
|
56
|
+
| `agledger_api` | Make any AGLedger API call (method, path, params). Every POST carries a generated `Idempotency-Key`; pass `idempotencyKey` to reuse the first attempt's key when retrying a call that may already have landed. The API returns `nextSteps` on every response for self-guided workflow discovery. |
|
|
57
57
|
| `agledger_verify` | Verify a record audit export offline (COSE_Sign1 envelopes per RFC 9052, hash chain + envelope signatures, Ed25519 or ES256). No network calls. Returns `valid`, `verifiedEntries`, and a `brokenAt` pointer with a canonical failure `code` on failure. Pass `publicKeys` to supply keys out of band and `requireOutOfBandKeys` for an independent audit that refuses the export's embedded keys. Built on the shared `@agledger/verify-core`. |
|
|
58
58
|
|
|
59
59
|
## Resources
|
package/dist/api-client.d.ts
CHANGED
package/dist/api-client.js
CHANGED
|
@@ -7,6 +7,40 @@ function stripTrailingSlashes(s) {
|
|
|
7
7
|
end--;
|
|
8
8
|
return s.slice(0, end);
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Serialize one query parameter.
|
|
12
|
+
*
|
|
13
|
+
* A plain object becomes the API's bracket notation (`metadata[key]=value`),
|
|
14
|
+
* which is what the `criteria` and `metadata` filters on
|
|
15
|
+
* GET /v1/records/search expect. Running it through `String(value)` instead
|
|
16
|
+
* sent the literal `[object Object]`, so every such filter returned 400.
|
|
17
|
+
*
|
|
18
|
+
* A Date becomes ISO-8601 rather than the JS locale form, which the date-time
|
|
19
|
+
* query params reject.
|
|
20
|
+
*/
|
|
21
|
+
function appendQueryParam(search, key, value) {
|
|
22
|
+
if (value instanceof Date) {
|
|
23
|
+
search.set(key, value.toISOString());
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (Array.isArray(value)) {
|
|
27
|
+
for (const item of value) {
|
|
28
|
+
if (item === undefined || item === null)
|
|
29
|
+
continue;
|
|
30
|
+
search.append(key, item instanceof Date ? item.toISOString() : String(item));
|
|
31
|
+
}
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (typeof value === 'object') {
|
|
35
|
+
for (const [sub, subValue] of Object.entries(value)) {
|
|
36
|
+
if (subValue === undefined || subValue === null)
|
|
37
|
+
continue;
|
|
38
|
+
search.set(`${key}[${sub}]`, subValue instanceof Date ? subValue.toISOString() : String(subValue));
|
|
39
|
+
}
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
search.set(key, String(value));
|
|
43
|
+
}
|
|
10
44
|
export class ApiClient {
|
|
11
45
|
apiUrl;
|
|
12
46
|
apiKey;
|
|
@@ -29,7 +63,7 @@ export class ApiClient {
|
|
|
29
63
|
if (options?.query) {
|
|
30
64
|
for (const [k, v] of Object.entries(options.query)) {
|
|
31
65
|
if (v !== undefined && v !== null) {
|
|
32
|
-
url.searchParams
|
|
66
|
+
appendQueryParam(url.searchParams, k, v);
|
|
33
67
|
}
|
|
34
68
|
}
|
|
35
69
|
}
|
|
@@ -41,6 +75,14 @@ export class ApiClient {
|
|
|
41
75
|
if (options?.body !== undefined) {
|
|
42
76
|
headers['Content-Type'] = 'application/json';
|
|
43
77
|
}
|
|
78
|
+
// POST is the only method the API arms for idempotency: all 18 routes that
|
|
79
|
+
// declare `idempotent: true` are POST, and on any other method the header is
|
|
80
|
+
// ignored. A generated key makes each write replay-safe by default. An agent
|
|
81
|
+
// that retries a tool call after a timeout passes the key it used the first
|
|
82
|
+
// time, so the retry dedups instead of notarizing the same work twice.
|
|
83
|
+
if (method.toUpperCase() === 'POST') {
|
|
84
|
+
headers['Idempotency-Key'] = options?.idempotencyKey ?? crypto.randomUUID();
|
|
85
|
+
}
|
|
44
86
|
const controller = new AbortController();
|
|
45
87
|
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
46
88
|
try {
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { parseArgs } from 'node:util';
|
|
3
3
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
4
|
import { AgledgerMcpServer, SERVER_VERSION } from './server.js';
|
|
5
|
+
import { resolveZodCopies, zodSplitWarning } from './zod-integrity.js';
|
|
5
6
|
/**
|
|
6
7
|
* Exit codes. A launcher that supervises this process, or a shell wrapping it,
|
|
7
8
|
* has only the code to go on: stderr is where the MCP client's own diagnostics
|
|
@@ -78,6 +79,15 @@ Exit codes: 0 clean, 1 runtime failure, 2 usage or configuration error.
|
|
|
78
79
|
process.exit(EXIT_USAGE_ERROR);
|
|
79
80
|
}
|
|
80
81
|
const server = new AgledgerMcpServer({ apiKey, apiUrl });
|
|
82
|
+
// A version-skewed zod resolution strips every argument description and the
|
|
83
|
+
// type of every JSON-string argument out of the published tool contract, and
|
|
84
|
+
// throws nothing while doing it. Two copies of the SAME version render fine,
|
|
85
|
+
// so this warns on skew only. Warn rather than exit: the server does still answer
|
|
86
|
+
// calls, and killing a working deployment over degraded guidance would be the
|
|
87
|
+
// worse failure. Silence when resolution cannot be inspected.
|
|
88
|
+
const zod = resolveZodCopies();
|
|
89
|
+
if (zod?.skewed)
|
|
90
|
+
process.stderr.write(zodSplitWarning(zod));
|
|
81
91
|
const transport = new StdioServerTransport();
|
|
82
92
|
server.mcp.connect(transport).catch((err) => {
|
|
83
93
|
process.stderr.write(`Fatal: failed to start MCP server: ${err instanceof Error ? err.message : String(err)}\n`);
|
package/dist/server.js
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
// `zod/v4`, not `zod`. The MCP SDK declares zod as a non-optional peer across
|
|
2
|
+
// `^3.25 || ^4.0` and imports the version-specific subpaths, so it runs on
|
|
3
|
+
// whichever major the host tree holds. Importing bare `zod` pinned us to v4 and
|
|
4
|
+
// forced npm to nest a second copy whenever a host held zod 3 -- and two copies
|
|
5
|
+
// of zod means two registries. `.describe()` and `.meta()` write into the
|
|
6
|
+
// registry rather than onto the schema, so the SDK rendered our tools against a
|
|
7
|
+
// registry that had never seen them: every argument description gone, and the
|
|
8
|
+
// type of every JSON-string argument with it. Nothing threw.
|
|
9
|
+
//
|
|
10
|
+
// zod 3.25 ships the v4 implementation under this subpath, so one import works
|
|
11
|
+
// on both majors and lets npm resolve a single shared copy. Matching the SDK's
|
|
12
|
+
// dependency range is what makes the dedupe possible; see `zod-integrity.ts`
|
|
13
|
+
// for the check that catches a tree which splits them anyway.
|
|
14
|
+
import { z } from 'zod/v4';
|
|
2
15
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
16
|
import { verifyAuditExport, } from '@agledger/verify-core';
|
|
4
17
|
import { ApiClient } from './api-client.js';
|
|
@@ -24,7 +37,7 @@ const DOCS = {
|
|
|
24
37
|
// The API's agent-oriented narrative. An MCP-connected agent never learned
|
|
25
38
|
// this existed: discover named only OpenAPI and resources/list offered only
|
|
26
39
|
// the spec, so the one integration surface built for agents hid the API's
|
|
27
|
-
// agent-facing documentation
|
|
40
|
+
// agent-facing documentation.
|
|
28
41
|
narrative: '/llms.txt',
|
|
29
42
|
narrativeResource: 'agledger://llms.txt',
|
|
30
43
|
};
|
|
@@ -35,7 +48,7 @@ function mirrorContent(structured) {
|
|
|
35
48
|
}
|
|
36
49
|
/**
|
|
37
50
|
* Structured error for CLI-origin failures (network, timeout, malformed input).
|
|
38
|
-
* API-origin errors are forwarded verbatim without enrichment
|
|
51
|
+
* API-origin errors are forwarded verbatim without enrichment; if the API
|
|
39
52
|
* returns a suggestion, agents see it; if not, that's an API concern to fix upstream.
|
|
40
53
|
*/
|
|
41
54
|
function errorResult(message, code, suggestion) {
|
|
@@ -52,11 +65,26 @@ function errorResult(message, code, suggestion) {
|
|
|
52
65
|
}
|
|
53
66
|
// Free-form object fields are declared as `string` on the wire so Gemini's
|
|
54
67
|
// function-call grammar (a strict OpenAPI 3.0 subset that rejects
|
|
55
|
-
// `additionalProperties` and properties-less OBJECT) can emit them.
|
|
56
|
-
// keeps the door open for object-native runtimes (Claude Desktop,
|
|
57
|
-
// that pass a native object
|
|
58
|
-
// handler JSON.parses uniformly.
|
|
59
|
-
|
|
68
|
+
// `additionalProperties` and properties-less OBJECT) can emit them. The
|
|
69
|
+
// transform keeps the door open for object-native runtimes (Claude Desktop,
|
|
70
|
+
// ChatGPT MCP) that pass a native object; it re-stringifies before validation,
|
|
71
|
+
// then the handler JSON.parses uniformly.
|
|
72
|
+
//
|
|
73
|
+
// Deliberately NOT `z.preprocess`, which published these fields as optional
|
|
74
|
+
// even when they were required. The MCP SDK renders tool schemas with
|
|
75
|
+
// `toJSONSchema(..., { io: 'input' })`, and that builds `required` from each
|
|
76
|
+
// field's `_zod.optin`. `z.preprocess` types its input as `unknown`, which
|
|
77
|
+
// subsumes `undefined`, so it sets `optin: 'optional'` and the field drops out
|
|
78
|
+
// of `required`. `agledger_verify` published no `required` array at all, which
|
|
79
|
+
// told every client its one mandatory argument was optional. Piping an explicit
|
|
80
|
+
// `unknown` through the transform leaves `optin` unset, so required-ness is
|
|
81
|
+
// reported correctly; `.meta` carries the wire type, which is otherwise the
|
|
82
|
+
// empty schema. `tests/tool-schema.test.ts` locks all of it.
|
|
83
|
+
const jsonStringField = z
|
|
84
|
+
.unknown()
|
|
85
|
+
.transform((v) => (v !== null && typeof v === 'object' ? JSON.stringify(v) : v))
|
|
86
|
+
.pipe(z.string())
|
|
87
|
+
.meta({ type: 'string' });
|
|
60
88
|
function parseJsonObject(value, fieldName) {
|
|
61
89
|
let parsed;
|
|
62
90
|
try {
|
|
@@ -106,7 +134,7 @@ function parseJsonObjectOrArray(value, fieldName) {
|
|
|
106
134
|
* returns an envelope `{ data: [{ keyId, publicKey, ... }], canonicalization, ... }`,
|
|
107
135
|
* not the bare array verify-core expects. An MCP agent's natural flow gets the
|
|
108
136
|
* envelope straight from `agledger_api` and has no `.data[]`-extraction step,
|
|
109
|
-
* so unwrap `.data` here
|
|
137
|
+
* so unwrap `.data` here, the MCP analogue of the CLI's fix. A
|
|
110
138
|
* bare `[{keyId, publicKey}]` list or a `{keyId: base64}` map passes through
|
|
111
139
|
* untouched; verify-core then validates the shape and throws on anything else.
|
|
112
140
|
*/
|
|
@@ -122,9 +150,9 @@ export class AgledgerMcpServer {
|
|
|
122
150
|
constructor(options) {
|
|
123
151
|
// No placeholder default. agledger.example.com resolves nowhere, so a
|
|
124
152
|
// missing --api-url surfaced as a DNS failure against a host the operator
|
|
125
|
-
// never configured, on every tool call. Same defect the CLI and SDK
|
|
126
|
-
//
|
|
127
|
-
//
|
|
153
|
+
// never configured, on every tool call. Same defect the CLI and SDK
|
|
154
|
+
// carried; every deployment is self-hosted, so there is no default worth
|
|
155
|
+
// having. Fail at startup, where it can be read.
|
|
128
156
|
const apiUrl = options.apiUrl;
|
|
129
157
|
if (!apiUrl) {
|
|
130
158
|
throw new Error('No API URL configured. AGLedger is self-hosted, so the MCP server cannot guess your Server: ' +
|
|
@@ -150,7 +178,7 @@ export class AgledgerMcpServer {
|
|
|
150
178
|
},
|
|
151
179
|
// SEP-1880 tool-level scopes (early adoption). This tool calls /health
|
|
152
180
|
// (public), /v1/scope-profiles (public, security:[]), and /v1/auth/me
|
|
153
|
-
// (authenticated but no scope gate by design
|
|
181
|
+
// (authenticated but no scope gate by design, since any valid key may
|
|
154
182
|
// introspect its own context). No NAMED scope is required, so the list
|
|
155
183
|
// is empty: a valid API key suffices, but no specific scope gates it.
|
|
156
184
|
_meta: { requiredScopes: [] },
|
|
@@ -199,6 +227,14 @@ export class AgledgerMcpServer {
|
|
|
199
227
|
'2. GET /v1/schemas/{type}, get required fields and examples. ' +
|
|
200
228
|
'3. POST /v1/records, create a record. ' +
|
|
201
229
|
'4. POST /v1/records/{id}/completions, submit evidence when done. ' +
|
|
230
|
+
'Keeping ongoing work answerable: the ledger is append-only, so every past state ' +
|
|
231
|
+
'keeps matching a filter forever. When a record replaces an earlier one, send ' +
|
|
232
|
+
'supersedesRecordId on the new record; then GET /v1/records/search?superseded=false ' +
|
|
233
|
+
'returns only what is current. Read supersededByCount on a record to tell whether it ' +
|
|
234
|
+
'is still current (0) or has been replaced; above 1 means two writers superseded it ' +
|
|
235
|
+
'independently, so there are that many current heads and no single answer. ' +
|
|
236
|
+
'Filter on signed fields with criteria[key]=value, which selects on the same bytes an ' +
|
|
237
|
+
'auditor verifies offline; metadata[key]=value filters an unsigned annotation instead. ' +
|
|
202
238
|
'If a call fails, read the suggestion field in the error response. ' +
|
|
203
239
|
'For the full API catalog, GET /openapi.json (or read the agledger://openapi resource); ' +
|
|
204
240
|
'for prose orientation, GET /llms.txt (or read the agledger://llms.txt resource). ' +
|
|
@@ -212,7 +248,21 @@ export class AgledgerMcpServer {
|
|
|
212
248
|
.optional()
|
|
213
249
|
.describe('Request parameters as a JSON-encoded string, e.g. \'{"type":"notarize-generic-v1","criteria":{"task_description":"..."}}\'. ' +
|
|
214
250
|
'For GET/DELETE: becomes query parameters. For POST/PUT/PATCH: becomes the JSON body. ' +
|
|
251
|
+
'The body is not type-coerced, so write each value as the type the schema declares. ' +
|
|
252
|
+
'Identifier fields (externalTaskId, correlationId, platformRef, projectRef, publisher) are ' +
|
|
253
|
+
'strings even when the identifier is all digits: send "4821", not 4821. ' +
|
|
215
254
|
'Native JSON objects are also accepted for compatibility.'),
|
|
255
|
+
idempotencyKey: z
|
|
256
|
+
.string()
|
|
257
|
+
.max(256)
|
|
258
|
+
.optional()
|
|
259
|
+
.describe('Optional dedup key for POST calls, max 256 characters. Ignored on other methods. ' +
|
|
260
|
+
'One is generated per call when you omit it, so a single call is already replay-safe. ' +
|
|
261
|
+
'Pass your own only when you are retrying a call that may have already reached the ' +
|
|
262
|
+
'Server (a timeout, a dropped connection): reuse the exact key from the first attempt ' +
|
|
263
|
+
'and the Server returns the original result instead of notarizing the work twice. ' +
|
|
264
|
+
'A key is bound to method, route, and body, so a retry that changes the body is ' +
|
|
265
|
+
'rejected with 400 rather than silently replaying the old response.'),
|
|
216
266
|
},
|
|
217
267
|
annotations: {
|
|
218
268
|
readOnlyHint: false,
|
|
@@ -223,7 +273,7 @@ export class AgledgerMcpServer {
|
|
|
223
273
|
openWorldHint: true,
|
|
224
274
|
},
|
|
225
275
|
// SEP-1880 _meta.requiredScopes is deliberately OMITTED for this tool.
|
|
226
|
-
// agledger_api is the universal dispatcher
|
|
276
|
+
// agledger_api is the universal dispatcher; it forwards arbitrary
|
|
227
277
|
// method+path to every route, each with its own scope requirement
|
|
228
278
|
// (records:read, records:write, etc.). The required scope is route-
|
|
229
279
|
// dependent and enforced server-side per request; it cannot be
|
|
@@ -232,7 +282,7 @@ export class AgledgerMcpServer {
|
|
|
232
282
|
// scopes in the API's 403 response (missingScopes), forwarded verbatim.
|
|
233
283
|
}, async (args) => {
|
|
234
284
|
try {
|
|
235
|
-
const { method, path, params } = args;
|
|
285
|
+
const { method, path, params, idempotencyKey } = args;
|
|
236
286
|
if (!path.startsWith('/')) {
|
|
237
287
|
return errorResult('Path must start with /. All API routes use /v1/ prefix. ' +
|
|
238
288
|
'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.');
|
|
@@ -252,6 +302,8 @@ export class AgledgerMcpServer {
|
|
|
252
302
|
return errorResult('Path contains control characters.', 'PATH_INVALID', 'Remove control characters (newlines, tabs, null bytes) from the path.');
|
|
253
303
|
}
|
|
254
304
|
const options = {};
|
|
305
|
+
if (idempotencyKey !== undefined)
|
|
306
|
+
options.idempotencyKey = idempotencyKey;
|
|
255
307
|
if (params !== undefined && params !== '') {
|
|
256
308
|
const decoded = parseJsonObject(params, 'params');
|
|
257
309
|
if (!decoded.ok)
|
|
@@ -340,7 +392,7 @@ export class AgledgerMcpServer {
|
|
|
340
392
|
openWorldHint: false,
|
|
341
393
|
},
|
|
342
394
|
// SEP-1880 tool-level scopes (early adoption). This tool verifies an
|
|
343
|
-
// audit export entirely offline (no network, no API key)
|
|
395
|
+
// audit export entirely offline (no network, no API key), so no scope is
|
|
344
396
|
// required to invoke it.
|
|
345
397
|
_meta: { requiredScopes: [] },
|
|
346
398
|
}, async (args) => {
|
|
@@ -380,7 +432,7 @@ export class AgledgerMcpServer {
|
|
|
380
432
|
registerResources() {
|
|
381
433
|
const client = this.client;
|
|
382
434
|
/**
|
|
383
|
-
* Proxies GET /openapi.json at read time. Keeps the spec fresh
|
|
435
|
+
* Proxies GET /openapi.json at read time. Keeps the spec fresh, with no local
|
|
384
436
|
* cache that could go stale. Clients (Claude Desktop, etc.) surface this
|
|
385
437
|
* in their resource picker, so users/agents can pull the spec into context
|
|
386
438
|
* without constructing an `agledger_api` call.
|
|
@@ -405,9 +457,9 @@ export class AgledgerMcpServer {
|
|
|
405
457
|
});
|
|
406
458
|
/**
|
|
407
459
|
* Proxies GET /llms.txt at read time. The API writes this narrative for
|
|
408
|
-
* agents, and an MCP-connected agent had no way to learn it existed
|
|
409
|
-
*
|
|
410
|
-
*
|
|
460
|
+
* agents, and an MCP-connected agent had no way to learn it existed: the
|
|
461
|
+
* CLI advertised it, this server did not. Same live-fetch approach as the
|
|
462
|
+
* spec resource, so it cannot go stale.
|
|
411
463
|
*/
|
|
412
464
|
this.mcp.registerResource('agledger-llms-txt', 'agledger://llms.txt', {
|
|
413
465
|
description: "The AGLedger API's agent-oriented documentation narrative (the llms.txt convention). " +
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which zod this package and the MCP SDK each resolve.
|
|
3
|
+
*
|
|
4
|
+
* They have to agree on the VERSION. The SDK renders our tool schemas with the
|
|
5
|
+
* zod it resolves, and a renderer from a different zod release does not
|
|
6
|
+
* understand the schema internals this one produces: a 4.4.3 schema rendered by
|
|
7
|
+
* 3.25.76 comes out as `{}`, losing every argument description and the `type`
|
|
8
|
+
* of every JSON-string argument. Nothing throws. The server starts, connects
|
|
9
|
+
* and answers calls; agents just receive the tool contract with the guidance
|
|
10
|
+
* stripped out of it.
|
|
11
|
+
*
|
|
12
|
+
* Two SEPARATE COPIES of the same version are fine, which is why this compares
|
|
13
|
+
* versions rather than paths. That distinction is measured, not assumed: a tree
|
|
14
|
+
* pinning zod below the `zod/v4` floor nests a private copy for each side, and
|
|
15
|
+
* with both on 4.4.3 the published contract is complete. Warning on that tree
|
|
16
|
+
* would be a false alarm on a working install.
|
|
17
|
+
*
|
|
18
|
+
* Matching the SDK's `^3.25 || ^4.0` range and importing `zod/v4` is what lets
|
|
19
|
+
* npm dedupe to one copy. This catches the trees where it cannot: a host pinned
|
|
20
|
+
* below 3.25, `--legacy-peer-deps`, a pnpm or yarn resolution.
|
|
21
|
+
*/
|
|
22
|
+
export interface ZodResolution {
|
|
23
|
+
/** Version of the zod this package uses. */
|
|
24
|
+
ours: string;
|
|
25
|
+
/** Version of the zod the MCP SDK uses. */
|
|
26
|
+
sdk: string;
|
|
27
|
+
/** True when the two are different releases, whether or not they are separate copies. */
|
|
28
|
+
skewed: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Returns null when resolution cannot be inspected at all (a bundled build, an
|
|
32
|
+
* unusual loader). Undetectable is not the same as broken, so callers stay
|
|
33
|
+
* quiet rather than warning about a tree they cannot see.
|
|
34
|
+
*/
|
|
35
|
+
export declare function resolveZodCopies(fromUrl?: string): ZodResolution | null;
|
|
36
|
+
/** Warning text for a version-skewed tree. */
|
|
37
|
+
export declare function zodSplitWarning(resolution: ZodResolution): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Returns null when resolution cannot be inspected at all (a bundled build, an
|
|
5
|
+
* unusual loader). Undetectable is not the same as broken, so callers stay
|
|
6
|
+
* quiet rather than warning about a tree they cannot see.
|
|
7
|
+
*/
|
|
8
|
+
export function resolveZodCopies(fromUrl = import.meta.url) {
|
|
9
|
+
try {
|
|
10
|
+
const require = createRequire(fromUrl);
|
|
11
|
+
const ours = require('zod/package.json');
|
|
12
|
+
const sdkDir = dirname(require.resolve('@modelcontextprotocol/sdk/package.json'));
|
|
13
|
+
const sdkRequire = createRequire(`${sdkDir}/`);
|
|
14
|
+
const sdk = sdkRequire('zod/package.json');
|
|
15
|
+
return { ours: ours.version, sdk: sdk.version, skewed: ours.version !== sdk.version };
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** Warning text for a version-skewed tree. */
|
|
22
|
+
export function zodSplitWarning(resolution) {
|
|
23
|
+
return ('Warning: this host tree resolved two different versions of zod.\n' +
|
|
24
|
+
` @agledger/mcp-server: zod ${resolution.ours}\n` +
|
|
25
|
+
` @modelcontextprotocol/sdk: zod ${resolution.sdk}\n` +
|
|
26
|
+
"The SDK renders this server's tool schemas with its own copy, and a renderer from a " +
|
|
27
|
+
'different zod release cannot read these schemas: every argument description and the ' +
|
|
28
|
+
'type of every JSON-string argument are dropped from the published contract. The server ' +
|
|
29
|
+
'still answers calls; agents receive it with the guidance removed.\n' +
|
|
30
|
+
'Fix: dedupe zod to one version (`npm dedupe`, or raise a zod pinned below 3.25 above ' +
|
|
31
|
+
'this package). This package accepts the same range the SDK does so a single copy can ' +
|
|
32
|
+
'serve both.\n');
|
|
33
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agledger/mcp-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.0",
|
|
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",
|
|
@@ -55,9 +55,12 @@
|
|
|
55
55
|
"prepublishOnly": "npm run build && npm run lint:pkg"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@agledger/verify-core": "^1.
|
|
58
|
+
"@agledger/verify-core": "^1.4.0",
|
|
59
59
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
60
|
-
"zod": "^4.
|
|
60
|
+
"zod": "^3.25.0 || ^4.0.0"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"zod": "^3.25.0 || ^4.0.0"
|
|
61
64
|
},
|
|
62
65
|
"devDependencies": {
|
|
63
66
|
"@arethetypeswrong/cli": "^0.18.3",
|