@maskera/mcp 0.4.0 → 0.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/dist/index.d.ts CHANGED
@@ -385,6 +385,13 @@ declare class SessionVault {
385
385
  sessionId: string | null;
386
386
  knownPlaceholders: number;
387
387
  };
388
+ /**
389
+ * Picks the session that restores `text` when the caller named none.
390
+ * A candidate must know every placeholder in the text. When several do and
391
+ * would restore it differently, the choice is ambiguous and refused, so a
392
+ * missing session_id can never put another document's values into a file.
393
+ */
394
+ resolveSessionFor(text: string): string;
388
395
  getMap(sessionId: string): Record<string, string>;
389
396
  entries(): Array<{
390
397
  sessionId: string;
@@ -512,7 +519,7 @@ declare function createSseRestorer(map: Readonly<Record<string, string>>): {
512
519
  declare function startMaskeraProxy(options?: ProxyOptions): Promise<RunningMaskeraProxy>;
513
520
 
514
521
  declare const SERVER_NAME = "maskera-mcp";
515
- declare const SERVER_VERSION = "0.4.0";
522
+ declare const SERVER_VERSION: string;
516
523
  interface JsonRpcResponse {
517
524
  jsonrpc: "2.0";
518
525
  id: string | number | null;
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ import { randomUUID, createHash } from 'crypto';
2
2
  import { constants } from 'fs';
3
3
  import { readFile, mkdir, realpath, writeFile, stat, access, appendFile, unlink, readdir, lstat, readlink } from 'fs/promises';
4
4
  import { dirname, resolve, join, isAbsolute, relative, sep, delimiter } from 'path';
5
+ import { createRequire } from 'module';
5
6
  import { MASKERA_SV_NER_MODEL, MASKERA_SV_NER_REVISION, redactFromDetections, hybridDefaultDetectors, runDetectors, clinicalPrecisionFilter, redact, redactWithNer, restore, createNerRecognizer } from 'maskera';
6
7
  import { spawn, spawnSync } from 'child_process';
7
8
  import { homedir } from 'os';
@@ -991,6 +992,32 @@ var SessionVault = class {
991
992
  knownPlaceholders: Object.keys(session.map).length
992
993
  };
993
994
  }
995
+ /**
996
+ * Picks the session that restores `text` when the caller named none.
997
+ * A candidate must know every placeholder in the text. When several do and
998
+ * would restore it differently, the choice is ambiguous and refused, so a
999
+ * missing session_id can never put another document's values into a file.
1000
+ */
1001
+ resolveSessionFor(text) {
1002
+ const tokens = [...new Set(text.match(EXISTING_TOKEN_RE) ?? [])];
1003
+ const candidates = [...this.sessions.values()].filter(
1004
+ (s) => tokens.every((token) => token in s.map)
1005
+ );
1006
+ if (candidates.length === 0) {
1007
+ throw new Error(
1008
+ tokens.length > 0 ? `No local session knows ${tokens.slice(0, 3).join(", ")}. Read the source with maskera_read_file or maskera_redact first, then pass its session_id.` : "No local session exists yet. Read the source with maskera_read_file or maskera_redact first, then pass its session_id."
1009
+ );
1010
+ }
1011
+ const restorations = new Set(candidates.map((s) => restore(text, s.map)));
1012
+ if (restorations.size > 1) {
1013
+ throw new Error(
1014
+ `The placeholders match ${candidates.length} sessions that restore them differently (${candidates.map((s) => s.id).join(", ")}). Pass the session_id from the maskera_read_file result.`
1015
+ );
1016
+ }
1017
+ const latest = candidates[candidates.length - 1];
1018
+ if (!latest) throw new Error("No local session can restore this text.");
1019
+ return latest.id;
1020
+ }
994
1021
  getMap(sessionId) {
995
1022
  const session = this.sessions.get(sessionId.trim());
996
1023
  return session ? { ...session.map } : {};
@@ -1026,7 +1053,7 @@ var SessionVault = class {
1026
1053
 
1027
1054
  // src/server.ts
1028
1055
  var SERVER_NAME = "maskera-mcp";
1029
- var SERVER_VERSION = "0.4.0";
1056
+ var SERVER_VERSION = createRequire(import.meta.url)("../package.json").version;
1030
1057
  var SUPPORTED_PROTOCOLS = ["2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05"];
1031
1058
  var PLACEHOLDER_QUERY_RE = /^\[[A-ZÅÄÖ][A-ZÅÄÖ0-9_]*_\d+\]$/;
1032
1059
  var COUNTS_SCHEMA = {
@@ -1203,14 +1230,14 @@ var TOOLS = [
1203
1230
  },
1204
1231
  session_id: {
1205
1232
  type: "string",
1206
- description: "Session ID containing the local restore map."
1233
+ description: "Session ID from maskera_read_file or maskera_redact. When omitted, the latest session that knows every placeholder in text is used; ambiguous matches are refused."
1207
1234
  },
1208
1235
  overwrite: {
1209
1236
  type: "boolean",
1210
1237
  description: "Allow overwriting an existing file. Default false."
1211
1238
  }
1212
1239
  },
1213
- required: ["path", "text", "session_id"]
1240
+ required: ["path", "text"]
1214
1241
  },
1215
1242
  outputSchema: {
1216
1243
  type: "object",
@@ -1773,10 +1800,7 @@ function createMaskeraMcpServer(options = {}) {
1773
1800
  if (name === "maskera_write_file") {
1774
1801
  if (typeof args.path !== "string") return finish(toolError("Missing required string: path"));
1775
1802
  if (typeof args.text !== "string") return finish(toolError("Missing required string: text"));
1776
- if (typeof args.session_id !== "string" || !args.session_id.trim()) {
1777
- return finish(toolError("Missing required non-empty string: session_id"));
1778
- }
1779
- const normalizedSessionId = args.session_id.trim();
1803
+ const normalizedSessionId = typeof args.session_id === "string" && args.session_id.trim() ? args.session_id.trim() : vault.resolveSessionFor(args.text);
1780
1804
  telemetrySessionId = normalizedSessionId;
1781
1805
  const { restored, knownPlaceholders } = vault.restore(args.text, {
1782
1806
  sessionId: normalizedSessionId