@ainra/mcp 0.4.1 → 0.6.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/README.md +13 -3
- package/package.json +3 -6
- package/src/server.mjs +1 -1
- package/src/tools.mjs +117 -28
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<!-- SPDX-License-Identifier: Apache-2.0 OR MIT -->
|
|
2
2
|
# @ainra/mcp
|
|
3
3
|
|
|
4
|
-
[AINRA](https://ainra.
|
|
4
|
+
[AINRA](https://ainra.org/) as native agent tools. A zero-dependency MCP server that hands an assistant the
|
|
5
5
|
real verifier, the public record, and — only if you point it at a registrar you control — the ability to issue,
|
|
6
6
|
renew, and revoke.
|
|
7
7
|
|
|
@@ -33,8 +33,18 @@ There is no hosted default and no fallback. If the target isn't reachable the to
|
|
|
33
33
|
|
|
34
34
|
## Tools
|
|
35
35
|
|
|
36
|
-
**Read-only** — `ainra_verify`
|
|
37
|
-
|
|
36
|
+
**Read-only** — `ainra_verify` decides whether a presentation someone handed you verifies, and says why in plain
|
|
37
|
+
words. It takes the signed `directory` and the `roots` you trust (or fetches a URL target's own), checks the one
|
|
38
|
+
against the other, authenticates the status list against the registrar's status key, and uses **your** clock,
|
|
39
|
+
freshness class and audience. Nothing a presenter put in the bundle is believed. The result carries
|
|
40
|
+
`decision: "accept" | "refuse"` and the policy that decided.
|
|
41
|
+
|
|
42
|
+
> **In 0.4.1 this tool did not do that.** It replayed the bundle through the fixture-semantics verifier with the
|
|
43
|
+
> bundle's own clock, freshness class and status list, so a revoked or expired presenter could be reported `valid`
|
|
44
|
+
> (D-074). Upgrade. In 0.5.0 replay was a separate, labelled mode (`anchors` plus `fixture: true`); since 0.6.0 the
|
|
45
|
+
> tool has no replay mode at all and every answer is a decision. To replay a conformance vector, use
|
|
46
|
+
> `@ainra/sdk/conformance`.
|
|
47
|
+
|
|
38
48
|
`ainra_lookup` resolves a name to its public record; `ainra_status` reports the target's head — network, root label,
|
|
39
49
|
registrar count, freshness window.
|
|
40
50
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ainra/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "AINRA as native agent tools — a zero-dependency MCP server wrapping the published verifier, the public record, and the registrar you control.",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -17,12 +17,9 @@
|
|
|
17
17
|
"src/"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@ainra/sdk": "
|
|
20
|
+
"@ainra/sdk": "^0.6.0"
|
|
21
21
|
},
|
|
22
|
-
"
|
|
23
|
-
"@ainra/sdk": "*"
|
|
24
|
-
},
|
|
25
|
-
"homepage": "https://ainra.vercel.app/",
|
|
22
|
+
"homepage": "https://ainra.org/",
|
|
26
23
|
"repository": {
|
|
27
24
|
"type": "git",
|
|
28
25
|
"url": "git+https://github.com/JacobJandon/ainra.git"
|
package/src/server.mjs
CHANGED
|
@@ -17,7 +17,7 @@ const fail = (id, code, message) => send({ jsonrpc: "2.0", id, error: { code, me
|
|
|
17
17
|
async function handle(msg) {
|
|
18
18
|
const { id, method, params } = msg;
|
|
19
19
|
if (method === "initialize")
|
|
20
|
-
return reply(id, { protocolVersion: PROTOCOL, capabilities: { tools: { listChanged: false } }, serverInfo: { name: "ainra", version: VERSION }, instructions: `AINRA tools. Target: ${TARGET_INFO.target} (${TARGET_INFO.mode}). Read-only: ainra_verify/lookup/status. Write (need confirm:true): ainra_issue/renew/revoke. Never targets a registrar you don't control.` });
|
|
20
|
+
return reply(id, { protocolVersion: PROTOCOL, capabilities: { tools: { listChanged: false } }, serverInfo: { name: "ainra", version: VERSION }, instructions: `AINRA tools. Target: ${TARGET_INFO.target} (${TARGET_INFO.mode}). Read-only: ainra_verify/verify_link/lookup/status. Write (need confirm:true): ainra_issue/renew/revoke. Never targets a registrar you don't control.` });
|
|
21
21
|
if (method === "notifications/initialized" || method === "notifications/cancelled") return; // no response to notifications
|
|
22
22
|
if (method === "ping") return reply(id, {});
|
|
23
23
|
if (method === "tools/list")
|
package/src/tools.mjs
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { readFileSync, existsSync } from "node:fs";
|
|
10
10
|
import { fileURLToPath } from "node:url";
|
|
11
11
|
import { execFileSync } from "node:child_process";
|
|
12
|
-
import {
|
|
12
|
+
import { Verifier, verdictEvent, serializeVerdictEvent, linkFromIndex, presentedKeyThumbprint, strictB64u } from "@ainra/sdk"; // file:../sdk-ts in a checkout; ^x.y.z when published
|
|
13
13
|
export { verdictEvent, serializeVerdictEvent }; // one event shape across CLI, middleware, MCP (docs/PRESENTATION.md)
|
|
14
14
|
|
|
15
15
|
const ROOT = fileURLToPath(new URL("../../../", import.meta.url));
|
|
@@ -100,50 +100,139 @@ export const TOOLS = [
|
|
|
100
100
|
{
|
|
101
101
|
name: "ainra_verify",
|
|
102
102
|
title: "Verify an AINRA passport",
|
|
103
|
-
description: "
|
|
103
|
+
description: "Decide whether a presentation someone handed you verifies. Pass the `presentation` with the signed `directory` and the two `roots` you trust (omit them and a URL target's own are fetched): the directory is checked against both roots, the status list against the registrar's status key, and the clock, the freshness class and the audience are YOURS — nothing a presenter put in the bundle is believed. Returns `decision` (accept or refuse), the verdict, and the named reason in plain words. Read-only. If the bundle carries an ADR-019 instance credential (a RUNNING COPY of an agent), pass your own `audience`; an empty audience refuses every instance credential. (Replaying a conformance vector is not this tool's job: use `@ainra/sdk/conformance`.)",
|
|
104
104
|
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
105
105
|
inputSchema: {
|
|
106
106
|
type: "object",
|
|
107
107
|
properties: {
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
presentation: { type: "object", description: "The presentation bundle to verify, exactly as the presenter sent it." },
|
|
109
|
+
directory: { type: "object", description: "The dual-root-signed directory (directory.json) of the network you trust." },
|
|
110
|
+
roots: { type: "object", description: "The two ceremony root keys, { root_ed25519, root_slh } (roots.json). Obtain them out of band — never from the presenter." },
|
|
110
111
|
audience: { type: "string", description: "YOUR audience (ADR-019), e.g. https://api.example. Required to accept an instance credential; a presenter can never supply it. Omit for plain passport bundles." },
|
|
112
|
+
freshness: { type: "string", enum: ["F1", "F2", "F3"], description: "How old a status publication you accept: F1 30 s, F2 5 min (default), F3 24 h. Yours, never the bundle's." },
|
|
113
|
+
now: { type: "integer", description: "Your clock, unix seconds. Defaults to this server's clock. Never read from the bundle." },
|
|
111
114
|
},
|
|
112
|
-
required: ["
|
|
115
|
+
required: ["presentation"],
|
|
113
116
|
},
|
|
114
|
-
handler(input) {
|
|
115
|
-
|
|
116
|
-
// is the same override the TS Verifier and the Python Verifier apply — a presenter naming its own audience
|
|
117
|
-
// would defeat audience binding entirely.
|
|
118
|
-
const presentation = { ...input.presentation, audience: input.audience ?? "" };
|
|
119
|
-
const v = runVector({ name: "mcp", expect: {}, anchors: input.anchors, presentation });
|
|
120
|
-
const event = verdictEvent(presentation, v, presentation?.now ?? 0);
|
|
117
|
+
async handler(input) {
|
|
118
|
+
const INSTANCE_REASONS = ["instance_expired", "instance_scope_exceeds", "instance_sig_invalid", "instance_pop_invalid"];
|
|
121
119
|
// Report the instance layer DISTINCTLY: an agent reading this must be able to tell "the running copy is not
|
|
122
120
|
// entitled" from "the lineage is not trusted", because the two have different remedies — renew the copy, or
|
|
123
121
|
// stop using the passport.
|
|
124
|
-
const
|
|
125
|
-
|
|
122
|
+
const instanceReport = (presentation, v, audience) => {
|
|
123
|
+
const inst = presentation.instance ?? null;
|
|
124
|
+
if (!inst) return { presented: false };
|
|
125
|
+
const atInstance = Boolean(v.reason && INSTANCE_REASONS.includes(v.reason));
|
|
126
|
+
return {
|
|
127
|
+
presented: true,
|
|
128
|
+
iid: inst.iid ?? null,
|
|
129
|
+
expires: inst.exp ?? null,
|
|
130
|
+
audience: audience || null,
|
|
131
|
+
layer: atInstance ? "instance" : v.verdict === "valid" ? "ok" : "passport",
|
|
132
|
+
note: atInstance
|
|
133
|
+
? "the RUNNING COPY is not entitled — the passport may be fine; mint a fresh instance credential"
|
|
134
|
+
: v.verdict === "valid" ? null
|
|
135
|
+
: "the failure is at the passport layer, not the running copy — the lineage itself did not verify",
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// Fixture mode was removed in 0.6.0 (PLAN-M48 step 7). It replayed a vector by believing the bundle's own clock,
|
|
140
|
+
// class and status list; an agent that reached for it to decide trust would have been told a revoked presenter
|
|
141
|
+
// was valid (D-074). Conformance replay lives in `@ainra/sdk/conformance`, where the import says what it is.
|
|
142
|
+
if (input.anchors !== undefined || input.fixture !== undefined)
|
|
143
|
+
throw new Error("ainra_verify no longer replays conformance vectors (fixture mode was removed in 0.6.0): it only decides, against a signed `directory` and its `roots`. To replay a vector, use `@ainra/sdk/conformance` or `ainra verify`. Nothing was verified.");
|
|
144
|
+
|
|
145
|
+
// ── gate mode: what a verifier decides. The directory against both roots; the status against the registrar's
|
|
146
|
+
// status key; the clock, the class and the audience from the CALLER. ─────────────────────────────────────────
|
|
147
|
+
let { directory, roots } = input;
|
|
148
|
+
let trust = "the directory and roots you passed";
|
|
149
|
+
if (directory === undefined && roots === undefined) {
|
|
150
|
+
if (!isUrl(TARGET))
|
|
151
|
+
throw new Error("ainra_verify needs the trust to verify against: pass the signed `directory` and the `roots`, or set AINRA_TARGET to the URL of a network that publishes /directory.json and /roots.json. Nothing was verified.");
|
|
152
|
+
[directory, roots] = [await getJson("/directory.json"), await getJson("/roots.json")];
|
|
153
|
+
trust = `directory.json and roots.json fetched from AINRA_TARGET (${TARGET})`;
|
|
154
|
+
}
|
|
155
|
+
if (!directory || !roots || typeof roots.root_ed25519 !== "string" || typeof roots.root_slh !== "string")
|
|
156
|
+
throw new Error("ainra_verify needs BOTH `directory` and `roots` ({ root_ed25519, root_slh }). Nothing was verified.");
|
|
157
|
+
const freshness = input.freshness ?? "F2";
|
|
158
|
+
if (!["F1", "F2", "F3"].includes(freshness)) throw new Error("freshness must be F1, F2 or F3. Nothing was verified.");
|
|
159
|
+
const audience = input.audience ?? "";
|
|
160
|
+
const verifier = Verifier.fromDirectoryB64(directory, roots.root_ed25519, roots.root_slh, freshness, false, audience);
|
|
161
|
+
if (!verifier)
|
|
162
|
+
throw new Error("the directory does not verify against the roots — nothing in it can be trusted, so nothing was verified.");
|
|
163
|
+
const now = Number.isInteger(input.now) ? input.now : Math.floor(Date.now() / 1000);
|
|
164
|
+
const v = verifier.verify(input.presentation, now);
|
|
126
165
|
return {
|
|
166
|
+
mode: "gate",
|
|
167
|
+
decision: v.verdict === "valid" ? "accept" : "refuse",
|
|
127
168
|
verdict: v.verdict,
|
|
128
169
|
reason: v.reason ?? null,
|
|
129
170
|
explanation: gloss(v),
|
|
130
|
-
event,
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
presented: true,
|
|
134
|
-
iid: inst.iid ?? null,
|
|
135
|
-
expires: inst.exp ?? null,
|
|
136
|
-
audience: presentation.audience || null,
|
|
137
|
-
layer: v.reason && INSTANCE_REASONS.includes(v.reason) ? "instance" : v.verdict === "valid" ? "ok" : "passport",
|
|
138
|
-
note: v.reason && INSTANCE_REASONS.includes(v.reason)
|
|
139
|
-
? "the RUNNING COPY is not entitled — the passport may be fine; mint a fresh instance credential"
|
|
140
|
-
: v.verdict === "valid" ? null
|
|
141
|
-
: "the failure is at the passport layer, not the running copy — the lineage itself did not verify",
|
|
142
|
-
}
|
|
143
|
-
: { presented: false },
|
|
171
|
+
event: verdictEvent(input.presentation, v, now),
|
|
172
|
+
policy: { now, freshness, audience: audience || null, trust },
|
|
173
|
+
instance: instanceReport(input.presentation, v, audience),
|
|
144
174
|
};
|
|
145
175
|
},
|
|
146
176
|
},
|
|
177
|
+
{
|
|
178
|
+
name: "ainra_verify_link",
|
|
179
|
+
title: "Who stands behind this agent key?",
|
|
180
|
+
description: "AINRA Link (D-078): after you have verified a signature with an agent's key — Ed25519, or secp256k1 as ES256K (D-082) — ask which accountable operator stands behind that key and whether the link is still good. Pass the key (`key`, base64url), and either the `link` as a gate receives it, or the registrar's link `index` (GET /links) and its signed `status` publication (GET /status-list), from which the link for your key is found. Trust is YOURS: the signed `directory` and the two `roots` (omit both to use AINRA_TARGET's). The status list is authenticated before it is read; the clock, freshness class and capability are yours. Returns `decision` (accept or refuse), the operator and passport on accept, or the named reason. Read-only. A key with no link at all is refused as not_linked.",
|
|
181
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
182
|
+
inputSchema: {
|
|
183
|
+
type: "object",
|
|
184
|
+
properties: {
|
|
185
|
+
key: { type: "string", description: "The public key (base64url) you ALREADY verified the signature with: 32 bytes for Ed25519, the 33-byte compressed point for ES256K (secp256k1)." },
|
|
186
|
+
link: { type: "object", description: "The link as a gate receives it (an index entry with the checkpoint and the signed status publication)." },
|
|
187
|
+
index: { type: "object", description: "Instead of `link`: the registrar's whole link index (GET /links)." },
|
|
188
|
+
status: { type: "object", description: "With `index`: the registrar's signed status publication (GET /status-list)." },
|
|
189
|
+
directory: { type: "object", description: "The dual-root-signed directory of the network you trust." },
|
|
190
|
+
roots: { type: "object", description: "The two ceremony root keys, { root_ed25519, root_slh }, obtained out of band." },
|
|
191
|
+
capability: { type: "string", description: "The capability the request exercises, if the link may be narrowed (e.g. read:invoices)." },
|
|
192
|
+
freshness: { type: "string", enum: ["F1", "F2", "F3"], description: "How old a status publication you accept: F1 30 s, F2 5 min (default), F3 24 h." },
|
|
193
|
+
now: { type: "integer", description: "Your clock, unix seconds. Defaults to this server's clock." },
|
|
194
|
+
},
|
|
195
|
+
required: ["key"],
|
|
196
|
+
},
|
|
197
|
+
async handler(input) {
|
|
198
|
+
const keyBytes = typeof input.key === "string" ? strictB64u(input.key) : null;
|
|
199
|
+
if (!keyBytes) throw new Error("`key` must be base64url. Nothing was verified.");
|
|
200
|
+
// By length, as every verifier: 32 bytes Ed25519, 33 a compressed secp256k1 point (D-082). Any other key is
|
|
201
|
+
// refused by name, as the core refuses it — not an input error, a decision.
|
|
202
|
+
if (keyBytes.length !== 32 && keyBytes.length !== 33)
|
|
203
|
+
return { decision: "refuse", verdict: "invalid", reason: "schema_violation" };
|
|
204
|
+
let link = input.link;
|
|
205
|
+
if (link === undefined) {
|
|
206
|
+
if (!input.index || !input.status) throw new Error("pass either `link`, or both `index` (GET /links) and `status` (GET /status-list). Nothing was verified.");
|
|
207
|
+
const tp = presentedKeyThumbprint(keyBytes);
|
|
208
|
+
link = tp === null ? null : linkFromIndex(input.index, input.status, tp);
|
|
209
|
+
if (!link)
|
|
210
|
+
return { decision: "refuse", verdict: "invalid", reason: "not_linked",
|
|
211
|
+
explanation: "This key has no link at this registrar: a valid signature from it is not, by itself, an accountable operator." };
|
|
212
|
+
}
|
|
213
|
+
let { directory, roots } = input;
|
|
214
|
+
let trust = "the directory and roots you passed";
|
|
215
|
+
if (directory === undefined && roots === undefined) {
|
|
216
|
+
if (!isUrl(TARGET))
|
|
217
|
+
throw new Error("ainra_verify_link needs the trust to verify against: pass the signed `directory` and the `roots`, or set AINRA_TARGET to the URL of a network that publishes /directory.json and /roots.json. Nothing was verified.");
|
|
218
|
+
[directory, roots] = [await getJson("/directory.json"), await getJson("/roots.json")];
|
|
219
|
+
trust = `directory.json and roots.json fetched from AINRA_TARGET (${TARGET})`;
|
|
220
|
+
}
|
|
221
|
+
if (!directory || !roots || typeof roots.root_ed25519 !== "string" || typeof roots.root_slh !== "string")
|
|
222
|
+
throw new Error("ainra_verify_link needs BOTH `directory` and `roots` ({ root_ed25519, root_slh }). Nothing was verified.");
|
|
223
|
+
const freshness = input.freshness ?? "F2";
|
|
224
|
+
if (!["F1", "F2", "F3"].includes(freshness)) throw new Error("freshness must be F1, F2 or F3. Nothing was verified.");
|
|
225
|
+
const verifier = Verifier.fromDirectoryB64(directory, roots.root_ed25519, roots.root_slh, freshness);
|
|
226
|
+
if (!verifier) throw new Error("the directory does not verify against the roots — nothing in it can be trusted, so nothing was verified.");
|
|
227
|
+
const now = Number.isInteger(input.now) ? input.now : Math.floor(Date.now() / 1000);
|
|
228
|
+
const v = verifier.verifyLink(link, keyBytes, now, input.capability);
|
|
229
|
+
return v.verdict === "valid"
|
|
230
|
+
? { decision: "accept", verdict: "valid", operator: v.operator, passport: v.passport, registrar: v.registrar, scope: v.scope,
|
|
231
|
+
explanation: `This key acts for operator "${v.operator}" under ${v.passport}, and the link has not been revoked.`,
|
|
232
|
+
policy: { now, freshness, capability: input.capability ?? null, trust } }
|
|
233
|
+
: { decision: "refuse", verdict: "invalid", reason: v.reason, explanation: gloss(v), policy: { now, freshness, capability: input.capability ?? null, trust } };
|
|
234
|
+
},
|
|
235
|
+
},
|
|
147
236
|
{
|
|
148
237
|
name: "ainra_lookup",
|
|
149
238
|
title: "Look up a public record",
|