@mcp-index/sdk 0.18.0 → 0.19.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 +22 -1
- package/README.md +178 -0
- package/dist/src/ai.d.ts +96 -0
- package/dist/src/ai.d.ts.map +1 -0
- package/dist/src/ai.js +151 -0
- package/dist/src/ai.js.map +1 -0
- package/dist/src/lock/check.d.ts +143 -0
- package/dist/src/lock/check.d.ts.map +1 -0
- package/dist/src/lock/check.js +274 -0
- package/dist/src/lock/check.js.map +1 -0
- package/dist/src/lock/digest.d.ts +48 -0
- package/dist/src/lock/digest.d.ts.map +1 -0
- package/dist/src/lock/digest.js +234 -0
- package/dist/src/lock/digest.js.map +1 -0
- package/dist/src/lock/events.d.ts +82 -0
- package/dist/src/lock/events.d.ts.map +1 -0
- package/dist/src/lock/events.js +80 -0
- package/dist/src/lock/events.js.map +1 -0
- package/dist/src/lock/index.d.ts +20 -0
- package/dist/src/lock/index.d.ts.map +1 -0
- package/dist/src/lock/index.js +14 -0
- package/dist/src/lock/index.js.map +1 -0
- package/dist/src/lock/lock.d.ts +195 -0
- package/dist/src/lock/lock.d.ts.map +1 -0
- package/dist/src/lock/lock.js +1075 -0
- package/dist/src/lock/lock.js.map +1 -0
- package/dist/src/lock/pg.d.ts +150 -0
- package/dist/src/lock/pg.d.ts.map +1 -0
- package/dist/src/lock/pg.js +539 -0
- package/dist/src/lock/pg.js.map +1 -0
- package/dist/src/lock/rawList.d.ts +127 -0
- package/dist/src/lock/rawList.d.ts.map +1 -0
- package/dist/src/lock/rawList.js +561 -0
- package/dist/src/lock/rawList.js.map +1 -0
- package/dist/src/lock/signing.d.ts +35 -0
- package/dist/src/lock/signing.d.ts.map +1 -0
- package/dist/src/lock/signing.js +85 -0
- package/dist/src/lock/signing.js.map +1 -0
- package/dist/src/lock/store.d.ts +149 -0
- package/dist/src/lock/store.d.ts.map +1 -0
- package/dist/src/lock/store.js +459 -0
- package/dist/src/lock/store.js.map +1 -0
- package/dist/src/wrap.d.ts.map +1 -1
- package/dist/src/wrap.js +85 -3
- package/dist/src/wrap.js.map +1 -1
- package/package.json +31 -2
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LockStore: where a host gets its lock snapshot and where approvals land.
|
|
3
|
+
*
|
|
4
|
+
* A snapshot is frozen and carries a snapshotId, so a decision can name the
|
|
5
|
+
* lock state it came from. loadSnapshot never throws for a bad lock: a lock
|
|
6
|
+
* failure comes back as a LockError inside the snapshot, and the check then
|
|
7
|
+
* withholds everything. It may throw when the store itself cannot be reached;
|
|
8
|
+
* hosts treat that as lock-unreadable.
|
|
9
|
+
*
|
|
10
|
+
* The file store reads `.mcp/` once per load (see lock.ts). Approvals and
|
|
11
|
+
* revocations take the existing create-excl file lock on `.mcp/lock.lck`
|
|
12
|
+
* (fileLock.ts), write the contract, then replace the shard (and the manifest,
|
|
13
|
+
* when one exists) by rename from a temporary file in `.mcp/`, so `.mcp/lock`
|
|
14
|
+
* never holds a partial file.
|
|
15
|
+
*/
|
|
16
|
+
import { closeSync, constants, fsyncSync, lstatSync, openSync, readFileSync, realpathSync, renameSync, statSync, unlinkSync, writeSync } from "node:fs";
|
|
17
|
+
import { randomBytes } from "node:crypto";
|
|
18
|
+
import { basename, dirname, isAbsolute, join, parse, resolve, sep } from "node:path";
|
|
19
|
+
import { canonicalBody, instructionsDigest, metaDigest, toolDigest } from "./digest.js";
|
|
20
|
+
import { FrozenMap, LockError, MANIFEST, VIA, formatManifest, formatShard, identityKey, loadLock, loadLockSync, readLockDir, shardFilename, validateIdentity, } from "./lock.js";
|
|
21
|
+
import { withExclusiveLock } from "../fileLock.js";
|
|
22
|
+
import { sigstoreVerifier } from "./signing.js";
|
|
23
|
+
export function nowRfc3339(date = new Date()) {
|
|
24
|
+
return date.toISOString().replace(/\.[0-9]{3}Z$/, "Z");
|
|
25
|
+
}
|
|
26
|
+
export function snapshotOfError(error, loadedAt = Date.now()) {
|
|
27
|
+
return Object.freeze({ snapshotId: `error:${error.reason}`, loadedAt, lock: error });
|
|
28
|
+
}
|
|
29
|
+
export function prepareTool(tool) {
|
|
30
|
+
if (tool === null || typeof tool !== "object" || Array.isArray(tool))
|
|
31
|
+
throw new Error("tool must be an object");
|
|
32
|
+
const name = Object.getOwnPropertyDescriptor(tool, "name")?.value;
|
|
33
|
+
if (typeof name !== "string")
|
|
34
|
+
throw new Error("tool has no string name");
|
|
35
|
+
const digest = toolDigest(tool);
|
|
36
|
+
const body = canonicalBody(tool);
|
|
37
|
+
if (digest === null || body === null)
|
|
38
|
+
throw new Error(`tool ${JSON.stringify(name)} has no digest; it cannot be approved`);
|
|
39
|
+
return { name, digest, contract: `sha256-${digest.slice("sha256:".length)}.json`, body, metaDigest: metaDigest(tool) };
|
|
40
|
+
}
|
|
41
|
+
export function checkApprovalFields(request, subject) {
|
|
42
|
+
if (!VIA.includes(request.via))
|
|
43
|
+
throw new Error(`unknown via ${String(request.via)}`);
|
|
44
|
+
if (typeof subject !== "string" || subject.length === 0)
|
|
45
|
+
throw new Error("approval needs a subject");
|
|
46
|
+
const at = request.at ?? nowRfc3339();
|
|
47
|
+
if (!/^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]+)?(Z|[+-][0-9]{2}:[0-9]{2})$/.test(at)) {
|
|
48
|
+
throw new Error("approval time is not RFC 3339");
|
|
49
|
+
}
|
|
50
|
+
if (request.ref !== undefined && typeof request.ref !== "string")
|
|
51
|
+
throw new Error("ref must be a string");
|
|
52
|
+
return request.ref !== undefined
|
|
53
|
+
? Object.freeze({ subject, at, via: request.via, ref: request.ref })
|
|
54
|
+
: Object.freeze({ subject, at, via: request.via });
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A host-owned file holding the sequence as ASCII digits and a newline, the
|
|
58
|
+
* format the Python host writes to its sequence_path. A missing file is no
|
|
59
|
+
* record; a file that is not a regular file or does not hold digits throws.
|
|
60
|
+
*/
|
|
61
|
+
export function fileSequenceStore(path) {
|
|
62
|
+
const full = resolve(path);
|
|
63
|
+
return {
|
|
64
|
+
read() {
|
|
65
|
+
let st;
|
|
66
|
+
try {
|
|
67
|
+
st = lstatSync(full);
|
|
68
|
+
}
|
|
69
|
+
catch (exc) {
|
|
70
|
+
if (exc.code === "ENOENT")
|
|
71
|
+
return null;
|
|
72
|
+
throw new Error("last accepted sequence is unreadable");
|
|
73
|
+
}
|
|
74
|
+
if (!st.isFile())
|
|
75
|
+
throw new Error("last accepted sequence is not a regular file");
|
|
76
|
+
let raw;
|
|
77
|
+
try {
|
|
78
|
+
raw = readFileSync(full);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
throw new Error("last accepted sequence is unreadable");
|
|
82
|
+
}
|
|
83
|
+
if (raw.some((b) => b > 0x7f))
|
|
84
|
+
throw new Error("last accepted sequence is unreadable");
|
|
85
|
+
const text = raw.toString("latin1").trim();
|
|
86
|
+
if (!/^[0-9]+$/.test(text))
|
|
87
|
+
throw new Error("last accepted sequence is not an integer");
|
|
88
|
+
const n = Number(text);
|
|
89
|
+
if (!Number.isSafeInteger(n))
|
|
90
|
+
throw new Error("last accepted sequence is not an integer");
|
|
91
|
+
return n;
|
|
92
|
+
},
|
|
93
|
+
write(sequence) {
|
|
94
|
+
writeAtomic(dirname(full), full, Buffer.from(`${sequence}\n`, "ascii"), basename(full));
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
// Host configuration paths ---------------------------------------------------
|
|
99
|
+
/** A host configuration the host must not run with. Thrown when a store is constructed. */
|
|
100
|
+
export class HostConfigError extends Error {
|
|
101
|
+
constructor(message) {
|
|
102
|
+
super(message);
|
|
103
|
+
this.name = "HostConfigError";
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function exists(path) {
|
|
107
|
+
try {
|
|
108
|
+
lstatSync(path);
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** (st_dev, st_ino) of what `path` resolves to, or null when it does not resolve. */
|
|
116
|
+
function identity(path) {
|
|
117
|
+
try {
|
|
118
|
+
const st = statSync(path, { bigint: true });
|
|
119
|
+
return `${st.dev}:${st.ino}`;
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function realpathOrSelf(path) {
|
|
126
|
+
try {
|
|
127
|
+
return realpathSync.native(path);
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return path;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* One host path walked without lexical normalization (section 8.2, draft
|
|
135
|
+
* 1e). A relative path gets the working directory prefixed as a string, so a
|
|
136
|
+
* `..` is left for the operating system: after a symlink it goes up from the
|
|
137
|
+
* link's target. The longest existing leading part is resolved with
|
|
138
|
+
* realpath(3) and the rest appended only when it holds no `..`.
|
|
139
|
+
*/
|
|
140
|
+
function walkHostPath(value) {
|
|
141
|
+
const absolute = isAbsolute(value) ? value : `${process.cwd()}${sep}${value}`;
|
|
142
|
+
const root = parse(absolute).root || sep;
|
|
143
|
+
const parts = absolute.slice(root.length).split(/[\\/]+/).filter((p) => p !== "" && p !== ".");
|
|
144
|
+
const prefixes = [root];
|
|
145
|
+
for (const part of parts) {
|
|
146
|
+
const last = prefixes[prefixes.length - 1];
|
|
147
|
+
prefixes.push(last.endsWith(sep) ? `${last}${part}` : `${last}${sep}${part}`);
|
|
148
|
+
}
|
|
149
|
+
let existing = 0;
|
|
150
|
+
while (existing + 1 < prefixes.length && identity(prefixes[existing + 1]) !== null)
|
|
151
|
+
existing += 1;
|
|
152
|
+
const real = realpathOrSelf(prefixes[existing]);
|
|
153
|
+
const rest = parts.slice(existing);
|
|
154
|
+
if (existing + 1 < prefixes.length && exists(prefixes[existing + 1])) {
|
|
155
|
+
return { refusal: "is a symbolic link that does not resolve", chain: [], resolved: real };
|
|
156
|
+
}
|
|
157
|
+
if (rest.includes(".."))
|
|
158
|
+
return { refusal: "has a .. below the part that exists", chain: [], resolved: real };
|
|
159
|
+
const chain = prefixes.slice(0, existing + 1);
|
|
160
|
+
for (let dir = real;; dir = dirname(dir)) {
|
|
161
|
+
chain.push(dir);
|
|
162
|
+
if (dirname(dir) === dir)
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
return { refusal: null, chain, resolved: rest.length === 0 ? real : join(real, ...rest) };
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Where the system puts a host path: realpath of its longest existing part
|
|
169
|
+
* with the rest appended. FileLockStore opens this form, so the file it
|
|
170
|
+
* writes is the one hostPathProblem checked.
|
|
171
|
+
*/
|
|
172
|
+
export function resolvedHostPath(value) {
|
|
173
|
+
return walkHostPath(value).resolved;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* What a `.git` file points at: "module" when its gitdir lies under
|
|
177
|
+
* `modules` inside a git directory (a submodule), "worktree" when under
|
|
178
|
+
* `worktrees` (a linked worktree), else "unknown".
|
|
179
|
+
*/
|
|
180
|
+
function gitFileKind(path) {
|
|
181
|
+
let text;
|
|
182
|
+
try {
|
|
183
|
+
text = readFileSync(path).subarray(0, 4096).toString("utf8");
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
return "unknown";
|
|
187
|
+
}
|
|
188
|
+
const line = text.split(/\r?\n/)[0] ?? "";
|
|
189
|
+
if (!line.startsWith("gitdir:"))
|
|
190
|
+
return "unknown";
|
|
191
|
+
const target = resolve(dirname(path), line.slice("gitdir:".length).trim());
|
|
192
|
+
const parts = target.split(sep);
|
|
193
|
+
const at = parts.lastIndexOf(".git");
|
|
194
|
+
if (at < 0)
|
|
195
|
+
return "unknown";
|
|
196
|
+
const tail = parts.slice(at + 1);
|
|
197
|
+
if (tail.includes("modules"))
|
|
198
|
+
return "module";
|
|
199
|
+
if (tail[0] === "worktrees")
|
|
200
|
+
return "worktree";
|
|
201
|
+
return "unknown";
|
|
202
|
+
}
|
|
203
|
+
function isDirectory(path) {
|
|
204
|
+
try {
|
|
205
|
+
return statSync(path).isDirectory();
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* The repository that holds the lock (section 8.2, draft 1e), walking up
|
|
213
|
+
* from the resolved lock root. A `.git` directory ends the walk, and so does
|
|
214
|
+
* a `.git` file pointing into a git directory's `worktrees/` (a linked
|
|
215
|
+
* worktree's top). Any other `.git` file, a submodule's or one that names
|
|
216
|
+
* neither, is a candidate: the walk goes on so a submodule resolves to its
|
|
217
|
+
* superproject, and the candidate stands when nothing above has a `.git`
|
|
218
|
+
* entry. With no entry at all the repository is the lock root, and only the
|
|
219
|
+
* lock root is protected.
|
|
220
|
+
*/
|
|
221
|
+
export function repositoryRoot(lockRoot) {
|
|
222
|
+
const start = resolvedHostPath(lockRoot);
|
|
223
|
+
let candidate = null;
|
|
224
|
+
for (let dir = start;; dir = dirname(dir)) {
|
|
225
|
+
const git = join(dir, ".git");
|
|
226
|
+
if (exists(git)) {
|
|
227
|
+
if (isDirectory(git) || gitFileKind(git) === "worktree")
|
|
228
|
+
return dir;
|
|
229
|
+
candidate ??= dir;
|
|
230
|
+
}
|
|
231
|
+
if (dirname(dir) === dir)
|
|
232
|
+
return candidate ?? start;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Null if every named host path lies outside the repository that holds the
|
|
237
|
+
* lock and the lock root, else what is wrong. Inside means an existing
|
|
238
|
+
* leading part of the path as given, or an ancestor of its resolved form, is
|
|
239
|
+
* the same directory (device and inode) as the repository root or the lock
|
|
240
|
+
* root.
|
|
241
|
+
*/
|
|
242
|
+
export function hostPathProblem(lockRoot, paths) {
|
|
243
|
+
const repo = repositoryRoot(lockRoot);
|
|
244
|
+
const roots = new Set([identity(repo), identity(lockRoot)].filter((i) => i !== null));
|
|
245
|
+
for (const [key, value] of Object.entries(paths)) {
|
|
246
|
+
if (value === null || value === undefined)
|
|
247
|
+
continue;
|
|
248
|
+
const { refusal, chain } = walkHostPath(value);
|
|
249
|
+
if (refusal !== null)
|
|
250
|
+
return `${key} ${refusal}`;
|
|
251
|
+
if (chain.some((dir) => roots.has(identity(dir) ?? ""))) {
|
|
252
|
+
return `${key} lies inside the repository that holds the lock (${repo}); whoever writes the lock could choose it`;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
function writeAtomic(dir, target, data, prefix = "") {
|
|
258
|
+
const tmp = join(dir, `.${prefix}mcplock-${process.pid}-${randomBytes(6).toString("hex")}.tmp`);
|
|
259
|
+
let flags = constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL;
|
|
260
|
+
if (typeof constants.O_NOFOLLOW === "number")
|
|
261
|
+
flags |= constants.O_NOFOLLOW;
|
|
262
|
+
const fd = openSync(tmp, flags, 0o644);
|
|
263
|
+
try {
|
|
264
|
+
writeSync(fd, data);
|
|
265
|
+
fsyncSync(fd);
|
|
266
|
+
}
|
|
267
|
+
finally {
|
|
268
|
+
closeSync(fd);
|
|
269
|
+
}
|
|
270
|
+
try {
|
|
271
|
+
renameSync(tmp, target);
|
|
272
|
+
}
|
|
273
|
+
catch (exc) {
|
|
274
|
+
try {
|
|
275
|
+
unlinkSync(tmp);
|
|
276
|
+
}
|
|
277
|
+
catch {
|
|
278
|
+
// best effort
|
|
279
|
+
}
|
|
280
|
+
throw exc;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/** The higher of two sequence floors; null only when both are. */
|
|
284
|
+
export function sequenceFloor(a, b) {
|
|
285
|
+
if (a === null)
|
|
286
|
+
return b;
|
|
287
|
+
if (b === null)
|
|
288
|
+
return a;
|
|
289
|
+
return Math.max(a, b);
|
|
290
|
+
}
|
|
291
|
+
export class FileLockStore {
|
|
292
|
+
#root;
|
|
293
|
+
#config;
|
|
294
|
+
#sequences;
|
|
295
|
+
/** In-memory floor for this store instance; never lowered. */
|
|
296
|
+
#lastSequence = null;
|
|
297
|
+
#now;
|
|
298
|
+
#verifier;
|
|
299
|
+
/** Throws HostConfigError when sequencePath or trustedRootPath lies inside the lock's repository. */
|
|
300
|
+
constructor(options) {
|
|
301
|
+
const problem = hostPathProblem(options.root, {
|
|
302
|
+
sequencePath: options.sequencePath,
|
|
303
|
+
trustedRootPath: options.trustedRootPath,
|
|
304
|
+
});
|
|
305
|
+
if (problem !== null)
|
|
306
|
+
throw new HostConfigError(problem);
|
|
307
|
+
this.#root = options.root;
|
|
308
|
+
this.#config = options;
|
|
309
|
+
// The resolved forms: the files opened are the ones the path rule checked.
|
|
310
|
+
this.#sequences =
|
|
311
|
+
options.sequenceStore ??
|
|
312
|
+
(options.sequencePath !== undefined ? fileSequenceStore(resolvedHostPath(options.sequencePath)) : null);
|
|
313
|
+
this.#verifier =
|
|
314
|
+
options.verifier ??
|
|
315
|
+
(options.trustedRootPath !== undefined
|
|
316
|
+
? sigstoreVerifier({ trustedRootPath: resolvedHostPath(options.trustedRootPath) })
|
|
317
|
+
: null);
|
|
318
|
+
this.#now = options.now ?? Date.now;
|
|
319
|
+
}
|
|
320
|
+
async loadSnapshot() {
|
|
321
|
+
const signer = this.#config.signer ?? null;
|
|
322
|
+
const loadedAt = this.#now();
|
|
323
|
+
try {
|
|
324
|
+
let last = null;
|
|
325
|
+
if (signer !== null) {
|
|
326
|
+
if (this.#sequences === null) {
|
|
327
|
+
throw new LockError("lock-signature-invalid", "a signer is configured but the host config names no sequence store (sequencePath); rollback cannot be refused");
|
|
328
|
+
}
|
|
329
|
+
let stored;
|
|
330
|
+
try {
|
|
331
|
+
stored = this.#sequences.read();
|
|
332
|
+
}
|
|
333
|
+
catch (exc) {
|
|
334
|
+
throw new LockError("lock-signature-invalid", exc.message ?? "last accepted sequence is unreadable");
|
|
335
|
+
}
|
|
336
|
+
last = sequenceFloor(stored, this.#lastSequence);
|
|
337
|
+
}
|
|
338
|
+
const config = {
|
|
339
|
+
requireManifest: this.#config.requireManifest ?? false,
|
|
340
|
+
signer,
|
|
341
|
+
sequenceStore: this.#sequences !== null,
|
|
342
|
+
verifier: this.#verifier,
|
|
343
|
+
lastSequence: last,
|
|
344
|
+
};
|
|
345
|
+
const loaded = await loadLock(this.#root, config);
|
|
346
|
+
const seq = loaded.lock.sequence;
|
|
347
|
+
if (signer !== null && seq !== null && (last === null || seq > last)) {
|
|
348
|
+
this.#lastSequence = seq;
|
|
349
|
+
try {
|
|
350
|
+
this.#sequences?.write(seq);
|
|
351
|
+
}
|
|
352
|
+
catch {
|
|
353
|
+
// As in the Python host: not recording the new floor weakens rollback
|
|
354
|
+
// protection on the next start; the in-memory floor still holds, and
|
|
355
|
+
// this load is no less trustworthy.
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return Object.freeze({ snapshotId: loaded.snapshotId, loadedAt, lock: loaded.lock });
|
|
359
|
+
}
|
|
360
|
+
catch (exc) {
|
|
361
|
+
if (exc instanceof LockError)
|
|
362
|
+
return snapshotOfError(exc, loadedAt);
|
|
363
|
+
return snapshotOfError(new LockError("lock-unreadable", exc.message ?? "read failed"), loadedAt);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
/** Edit one shard under the file lock. `edit` returns the new shard. */
|
|
367
|
+
#edit(identity, edit) {
|
|
368
|
+
const ident = validateIdentity(identity);
|
|
369
|
+
const mcp = join(this.#root, ".mcp");
|
|
370
|
+
const lockDir = join(mcp, "lock");
|
|
371
|
+
withExclusiveLock(lockDir, () => {
|
|
372
|
+
// A writer refuses to build on a lock it cannot read. Signatures are not
|
|
373
|
+
// checked here; the next signed load verifies whatever was written.
|
|
374
|
+
const current = loadLockSync(this.#root, { requireManifest: false });
|
|
375
|
+
const shard = current.lock.shards.get(identityKey(ident)) ?? null;
|
|
376
|
+
const contractsDir = join(mcp, "contracts");
|
|
377
|
+
const writeContract = (p) => {
|
|
378
|
+
// The contract name is its own digest, so an existing file with that
|
|
379
|
+
// name was already verified by the load above if referenced; rewriting
|
|
380
|
+
// the same bytes is harmless.
|
|
381
|
+
try {
|
|
382
|
+
writeAtomic(contractsDir, join(contractsDir, p.contract), p.body);
|
|
383
|
+
}
|
|
384
|
+
catch (exc) {
|
|
385
|
+
const code = exc.code;
|
|
386
|
+
if (code !== "ENOENT")
|
|
387
|
+
throw exc;
|
|
388
|
+
throw new Error(".mcp/contracts is missing; create it before approving");
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
const next = edit(shard, writeContract);
|
|
392
|
+
const name = shardFilename(next.identity);
|
|
393
|
+
const bytes = formatShard(next);
|
|
394
|
+
writeAtomic(mcp, join(lockDir, name), bytes);
|
|
395
|
+
const signer = this.#config.signer ?? null;
|
|
396
|
+
if (current.lock.sequence !== null || this.#config.requireManifest === true || signer !== null) {
|
|
397
|
+
// Same rule as the Python store: write a manifest when one exists or
|
|
398
|
+
// the host requires or signs one. The old signature no longer covers
|
|
399
|
+
// it; re-signing is the signer's job, and a signed host fails closed
|
|
400
|
+
// until then.
|
|
401
|
+
const sequence = current.lock.sequence === null ? 1 : current.lock.sequence + 1;
|
|
402
|
+
writeAtomic(mcp, join(lockDir, MANIFEST), formatManifest(sequence, readLockDir(lockDir)));
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
async approve(request) {
|
|
407
|
+
const subject = request.subject;
|
|
408
|
+
if (subject === undefined)
|
|
409
|
+
throw new Error("file store approvals need a subject");
|
|
410
|
+
const approval = checkApprovalFields(request, subject);
|
|
411
|
+
if ("tool" in request) {
|
|
412
|
+
const prepared = prepareTool(request.tool);
|
|
413
|
+
this.#edit(request.identity, (shard, writeContract) => {
|
|
414
|
+
writeContract(prepared);
|
|
415
|
+
const entry = prepared.metaDigest === null
|
|
416
|
+
? Object.freeze({ digest: prepared.digest, contract: prepared.contract, approval })
|
|
417
|
+
: Object.freeze({ digest: prepared.digest, contract: prepared.contract, metaDigest: prepared.metaDigest, approval });
|
|
418
|
+
const tools = new Map(shard?.tools ?? []);
|
|
419
|
+
tools.set(prepared.name, entry); // Map.set keeps an existing name in place, appends a new one
|
|
420
|
+
return {
|
|
421
|
+
identity: shard?.identity ?? validateIdentity(request.identity),
|
|
422
|
+
attributes: shard?.attributes ?? null,
|
|
423
|
+
instructions: shard?.instructions ?? null,
|
|
424
|
+
tools: new FrozenMap(tools),
|
|
425
|
+
};
|
|
426
|
+
});
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
const digest = instructionsDigest(request.instructions);
|
|
430
|
+
if (digest === null)
|
|
431
|
+
throw new Error("instructions have no digest; they cannot be approved");
|
|
432
|
+
this.#edit(request.identity, (shard) => ({
|
|
433
|
+
identity: shard?.identity ?? validateIdentity(request.identity),
|
|
434
|
+
attributes: shard?.attributes ?? null,
|
|
435
|
+
instructions: digest,
|
|
436
|
+
tools: shard?.tools ?? new FrozenMap([]),
|
|
437
|
+
}));
|
|
438
|
+
}
|
|
439
|
+
async revoke(request) {
|
|
440
|
+
this.#edit(request.identity, (shard) => {
|
|
441
|
+
if (shard === null)
|
|
442
|
+
throw new Error("no shard for this identity");
|
|
443
|
+
if ("tool" in request) {
|
|
444
|
+
if (!shard.tools.has(request.tool))
|
|
445
|
+
throw new Error(`tool ${JSON.stringify(request.tool)} is not approved`);
|
|
446
|
+
const tools = new Map(shard.tools);
|
|
447
|
+
tools.delete(request.tool);
|
|
448
|
+
return { ...shardFields(shard), tools: new FrozenMap(tools) };
|
|
449
|
+
}
|
|
450
|
+
if (shard.instructions === null)
|
|
451
|
+
throw new Error("instructions are not approved");
|
|
452
|
+
return { ...shardFields(shard), instructions: null };
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
function shardFields(shard) {
|
|
457
|
+
return { identity: shard.identity, attributes: shard.attributes, instructions: shard.instructions, tools: shard.tools };
|
|
458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AE,OAAO,CAAC;CACnC,CAAC;AAEF,wBAAgB,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,GAAE,WAAgB,GAAG,OAAO,CAAC,CAAC,CAAC,CAmGrF;AAED,gFAAgF;AAChF,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,EAAE,CAExF"}
|
package/dist/src/wrap.js
CHANGED
|
@@ -187,6 +187,12 @@ function cursorOfRequest(request) {
|
|
|
187
187
|
return null;
|
|
188
188
|
return cursorText(params.cursor);
|
|
189
189
|
}
|
|
190
|
+
/** The task id a `tasks/result` request names, or that a CreateTaskResult carries. */
|
|
191
|
+
function taskIdOf(value, key) {
|
|
192
|
+
const holder = attrOrKey(value, key);
|
|
193
|
+
const id = attrOrKey(holder, "taskId");
|
|
194
|
+
return typeof id === "string" && id.length > 0 ? id : null;
|
|
195
|
+
}
|
|
190
196
|
function cursorText(value) {
|
|
191
197
|
return typeof value === "string" && value.length > 0 ? value : null;
|
|
192
198
|
}
|
|
@@ -232,6 +238,8 @@ class Interceptor {
|
|
|
232
238
|
// list page that started after the notification carries it; until then its calls hold
|
|
233
239
|
// under guard and strict. Per name, because the MCP client's refresh reads page 1 only.
|
|
234
240
|
staleNames = new Set();
|
|
241
|
+
// Task id -> the tool whose gated call created it, so a task result is scanned under that name.
|
|
242
|
+
taskTools = new Map();
|
|
235
243
|
contextWatcher;
|
|
236
244
|
contextObserved = false;
|
|
237
245
|
// Names pinned by the current list window when it opened on an empty, untainted
|
|
@@ -715,6 +723,9 @@ class Interceptor {
|
|
|
715
723
|
return result.then((r) => this.filterList(r, window, epoch, firstSight));
|
|
716
724
|
return this.filterList(result, window, epoch, firstSight);
|
|
717
725
|
}
|
|
726
|
+
if (method === "tasks/result") {
|
|
727
|
+
return this.gateResult(this.taskToolName(taskIdOf(args[0], "params")), reqFn.apply(target, args));
|
|
728
|
+
}
|
|
718
729
|
if (method !== "tools/call") {
|
|
719
730
|
return reqFn.apply(target, args);
|
|
720
731
|
}
|
|
@@ -727,7 +738,12 @@ class Interceptor {
|
|
|
727
738
|
// resolves a CallToolResult (the SAME shape `gateResult` extracts content/structuredContent
|
|
728
739
|
// from). A transport/schema that resolves a raw envelope instead -> content/structuredContent
|
|
729
740
|
// absent -> not scanned (v1 boundary, documented; the pre-call gate still covers the call).
|
|
730
|
-
|
|
741
|
+
// A task-augmented call resolves a CreateTaskResult; its id is kept for the later result.
|
|
742
|
+
const raw = reqFn.apply(target, args);
|
|
743
|
+
const noted = isThenable(raw)
|
|
744
|
+
? raw.then((value) => this.noteTask(toolName, value, "task"))
|
|
745
|
+
: this.noteTask(toolName, raw, "task");
|
|
746
|
+
return this.gateResult(toolName, noted);
|
|
731
747
|
}
|
|
732
748
|
// The SDK `request()` is async (returns a Promise<SchemaOutput>), so — like
|
|
733
749
|
// `callTool` — a HOLD must surface as a REJECTED Promise, not a sync throw,
|
|
@@ -751,6 +767,17 @@ class Interceptor {
|
|
|
751
767
|
* `_client` for the experimental seam, which it captured itself). */
|
|
752
768
|
requestStream(streamFn, receiver, args) {
|
|
753
769
|
const [method, toolName] = requestMethodAndTool(args[0]);
|
|
770
|
+
if (method === "tools/list") {
|
|
771
|
+
// The same listing filter as `request`: a list read through the stream is not a way around it.
|
|
772
|
+
const window = this.openListingWindow(cursorOfRequest(args[0]));
|
|
773
|
+
const epoch = this.listEpoch;
|
|
774
|
+
const firstSight = this.firstSightNames;
|
|
775
|
+
return this.gateStream(streamFn.apply(receiver, args), "", (r) => this.filterList(r, window, epoch, firstSight));
|
|
776
|
+
}
|
|
777
|
+
if (method === "tasks/result") {
|
|
778
|
+
const name = this.taskToolName(taskIdOf(args[0], "params"));
|
|
779
|
+
return this.gateStream(streamFn.apply(receiver, args), name, (r) => this.scanStreamed(name, r));
|
|
780
|
+
}
|
|
754
781
|
if (method !== "tools/call") {
|
|
755
782
|
return streamFn.apply(receiver, args);
|
|
756
783
|
}
|
|
@@ -758,10 +785,51 @@ class Interceptor {
|
|
|
758
785
|
if (verdict.decision === Decision.PROCEED) {
|
|
759
786
|
if (verdict.failOpenWarning)
|
|
760
787
|
warn(verdict);
|
|
761
|
-
return streamFn.apply(receiver, args);
|
|
788
|
+
return this.gateStream(streamFn.apply(receiver, args), toolName, (r) => this.scanStreamed(toolName, r));
|
|
762
789
|
}
|
|
763
790
|
return this.refuseStream(toolName, verdict);
|
|
764
791
|
}
|
|
792
|
+
/** Pass a request stream through, gating each `result` message with `onResult` and
|
|
793
|
+
* keeping the id of any task the stream creates. A HOLD thrown by `onResult` ends
|
|
794
|
+
* the stream for the caller, and the upstream stream is closed. */
|
|
795
|
+
async *gateStream(upstream, name, onResult) {
|
|
796
|
+
for await (const message of upstream) {
|
|
797
|
+
const type = attrOrKey(message, "type");
|
|
798
|
+
if (type === "taskCreated")
|
|
799
|
+
this.noteTask(name, message, "task");
|
|
800
|
+
if (type !== "result") {
|
|
801
|
+
yield message;
|
|
802
|
+
continue;
|
|
803
|
+
}
|
|
804
|
+
const result = attrOrKey(message, "result");
|
|
805
|
+
// An onHold callback may answer with a Promise; the stream yields what it resolves to.
|
|
806
|
+
const gated = await Promise.resolve(onResult(result));
|
|
807
|
+
yield gated === result ? message : { ...message, result: gated };
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
/** The result scan for a streamed result, which arrives as a value. */
|
|
811
|
+
scanStreamed(name, result) {
|
|
812
|
+
return this.scanResults ? this.gateResultValue(name, result) : result;
|
|
813
|
+
}
|
|
814
|
+
noteTask(name, value, key) {
|
|
815
|
+
const id = taskIdOf(value, key);
|
|
816
|
+
if (id !== null && name) {
|
|
817
|
+
// Bounded like the Python wrapper's map: the oldest entry goes first.
|
|
818
|
+
if (this.taskTools.size >= 1024 && !this.taskTools.has(id)) {
|
|
819
|
+
this.taskTools.delete(this.taskTools.keys().next().value);
|
|
820
|
+
}
|
|
821
|
+
this.taskTools.set(id, name);
|
|
822
|
+
}
|
|
823
|
+
return value;
|
|
824
|
+
}
|
|
825
|
+
/** Session-level `getTaskResult({taskId}, ...)`: the result scan, under the creating tool's name. */
|
|
826
|
+
taskResult(target, args) {
|
|
827
|
+
const name = this.taskToolName(taskIdOf({ params: args[0] }, "params"));
|
|
828
|
+
return this.gateResult(name, target["getTaskResult"].apply(target, args));
|
|
829
|
+
}
|
|
830
|
+
taskToolName(taskId) {
|
|
831
|
+
return (taskId !== null && this.taskTools.get(taskId)) || "";
|
|
832
|
+
}
|
|
765
833
|
/** A HELD streaming seam: an async generator that raises the SAME
|
|
766
834
|
* `PreflightHold` (or onHold result) as `refuseAsync`, on first iteration,
|
|
767
835
|
* before the upstream stream is ever opened. Shares `heldSurface` / `onHold`
|
|
@@ -801,11 +869,20 @@ class Interceptor {
|
|
|
801
869
|
if (verdict.decision === Decision.PROCEED) {
|
|
802
870
|
if (verdict.failOpenWarning)
|
|
803
871
|
warn(verdict);
|
|
804
|
-
|
|
872
|
+
const upstream = realTasks.callToolStream.apply(realTasks, a);
|
|
873
|
+
return self.gateStream(upstream, toolName, (r) => self.scanStreamed(toolName, r));
|
|
805
874
|
}
|
|
806
875
|
return self.refuseStream(toolName, verdict);
|
|
807
876
|
};
|
|
808
877
|
}
|
|
878
|
+
if (prop === "getTaskResult" && typeof Reflect.get(t, prop, t) === "function") {
|
|
879
|
+
// getTaskResult(taskId, resultSchema?, options?) reads a task's result off the
|
|
880
|
+
// unwrapped client; scan it like the call that created the task.
|
|
881
|
+
return (...a) => {
|
|
882
|
+
const name = self.taskToolName(typeof a[0] === "string" ? a[0] : null);
|
|
883
|
+
return self.gateResult(name, realTasks.getTaskResult.apply(realTasks, a));
|
|
884
|
+
};
|
|
885
|
+
}
|
|
809
886
|
if (prop === "requestStream") {
|
|
810
887
|
// tasks.requestStream(request, ...) takes the raw {method,params} shape —
|
|
811
888
|
// route it through the SAME gate as the session-level seam, delegating
|
|
@@ -1067,6 +1144,11 @@ export function wrap(session, opts = {}) {
|
|
|
1067
1144
|
return interceptor.requestStream(fn, target, args);
|
|
1068
1145
|
};
|
|
1069
1146
|
}
|
|
1147
|
+
if (prop === "getTaskResult" && typeof Reflect.get(target, prop, target) === "function") {
|
|
1148
|
+
// getTaskResult({taskId}, resultSchema?, options?) reads a task's result; scan it
|
|
1149
|
+
// like the call that created the task.
|
|
1150
|
+
return (...args) => interceptor.taskResult(target, args);
|
|
1151
|
+
}
|
|
1070
1152
|
if (prop === "experimental") {
|
|
1071
1153
|
// The SDK `experimental` accessor returns an object whose `tasks` holds
|
|
1072
1154
|
// the UNWRAPPED client; left untouched it bypasses the gate. Return a
|