@stll/anonymize-mcp 0.0.1-placeholder.0 → 2.4.1
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/LICENSE +17 -0
- package/README.md +160 -0
- package/dist/index.d.mts +172 -0
- package/dist/index.mjs +2 -0
- package/dist/local.mjs +1181 -0
- package/dist/local.mjs.map +1 -0
- package/dist/server-entry.d.mts +1 -0
- package/dist/server-entry.mjs +12 -0
- package/dist/server-entry.mjs.map +1 -0
- package/dist/server.d.mts +28 -0
- package/dist/server.mjs +141 -0
- package/dist/server.mjs.map +1 -0
- package/package.json +54 -3
package/dist/local.mjs
ADDED
|
@@ -0,0 +1,1181 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { CAPABILITY_MANIFEST } from "@stll/anonymize";
|
|
3
|
+
import { DOCX_ARCHIVE_MAX_BYTES, DOCX_COVERAGE_MODES, anonymizeDocx, extractDocxText, restoreDocxText } from "@stll/anonymize-docx";
|
|
4
|
+
import { PDF_DOCUMENT_MAX_BYTES, anonymizePdfRaster, renderPdfWithPopplerTesseract } from "@stll/anonymize-pdf";
|
|
5
|
+
import * as nativeNode from "@stll/anonymize/native-node";
|
|
6
|
+
import { constants, link, lstat, open, readdir, realpath, rename, stat, unlink } from "node:fs/promises";
|
|
7
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
8
|
+
import { dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
9
|
+
import * as z from "zod/v4";
|
|
10
|
+
//#region src/durable-sessions.ts
|
|
11
|
+
const SESSION_ARCHIVE_KEY_BYTES = 32;
|
|
12
|
+
const SESSION_ARCHIVE_MAX_BYTES = 16777273;
|
|
13
|
+
const SESSION_ARCHIVE_MAX_COUNT = 256;
|
|
14
|
+
const SESSION_ARCHIVE_TOTAL_MAX_BYTES = 256 * 1024 * 1024;
|
|
15
|
+
const ARCHIVE_NAME = /^[a-f0-9]{64}\.stlasess$/u;
|
|
16
|
+
const SESSION_ID$1 = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/u;
|
|
17
|
+
const STAGING_NAME = /^[a-f0-9]{64}\.stlasess\.tmp\.[0-9a-f]{8}-[0-9a-f-]{27}$/u;
|
|
18
|
+
const READ_CHUNK_BYTES$1 = 64 * 1024;
|
|
19
|
+
const LOCK_FILE_NAME = ".stella-session.lock";
|
|
20
|
+
const DURABLE_SESSION_FAULT_POINTS = {
|
|
21
|
+
beforeDirectoryFsync: "before-directory-fsync",
|
|
22
|
+
beforeRename: "before-rename",
|
|
23
|
+
beforeStagingFsync: "before-staging-fsync",
|
|
24
|
+
beforeStagingWrite: "before-staging-write"
|
|
25
|
+
};
|
|
26
|
+
const sameFile$1 = (left, right) => left.dev === right.dev && left.ino === right.ino;
|
|
27
|
+
const assertOwner = (uid, label) => {
|
|
28
|
+
if (typeof process.getuid === "function" && uid !== process.getuid()) throw new Error(`${label} must be owned by the current user`);
|
|
29
|
+
};
|
|
30
|
+
const assertPrivateMode = (mode, label) => {
|
|
31
|
+
if ((mode & 63) !== 0) throw new Error(`${label} must not grant group or other permissions`);
|
|
32
|
+
};
|
|
33
|
+
const assertPosixDurabilitySupport = () => {
|
|
34
|
+
if (process.platform !== "darwin" && process.platform !== "linux" || typeof process.getuid !== "function" || typeof constants.O_NOFOLLOW !== "number" || constants.O_NOFOLLOW === 0 || typeof constants.O_DIRECTORY !== "number" || constants.O_DIRECTORY === 0) throw new Error("Encrypted durable MCP sessions require supported POSIX owner, nofollow, directory-fsync, and advisory-lock semantics on macOS or Linux");
|
|
35
|
+
};
|
|
36
|
+
const acquireDirectoryLock = async (directoryPath) => {
|
|
37
|
+
const handle = await open(join(directoryPath, LOCK_FILE_NAME), constants.O_RDWR | constants.O_CREAT | constants.O_NOFOLLOW | constants.O_NONBLOCK, 384);
|
|
38
|
+
try {
|
|
39
|
+
const metadata = await handle.stat();
|
|
40
|
+
if (!metadata.isFile()) throw new Error("MCP session lock must be a regular file");
|
|
41
|
+
assertOwner(metadata.uid, "MCP session lock");
|
|
42
|
+
assertPrivateMode(metadata.mode, "MCP session lock");
|
|
43
|
+
const { tryLock } = await import("fs-native-extensions");
|
|
44
|
+
if (!tryLock(handle.fd)) throw new Error("MCP session directory is already locked by another server");
|
|
45
|
+
return handle;
|
|
46
|
+
} catch (error) {
|
|
47
|
+
await handle.close().catch(() => void 0);
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const canonicalAbsolutePath = async (path, label) => {
|
|
52
|
+
if (!isAbsolute(path)) throw new Error(`${label} must be an absolute path`);
|
|
53
|
+
const normalized = resolve(path);
|
|
54
|
+
const canonical = await realpath(normalized);
|
|
55
|
+
if (canonical !== normalized) throw new Error(`${label} must not contain symbolic links`);
|
|
56
|
+
return canonical;
|
|
57
|
+
};
|
|
58
|
+
const readHandleBounded$1 = async (handle, maximumBytes) => {
|
|
59
|
+
const chunks = [];
|
|
60
|
+
let total = 0;
|
|
61
|
+
for (;;) {
|
|
62
|
+
const remaining = maximumBytes - total;
|
|
63
|
+
const chunk = Buffer.allocUnsafe(Math.min(READ_CHUNK_BYTES$1, remaining + 1));
|
|
64
|
+
const { bytesRead } = await handle.read(chunk, 0, chunk.byteLength, null);
|
|
65
|
+
if (bytesRead === 0) return Buffer.concat(chunks, total);
|
|
66
|
+
total += bytesRead;
|
|
67
|
+
if (total > maximumBytes) throw new Error("Encrypted session archive exceeds the byte limit");
|
|
68
|
+
chunks.push(chunk.subarray(0, bytesRead));
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const readKey = async (path) => {
|
|
72
|
+
const canonical = await canonicalAbsolutePath(path, "MCP session key file");
|
|
73
|
+
const linkedMetadata = await lstat(canonical);
|
|
74
|
+
if (!linkedMetadata.isFile() || linkedMetadata.isSymbolicLink()) throw new Error("MCP session key file must be a regular file");
|
|
75
|
+
assertOwner(linkedMetadata.uid, "MCP session key file");
|
|
76
|
+
assertPrivateMode(linkedMetadata.mode, "MCP session key file");
|
|
77
|
+
if (linkedMetadata.size !== 32) throw new Error(`MCP session key file must contain exactly 32 raw bytes`);
|
|
78
|
+
const handle = await open(canonical, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
79
|
+
let keyBuffer;
|
|
80
|
+
try {
|
|
81
|
+
const openedMetadata = await handle.stat();
|
|
82
|
+
if (!openedMetadata.isFile() || !sameFile$1(linkedMetadata, openedMetadata) || openedMetadata.size !== 32) throw new Error("MCP session key file changed while it was validated");
|
|
83
|
+
keyBuffer = Buffer.alloc(33);
|
|
84
|
+
let keyLength = 0;
|
|
85
|
+
for (;;) {
|
|
86
|
+
const { bytesRead } = await handle.read(keyBuffer, keyLength, keyBuffer.byteLength - keyLength, null);
|
|
87
|
+
if (bytesRead === 0 || keyLength + bytesRead === keyBuffer.byteLength) {
|
|
88
|
+
keyLength += bytesRead;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
keyLength += bytesRead;
|
|
92
|
+
}
|
|
93
|
+
if (keyLength !== 32) {
|
|
94
|
+
keyBuffer.fill(0);
|
|
95
|
+
throw new Error(`MCP session key file must contain exactly 32 raw bytes`);
|
|
96
|
+
}
|
|
97
|
+
const currentMetadata = await stat(canonical);
|
|
98
|
+
if (!sameFile$1(openedMetadata, currentMetadata)) {
|
|
99
|
+
keyBuffer.fill(0);
|
|
100
|
+
throw new Error("MCP session key file changed while it was read");
|
|
101
|
+
}
|
|
102
|
+
const key = /* @__PURE__ */ new Uint8Array(32);
|
|
103
|
+
key.set(keyBuffer.subarray(0, 32));
|
|
104
|
+
keyBuffer.fill(0);
|
|
105
|
+
return key;
|
|
106
|
+
} finally {
|
|
107
|
+
keyBuffer?.fill(0);
|
|
108
|
+
await handle.close();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const archiveName = (sessionId) => `${createHash("sha256").update(sessionId, "utf8").digest("hex")}.stlasess`;
|
|
112
|
+
const assertSessionId = (sessionId) => {
|
|
113
|
+
if (!SESSION_ID$1.test(sessionId)) throw new Error("MCP session ID is invalid");
|
|
114
|
+
};
|
|
115
|
+
var DurableSessionStore = class DurableSessionStore {
|
|
116
|
+
#closePromise;
|
|
117
|
+
#directory;
|
|
118
|
+
#faultInjector;
|
|
119
|
+
#key;
|
|
120
|
+
#lockHandle;
|
|
121
|
+
#mutationTail = Promise.resolve();
|
|
122
|
+
#state = "open";
|
|
123
|
+
constructor(directory, key, lockHandle, faultInjector) {
|
|
124
|
+
this.#directory = directory;
|
|
125
|
+
this.#key = key;
|
|
126
|
+
this.#lockHandle = lockHandle;
|
|
127
|
+
this.#faultInjector = faultInjector;
|
|
128
|
+
}
|
|
129
|
+
static async create({ keyFile, sessionDirectory, faultInjector }) {
|
|
130
|
+
assertPosixDurabilitySupport();
|
|
131
|
+
const directoryPath = await canonicalAbsolutePath(sessionDirectory, "MCP session directory");
|
|
132
|
+
const metadata = await lstat(directoryPath);
|
|
133
|
+
if (!metadata.isDirectory() || metadata.isSymbolicLink()) throw new Error("MCP session directory must be a directory");
|
|
134
|
+
assertOwner(metadata.uid, "MCP session directory");
|
|
135
|
+
assertPrivateMode(metadata.mode, "MCP session directory");
|
|
136
|
+
const key = await readKey(keyFile);
|
|
137
|
+
let lockHandle;
|
|
138
|
+
try {
|
|
139
|
+
lockHandle = await acquireDirectoryLock(directoryPath);
|
|
140
|
+
const store = new DurableSessionStore({
|
|
141
|
+
dev: metadata.dev,
|
|
142
|
+
ino: metadata.ino,
|
|
143
|
+
path: directoryPath
|
|
144
|
+
}, key, lockHandle, faultInjector);
|
|
145
|
+
await store.#validateInventory({ removeStagingFiles: true });
|
|
146
|
+
await store.#syncDirectory();
|
|
147
|
+
return store;
|
|
148
|
+
} catch (error) {
|
|
149
|
+
key.fill(0);
|
|
150
|
+
await lockHandle?.close().catch(() => void 0);
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
seal(session, observedAtEpochSeconds) {
|
|
155
|
+
this.#assertOpen();
|
|
156
|
+
return session.toEncryptedArchiveAt(this.#key, observedAtEpochSeconds);
|
|
157
|
+
}
|
|
158
|
+
restore({ archive, expectedSessionId, observedAtEpochSeconds, restorer }) {
|
|
159
|
+
this.#assertOpen();
|
|
160
|
+
return restorer.restoreEncryptedRedactionSession({
|
|
161
|
+
archive,
|
|
162
|
+
expectedSessionId,
|
|
163
|
+
key: this.#key,
|
|
164
|
+
observedAtEpochSeconds
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
async close() {
|
|
168
|
+
if (this.#closePromise !== void 0) return this.#closePromise;
|
|
169
|
+
this.#state = "closing";
|
|
170
|
+
this.#closePromise = (async () => {
|
|
171
|
+
await this.#mutationTail;
|
|
172
|
+
this.#key.fill(0);
|
|
173
|
+
await this.#lockHandle.close();
|
|
174
|
+
this.#state = "closed";
|
|
175
|
+
})();
|
|
176
|
+
return this.#closePromise;
|
|
177
|
+
}
|
|
178
|
+
async load(sessionId) {
|
|
179
|
+
this.#assertOpen();
|
|
180
|
+
return this.#withMutation(() => this.#load(sessionId));
|
|
181
|
+
}
|
|
182
|
+
async #load(sessionId) {
|
|
183
|
+
assertSessionId(sessionId);
|
|
184
|
+
await this.#validateInventory({ removeStagingFiles: false });
|
|
185
|
+
const path = this.#path(sessionId);
|
|
186
|
+
let handle;
|
|
187
|
+
try {
|
|
188
|
+
handle = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
if (error.code === "ENOENT") return;
|
|
191
|
+
throw new Error("Encrypted session archive could not be opened", { cause: error });
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
const metadata = await handle.stat();
|
|
195
|
+
if (!metadata.isFile()) throw new Error("Encrypted session archive must be a regular file");
|
|
196
|
+
assertOwner(metadata.uid, "Encrypted session archive");
|
|
197
|
+
assertPrivateMode(metadata.mode, "Encrypted session archive");
|
|
198
|
+
if (metadata.size > 16777273) throw new Error("Encrypted session archive exceeds the byte limit");
|
|
199
|
+
const bytes = await readHandleBounded$1(handle, SESSION_ARCHIVE_MAX_BYTES);
|
|
200
|
+
await this.#assertDirectory();
|
|
201
|
+
const currentMetadata = await lstat(path);
|
|
202
|
+
if (!currentMetadata.isFile() || !sameFile$1(metadata, currentMetadata)) throw new Error("Encrypted session archive changed while it was read");
|
|
203
|
+
return { bytes };
|
|
204
|
+
} finally {
|
|
205
|
+
await handle.close();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
async save(sessionId, archive) {
|
|
209
|
+
this.#assertOpen();
|
|
210
|
+
return this.#withMutation(() => this.#save(sessionId, archive));
|
|
211
|
+
}
|
|
212
|
+
async #save(sessionId, archive) {
|
|
213
|
+
assertSessionId(sessionId);
|
|
214
|
+
if (archive.byteLength > 16777273) throw new Error("Encrypted session archive exceeds the byte limit");
|
|
215
|
+
const inventory = await this.#validateInventory({ removeStagingFiles: false });
|
|
216
|
+
await this.#assertDirectory();
|
|
217
|
+
const destination = this.#path(sessionId);
|
|
218
|
+
const temporary = `${destination}.tmp.${randomUUID()}`;
|
|
219
|
+
const handle = await open(temporary, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 384);
|
|
220
|
+
try {
|
|
221
|
+
const openedMetadata = await handle.stat();
|
|
222
|
+
if (!openedMetadata.isFile()) throw new Error("Encrypted session staging path is not a regular file");
|
|
223
|
+
await this.#inject(DURABLE_SESSION_FAULT_POINTS.beforeStagingWrite);
|
|
224
|
+
await handle.writeFile(archive);
|
|
225
|
+
await this.#inject(DURABLE_SESSION_FAULT_POINTS.beforeStagingFsync);
|
|
226
|
+
await handle.sync();
|
|
227
|
+
const stagedMetadata = await lstat(temporary);
|
|
228
|
+
if (!stagedMetadata.isFile() || !sameFile$1(openedMetadata, stagedMetadata)) throw new Error("Encrypted session staging file changed before publication");
|
|
229
|
+
await this.#assertDirectory();
|
|
230
|
+
const existing = await lstat(destination).catch((error) => {
|
|
231
|
+
if (error.code === "ENOENT") return;
|
|
232
|
+
throw error;
|
|
233
|
+
});
|
|
234
|
+
if (existing !== void 0 && (!existing.isFile() || existing.isSymbolicLink())) throw new Error("Encrypted session archive path is not a regular file");
|
|
235
|
+
const nextCount = inventory.archiveCount + (existing === void 0 ? 1 : 0);
|
|
236
|
+
const nextTotalBytes = inventory.totalBytes - (existing?.size ?? 0) + archive.byteLength;
|
|
237
|
+
if (nextCount > 256) throw new Error(`MCP session archives must not exceed 256`);
|
|
238
|
+
if (nextTotalBytes > 268435456) throw new Error("MCP session archives exceed the aggregate byte limit");
|
|
239
|
+
await this.#inject(DURABLE_SESSION_FAULT_POINTS.beforeRename);
|
|
240
|
+
await rename(temporary, destination);
|
|
241
|
+
await this.#assertDirectory();
|
|
242
|
+
const published = await lstat(destination);
|
|
243
|
+
if (!published.isFile() || !sameFile$1(openedMetadata, published)) throw new Error("Encrypted session archive publication was not atomic");
|
|
244
|
+
await this.#syncDirectory();
|
|
245
|
+
} finally {
|
|
246
|
+
await handle.close().catch(() => void 0);
|
|
247
|
+
await unlink(temporary).catch(() => void 0);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
async delete(sessionId) {
|
|
251
|
+
this.#assertOpen();
|
|
252
|
+
return this.#withMutation(() => this.#delete(sessionId));
|
|
253
|
+
}
|
|
254
|
+
async #delete(sessionId) {
|
|
255
|
+
assertSessionId(sessionId);
|
|
256
|
+
await this.#assertDirectory();
|
|
257
|
+
const path = this.#path(sessionId);
|
|
258
|
+
const metadata = await lstat(path).catch((error) => {
|
|
259
|
+
if (error.code === "ENOENT") return;
|
|
260
|
+
throw error;
|
|
261
|
+
});
|
|
262
|
+
if (metadata === void 0) return;
|
|
263
|
+
if (!metadata.isFile() || metadata.isSymbolicLink()) throw new Error("Encrypted session archive path is not a regular file");
|
|
264
|
+
await unlink(path);
|
|
265
|
+
await this.#syncDirectory();
|
|
266
|
+
await this.#assertDirectory();
|
|
267
|
+
}
|
|
268
|
+
#path(sessionId) {
|
|
269
|
+
return join(this.#directory.path, archiveName(sessionId));
|
|
270
|
+
}
|
|
271
|
+
#assertOpen() {
|
|
272
|
+
if (this.#state !== "open") throw new Error("MCP durable session store is closing or closed");
|
|
273
|
+
}
|
|
274
|
+
async #withMutation(operation) {
|
|
275
|
+
const previous = this.#mutationTail;
|
|
276
|
+
let release = () => void 0;
|
|
277
|
+
const current = new Promise((resolvePromise) => {
|
|
278
|
+
release = resolvePromise;
|
|
279
|
+
});
|
|
280
|
+
this.#mutationTail = previous.then(() => current);
|
|
281
|
+
await previous;
|
|
282
|
+
try {
|
|
283
|
+
return await operation();
|
|
284
|
+
} finally {
|
|
285
|
+
release();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
async #assertDirectory() {
|
|
289
|
+
const canonical = await realpath(this.#directory.path);
|
|
290
|
+
const metadata = await lstat(this.#directory.path);
|
|
291
|
+
if (canonical !== this.#directory.path || !metadata.isDirectory() || metadata.isSymbolicLink() || !sameFile$1(this.#directory, metadata)) throw new Error("MCP session directory changed while it was being used");
|
|
292
|
+
assertOwner(metadata.uid, "MCP session directory");
|
|
293
|
+
assertPrivateMode(metadata.mode, "MCP session directory");
|
|
294
|
+
}
|
|
295
|
+
async #syncDirectory() {
|
|
296
|
+
await this.#inject(DURABLE_SESSION_FAULT_POINTS.beforeDirectoryFsync);
|
|
297
|
+
const handle = await open(this.#directory.path, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
|
|
298
|
+
try {
|
|
299
|
+
const metadata = await handle.stat();
|
|
300
|
+
if (!metadata.isDirectory() || !sameFile$1(this.#directory, metadata)) throw new Error("MCP session directory changed before synchronization");
|
|
301
|
+
await handle.sync();
|
|
302
|
+
} finally {
|
|
303
|
+
await handle.close();
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
async #inject(point) {
|
|
307
|
+
await this.#faultInjector?.(point);
|
|
308
|
+
}
|
|
309
|
+
async #validateInventory({ removeStagingFiles }) {
|
|
310
|
+
await this.#assertDirectory();
|
|
311
|
+
const entries = await readdir(this.#directory.path, { withFileTypes: true });
|
|
312
|
+
let archiveCount = 0;
|
|
313
|
+
let totalBytes = 0;
|
|
314
|
+
for (const entry of entries) {
|
|
315
|
+
const path = join(this.#directory.path, entry.name);
|
|
316
|
+
if (entry.name === LOCK_FILE_NAME) {
|
|
317
|
+
const metadata = await lstat(path);
|
|
318
|
+
if (!metadata.isFile() || metadata.isSymbolicLink()) throw new Error("MCP session directory contains an unsafe lock path");
|
|
319
|
+
assertOwner(metadata.uid, "MCP session lock");
|
|
320
|
+
assertPrivateMode(metadata.mode, "MCP session lock");
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
if (STAGING_NAME.test(entry.name)) {
|
|
324
|
+
if (!removeStagingFiles) throw new Error("MCP session directory contains a partial archive");
|
|
325
|
+
const metadata = await lstat(path);
|
|
326
|
+
if (!metadata.isFile() || metadata.isSymbolicLink()) throw new Error("MCP session directory contains an unsafe staging path");
|
|
327
|
+
await unlink(path);
|
|
328
|
+
await this.#syncDirectory();
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
if (!ARCHIVE_NAME.test(entry.name) || !entry.isFile() || entry.isSymbolicLink()) throw new Error("MCP session directory contains an unsupported entry");
|
|
332
|
+
const metadata = await lstat(path);
|
|
333
|
+
if (!metadata.isFile() || metadata.isSymbolicLink()) throw new Error("MCP session directory contains an unsafe archive path");
|
|
334
|
+
assertOwner(metadata.uid, "Encrypted session archive");
|
|
335
|
+
assertPrivateMode(metadata.mode, "Encrypted session archive");
|
|
336
|
+
if (metadata.size > 16777273) throw new Error("Encrypted session archive exceeds the byte limit");
|
|
337
|
+
archiveCount += 1;
|
|
338
|
+
totalBytes += metadata.size;
|
|
339
|
+
if (archiveCount > 256) throw new Error(`MCP session archives must not exceed 256`);
|
|
340
|
+
if (totalBytes > 268435456) throw new Error("MCP session archives exceed the aggregate byte limit");
|
|
341
|
+
}
|
|
342
|
+
await this.#assertDirectory();
|
|
343
|
+
return {
|
|
344
|
+
archiveCount,
|
|
345
|
+
totalBytes
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region src/local.ts
|
|
351
|
+
const TEXT_MAX_BYTES = 64 * 1024 * 1024;
|
|
352
|
+
const EXTERNAL_DETECTION_BATCH_MAX_BYTES = 16 * 1024 * 1024;
|
|
353
|
+
const EXTERNAL_DETECTION_BATCH_VERSION = 1;
|
|
354
|
+
const PATH_MAX_CHARACTERS = 32768;
|
|
355
|
+
const SESSION_MAX_COUNT = 256;
|
|
356
|
+
const SESSION_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/u;
|
|
357
|
+
const READ_CHUNK_BYTES = 64 * 1024;
|
|
358
|
+
const observedAtEpochSeconds = () => {
|
|
359
|
+
const seconds = Math.floor(Date.now() / 1e3);
|
|
360
|
+
if (seconds < 0 || seconds > 4294967295) throw new Error("The current time is outside the supported session range");
|
|
361
|
+
return seconds;
|
|
362
|
+
};
|
|
363
|
+
const MCP_SESSION_MODES = {
|
|
364
|
+
durableEncrypted: "durable-encrypted",
|
|
365
|
+
memory: "memory"
|
|
366
|
+
};
|
|
367
|
+
const EXTERNAL_DETECTION_FAILURES = {
|
|
368
|
+
batchRejected: {
|
|
369
|
+
code: "EXTERNAL_DETECTION_BATCH_REJECTED",
|
|
370
|
+
message: "The external detection batch was rejected."
|
|
371
|
+
},
|
|
372
|
+
documentRejected: {
|
|
373
|
+
code: "EXTERNAL_DETECTION_DOCUMENT_REJECTED",
|
|
374
|
+
message: "The external detection document was rejected."
|
|
375
|
+
},
|
|
376
|
+
inputRejected: {
|
|
377
|
+
code: "EXTERNAL_DETECTION_INPUT_REJECTED",
|
|
378
|
+
message: "The external detection request paths were rejected."
|
|
379
|
+
},
|
|
380
|
+
operationFailed: {
|
|
381
|
+
code: "EXTERNAL_DETECTION_OPERATION_FAILED",
|
|
382
|
+
message: "The external detection operation failed safely."
|
|
383
|
+
},
|
|
384
|
+
sessionRejected: {
|
|
385
|
+
code: "EXTERNAL_DETECTION_SESSION_REJECTED",
|
|
386
|
+
message: "The external detection session was rejected."
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
var ExternalDetectionAuditError = class extends Error {
|
|
390
|
+
code;
|
|
391
|
+
constructor(failure) {
|
|
392
|
+
super(failure.message);
|
|
393
|
+
this.name = "ExternalDetectionAuditError";
|
|
394
|
+
this.code = failure.code;
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
const externalDetectionFailure = (error, failure) => error instanceof ExternalDetectionAuditError ? error : new ExternalDetectionAuditError(failure);
|
|
398
|
+
const externalDetectionStep = async (failure, operation) => {
|
|
399
|
+
try {
|
|
400
|
+
return await operation();
|
|
401
|
+
} catch (error) {
|
|
402
|
+
throw externalDetectionFailure(error, failure);
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
const inside = (root, target) => {
|
|
406
|
+
const path = relative(root, target);
|
|
407
|
+
return path === "" || path !== ".." && !path.startsWith(`..${sep}`) && !isAbsolute(path);
|
|
408
|
+
};
|
|
409
|
+
const readHandleBounded = async (handle, maximumBytes, label) => {
|
|
410
|
+
const chunks = [];
|
|
411
|
+
let total = 0;
|
|
412
|
+
for (;;) {
|
|
413
|
+
const chunk = Buffer.allocUnsafe(Math.min(READ_CHUNK_BYTES, maximumBytes - total + 1));
|
|
414
|
+
const { bytesRead } = await handle.read(chunk, 0, chunk.byteLength, null);
|
|
415
|
+
if (bytesRead === 0) return Buffer.concat(chunks, total);
|
|
416
|
+
total += bytesRead;
|
|
417
|
+
if (total > maximumBytes) throw new Error(`${label} inputs must not exceed ${maximumBytes} bytes`);
|
|
418
|
+
chunks.push(chunk.subarray(0, bytesRead));
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
var ScopedOutput = class {
|
|
422
|
+
parent;
|
|
423
|
+
path;
|
|
424
|
+
constructor(path, parent) {
|
|
425
|
+
this.path = path;
|
|
426
|
+
this.parent = parent;
|
|
427
|
+
}
|
|
428
|
+
async write(bytes) {
|
|
429
|
+
await safeWrite(this, bytes);
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
var PathScope = class PathScope {
|
|
433
|
+
#roots;
|
|
434
|
+
constructor(roots) {
|
|
435
|
+
this.#roots = roots;
|
|
436
|
+
}
|
|
437
|
+
static async create(roots) {
|
|
438
|
+
if (roots.length === 0) throw new Error("At least one --root directory is required");
|
|
439
|
+
const canonical = await Promise.all(roots.map(async (root) => {
|
|
440
|
+
if (!isAbsolute(root)) throw new Error("MCP roots must be absolute paths");
|
|
441
|
+
const path = await realpath(root);
|
|
442
|
+
if (!(await stat(path)).isDirectory()) throw new Error("Every MCP root must be a directory");
|
|
443
|
+
return path;
|
|
444
|
+
}));
|
|
445
|
+
return new PathScope([...new Set(canonical)]);
|
|
446
|
+
}
|
|
447
|
+
async readInput({ path, extension, maximumBytes, label }) {
|
|
448
|
+
if (!isAbsolute(path) || extname(path).toLowerCase() !== extension) throw new Error(`Input must be an absolute ${extension} path`);
|
|
449
|
+
const initiallyCanonical = await realpath(path);
|
|
450
|
+
if (!this.#roots.some((root) => inside(root, initiallyCanonical))) throw new Error("Input is outside the configured roots");
|
|
451
|
+
if (!(await lstat(path)).isFile()) throw new Error("Input must be a regular file");
|
|
452
|
+
const handle = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
453
|
+
try {
|
|
454
|
+
const openedMetadata = await handle.stat();
|
|
455
|
+
if (!openedMetadata.isFile()) throw new Error("Input must be a regular file");
|
|
456
|
+
const canonical = await realpath(path);
|
|
457
|
+
if (!this.#roots.some((root) => inside(root, canonical))) throw new Error("Input is outside the configured roots");
|
|
458
|
+
const currentMetadata = await stat(canonical);
|
|
459
|
+
if (currentMetadata.dev !== openedMetadata.dev || currentMetadata.ino !== openedMetadata.ino) throw new Error("Input changed while it was being validated");
|
|
460
|
+
if (openedMetadata.size > maximumBytes) throw new Error(`${label} inputs must not exceed ${maximumBytes} bytes`);
|
|
461
|
+
return {
|
|
462
|
+
bytes: await readHandleBounded(handle, maximumBytes, label),
|
|
463
|
+
path: canonical
|
|
464
|
+
};
|
|
465
|
+
} finally {
|
|
466
|
+
await handle.close();
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
async output(path, extension) {
|
|
470
|
+
if (!isAbsolute(path) || extname(path).toLowerCase() !== extension) throw new Error(`Output must be an absolute ${extension} path`);
|
|
471
|
+
const normalized = resolve(path);
|
|
472
|
+
const parent = await realpath(dirname(normalized));
|
|
473
|
+
if (!this.#roots.some((root) => inside(root, parent))) throw new Error("Output is outside the configured roots");
|
|
474
|
+
const parentMetadata = await stat(parent);
|
|
475
|
+
try {
|
|
476
|
+
await lstat(normalized);
|
|
477
|
+
} catch (error) {
|
|
478
|
+
if (error.code === "ENOENT") return new ScopedOutput(normalized, {
|
|
479
|
+
dev: parentMetadata.dev,
|
|
480
|
+
ino: parentMetadata.ino,
|
|
481
|
+
path: parent
|
|
482
|
+
});
|
|
483
|
+
throw new Error("Output availability could not be verified", { cause: error });
|
|
484
|
+
}
|
|
485
|
+
throw new Error("Output already exists; overwriting is not supported");
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
const nativeNodeSurface = nativeNode;
|
|
489
|
+
const assertOutputParent = async ({ parent, path }) => {
|
|
490
|
+
const canonical = await realpath(dirname(path));
|
|
491
|
+
const metadata = await stat(canonical);
|
|
492
|
+
if (canonical !== parent.path || metadata.dev !== parent.dev || metadata.ino !== parent.ino) throw new Error("Output directory changed while it was being used");
|
|
493
|
+
};
|
|
494
|
+
const sameFile = (left, right) => left.dev === right.dev && left.ino === right.ino;
|
|
495
|
+
const safeWrite = async (output, bytes) => {
|
|
496
|
+
await assertOutputParent(output);
|
|
497
|
+
const temporary = `${output.path}.stella-${randomUUID()}.tmp`;
|
|
498
|
+
let published = false;
|
|
499
|
+
let committed = false;
|
|
500
|
+
let temporaryMetadata;
|
|
501
|
+
const handle = await open(temporary, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 256);
|
|
502
|
+
try {
|
|
503
|
+
temporaryMetadata = await handle.stat();
|
|
504
|
+
const canonicalTemporary = await realpath(temporary);
|
|
505
|
+
const currentTemporaryMetadata = await lstat(temporary);
|
|
506
|
+
if (dirname(canonicalTemporary) !== output.parent.path || !currentTemporaryMetadata.isFile() || !sameFile(temporaryMetadata, currentTemporaryMetadata)) throw new Error("Output staging file changed while it was being used");
|
|
507
|
+
await handle.writeFile(bytes);
|
|
508
|
+
await handle.sync();
|
|
509
|
+
await assertOutputParent(output);
|
|
510
|
+
const stagedMetadata = await lstat(temporary);
|
|
511
|
+
if (!stagedMetadata.isFile() || !sameFile(temporaryMetadata, stagedMetadata)) throw new Error("Output staging file changed before publication");
|
|
512
|
+
await link(temporary, output.path);
|
|
513
|
+
published = true;
|
|
514
|
+
const publishedMetadata = await lstat(output.path);
|
|
515
|
+
if (!publishedMetadata.isFile() || !sameFile(temporaryMetadata, publishedMetadata)) throw new Error("Published output does not match the staged file");
|
|
516
|
+
await assertOutputParent(output);
|
|
517
|
+
await handle.chmod(384);
|
|
518
|
+
await handle.sync();
|
|
519
|
+
committed = true;
|
|
520
|
+
} finally {
|
|
521
|
+
if (!committed) {
|
|
522
|
+
await handle.truncate(0).catch(() => void 0);
|
|
523
|
+
await handle.sync().catch(() => void 0);
|
|
524
|
+
await handle.chmod(0).catch(() => void 0);
|
|
525
|
+
}
|
|
526
|
+
await handle.close().catch(() => void 0);
|
|
527
|
+
await unlink(temporary).catch(() => void 0);
|
|
528
|
+
if (published && !committed && temporaryMetadata !== void 0) {
|
|
529
|
+
const publishedMetadata = await lstat(output.path).catch(() => void 0);
|
|
530
|
+
if (publishedMetadata !== void 0 && sameFile(temporaryMetadata, publishedMetadata)) await unlink(output.path).catch(() => void 0);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
const decodeText = (bytes) => {
|
|
535
|
+
return decodeUtf8(bytes, "Text inputs");
|
|
536
|
+
};
|
|
537
|
+
const decodeUtf8 = (bytes, label) => {
|
|
538
|
+
try {
|
|
539
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
540
|
+
} catch (error) {
|
|
541
|
+
throw new Error(`${label} must contain valid UTF-8`, { cause: error });
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
const applyTextReplacements = (text, replacements) => {
|
|
545
|
+
const parts = [];
|
|
546
|
+
let cursor = 0;
|
|
547
|
+
for (const replacement of replacements) {
|
|
548
|
+
if (!Number.isSafeInteger(replacement.start) || !Number.isSafeInteger(replacement.end) || replacement.start < cursor || replacement.end <= replacement.start || replacement.end > text.length || !isUtf16Boundary(text, replacement.start) || !isUtf16Boundary(text, replacement.end)) throw new Error("Native caller-detection plan returned invalid replacements");
|
|
549
|
+
parts.push(text.slice(cursor, replacement.start), replacement.replacement);
|
|
550
|
+
cursor = replacement.end;
|
|
551
|
+
}
|
|
552
|
+
parts.push(text.slice(cursor));
|
|
553
|
+
return parts.join("");
|
|
554
|
+
};
|
|
555
|
+
const isUtf16Boundary = (text, offset) => {
|
|
556
|
+
if (offset <= 0 || offset >= text.length) return true;
|
|
557
|
+
const before = text.charCodeAt(offset - 1);
|
|
558
|
+
const after = text.charCodeAt(offset);
|
|
559
|
+
return !(before >= 55296 && before <= 56319 && after >= 56320 && after <= 57343);
|
|
560
|
+
};
|
|
561
|
+
const assertDifferentPaths = (input, output) => {
|
|
562
|
+
if (input === output) throw new Error("Input and output paths must differ");
|
|
563
|
+
};
|
|
564
|
+
const textInput = z.object({
|
|
565
|
+
inputPath: z.string().min(1).max(PATH_MAX_CHARACTERS),
|
|
566
|
+
outputPath: z.string().min(1).max(PATH_MAX_CHARACTERS),
|
|
567
|
+
sessionId: z.string().regex(SESSION_ID),
|
|
568
|
+
language: z.string().min(2).max(35).optional()
|
|
569
|
+
});
|
|
570
|
+
const externalDetectionTextInput = textInput.extend({ detectionBatchPath: z.string().min(1).max(PATH_MAX_CHARACTERS) });
|
|
571
|
+
const restoreInput = z.object({
|
|
572
|
+
inputPath: z.string().min(1).max(PATH_MAX_CHARACTERS),
|
|
573
|
+
outputPath: z.string().min(1).max(PATH_MAX_CHARACTERS),
|
|
574
|
+
sessionId: z.string().regex(SESSION_ID)
|
|
575
|
+
});
|
|
576
|
+
const docxRestoreInput = restoreInput.extend({ allowPartialCoverage: z.boolean().optional().default(false) });
|
|
577
|
+
const docxInput = textInput.extend({ allowPartialCoverage: z.boolean().optional().default(false) });
|
|
578
|
+
const pdfInput = z.object({
|
|
579
|
+
inputPath: z.string().min(1).max(PATH_MAX_CHARACTERS),
|
|
580
|
+
outputPath: z.string().min(1).max(PATH_MAX_CHARACTERS),
|
|
581
|
+
ocrLanguage: z.string().regex(/^[A-Za-z0-9][A-Za-z0-9_.-]*$/u),
|
|
582
|
+
detectionLanguage: z.string().min(2).max(35).optional(),
|
|
583
|
+
dpi: z.number().int().min(72).max(600).optional().default(300),
|
|
584
|
+
timeoutMs: z.number().int().min(100).max(3e5).optional().default(12e4),
|
|
585
|
+
fillRgb: z.tuple([
|
|
586
|
+
z.number().int().min(0).max(255),
|
|
587
|
+
z.number().int().min(0).max(255),
|
|
588
|
+
z.number().int().min(0).max(255)
|
|
589
|
+
]).optional().default([
|
|
590
|
+
0,
|
|
591
|
+
0,
|
|
592
|
+
0
|
|
593
|
+
])
|
|
594
|
+
});
|
|
595
|
+
var LocalAnonymizeService = class {
|
|
596
|
+
#activeOperations = 0;
|
|
597
|
+
#closePromise;
|
|
598
|
+
#operationsDrained;
|
|
599
|
+
#scope;
|
|
600
|
+
#pdfOperationTail = Promise.resolve();
|
|
601
|
+
#sessionInitializations = /* @__PURE__ */ new Set();
|
|
602
|
+
#sessions = /* @__PURE__ */ new Map();
|
|
603
|
+
#state = "open";
|
|
604
|
+
#durableSessions;
|
|
605
|
+
#faults;
|
|
606
|
+
#pdfProvider;
|
|
607
|
+
constructor(scope, options = {}) {
|
|
608
|
+
if (options instanceof DurableSessionStore) throw new TypeError("LocalAnonymizeService requires { durableSessions } as its second argument");
|
|
609
|
+
const { durableSessions, faults = {}, pdfProvider = {} } = options;
|
|
610
|
+
this.#scope = scope;
|
|
611
|
+
this.#durableSessions = durableSessions;
|
|
612
|
+
this.#faults = faults;
|
|
613
|
+
this.#pdfProvider = pdfProvider;
|
|
614
|
+
}
|
|
615
|
+
get sessionMode() {
|
|
616
|
+
return this.#durableSessions === void 0 ? MCP_SESSION_MODES.memory : MCP_SESSION_MODES.durableEncrypted;
|
|
617
|
+
}
|
|
618
|
+
async close() {
|
|
619
|
+
if (this.#closePromise !== void 0) return this.#closePromise;
|
|
620
|
+
this.#state = "closing";
|
|
621
|
+
this.#closePromise = (async () => {
|
|
622
|
+
if (this.#activeOperations > 0) await new Promise((resolvePromise) => {
|
|
623
|
+
this.#operationsDrained = resolvePromise;
|
|
624
|
+
});
|
|
625
|
+
this.#sessions.clear();
|
|
626
|
+
await this.#durableSessions?.close();
|
|
627
|
+
this.#state = "closed";
|
|
628
|
+
})();
|
|
629
|
+
return this.#closePromise;
|
|
630
|
+
}
|
|
631
|
+
async #runOperation(operation) {
|
|
632
|
+
if (this.#state !== "open") throw new Error("MCP anonymize service is closing or closed");
|
|
633
|
+
this.#activeOperations += 1;
|
|
634
|
+
try {
|
|
635
|
+
return await operation();
|
|
636
|
+
} finally {
|
|
637
|
+
this.#activeOperations -= 1;
|
|
638
|
+
if (this.#activeOperations === 0) {
|
|
639
|
+
this.#operationsDrained?.();
|
|
640
|
+
this.#operationsDrained = void 0;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
async #session(sessionId, language) {
|
|
645
|
+
if (this.#durableSessions !== void 0 && language !== void 0) throw new Error("Durable sessions use the full all-language pipeline; omit language");
|
|
646
|
+
const existing = this.#sessions.get(sessionId);
|
|
647
|
+
if (existing !== void 0) {
|
|
648
|
+
if (language !== void 0 && existing.language !== language) throw new Error("A session cannot change language");
|
|
649
|
+
if (existing.status === "initializing") throw new Error("The requested session is still initializing");
|
|
650
|
+
if (existing.status === "busy") throw new Error("The requested session is handling another operation");
|
|
651
|
+
const checkpoint = existing.session.toPlaintextJson();
|
|
652
|
+
existing.status = "busy";
|
|
653
|
+
return {
|
|
654
|
+
entry: existing,
|
|
655
|
+
sessionId,
|
|
656
|
+
rollback: {
|
|
657
|
+
type: "restore",
|
|
658
|
+
checkpoint
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
if (this.#sessionInitializations.has(sessionId)) throw new Error("The requested session is still initializing");
|
|
663
|
+
this.#sessionInitializations.add(sessionId);
|
|
664
|
+
try {
|
|
665
|
+
if (this.#sessions.size >= SESSION_MAX_COUNT) throw new Error(`MCP sessions must not exceed ${SESSION_MAX_COUNT}`);
|
|
666
|
+
const pipeline = nativeNodeSurface.getDefaultNativePipeline(language === void 0 ? {} : { language });
|
|
667
|
+
const durableSessions = this.#durableSessions;
|
|
668
|
+
const stored = durableSessions === void 0 ? void 0 : await durableSessions.load(sessionId);
|
|
669
|
+
let session;
|
|
670
|
+
if (stored === void 0) session = pipeline.createRedactionSession(sessionId);
|
|
671
|
+
else {
|
|
672
|
+
if (durableSessions === void 0) throw new Error("Durable session storage is unavailable");
|
|
673
|
+
try {
|
|
674
|
+
session = durableSessions.restore({
|
|
675
|
+
archive: stored.bytes,
|
|
676
|
+
expectedSessionId: sessionId,
|
|
677
|
+
observedAtEpochSeconds: observedAtEpochSeconds(),
|
|
678
|
+
restorer: pipeline
|
|
679
|
+
});
|
|
680
|
+
} catch (error) {
|
|
681
|
+
throw new Error("The requested durable session is unavailable", { cause: error });
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
const entry = {
|
|
685
|
+
language,
|
|
686
|
+
session,
|
|
687
|
+
restoreSession: (plaintextJson) => pipeline.restoreRedactionSession(plaintextJson),
|
|
688
|
+
status: "initializing"
|
|
689
|
+
};
|
|
690
|
+
this.#sessions.set(sessionId, entry);
|
|
691
|
+
return {
|
|
692
|
+
entry,
|
|
693
|
+
sessionId,
|
|
694
|
+
rollback: stored === void 0 ? { type: "delete" } : {
|
|
695
|
+
type: "restore",
|
|
696
|
+
checkpoint: session.toPlaintextJson()
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
} finally {
|
|
700
|
+
this.#sessionInitializations.delete(sessionId);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
#commitSession({ entry }) {
|
|
704
|
+
entry.status = "ready";
|
|
705
|
+
}
|
|
706
|
+
async #rollbackSession({ entry, rollback, sessionId }) {
|
|
707
|
+
if (this.#sessions.get(sessionId) !== entry) return;
|
|
708
|
+
if (rollback.type === "delete") {
|
|
709
|
+
this.#sessions.delete(sessionId);
|
|
710
|
+
await this.#durableSessions?.delete(sessionId).catch(() => void 0);
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
if (rollback.type === "release") {
|
|
714
|
+
entry.status = "ready";
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
try {
|
|
718
|
+
entry.session = entry.restoreSession(rollback.checkpoint);
|
|
719
|
+
entry.status = "ready";
|
|
720
|
+
await this.#persistSession(sessionId, entry.session);
|
|
721
|
+
} catch {
|
|
722
|
+
this.#sessions.delete(sessionId);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
async #readSession(sessionId) {
|
|
726
|
+
let entry = this.#sessions.get(sessionId);
|
|
727
|
+
if (entry === void 0 && this.#durableSessions !== void 0) {
|
|
728
|
+
if (this.#sessionInitializations.has(sessionId)) throw new Error("The requested session is still initializing");
|
|
729
|
+
this.#sessionInitializations.add(sessionId);
|
|
730
|
+
try {
|
|
731
|
+
const pipeline = nativeNodeSurface.getDefaultNativePipeline({});
|
|
732
|
+
const stored = await this.#durableSessions.load(sessionId);
|
|
733
|
+
if (stored !== void 0) try {
|
|
734
|
+
entry = {
|
|
735
|
+
language: void 0,
|
|
736
|
+
session: this.#durableSessions.restore({
|
|
737
|
+
archive: stored.bytes,
|
|
738
|
+
expectedSessionId: sessionId,
|
|
739
|
+
observedAtEpochSeconds: observedAtEpochSeconds(),
|
|
740
|
+
restorer: pipeline
|
|
741
|
+
}),
|
|
742
|
+
restoreSession: (plaintextJson) => pipeline.restoreRedactionSession(plaintextJson),
|
|
743
|
+
status: "ready"
|
|
744
|
+
};
|
|
745
|
+
this.#sessions.set(sessionId, entry);
|
|
746
|
+
} catch (error) {
|
|
747
|
+
throw new Error("The requested durable session is unavailable", { cause: error });
|
|
748
|
+
}
|
|
749
|
+
} finally {
|
|
750
|
+
this.#sessionInitializations.delete(sessionId);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
if (entry === void 0) throw new Error("The requested session is unavailable");
|
|
754
|
+
if (entry.status !== "ready") throw new Error("The requested in-memory session is unavailable");
|
|
755
|
+
entry.status = "busy";
|
|
756
|
+
return {
|
|
757
|
+
entry,
|
|
758
|
+
sessionId,
|
|
759
|
+
rollback: { type: "release" }
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
async #persistSession(sessionId, session) {
|
|
763
|
+
if (this.#durableSessions === void 0) return;
|
|
764
|
+
const archive = this.#durableSessions.seal(session, observedAtEpochSeconds());
|
|
765
|
+
await this.#durableSessions.save(sessionId, archive);
|
|
766
|
+
}
|
|
767
|
+
async anonymizeText(input) {
|
|
768
|
+
return this.#runOperation(() => this.#anonymizeText(input));
|
|
769
|
+
}
|
|
770
|
+
async anonymizePdf(input) {
|
|
771
|
+
return this.#runOperation(() => this.#serializePdfOperation(() => this.#anonymizePdf(input)));
|
|
772
|
+
}
|
|
773
|
+
async #serializePdfOperation(operation) {
|
|
774
|
+
const previous = this.#pdfOperationTail;
|
|
775
|
+
let release = () => void 0;
|
|
776
|
+
this.#pdfOperationTail = new Promise((resolvePromise) => {
|
|
777
|
+
release = resolvePromise;
|
|
778
|
+
});
|
|
779
|
+
await previous;
|
|
780
|
+
try {
|
|
781
|
+
return await operation();
|
|
782
|
+
} finally {
|
|
783
|
+
release();
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
async #anonymizePdf(input) {
|
|
787
|
+
const source = await this.#scope.readInput({
|
|
788
|
+
path: input.inputPath,
|
|
789
|
+
extension: ".pdf",
|
|
790
|
+
maximumBytes: PDF_DOCUMENT_MAX_BYTES,
|
|
791
|
+
label: "PDF"
|
|
792
|
+
});
|
|
793
|
+
const destination = await this.#scope.output(input.outputPath, ".pdf");
|
|
794
|
+
assertDifferentPaths(source.path, destination.path);
|
|
795
|
+
const pipeline = nativeNodeSurface.getDefaultNativePipeline(input.detectionLanguage === void 0 ? {} : { language: input.detectionLanguage });
|
|
796
|
+
const observed = await renderPdfWithPopplerTesseract({
|
|
797
|
+
document: source.bytes,
|
|
798
|
+
ocrLanguage: input.ocrLanguage,
|
|
799
|
+
dpi: input.dpi,
|
|
800
|
+
timeoutMs: input.timeoutMs,
|
|
801
|
+
...this.#pdfProvider
|
|
802
|
+
});
|
|
803
|
+
const anonymized = anonymizePdfRaster({
|
|
804
|
+
document: source.bytes,
|
|
805
|
+
pipeline,
|
|
806
|
+
provider: observed.provider,
|
|
807
|
+
pages: observed.pages,
|
|
808
|
+
fillRgb: input.fillRgb
|
|
809
|
+
});
|
|
810
|
+
if (anonymized.certificate.structurePixelRewriteVerified !== true || anonymized.certificate.piiCleanGuaranteed !== false) throw new Error("PDF raster verification did not satisfy MCP policy");
|
|
811
|
+
await this.#faults.beforeOutputPublish?.();
|
|
812
|
+
await destination.write(anonymized.document);
|
|
813
|
+
return {
|
|
814
|
+
operation: "anonymize",
|
|
815
|
+
format: "pdf",
|
|
816
|
+
outputCreated: true,
|
|
817
|
+
pageCount: anonymized.certificate.pageCount,
|
|
818
|
+
entityCount: anonymized.certificate.detectionCount,
|
|
819
|
+
mappedRegionCount: anonymized.certificate.mappedRegionCount,
|
|
820
|
+
structurePixelRewriteVerified: true,
|
|
821
|
+
piiCleanGuaranteed: false
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
async #anonymizeText(input) {
|
|
825
|
+
const source = await this.#scope.readInput({
|
|
826
|
+
path: input.inputPath,
|
|
827
|
+
extension: ".txt",
|
|
828
|
+
maximumBytes: TEXT_MAX_BYTES,
|
|
829
|
+
label: "Text"
|
|
830
|
+
});
|
|
831
|
+
const destination = await this.#scope.output(input.outputPath, ".txt");
|
|
832
|
+
assertDifferentPaths(source.path, destination.path);
|
|
833
|
+
const text = decodeText(source.bytes);
|
|
834
|
+
const lease = await this.#session(input.sessionId, input.language);
|
|
835
|
+
try {
|
|
836
|
+
const result = lease.entry.session.redact_text(text);
|
|
837
|
+
await this.#persistSession(input.sessionId, lease.entry.session);
|
|
838
|
+
await this.#faults.beforeOutputPublish?.();
|
|
839
|
+
await destination.write(result.redaction.redactedText);
|
|
840
|
+
this.#commitSession(lease);
|
|
841
|
+
return {
|
|
842
|
+
operation: "anonymize",
|
|
843
|
+
format: "text",
|
|
844
|
+
outputCreated: true,
|
|
845
|
+
sessionId: input.sessionId,
|
|
846
|
+
entityCount: result.redaction.entityCount
|
|
847
|
+
};
|
|
848
|
+
} catch (error) {
|
|
849
|
+
await this.#rollbackSession(lease);
|
|
850
|
+
throw error;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
async restoreText(input) {
|
|
854
|
+
return this.#runOperation(() => this.#restoreText(input));
|
|
855
|
+
}
|
|
856
|
+
async anonymizeTextWithExternalDetections(input) {
|
|
857
|
+
try {
|
|
858
|
+
return await this.#runOperation(() => this.#anonymizeTextWithExternalDetections(input));
|
|
859
|
+
} catch (error) {
|
|
860
|
+
throw externalDetectionFailure(error, EXTERNAL_DETECTION_FAILURES.operationFailed);
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
async #anonymizeTextWithExternalDetections(input) {
|
|
864
|
+
const { batch, destination, source } = await externalDetectionStep(EXTERNAL_DETECTION_FAILURES.inputRejected, async () => {
|
|
865
|
+
const scopedSource = await this.#scope.readInput({
|
|
866
|
+
path: input.inputPath,
|
|
867
|
+
extension: ".txt",
|
|
868
|
+
maximumBytes: TEXT_MAX_BYTES,
|
|
869
|
+
label: "Text"
|
|
870
|
+
});
|
|
871
|
+
const scopedBatch = await this.#scope.readInput({
|
|
872
|
+
path: input.detectionBatchPath,
|
|
873
|
+
extension: ".json",
|
|
874
|
+
maximumBytes: EXTERNAL_DETECTION_BATCH_MAX_BYTES,
|
|
875
|
+
label: "External detection batch"
|
|
876
|
+
});
|
|
877
|
+
const scopedDestination = await this.#scope.output(input.outputPath, ".txt");
|
|
878
|
+
assertDifferentPaths(scopedSource.path, scopedDestination.path);
|
|
879
|
+
assertDifferentPaths(scopedBatch.path, scopedDestination.path);
|
|
880
|
+
assertDifferentPaths(scopedSource.path, scopedBatch.path);
|
|
881
|
+
return {
|
|
882
|
+
batch: scopedBatch,
|
|
883
|
+
destination: scopedDestination,
|
|
884
|
+
source: scopedSource
|
|
885
|
+
};
|
|
886
|
+
});
|
|
887
|
+
const text = await externalDetectionStep(EXTERNAL_DETECTION_FAILURES.documentRejected, () => decodeText(source.bytes));
|
|
888
|
+
const detections = await externalDetectionStep(EXTERNAL_DETECTION_FAILURES.batchRejected, () => nativeNodeSurface.convert_external_detection_batch(source.bytes, decodeUtf8(batch.bytes, "External detection batches")));
|
|
889
|
+
const lease = await externalDetectionStep(EXTERNAL_DETECTION_FAILURES.sessionRejected, () => this.#session(input.sessionId, input.language));
|
|
890
|
+
try {
|
|
891
|
+
const plan = lease.entry.session.planTextBatchWithCallerDetections({ inputs: [{
|
|
892
|
+
fullText: text,
|
|
893
|
+
detections
|
|
894
|
+
}] });
|
|
895
|
+
const block = plan.blocks.at(0);
|
|
896
|
+
if (plan.blocks.length !== 1 || block === void 0) throw new Error("Native caller-detection plan did not match the text input");
|
|
897
|
+
const redactedText = applyTextReplacements(text, block.replacements);
|
|
898
|
+
plan.commit();
|
|
899
|
+
await this.#persistSession(input.sessionId, lease.entry.session);
|
|
900
|
+
await this.#faults.beforeOutputPublish?.();
|
|
901
|
+
await destination.write(redactedText);
|
|
902
|
+
this.#commitSession(lease);
|
|
903
|
+
return {
|
|
904
|
+
operation: "anonymize",
|
|
905
|
+
format: "text",
|
|
906
|
+
outputCreated: true,
|
|
907
|
+
sessionId: input.sessionId,
|
|
908
|
+
entityCount: block.entityCount,
|
|
909
|
+
externalDetectionBatchStatus: "accepted",
|
|
910
|
+
externalDetectionCount: detections.length,
|
|
911
|
+
retainedExternalDetectionCount: block.callerEntityCount
|
|
912
|
+
};
|
|
913
|
+
} catch (error) {
|
|
914
|
+
await this.#rollbackSession(lease);
|
|
915
|
+
throw externalDetectionFailure(error, EXTERNAL_DETECTION_FAILURES.operationFailed);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
async #restoreText(input) {
|
|
919
|
+
const source = await this.#scope.readInput({
|
|
920
|
+
path: input.inputPath,
|
|
921
|
+
extension: ".txt",
|
|
922
|
+
maximumBytes: TEXT_MAX_BYTES,
|
|
923
|
+
label: "Text"
|
|
924
|
+
});
|
|
925
|
+
const destination = await this.#scope.output(input.outputPath, ".txt");
|
|
926
|
+
assertDifferentPaths(source.path, destination.path);
|
|
927
|
+
const text = decodeText(source.bytes);
|
|
928
|
+
const lease = await this.#readSession(input.sessionId);
|
|
929
|
+
try {
|
|
930
|
+
const restored = lease.entry.session.restoreText(text);
|
|
931
|
+
await destination.write(restored);
|
|
932
|
+
this.#commitSession(lease);
|
|
933
|
+
return {
|
|
934
|
+
operation: "restore",
|
|
935
|
+
format: "text",
|
|
936
|
+
outputCreated: true,
|
|
937
|
+
sessionId: input.sessionId
|
|
938
|
+
};
|
|
939
|
+
} catch (error) {
|
|
940
|
+
await this.#rollbackSession(lease);
|
|
941
|
+
throw error;
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
async anonymizeDocx(input) {
|
|
945
|
+
return this.#runOperation(() => this.#anonymizeDocx(input));
|
|
946
|
+
}
|
|
947
|
+
async #anonymizeDocx(input) {
|
|
948
|
+
const source = await this.#scope.readInput({
|
|
949
|
+
path: input.inputPath,
|
|
950
|
+
extension: ".docx",
|
|
951
|
+
maximumBytes: DOCX_ARCHIVE_MAX_BYTES,
|
|
952
|
+
label: "DOCX"
|
|
953
|
+
});
|
|
954
|
+
const destination = await this.#scope.output(input.outputPath, ".docx");
|
|
955
|
+
assertDifferentPaths(source.path, destination.path);
|
|
956
|
+
const lease = await this.#session(input.sessionId, input.language);
|
|
957
|
+
try {
|
|
958
|
+
const result = anonymizeDocx({
|
|
959
|
+
document: source.bytes,
|
|
960
|
+
session: lease.entry.session,
|
|
961
|
+
expectedSessionId: input.sessionId,
|
|
962
|
+
policy: { coverage: { mode: input.allowPartialCoverage ? DOCX_COVERAGE_MODES.allowPartial : DOCX_COVERAGE_MODES.requireFull } }
|
|
963
|
+
});
|
|
964
|
+
await this.#persistSession(input.sessionId, lease.entry.session);
|
|
965
|
+
await this.#faults.beforeOutputPublish?.();
|
|
966
|
+
await destination.write(result.document);
|
|
967
|
+
this.#commitSession(lease);
|
|
968
|
+
return {
|
|
969
|
+
operation: "anonymize",
|
|
970
|
+
format: "docx",
|
|
971
|
+
outputCreated: true,
|
|
972
|
+
sessionId: input.sessionId,
|
|
973
|
+
entityCount: result.summary.entityCount,
|
|
974
|
+
blockCount: result.summary.blockCount,
|
|
975
|
+
rewrittenBlockCount: result.summary.rewrittenBlockCount,
|
|
976
|
+
coverageStatus: result.summary.coverage.status
|
|
977
|
+
};
|
|
978
|
+
} catch (error) {
|
|
979
|
+
await this.#rollbackSession(lease);
|
|
980
|
+
throw error;
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
async restoreDocx(input) {
|
|
984
|
+
return this.#runOperation(() => this.#restoreDocx(input));
|
|
985
|
+
}
|
|
986
|
+
async #restoreDocx(input) {
|
|
987
|
+
const source = await this.#scope.readInput({
|
|
988
|
+
path: input.inputPath,
|
|
989
|
+
extension: ".docx",
|
|
990
|
+
maximumBytes: DOCX_ARCHIVE_MAX_BYTES,
|
|
991
|
+
label: "DOCX"
|
|
992
|
+
});
|
|
993
|
+
const destination = await this.#scope.output(input.outputPath, ".docx");
|
|
994
|
+
assertDifferentPaths(source.path, destination.path);
|
|
995
|
+
const lease = await this.#readSession(input.sessionId);
|
|
996
|
+
try {
|
|
997
|
+
const result = restoreDocxText({
|
|
998
|
+
document: source.bytes,
|
|
999
|
+
session: lease.entry.session,
|
|
1000
|
+
expectedSessionId: input.sessionId
|
|
1001
|
+
});
|
|
1002
|
+
if (result.coverage.status === "partial" && !input.allowPartialCoverage) throw new Error("DOCX restoration has partial coverage; set allowPartialCoverage to publish it");
|
|
1003
|
+
await destination.write(result.document);
|
|
1004
|
+
this.#commitSession(lease);
|
|
1005
|
+
return {
|
|
1006
|
+
operation: "restore",
|
|
1007
|
+
format: "docx",
|
|
1008
|
+
outputCreated: true,
|
|
1009
|
+
sessionId: input.sessionId,
|
|
1010
|
+
rewrittenBlockCount: result.restoredBlockCount,
|
|
1011
|
+
restoredPlaceholderCount: result.restoredPlaceholderCount,
|
|
1012
|
+
coverageStatus: result.coverage.status
|
|
1013
|
+
};
|
|
1014
|
+
} catch (error) {
|
|
1015
|
+
await this.#rollbackSession(lease);
|
|
1016
|
+
throw error;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
async inspectDocx(inputPath) {
|
|
1020
|
+
return this.#runOperation(() => this.#inspectDocx(inputPath));
|
|
1021
|
+
}
|
|
1022
|
+
async #inspectDocx(inputPath) {
|
|
1023
|
+
const extraction = extractDocxText((await this.#scope.readInput({
|
|
1024
|
+
path: inputPath,
|
|
1025
|
+
extension: ".docx",
|
|
1026
|
+
maximumBytes: DOCX_ARCHIVE_MAX_BYTES,
|
|
1027
|
+
label: "DOCX"
|
|
1028
|
+
})).bytes);
|
|
1029
|
+
const unsupported = extraction.coverage.parts.some((part) => part.status === "unsupported");
|
|
1030
|
+
const structuralGap = extraction.coverage.hyperlinkTextSegmentCount > 0 || extraction.coverage.revisionTextSegmentCount > 0 || extraction.coverage.unsupportedAlternateContentCount > 0 || extraction.coverage.unsupportedFieldInstructionCount > 0 || extraction.coverage.unsupportedSymbolCount > 0;
|
|
1031
|
+
return {
|
|
1032
|
+
operation: "inspect",
|
|
1033
|
+
format: "docx",
|
|
1034
|
+
outputCreated: false,
|
|
1035
|
+
blockCount: extraction.blocks.length,
|
|
1036
|
+
coverageStatus: unsupported || structuralGap ? "partial" : "full"
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
const result = (value) => ({
|
|
1041
|
+
content: [{
|
|
1042
|
+
type: "text",
|
|
1043
|
+
text: JSON.stringify(value)
|
|
1044
|
+
}],
|
|
1045
|
+
structuredContent: { ...value }
|
|
1046
|
+
});
|
|
1047
|
+
const MCP_TOOL_NAMES = [
|
|
1048
|
+
"anonymize_docx_file",
|
|
1049
|
+
"anonymize_pdf_file",
|
|
1050
|
+
"anonymize_text_file",
|
|
1051
|
+
"anonymize_text_file_with_external_detections",
|
|
1052
|
+
"capabilities",
|
|
1053
|
+
"inspect_docx_file",
|
|
1054
|
+
"restore_docx_file",
|
|
1055
|
+
"restore_text_file"
|
|
1056
|
+
];
|
|
1057
|
+
const capabilitiesResult = (service) => {
|
|
1058
|
+
const value = {
|
|
1059
|
+
capabilityManifest: CAPABILITY_MANIFEST,
|
|
1060
|
+
runtimeVersion: nativeNodeSurface.native_package_version(),
|
|
1061
|
+
mcp: {
|
|
1062
|
+
externalDetectionBatch: {
|
|
1063
|
+
ingestion: "path-only",
|
|
1064
|
+
version: EXTERNAL_DETECTION_BATCH_VERSION
|
|
1065
|
+
},
|
|
1066
|
+
formats: [
|
|
1067
|
+
"docx",
|
|
1068
|
+
"pdf",
|
|
1069
|
+
"text"
|
|
1070
|
+
],
|
|
1071
|
+
sessionMode: service.sessionMode,
|
|
1072
|
+
tools: MCP_TOOL_NAMES,
|
|
1073
|
+
transport: "stdio"
|
|
1074
|
+
}
|
|
1075
|
+
};
|
|
1076
|
+
return {
|
|
1077
|
+
content: [{
|
|
1078
|
+
type: "text",
|
|
1079
|
+
text: JSON.stringify(value)
|
|
1080
|
+
}],
|
|
1081
|
+
structuredContent: value
|
|
1082
|
+
};
|
|
1083
|
+
};
|
|
1084
|
+
const externalDetectionErrorResult = (error) => {
|
|
1085
|
+
const failure = externalDetectionFailure(error, EXTERNAL_DETECTION_FAILURES.operationFailed);
|
|
1086
|
+
const value = {
|
|
1087
|
+
errorCode: failure.code,
|
|
1088
|
+
message: failure.message
|
|
1089
|
+
};
|
|
1090
|
+
return {
|
|
1091
|
+
isError: true,
|
|
1092
|
+
content: [{
|
|
1093
|
+
type: "text",
|
|
1094
|
+
text: JSON.stringify(value)
|
|
1095
|
+
}],
|
|
1096
|
+
structuredContent: value
|
|
1097
|
+
};
|
|
1098
|
+
};
|
|
1099
|
+
const createAnonymizeMcpServer = (service) => {
|
|
1100
|
+
const server = new McpServer({
|
|
1101
|
+
name: "stella-anonymize-local",
|
|
1102
|
+
version: nativeNodeSurface.native_package_version()
|
|
1103
|
+
}, { instructions: "All tools accept local paths only. Never request or return document contents or session mappings. Outputs must be new explicit paths inside configured roots." });
|
|
1104
|
+
server.registerTool("capabilities", {
|
|
1105
|
+
description: "Return the public runtime capability manifest and MCP surface metadata.",
|
|
1106
|
+
inputSchema: z.object({}),
|
|
1107
|
+
annotations: {
|
|
1108
|
+
readOnlyHint: true,
|
|
1109
|
+
destructiveHint: false,
|
|
1110
|
+
idempotentHint: true
|
|
1111
|
+
}
|
|
1112
|
+
}, async () => capabilitiesResult(service));
|
|
1113
|
+
server.registerTool("anonymize_text_file", {
|
|
1114
|
+
description: "Anonymize a local UTF-8 text file into a new local file.",
|
|
1115
|
+
inputSchema: textInput,
|
|
1116
|
+
annotations: {
|
|
1117
|
+
destructiveHint: false,
|
|
1118
|
+
idempotentHint: false
|
|
1119
|
+
}
|
|
1120
|
+
}, async (input) => result(await service.anonymizeText(input)));
|
|
1121
|
+
server.registerTool("restore_text_file", {
|
|
1122
|
+
description: "Restore a text file using the configured session store.",
|
|
1123
|
+
inputSchema: restoreInput,
|
|
1124
|
+
annotations: {
|
|
1125
|
+
destructiveHint: false,
|
|
1126
|
+
idempotentHint: false
|
|
1127
|
+
}
|
|
1128
|
+
}, async (input) => result(await service.restoreText(input)));
|
|
1129
|
+
server.registerTool("anonymize_text_file_with_external_detections", {
|
|
1130
|
+
description: "Anonymize a local UTF-8 text file with a provider-neutral ExternalDetectionBatch v1 JSON sidecar into a new local file.",
|
|
1131
|
+
inputSchema: externalDetectionTextInput,
|
|
1132
|
+
annotations: {
|
|
1133
|
+
destructiveHint: false,
|
|
1134
|
+
idempotentHint: false
|
|
1135
|
+
}
|
|
1136
|
+
}, async (input) => {
|
|
1137
|
+
try {
|
|
1138
|
+
return result(await service.anonymizeTextWithExternalDetections(input));
|
|
1139
|
+
} catch (error) {
|
|
1140
|
+
return externalDetectionErrorResult(error);
|
|
1141
|
+
}
|
|
1142
|
+
});
|
|
1143
|
+
server.registerTool("anonymize_docx_file", {
|
|
1144
|
+
description: "Structure-preservingly anonymize a local DOCX into a new local DOCX.",
|
|
1145
|
+
inputSchema: docxInput,
|
|
1146
|
+
annotations: {
|
|
1147
|
+
destructiveHint: false,
|
|
1148
|
+
idempotentHint: false
|
|
1149
|
+
}
|
|
1150
|
+
}, async (input) => result(await service.anonymizeDocx(input)));
|
|
1151
|
+
server.registerTool("anonymize_pdf_file", {
|
|
1152
|
+
description: "Destructively raster-anonymize a local PDF into a fresh image-only PDF. Returns aggregate verification only; it does not claim perfect OCR or detector recall.",
|
|
1153
|
+
inputSchema: pdfInput,
|
|
1154
|
+
annotations: {
|
|
1155
|
+
destructiveHint: false,
|
|
1156
|
+
idempotentHint: false
|
|
1157
|
+
}
|
|
1158
|
+
}, async (input) => result(await service.anonymizePdf(input)));
|
|
1159
|
+
server.registerTool("restore_docx_file", {
|
|
1160
|
+
description: "Restore a DOCX using the configured session store.",
|
|
1161
|
+
inputSchema: docxRestoreInput,
|
|
1162
|
+
annotations: {
|
|
1163
|
+
destructiveHint: false,
|
|
1164
|
+
idempotentHint: false
|
|
1165
|
+
}
|
|
1166
|
+
}, async (input) => result(await service.restoreDocx(input)));
|
|
1167
|
+
server.registerTool("inspect_docx_file", {
|
|
1168
|
+
description: "Return only aggregate DOCX coverage and block counts; never document text.",
|
|
1169
|
+
inputSchema: z.object({ inputPath: z.string().min(1).max(PATH_MAX_CHARACTERS) }),
|
|
1170
|
+
annotations: {
|
|
1171
|
+
readOnlyHint: true,
|
|
1172
|
+
destructiveHint: false,
|
|
1173
|
+
idempotentHint: true
|
|
1174
|
+
}
|
|
1175
|
+
}, async ({ inputPath }) => result(await service.inspectDocx(inputPath)));
|
|
1176
|
+
return server;
|
|
1177
|
+
};
|
|
1178
|
+
//#endregion
|
|
1179
|
+
export { DURABLE_SESSION_FAULT_POINTS as a, SESSION_ARCHIVE_MAX_BYTES as c, createAnonymizeMcpServer as i, SESSION_ARCHIVE_MAX_COUNT as l, MCP_SESSION_MODES as n, DurableSessionStore as o, PathScope as r, SESSION_ARCHIVE_KEY_BYTES as s, LocalAnonymizeService as t, SESSION_ARCHIVE_TOTAL_MAX_BYTES as u };
|
|
1180
|
+
|
|
1181
|
+
//# sourceMappingURL=local.mjs.map
|