@aikdna/kdna-mcp-server 0.8.7 → 0.8.9
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 +10 -10
- package/bin/kdna-mcp.mjs +87 -27
- package/bin/model-view.mjs +9 -6
- package/bin/read-session.mjs +160 -22
- package/bin/reading-views.mjs +9 -2
- package/package.json +5 -21
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# KDNA MCP 0.8.
|
|
1
|
+
# KDNA MCP 0.8.9 — local stdio Read adapter
|
|
2
2
|
|
|
3
|
-
This local stdio MCP server (`@aikdna/kdna-mcp-server@0.8.
|
|
3
|
+
This local stdio MCP server (`@aikdna/kdna-mcp-server@0.8.9`) delegates native container `0.6.0` admission and scoped Read operations to the locally resolved CLI `0.47.4`+ / Core `0.37.14`+ / Read `0.13.8`+ graph (`kdna.read/0.7.0-candidate`). Historical MCP `0.5.0`–`0.5.1` and CLI `0.36.x` workspace flows are superseded by this operator-bound native `0.6.0` adapter.
|
|
4
4
|
|
|
5
5
|
## Operator-controlled startup
|
|
6
6
|
|
|
@@ -100,11 +100,11 @@ argument or method parameter beyond request-level `_meta`.
|
|
|
100
100
|
| Tool | Arguments | Result |
|
|
101
101
|
| --- | --- | --- |
|
|
102
102
|
| kdna.binding-status | {} | Local binding state (including `bound_asset_count` and `bound_assets`), not a public authority receipt |
|
|
103
|
-
| kdna.inspect | optional `asset_id` | Official CLI technical admission/metadata (all bound assets when omitted in multi-asset mode) |
|
|
104
|
-
| kdna.catalog | optional `asset_id`, optional `budget_bytes` (default 1000000); optional `presentation` | Complete public catalog within the budget (projected body budget in default body mode; official envelope budget in full/task mode) |
|
|
105
|
-
| kdna.catalog_all | optional `budget_bytes` (default 1000000); optional `presentation` | Aggregated public catalogs across all operator-bound assets in one call (fail-closed if any bound asset fails admission or exceeds budget) |
|
|
106
|
-
| kdna.read | `selection
|
|
107
|
-
| kdna.expand | exactly one of `handle` or `handle_ref`, `budget_bytes`; optional `presentation` | Original issued handle passed to the same official session |
|
|
103
|
+
| kdna.inspect | optional `asset_id`, optional `artifact_digest` | Official CLI technical admission/metadata (all bound assets when omitted in multi-asset mode) |
|
|
104
|
+
| kdna.catalog | optional `asset_id`, optional `artifact_digest`, optional `budget_bytes` (default 1000000); optional `presentation` | Complete public catalog within the budget (projected body budget in default body mode; official envelope budget in full/task mode) |
|
|
105
|
+
| kdna.catalog_all | optional `budget_bytes` (default 1000000); optional `presentation` | Aggregated public catalogs across all operator-bound assets (including each asset's `artifact_digest`) in one call (fail-closed if any bound asset fails admission or exceeds budget) |
|
|
106
|
+
| kdna.read | `selection` (optional `selection.artifact_digest`), `budget_bytes`; optional `presentation` | Exact selection and mandatory closure (`selection.asset_id` + `selection.asset_version` + optional `selection.artifact_digest` routes strictly to the matching bound asset's isolated CLI session in multi-asset mode) |
|
|
107
|
+
| kdna.expand | exactly one of `handle` or `handle_ref`, optional `artifact_digest`, `budget_bytes`; optional `presentation` | Original issued handle passed to the same official session (fails closed with `MCP_ARTIFACT_DIGEST_MISMATCH` if `artifact_digest` disagrees) |
|
|
108
108
|
| kdna.audit | `audit_ref`, `budget_bytes` | Exact original full result of an earlier task delivery |
|
|
109
109
|
| kdna.cancel | {} | Closes every bound asset's session and revokes the entire process binding |
|
|
110
110
|
|
|
@@ -312,7 +312,7 @@ The script verifies the source runtime, packs the current MCP implementation and
|
|
|
312
312
|
writes a consumer manifest, lock, archive hashes and thirteen archives. It
|
|
313
313
|
refuses an existing destination. Each runtime archive is an exact root `file:`
|
|
314
314
|
dependency, with a matching root override. This lets npm resolve dependencies
|
|
315
|
-
before extracting the MCP package. The MCP manifest
|
|
315
|
+
before extracting the MCP package. The published MCP manifest declares `@aikdna/kdna-cli@0.47.4` as its sole direct dependency (without duplicated transitive pins or `overrides`), while `@aikdna/kdna-core`, `@aikdna/kdna-read`, and `@aikdna/kdna-cli` use 3-package exact-pin atomic lockstep releases until `1.0` ABI stabilization; this explicit companion graph supplies the same checked bytes for offline use without depending on package-relative archive lookup.
|
|
316
316
|
|
|
317
317
|
The MCP tar has ten regular members: bin modules, package metadata,
|
|
318
318
|
README, LICENSE, and NOTICE (offline `vendor/*.tgz` archives stay excluded from
|
|
@@ -321,11 +321,11 @@ package-lock.json are excluded. The companion consumer lock is generated from
|
|
|
321
321
|
the checked source graph. The packed-consumer test installs with an empty npm
|
|
322
322
|
cache, then runs the same real stdio boundary suite against the installed bin.
|
|
323
323
|
|
|
324
|
-
Canonical npm publication of `@aikdna/kdna-mcp-server@0.8.
|
|
324
|
+
Canonical npm publication of `@aikdna/kdna-mcp-server@0.8.9` runs exclusively via the GitHub Release workflow (`kdna-mcp-server-0.8.9`) after companion packages (`@aikdna/kdna-core@0.37.14`, `@aikdna/kdna-read@0.13.8`, `@aikdna/kdna-cli@0.47.4`) are published on the official registry. Source and installed process tests do not
|
|
325
325
|
establish named Host adoption, human review, authorship or Creation acceptance.
|
|
326
326
|
|
|
327
327
|
## Native section contract boundary
|
|
328
328
|
|
|
329
|
-
|
|
329
|
+
Until `1.0` ABI stabilization, `@aikdna/kdna-core`, `@aikdna/kdna-read`, and `@aikdna/kdna-cli` use **3-package exact-pin atomic lockstep releases**. At runtime, `@aikdna/kdna-mcp-server` resolves `@aikdna/kdna-core` and `@aikdna/kdna-read` strictly through `@aikdna/kdna-cli`'s own module graph (so isolated global co-installs work cleanly without `MCP_RUNTIME_INVALID`), loads `model-view` from that same CLI-resolved Read directory, and maintains **same-minor forward compatibility** (`cli >= 0.47.4`, `core >= 0.37.14`, `read >= 0.13.8`) without brittle single-commit `bindingBytes` SHA-256 lockstep while remaining fail-closed against real diamond Core splits between CLI and Read, version downgrades, container/Read tuple drift (`0.6.0` / `kdna.read/0.7.0-candidate`), and untrusted symlink escapes. In this source checkout, the offline verification harness additionally pins the exact CLI `0.47.4` binding SHA-256 `c8a92aaec0d71df8d0d04404509043bad8d473fc8fd25b4165a8c667111b96bd` and twelve vendored archives. The adapter delegates native admission and retained section reads to that runtime. Preserve catalog-only status, mandatory closure, native handle origin, diagnostics, absent declarations and explicit empty states. Technical validity, Read and static declarations do not establish live Creation authority, human confirmation or action permission.
|
|
330
330
|
|
|
331
331
|
The public regression corpus is generated from synthetic authored JSON with the fixed CLI. It tests real native containers and one deliberately truncated container; no legacy component-format asset is treated as current native input.
|
package/bin/kdna-mcp.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { bindOperatorInput, AdapterError } from "./operator-binding.mjs";
|
|
4
|
-
import { ReadSession, inspectBoundFile, packageInfo, publicBinding } from "./read-session.mjs";
|
|
4
|
+
import { ReadSession, inspectBoundFile, packageInfo, publicBinding, resolvedRuntime } from "./read-session.mjs";
|
|
5
5
|
import { ReadingViews } from "./reading-views.mjs";
|
|
6
6
|
import { loadModelView, projectBody } from "./model-view.mjs";
|
|
7
7
|
|
|
@@ -10,30 +10,32 @@ const keys = (value, expected) => object(value) && Object.keys(value).length ===
|
|
|
10
10
|
const DEFAULT_CATALOG_BUDGET_BYTES = 1000000;
|
|
11
11
|
const CATALOG_BODY_ENVELOPE_BUDGET_BYTES = 4000000;
|
|
12
12
|
const budgetSchema = { type: "integer", minimum: 0, maximum: 1000000 };
|
|
13
|
-
const catalogBudgetSchema = { type: "integer", minimum: 0, maximum: 1000000, default: DEFAULT_CATALOG_BUDGET_BYTES, description: "Optional UTF-8 byte budget (0..1000000, default 1000000). For the default body presentation, bounds the projected body response (recommended >= 32768; large
|
|
13
|
+
const catalogBudgetSchema = { type: "integer", minimum: 0, maximum: 1000000, default: DEFAULT_CATALOG_BUDGET_BYTES, description: "Optional UTF-8 byte budget (0..1000000, default 1000000). For the default body presentation, bounds the projected body response (recommended >= 32768; large 40-judgment catalogs are ~8-12 KiB projected vs >200 KiB raw). For presentation:\"full\" or \"task\", bounds the complete official Read envelope (recommended >= 1000000)." };
|
|
14
14
|
const presentationProperties = { presentation: { type: "string", enum: ["body", "full", "task"] }, view_budget_bytes: budgetSchema };
|
|
15
15
|
const presentationRules = [{ if: { required: ["presentation"], properties: { presentation: { const: "task" } } }, then: { required: ["view_budget_bytes"] }, else: { not: { required: ["view_budget_bytes"] } } }];
|
|
16
16
|
const emptySchema = { type: "object", properties: {}, additionalProperties: false };
|
|
17
17
|
// One or several exact judgments, selected by the operator-provided binding. Both
|
|
18
18
|
// forms map to the same official Read `exact_selection` call: `judgment_id` stays
|
|
19
19
|
// accepted for compatibility, and `judgment_ids` lets one call carry the whole
|
|
20
|
-
// selection set instead of repeating the full envelope per judgment.
|
|
20
|
+
// selection set instead of repeating the full envelope per judgment. Optional
|
|
21
|
+
// `artifact_digest` disambiguates same-(asset_id, asset_version) bilingual editions.
|
|
21
22
|
const selectionKey = { type: "string", minLength: 1, maxLength: 4096 };
|
|
22
23
|
// Exactly one of the two forms is accepted, judged by key presence first and
|
|
23
24
|
// value second, so the declared schema and the runtime check below agree: a
|
|
24
25
|
// caller that skips schema validation gets the same refusals as one that does
|
|
25
26
|
// not. `oneOf` (not `anyOf`) is what makes "both keys present" invalid in both.
|
|
26
|
-
const selectionSchema = { type: "object", required: ["asset_id", "asset_version"], additionalProperties: false, oneOf: [{ required: ["judgment_id"] }, { required: ["judgment_ids"] }], properties: { asset_id: selectionKey, asset_version: selectionKey, judgment_id: selectionKey, judgment_ids: { type: "array", minItems: 1, maxItems: 64, uniqueItems: true, items: selectionKey } } };
|
|
27
|
+
const selectionSchema = { type: "object", required: ["asset_id", "asset_version"], additionalProperties: false, oneOf: [{ required: ["judgment_id"] }, { required: ["judgment_ids"] }], properties: { asset_id: selectionKey, asset_version: selectionKey, artifact_digest: selectionKey, judgment_id: selectionKey, judgment_ids: { type: "array", minItems: 1, maxItems: 64, uniqueItems: true, items: selectionKey } } };
|
|
27
28
|
const validId = value => typeof value === "string" && value.length > 0 && value.length <= 4096;
|
|
28
29
|
// Exactly one of the two keys must be PRESENT: the compatibility singular field,
|
|
29
30
|
// or the plural set that one call can carry. Presence is checked before the
|
|
30
31
|
// value, so `judgment_id: null` alongside a valid `judgment_ids` is refused
|
|
31
32
|
// rather than silently ignored.
|
|
32
|
-
const selectionKeys = ["asset_id", "asset_version", "judgment_id", "judgment_ids"];
|
|
33
|
+
const selectionKeys = ["asset_id", "asset_version", "artifact_digest", "judgment_id", "judgment_ids"];
|
|
33
34
|
function validReadSelection(selection) {
|
|
34
35
|
if (!selection || typeof selection !== "object" || Array.isArray(selection)) return false;
|
|
35
36
|
if (Object.keys(selection).some(key => !selectionKeys.includes(key))) return false;
|
|
36
37
|
if (!validId(selection.asset_id) || !validId(selection.asset_version)) return false;
|
|
38
|
+
if (Object.hasOwn(selection, "artifact_digest") && !validId(selection.artifact_digest)) return false;
|
|
37
39
|
const hasSingular = Object.hasOwn(selection, "judgment_id"), hasPlural = Object.hasOwn(selection, "judgment_ids");
|
|
38
40
|
if (hasSingular === hasPlural) return false;
|
|
39
41
|
if (!hasPlural) return validId(selection.judgment_id);
|
|
@@ -45,11 +47,11 @@ function selectionIds(selection) {
|
|
|
45
47
|
}
|
|
46
48
|
const tools = [
|
|
47
49
|
{ name: "kdna.binding-status", description: "Report only this process's operator-established local binding. It grants no new permission.", inputSchema: emptySchema },
|
|
48
|
-
{ name: "kdna.inspect", description: "Inspect the bound file(s) through the official CLI; technical facts do not authorize actions or establish authorship. Optional asset_id
|
|
49
|
-
{ name: "kdna.catalog", description: "Read the complete public catalog once. On a multi-asset operator binding, pass asset_id or use kdna.catalog_all. budget_bytes is optional (0..1000000, default 1000000): in the default body presentation it bounds the projected body view (recommended >= 32768; e.g. a
|
|
50
|
+
{ name: "kdna.inspect", description: "Inspect the bound file(s) through the official CLI; technical facts do not authorize actions or establish authorship. Optional asset_id and/or artifact_digest select one asset when multiple assets are operator-bound (including bilingual editions sharing asset_id and asset_version).", inputSchema: { type: "object", additionalProperties: false, properties: { asset_id: selectionKey, artifact_digest: selectionKey } } },
|
|
51
|
+
{ name: "kdna.catalog", description: "Read the complete public catalog once. On a multi-asset operator binding, pass asset_id (and optional artifact_digest to disambiguate same-(asset_id, asset_version) editions) or use kdna.catalog_all. budget_bytes is optional (0..1000000, default 1000000): in the default body presentation it bounds the projected body view (recommended >= 32768; e.g. a 40-judgment catalog is ~8-12 KiB projected vs >200 KiB raw); in presentation:\"full\" or \"task\" it bounds the complete official Read envelope (recommended >= 1000000). The default presentation is the installed Read body view (authored content plus one fingerprint); presentation:\"full\" returns the complete official envelope and an explicit body request is refused when that package cannot project; optional task presentation requires an independent view_budget_bytes.", inputSchema: { type: "object", additionalProperties: false, allOf: presentationRules, properties: { asset_id: selectionKey, artifact_digest: selectionKey, budget_bytes: catalogBudgetSchema, ...presentationProperties } } },
|
|
50
52
|
{ name: "kdna.catalog_all", description: "Read the complete public catalog across all operator-bound assets in one call (explicit OS argv allowlist only; zero directory scanning). budget_bytes is optional (0..1000000, default 1000000) and bounds the complete aggregated projected body response (or each official envelope in full/task presentation).", inputSchema: { type: "object", additionalProperties: false, allOf: presentationRules, properties: { budget_bytes: catalogBudgetSchema, ...presentationProperties } } },
|
|
51
|
-
{ name: "kdna.read", description: "Batch the exact judgments needed for this task with mandatory closure in one snapshot. On multi-asset operator bindings, selection.asset_id and selection.
|
|
52
|
-
{ name: "kdna.expand", description: "Return an original handle or this process's short handle_ref to the same official CLI. The default presentation is the installed Read body view; presentation:\"full\" returns the complete official envelope. A reference grants no permission; Read still validates scope, snapshot, epoch and expiry.", inputSchema: { type: "object", required: ["budget_bytes"], additionalProperties: false, oneOf: [{ required: ["handle"] }, { required: ["handle_ref"] }], allOf: presentationRules, properties: { handle: { type: "object" }, handle_ref: selectionKey, budget_bytes: budgetSchema, ...presentationProperties } } },
|
|
53
|
+
{ name: "kdna.read", description: "Batch the exact judgments needed for this task with mandatory closure in one snapshot. On multi-asset operator bindings, selection.asset_id, selection.asset_version, and optional selection.artifact_digest route strictly to that bound asset's isolated CLI session. The default presentation is the installed Read body view; presentation:\"full\" returns the complete official envelope. Keep the complete result; repeat only for a new need. Optional task is a lossless adapter view, not an official Read envelope.", inputSchema: { type: "object", required: ["selection", "budget_bytes"], additionalProperties: false, allOf: presentationRules, properties: { selection: selectionSchema, budget_bytes: budgetSchema, ...presentationProperties } } },
|
|
54
|
+
{ name: "kdna.expand", description: "Return an original handle or this process's short handle_ref to the same official CLI. Optional artifact_digest disambiguates bilingual editions and verifies container digest alignment. The default presentation is the installed Read body view; presentation:\"full\" returns the complete official envelope. A reference grants no permission; Read still validates scope, snapshot, epoch and expiry.", inputSchema: { type: "object", required: ["budget_bytes"], additionalProperties: false, oneOf: [{ required: ["handle"] }, { required: ["handle_ref"] }], allOf: presentationRules, properties: { handle: { type: "object" }, handle_ref: selectionKey, artifact_digest: selectionKey, budget_bytes: budgetSchema, ...presentationProperties } } },
|
|
53
55
|
{ name: "kdna.audit", description: "Retrieve the exact past full result for a delivered task audit_ref, within an explicit budget and the same live operator binding. This performs no new verification, reading or authorization.", inputSchema: { type: "object", required: ["audit_ref", "budget_bytes"], additionalProperties: false, properties: { audit_ref: selectionKey, budget_bytes: budgetSchema } } },
|
|
54
56
|
{ name: "kdna.cancel", description: "Cancel local presentation and revoke this process binding. Only a new operator-controlled launch can select again.", inputSchema: emptySchema },
|
|
55
57
|
];
|
|
@@ -67,10 +69,11 @@ if (binding) {
|
|
|
67
69
|
views: new ReadingViews(assetBinding, session),
|
|
68
70
|
asset_id: null,
|
|
69
71
|
asset_version: null,
|
|
72
|
+
artifact_digest: assetBinding.digest ?? null,
|
|
70
73
|
identityChecked: false,
|
|
71
74
|
};
|
|
72
75
|
});
|
|
73
|
-
const modelView = loadModelView();
|
|
76
|
+
const modelView = loadModelView(resolvedRuntime.read.directory);
|
|
74
77
|
const defaultPresentation = modelView ? "body" : "full";
|
|
75
78
|
// What the model receives is the official Read projection of the complete
|
|
76
79
|
// result this process already validated; the full result stays available to
|
|
@@ -84,12 +87,30 @@ if (binding) {
|
|
|
84
87
|
}
|
|
85
88
|
function observeIdentity(slot, value) {
|
|
86
89
|
const asset = value?.channel === "read_envelope" ? value.envelope?.asset : value?.status === "accepted" ? value.asset : null;
|
|
90
|
+
const observedDigest = value?.channel === "read_envelope"
|
|
91
|
+
? value.envelope?.digests?.A?.observed
|
|
92
|
+
: value?.status === "accepted"
|
|
93
|
+
? value.digests?.A?.observed
|
|
94
|
+
: null;
|
|
95
|
+
if (typeof observedDigest === "string" && observedDigest.length > 0) {
|
|
96
|
+
slot.artifact_digest = observedDigest;
|
|
97
|
+
}
|
|
87
98
|
if (asset && typeof asset.asset_id === "string" && asset.asset_id.length > 0) {
|
|
88
99
|
slot.asset_id = asset.asset_id;
|
|
89
100
|
slot.asset_version = typeof asset.asset_version === "string" ? asset.asset_version : slot.asset_version;
|
|
90
101
|
slot.identityChecked = true;
|
|
91
102
|
}
|
|
92
103
|
}
|
|
104
|
+
function slotDigest(slot) {
|
|
105
|
+
return slot.artifact_digest ?? slot.binding.digest ?? null;
|
|
106
|
+
}
|
|
107
|
+
function assertSlotDigestMatches(slot, expectedDigest) {
|
|
108
|
+
if (!expectedDigest) return;
|
|
109
|
+
const actual = slotDigest(slot);
|
|
110
|
+
if (!actual || actual !== expectedDigest) {
|
|
111
|
+
throw new AdapterError("MCP_ARTIFACT_DIGEST_MISMATCH", "The requested artifact_digest does not match the bound asset's container digest.");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
93
114
|
async function ensureSlotIdentities(signal) {
|
|
94
115
|
for (const slot of slots) {
|
|
95
116
|
if (slot.identityChecked) continue;
|
|
@@ -98,17 +119,37 @@ if (binding) {
|
|
|
98
119
|
observeIdentity(slot, inspected);
|
|
99
120
|
}
|
|
100
121
|
}
|
|
101
|
-
async function resolveSlotByAsset(assetId, assetVersion, signal) {
|
|
122
|
+
async function resolveSlotByAsset(assetId, assetVersion, artifactDigest, signal) {
|
|
102
123
|
binding.assertReadable();
|
|
103
124
|
await ensureSlotIdentities(signal);
|
|
125
|
+
if (artifactDigest) {
|
|
126
|
+
let candidates = slots.filter(slot => slotDigest(slot) === artifactDigest);
|
|
127
|
+
if (candidates.length === 0) {
|
|
128
|
+
const hasAssetMatch = assetId ? slots.some(slot => slot.asset_id === assetId) : false;
|
|
129
|
+
if (hasAssetMatch || slots.length === 1) {
|
|
130
|
+
throw new AdapterError("MCP_ARTIFACT_DIGEST_MISMATCH", "The requested artifact_digest does not match any bound asset for that identity.");
|
|
131
|
+
}
|
|
132
|
+
throw new AdapterError("MCP_ASSET_NOT_BOUND", "The requested artifact_digest is not in this process's operator-bound allowlist.");
|
|
133
|
+
}
|
|
134
|
+
if (assetId) {
|
|
135
|
+
candidates = candidates.filter(slot => slot.asset_id === assetId);
|
|
136
|
+
if (candidates.length === 0) throw new AdapterError("MCP_ARTIFACT_DIGEST_MISMATCH", "The requested artifact_digest belongs to a different asset_id.");
|
|
137
|
+
}
|
|
138
|
+
if (assetVersion) {
|
|
139
|
+
candidates = candidates.filter(slot => slot.asset_version === assetVersion);
|
|
140
|
+
if (candidates.length === 0) throw new AdapterError("MCP_ARTIFACT_DIGEST_MISMATCH", "The requested artifact_digest belongs to a different asset_version.");
|
|
141
|
+
}
|
|
142
|
+
if (candidates.length === 1) return candidates[0];
|
|
143
|
+
throw new AdapterError("MCP_ASSET_AMBIGUOUS", "Multiple bound files match the requested identity and artifact_digest.");
|
|
144
|
+
}
|
|
104
145
|
if (assetVersion) {
|
|
105
146
|
const exactMatches = slots.filter(slot => slot.asset_id === assetId && slot.asset_version === assetVersion);
|
|
106
147
|
if (exactMatches.length === 1) return exactMatches[0];
|
|
107
|
-
if (exactMatches.length > 1) throw new AdapterError("MCP_ASSET_AMBIGUOUS", "Multiple bound files declare the same asset_id and asset_version.");
|
|
148
|
+
if (exactMatches.length > 1) throw new AdapterError("MCP_ASSET_AMBIGUOUS", "Multiple bound files declare the same asset_id and asset_version; specify artifact_digest to disambiguate.");
|
|
108
149
|
}
|
|
109
150
|
const idMatches = slots.filter(slot => slot.asset_id === assetId);
|
|
110
151
|
if (idMatches.length === 1) return idMatches[0];
|
|
111
|
-
if (idMatches.length > 1) throw new AdapterError("MCP_ASSET_AMBIGUOUS", "Multiple bound files declare the same asset_id; specify an unambiguous asset_version or
|
|
152
|
+
if (idMatches.length > 1) throw new AdapterError("MCP_ASSET_AMBIGUOUS", "Multiple bound files declare the same asset_id; specify an unambiguous asset_version or artifact_digest.");
|
|
112
153
|
throw new AdapterError("MCP_ASSET_NOT_BOUND", "The requested asset_id is not in this process's operator-bound allowlist.");
|
|
113
154
|
}
|
|
114
155
|
let initialized = false, ready = false, active = null, shuttingDown = false, shutdownWork = null, outputFailed = false, writing = Promise.resolve();
|
|
@@ -160,14 +201,14 @@ if (binding) {
|
|
|
160
201
|
}
|
|
161
202
|
function validCall(name, args) {
|
|
162
203
|
if (["kdna.binding-status", "kdna.cancel"].includes(name)) return keys(args, []);
|
|
163
|
-
if (name === "kdna.inspect") return object(args) && Object.keys(args).every(key => key === "asset_id") && (!Object.hasOwn(args, "asset_id") || validId(args.asset_id));
|
|
164
|
-
if (name === "kdna.catalog") return validPresentation(args, [], ["asset_id", "budget_bytes"]) && (!Object.hasOwn(args, "budget_bytes") || validBudget(args.budget_bytes)) && (!Object.hasOwn(args, "asset_id") || validId(args.asset_id));
|
|
204
|
+
if (name === "kdna.inspect") return object(args) && Object.keys(args).every(key => key === "asset_id" || key === "artifact_digest") && (!Object.hasOwn(args, "asset_id") || validId(args.asset_id)) && (!Object.hasOwn(args, "artifact_digest") || validId(args.artifact_digest));
|
|
205
|
+
if (name === "kdna.catalog") return validPresentation(args, [], ["asset_id", "artifact_digest", "budget_bytes"]) && (!Object.hasOwn(args, "budget_bytes") || validBudget(args.budget_bytes)) && (!Object.hasOwn(args, "asset_id") || validId(args.asset_id)) && (!Object.hasOwn(args, "artifact_digest") || validId(args.artifact_digest));
|
|
165
206
|
if (name === "kdna.catalog_all") return validPresentation(args, [], ["budget_bytes"]) && (!Object.hasOwn(args, "budget_bytes") || validBudget(args.budget_bytes));
|
|
166
207
|
if (name === "kdna.read") return validPresentation(args, ["selection", "budget_bytes"]) && validBudget(args.budget_bytes) && validReadSelection(args.selection);
|
|
167
208
|
if (name === "kdna.expand") {
|
|
168
209
|
if (!object(args) || Object.hasOwn(args, "handle") === Object.hasOwn(args, "handle_ref")) return false;
|
|
169
210
|
const key = Object.hasOwn(args, "handle") ? "handle" : "handle_ref";
|
|
170
|
-
return validPresentation(args, [key, "budget_bytes"]) && validBudget(args.budget_bytes) && (key === "handle" ? object(args.handle) : validId(args.handle_ref));
|
|
211
|
+
return validPresentation(args, [key, "budget_bytes"], ["artifact_digest"]) && validBudget(args.budget_bytes) && (key === "handle" ? object(args.handle) : validId(args.handle_ref)) && (!Object.hasOwn(args, "artifact_digest") || validId(args.artifact_digest));
|
|
171
212
|
}
|
|
172
213
|
if (name === "kdna.audit") return keys(args, ["audit_ref", "budget_bytes"]) && validId(args.audit_ref) && validBudget(args.budget_bytes);
|
|
173
214
|
return false;
|
|
@@ -199,6 +240,7 @@ if (binding) {
|
|
|
199
240
|
index: slot.binding.index,
|
|
200
241
|
file_name: slot.binding.name,
|
|
201
242
|
local_binding_digest: slot.binding.digest,
|
|
243
|
+
artifact_digest: slotDigest(slot),
|
|
202
244
|
asset_id: slot.asset_id,
|
|
203
245
|
asset_version: slot.asset_version,
|
|
204
246
|
catalog: presented,
|
|
@@ -227,7 +269,7 @@ if (binding) {
|
|
|
227
269
|
await result(id, text(aggregated));
|
|
228
270
|
return;
|
|
229
271
|
}
|
|
230
|
-
if (name === "kdna.inspect" && slots.length > 1 && !Object.hasOwn(args, "asset_id")) {
|
|
272
|
+
if (name === "kdna.inspect" && slots.length > 1 && !Object.hasOwn(args, "asset_id") && !Object.hasOwn(args, "artifact_digest")) {
|
|
231
273
|
const assets = [];
|
|
232
274
|
let allAccepted = true;
|
|
233
275
|
for (const slot of slots) {
|
|
@@ -236,35 +278,53 @@ if (binding) {
|
|
|
236
278
|
slot.identityChecked = true;
|
|
237
279
|
observeIdentity(slot, inspected);
|
|
238
280
|
if (inspected.status !== "accepted") allAccepted = false;
|
|
239
|
-
assets.push({ index: slot.binding.index, file_name: slot.binding.name, local_binding_digest: slot.binding.digest, inspection: inspected });
|
|
281
|
+
assets.push({ index: slot.binding.index, file_name: slot.binding.name, local_binding_digest: slot.binding.digest, artifact_digest: slotDigest(slot), inspection: inspected });
|
|
240
282
|
}
|
|
241
283
|
await result(id, { ...text({ status: allAccepted ? "accepted" : "rejected", bound_asset_count: slots.length, action_authorized: false, assets }), ...(allAccepted ? {} : { isError: true }) });
|
|
242
284
|
return;
|
|
243
285
|
}
|
|
244
286
|
let slot;
|
|
287
|
+
const requestedDigest = name === "kdna.read"
|
|
288
|
+
? (Object.hasOwn(args.selection, "artifact_digest") ? args.selection.artifact_digest : null)
|
|
289
|
+
: (Object.hasOwn(args, "artifact_digest") ? args.artifact_digest : null);
|
|
245
290
|
if (name === "kdna.audit") {
|
|
246
291
|
slot = slots.length === 1 ? slots[0] : slots.find(candidate => candidate.views.hasAudit(args.audit_ref));
|
|
247
292
|
if (!slot) throw new AdapterError("MCP_REFERENCE_UNAVAILABLE", "The reference is absent, expired or outside this live operator-bound session. A reference grants no permission.");
|
|
248
293
|
} else if (name === "kdna.expand") {
|
|
249
|
-
if (slots.length === 1)
|
|
250
|
-
|
|
294
|
+
if (slots.length === 1) {
|
|
295
|
+
slot = slots[0];
|
|
296
|
+
if (requestedDigest && !Object.hasOwn(args, "handle_ref")) assertSlotDigestMatches(slot, requestedDigest);
|
|
297
|
+
} else if (Object.hasOwn(args, "handle_ref")) {
|
|
251
298
|
slot = slots.find(candidate => candidate.views.hasHandle(args.handle_ref));
|
|
252
299
|
if (!slot) throw new AdapterError("MCP_REFERENCE_UNAVAILABLE", "The reference is absent, expired or outside this live operator-bound session. A reference grants no permission.");
|
|
253
300
|
} else {
|
|
254
301
|
const handleAsset = args.handle?.asset;
|
|
255
302
|
if (!handleAsset || !validId(handleAsset.asset_id)) throw new AdapterError("MCP_ASSET_NOT_BOUND", "The expansion handle does not identify a bound asset.");
|
|
256
|
-
slot = await resolveSlotByAsset(handleAsset.asset_id, validId(handleAsset.asset_version) ? handleAsset.asset_version : null, operation.controller.signal);
|
|
303
|
+
slot = await resolveSlotByAsset(handleAsset.asset_id, validId(handleAsset.asset_version) ? handleAsset.asset_version : null, requestedDigest, operation.controller.signal);
|
|
257
304
|
}
|
|
258
305
|
} else if (name === "kdna.read") {
|
|
259
|
-
|
|
306
|
+
if (slots.length === 1) {
|
|
307
|
+
slot = slots[0];
|
|
308
|
+
if (requestedDigest) assertSlotDigestMatches(slot, requestedDigest);
|
|
309
|
+
} else {
|
|
310
|
+
slot = await resolveSlotByAsset(args.selection.asset_id, args.selection.asset_version, requestedDigest, operation.controller.signal);
|
|
311
|
+
}
|
|
260
312
|
} else if (name === "kdna.catalog") {
|
|
261
|
-
if (Object.hasOwn(args, "asset_id")
|
|
262
|
-
|
|
263
|
-
else
|
|
313
|
+
if (Object.hasOwn(args, "asset_id") || Object.hasOwn(args, "artifact_digest")) {
|
|
314
|
+
slot = await resolveSlotByAsset(args.asset_id ?? null, null, requestedDigest, operation.controller.signal);
|
|
315
|
+
} else if (slots.length === 1) {
|
|
316
|
+
slot = slots[0];
|
|
317
|
+
} else {
|
|
318
|
+
throw new AdapterError("MCP_ASSET_SELECTION_REQUIRED", "Multiple assets are bound; call kdna.catalog_all or specify asset_id (and optional artifact_digest) on kdna.catalog.");
|
|
319
|
+
}
|
|
264
320
|
} else if (name === "kdna.inspect") {
|
|
265
|
-
|
|
321
|
+
if (Object.hasOwn(args, "asset_id") || Object.hasOwn(args, "artifact_digest")) {
|
|
322
|
+
slot = await resolveSlotByAsset(args.asset_id ?? null, null, requestedDigest, operation.controller.signal);
|
|
323
|
+
} else {
|
|
324
|
+
slot = slots[0];
|
|
325
|
+
}
|
|
266
326
|
}
|
|
267
|
-
const handle = Object.hasOwn(args, "handle_ref") ? slot.views.expand(args.handle_ref) : args.handle ?? null;
|
|
327
|
+
const handle = Object.hasOwn(args, "handle_ref") ? slot.views.expand(args.handle_ref, requestedDigest) : args.handle ?? null;
|
|
268
328
|
const callerBudget = name === "kdna.catalog" && !Object.hasOwn(args, "budget_bytes") ? DEFAULT_CATALOG_BUDGET_BYTES : args.budget_bytes;
|
|
269
329
|
const isCatalogBody = name === "kdna.catalog" && selectedPresentation === "body" && modelView !== null;
|
|
270
330
|
const officialBudget = isCatalogBody && callerBudget > 0 ? Math.max(callerBudget, CATALOG_BODY_ENVELOPE_BUDGET_BYTES) : callerBudget;
|
package/bin/model-view.mjs
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
import { createRequire } from "node:module";
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
+
const defaultRequire = createRequire(import.meta.url);
|
|
4
5
|
|
|
5
6
|
// The installed Read package owns the projection function; this adapter calls
|
|
6
|
-
// the same official entry the CLI uses and never reshapes fields itself.
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
export function loadModelView() {
|
|
7
|
+
// the same official entry the CLI uses and never reshapes fields itself. When
|
|
8
|
+
// given the CLI-resolved Read directory, projection is guaranteed to load the
|
|
9
|
+
// exact same @aikdna/kdna-read installation as the spawned CLI session.
|
|
10
|
+
export function loadModelView(readDirectory = null) {
|
|
10
11
|
try {
|
|
11
|
-
const module =
|
|
12
|
+
const module = readDirectory
|
|
13
|
+
? createRequire(path.join(readDirectory, "package.json"))(".")
|
|
14
|
+
: defaultRequire("@aikdna/kdna-read");
|
|
12
15
|
return typeof module.projectModelView === "function" &&
|
|
13
16
|
typeof module.MODEL_VIEW_CONTRACT === "string"
|
|
14
17
|
? module
|
package/bin/read-session.mjs
CHANGED
|
@@ -2,36 +2,174 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { spawn } from "node:child_process";
|
|
5
|
-
import { createHash } from "node:crypto";
|
|
6
5
|
import { createRequire } from "node:module";
|
|
7
6
|
import { AdapterError } from "./operator-binding.mjs";
|
|
8
7
|
|
|
9
8
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
|
|
10
|
+
// Minimum compatible versions within the same minor line (blocks downgrades and
|
|
11
|
+
// major/minor drift while allowing patch updates without single-commit SHA lockstep).
|
|
12
|
+
export const MIN_RUNTIME_VERSIONS = Object.freeze({
|
|
13
|
+
cli: "0.47.4",
|
|
14
|
+
core: "0.37.14",
|
|
15
|
+
read: "0.13.8",
|
|
16
|
+
container: "0.6.0",
|
|
17
|
+
read_contract: "kdna.read/0.7.0-candidate",
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const SEMVER_STABLE = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/u;
|
|
21
|
+
|
|
22
|
+
export function isCompatibleSameMinor(actual, minimum) {
|
|
23
|
+
if (typeof actual !== "string" || typeof minimum !== "string") return false;
|
|
24
|
+
const a = SEMVER_STABLE.exec(actual);
|
|
25
|
+
const m = SEMVER_STABLE.exec(minimum);
|
|
26
|
+
if (!a || !m) return false;
|
|
27
|
+
return Number(a[1]) === Number(m[1]) && Number(a[2]) === Number(m[2]) && Number(a[3]) >= Number(m[3]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function runtimeError(message) {
|
|
31
|
+
return new AdapterError("MCP_RUNTIME_INVALID", message);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function assertRealPackageFile(filePath, message) {
|
|
35
|
+
let stat;
|
|
36
|
+
try { stat = fs.lstatSync(filePath); }
|
|
37
|
+
catch { throw runtimeError(message); }
|
|
38
|
+
if (!stat.isFile() || stat.isSymbolicLink()) throw runtimeError(message);
|
|
39
|
+
let real;
|
|
40
|
+
try { real = fs.realpathSync(filePath); }
|
|
41
|
+
catch { throw runtimeError(message); }
|
|
42
|
+
if (real !== filePath) throw runtimeError(message);
|
|
43
|
+
return real;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function assertRealPackageDir(directory, message) {
|
|
47
|
+
let stat;
|
|
48
|
+
try { stat = fs.lstatSync(directory); }
|
|
49
|
+
catch { throw runtimeError(message); }
|
|
50
|
+
if (!stat.isDirectory() || stat.isSymbolicLink()) throw runtimeError(message);
|
|
51
|
+
let real;
|
|
52
|
+
try { real = fs.realpathSync(directory); }
|
|
53
|
+
catch { throw runtimeError(message); }
|
|
54
|
+
if (real !== directory) throw runtimeError(message);
|
|
55
|
+
return real;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function readJsonStrict(filePath, message) {
|
|
59
|
+
try { return JSON.parse(fs.readFileSync(filePath, "utf8")); }
|
|
60
|
+
catch { throw runtimeError(message); }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function resolveCliPackage(realRoot) {
|
|
64
|
+
const roots = [path.join(realRoot, "node_modules")];
|
|
65
|
+
if (path.basename(path.dirname(realRoot)) === "@aikdna" && path.basename(path.dirname(path.dirname(realRoot))) === "node_modules") {
|
|
66
|
+
roots.push(path.dirname(path.dirname(realRoot)));
|
|
67
|
+
}
|
|
15
68
|
for (const base of roots) {
|
|
16
|
-
const directory = path.join(base, "@aikdna", "kdna-"
|
|
17
|
-
|
|
18
|
-
if (fs.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
69
|
+
const directory = path.join(base, "@aikdna", "kdna-cli");
|
|
70
|
+
const pkgPath = path.join(directory, "package.json");
|
|
71
|
+
if (!fs.existsSync(pkgPath)) continue;
|
|
72
|
+
assertRealPackageDir(directory, "The local KDNA CLI installation is unavailable or symlinked.");
|
|
73
|
+
assertRealPackageFile(pkgPath, "The local KDNA CLI manifest is unavailable or symlinked.");
|
|
74
|
+
const value = readJsonStrict(pkgPath, "The local KDNA CLI manifest is invalid.");
|
|
75
|
+
if (value.name !== "@aikdna/kdna-cli" || !isCompatibleSameMinor(value.version, MIN_RUNTIME_VERSIONS.cli)) {
|
|
76
|
+
throw runtimeError("The local KDNA CLI installation does not meet the minimum compatible runtime version.");
|
|
77
|
+
}
|
|
78
|
+
return { directory, base, pkgPath, value, searchRoots: roots };
|
|
79
|
+
}
|
|
80
|
+
throw runtimeError("The local CLI/Core/Read installation is unavailable.");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function resolveFromCli(cli, pkgName, minVersion) {
|
|
84
|
+
const cliRequire = createRequire(cli.pkgPath);
|
|
85
|
+
let resolvedPkgPath;
|
|
86
|
+
try { resolvedPkgPath = cliRequire.resolve(pkgName + "/package.json"); }
|
|
87
|
+
catch { throw runtimeError("The local CLI runtime dependency " + pkgName + " is unavailable."); }
|
|
88
|
+
let realPkgPath;
|
|
89
|
+
try { realPkgPath = fs.realpathSync(resolvedPkgPath); }
|
|
90
|
+
catch { throw runtimeError("The local CLI runtime dependency " + pkgName + " cannot be resolved."); }
|
|
91
|
+
if (realPkgPath !== resolvedPkgPath) {
|
|
92
|
+
throw runtimeError("The local CLI runtime dependency " + pkgName + " resolves through an untrusted symlink.");
|
|
93
|
+
}
|
|
94
|
+
const directory = path.dirname(realPkgPath);
|
|
95
|
+
assertRealPackageDir(directory, "The local CLI runtime dependency " + pkgName + " directory is untrusted.");
|
|
96
|
+
assertRealPackageFile(realPkgPath, "The local CLI runtime dependency " + pkgName + " manifest is untrusted.");
|
|
97
|
+
const allowedBases = new Set([
|
|
98
|
+
path.join(cli.directory, "node_modules"),
|
|
99
|
+
cli.base,
|
|
100
|
+
...cli.searchRoots,
|
|
101
|
+
]);
|
|
102
|
+
const parts = pkgName.split("/");
|
|
103
|
+
const insideAllowedBase = [...allowedBases].some(base => directory === path.join(base, ...parts));
|
|
104
|
+
if (!insideAllowedBase) {
|
|
105
|
+
throw runtimeError("The local CLI runtime dependency " + pkgName + " resolved outside the trusted installation tree.");
|
|
106
|
+
}
|
|
107
|
+
const value = readJsonStrict(realPkgPath, "The local CLI runtime dependency " + pkgName + " manifest is invalid.");
|
|
108
|
+
if (value.name !== pkgName || !isCompatibleSameMinor(value.version, minVersion)) {
|
|
109
|
+
throw runtimeError("The local CLI runtime dependency " + pkgName + " does not meet the minimum compatible runtime version.");
|
|
22
110
|
}
|
|
23
|
-
|
|
111
|
+
return { directory, pkgPath: realPkgPath, value };
|
|
24
112
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
113
|
+
|
|
114
|
+
export function resolveNativeRuntime(mcpRoot = root) {
|
|
115
|
+
let realRoot;
|
|
116
|
+
try { realRoot = fs.realpathSync(mcpRoot); }
|
|
117
|
+
catch { throw runtimeError("The MCP package root cannot be resolved."); }
|
|
118
|
+
const pkgInfo = readJsonStrict(path.join(realRoot, "package.json"), "The MCP package manifest is invalid.");
|
|
119
|
+
if (
|
|
120
|
+
!isCompatibleSameMinor(pkgInfo.kdna_runtime?.cli, MIN_RUNTIME_VERSIONS.cli) ||
|
|
121
|
+
!isCompatibleSameMinor(pkgInfo.kdna_runtime?.core, MIN_RUNTIME_VERSIONS.core) ||
|
|
122
|
+
!isCompatibleSameMinor(pkgInfo.kdna_runtime?.read, MIN_RUNTIME_VERSIONS.read) ||
|
|
123
|
+
pkgInfo.kdna_runtime?.read_contract !== MIN_RUNTIME_VERSIONS.read_contract
|
|
124
|
+
) {
|
|
125
|
+
throw runtimeError("The MCP manifest runtime declaration is invalid.");
|
|
126
|
+
}
|
|
127
|
+
const cli = resolveCliPackage(realRoot);
|
|
128
|
+
// Resolve Core and Read strictly through CLI's own module resolution graph so
|
|
129
|
+
// global co-installs (npm 11 isolated global trees) never trip over separate
|
|
130
|
+
// copies while still blocking real diamond Core splits and untrusted symlinks.
|
|
131
|
+
const core = resolveFromCli(cli, "@aikdna/kdna-core", MIN_RUNTIME_VERSIONS.core);
|
|
132
|
+
const read = resolveFromCli(cli, "@aikdna/kdna-read", MIN_RUNTIME_VERSIONS.read);
|
|
133
|
+
|
|
134
|
+
let coreSeenByRead;
|
|
135
|
+
try { coreSeenByRead = createRequire(read.pkgPath).resolve("@aikdna/kdna-core/package.json"); }
|
|
136
|
+
catch { throw runtimeError("The local Read package cannot resolve @aikdna/kdna-core."); }
|
|
137
|
+
let realCoreSeenByRead;
|
|
138
|
+
try { realCoreSeenByRead = fs.realpathSync(coreSeenByRead); }
|
|
139
|
+
catch { throw runtimeError("The local Read package Core resolution cannot be verified."); }
|
|
140
|
+
if (realCoreSeenByRead !== core.pkgPath) {
|
|
141
|
+
throw runtimeError("The native runtime contains a shadow Core dependency between CLI and Read.");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const bindingPath = path.join(cli.directory, "public-contract-binding.json");
|
|
145
|
+
assertRealPackageFile(bindingPath, "The CLI public contract binding is unavailable or symlinked.");
|
|
146
|
+
const binding = readJsonStrict(bindingPath, "The CLI public contract binding is invalid.");
|
|
147
|
+
|
|
148
|
+
const cliEntry = path.resolve(cli.directory, cli.value.bin?.kdna || "");
|
|
149
|
+
if (!cliEntry.startsWith(cli.directory + path.sep)) {
|
|
150
|
+
throw runtimeError("The CLI entry point escapes the CLI package directory.");
|
|
151
|
+
}
|
|
152
|
+
assertRealPackageFile(cliEntry, "The CLI entry point is unavailable or symlinked.");
|
|
153
|
+
|
|
154
|
+
if (
|
|
155
|
+
binding.implementation?.name !== "@aikdna/kdna-cli" ||
|
|
156
|
+
binding.implementation?.version !== cli.value.version ||
|
|
157
|
+
binding.tuple?.container !== MIN_RUNTIME_VERSIONS.container ||
|
|
158
|
+
binding.tuple?.read !== MIN_RUNTIME_VERSIONS.read_contract ||
|
|
159
|
+
binding.accepted_core?.version !== core.value.version ||
|
|
160
|
+
binding.accepted_read?.version !== read.value.version
|
|
161
|
+
) {
|
|
162
|
+
throw runtimeError("The native runtime contract binding is incompatible with the installed CLI/Core/Read.");
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return { packageInfo: pkgInfo, cli, core, read, cliEntry, publicBinding: binding };
|
|
34
166
|
}
|
|
167
|
+
|
|
168
|
+
export const resolvedRuntime = resolveNativeRuntime(root);
|
|
169
|
+
export const packageInfo = resolvedRuntime.packageInfo;
|
|
170
|
+
export const publicBinding = resolvedRuntime.publicBinding;
|
|
171
|
+
const cliEntry = resolvedRuntime.cliEntry;
|
|
172
|
+
|
|
35
173
|
const ALLOWED_CHILD_ENV_KEYS = new Set([
|
|
36
174
|
"HOME",
|
|
37
175
|
"TMPDIR",
|
package/bin/reading-views.mjs
CHANGED
|
@@ -111,7 +111,8 @@ export class ReadingViews {
|
|
|
111
111
|
if (!exact(h, handleKeys) || h.binding_kind !== "retained_section_snapshot" || h.origin?.snapshot_id !== e.snapshot_id || h.host_id !== e.receipt.host_id || h.host_epoch !== e.receipt.host_epoch || encode(h.asset) !== encode(e.asset) || encode(h.tuple) !== encode(e.tuple) || !Array.isArray(h.scope) || !Number.isSafeInteger(h.expires_at) || !Number.isSafeInteger(h.issued_at)) unavailable();
|
|
112
112
|
const ref = "handle:" + randomUUID(), remaining = Math.max(0, Math.min(this.ttl, h.expires_at - this.wallNow())), until = this.now() + remaining;
|
|
113
113
|
const handle = structuredClone(h), size = bytes(handle);
|
|
114
|
-
|
|
114
|
+
const artifact_digest = typeof e.digests?.A?.observed === "string" ? e.digests.A.observed : null;
|
|
115
|
+
handleRecords.push([ref, { handle, expires: until, size, scope: this.scope, ...(artifact_digest ? { artifact_digest } : {}) }]); ids.set(h.handle_id, ref);
|
|
115
116
|
return { handle_ref: ref, target: h.target, anchor: h.anchor, scope: h.scope, scope_digest: digest(h.scope), expires_at: this.wallNow() + remaining, availability: remaining > 0 ? "current" : "expired", body_delivery: "unread", permission: "Reference only; the original official Read validates any expansion." };
|
|
116
117
|
});
|
|
117
118
|
}
|
|
@@ -168,10 +169,16 @@ export class ReadingViews {
|
|
|
168
169
|
if (record.size > budget) fail("MCP_AUDIT_BUDGET_EXCEEDED", "The exact past result requires " + record.size + " UTF-8 bytes; no partial audit was delivered.");
|
|
169
170
|
return JSON.parse(record.fullText);
|
|
170
171
|
}
|
|
171
|
-
expand(ref) {
|
|
172
|
+
expand(ref, artifactDigest = null) {
|
|
172
173
|
this.assertLive(); this.prune();
|
|
173
174
|
const record = this.handles.get(ref);
|
|
174
175
|
if (!record || record.scope !== this.scope) stale();
|
|
176
|
+
if (artifactDigest !== null && artifactDigest !== undefined) {
|
|
177
|
+
const expectedDigest = record.artifact_digest ?? this.binding?.digest ?? null;
|
|
178
|
+
if (!expectedDigest || expectedDigest !== artifactDigest) {
|
|
179
|
+
fail("MCP_ARTIFACT_DIGEST_MISMATCH", "The requested artifact_digest does not match the handle's observed container digest.");
|
|
180
|
+
}
|
|
181
|
+
}
|
|
175
182
|
return structuredClone(record.handle);
|
|
176
183
|
}
|
|
177
184
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aikdna/kdna-mcp-server",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.9",
|
|
4
4
|
"description": "Local stdio Read adapter for operator-bound KDNA assets.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"homepage": "https://aikdna.com",
|
|
@@ -40,31 +40,15 @@
|
|
|
40
40
|
},
|
|
41
41
|
"license": "Apache-2.0",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@aikdna/kdna-
|
|
44
|
-
"@aikdna/kdna-read": "0.13.7",
|
|
45
|
-
"ajv": "8.20.0",
|
|
46
|
-
"ajv-formats": "3.0.1",
|
|
47
|
-
"cbor-x": "1.6.9",
|
|
48
|
-
"fast-deep-equal": "3.1.3",
|
|
49
|
-
"fast-uri": "3.1.9",
|
|
50
|
-
"json-schema-traverse": "1.0.0",
|
|
51
|
-
"@noble/hashes": "1.8.0",
|
|
52
|
-
"pako": "2.1.0",
|
|
53
|
-
"require-from-string": "2.0.2",
|
|
54
|
-
"@aikdna/kdna-cli": "0.47.2"
|
|
43
|
+
"@aikdna/kdna-cli": "0.47.4"
|
|
55
44
|
},
|
|
56
45
|
"kdna_runtime": {
|
|
57
|
-
"cli": "0.47.
|
|
58
|
-
"core": "0.37.
|
|
59
|
-
"read": "0.13.
|
|
46
|
+
"cli": "0.47.4",
|
|
47
|
+
"core": "0.37.14",
|
|
48
|
+
"read": "0.13.8",
|
|
60
49
|
"read_contract": "kdna.read/0.7.0-candidate"
|
|
61
50
|
},
|
|
62
51
|
"engines": {
|
|
63
52
|
"node": ">=22"
|
|
64
|
-
},
|
|
65
|
-
"overrides": {
|
|
66
|
-
"fast-uri": "$fast-uri",
|
|
67
|
-
"@aikdna/kdna-core": "$@aikdna/kdna-core",
|
|
68
|
-
"@aikdna/kdna-read": "$@aikdna/kdna-read"
|
|
69
53
|
}
|
|
70
54
|
}
|