@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/README.md CHANGED
@@ -113,7 +113,7 @@ Tools (all declare `inputSchema`, `outputSchema`, and MCP tool `annotations`):
113
113
  - `maskera_list_files`: List files inside allowed workspace roots without reading contents.
114
114
  - `maskera_search_files`: Search UTF-8 files locally and redact every matched line before returning (supports searching by an existing placeholder like `[NAMN_1]`).
115
115
  - `maskera_read_file`: Read a local UTF-8 file already redacted, storing the restore map locally under `session_id`.
116
- - `maskera_write_file`: Restore placeholders from `session_id` and write directly to disk without exposing raw PII back to the LLM.
116
+ - `maskera_write_file`: Restore placeholders from `session_id` and write directly to disk without exposing raw PII back to the LLM. Without `session_id` it uses the latest session that knows every placeholder in the text, and refuses when several sessions would restore it differently.
117
117
  - `maskera_redact`: Redact text locally (`mode: "auto"` or `"rules"`, `profile: "general" | "clinical"`, `custom_terms`).
118
118
  - `maskera_restore`: Restore placeholders using `session_id` or an explicit map (hidden and blocked under `--no-raw-restore`, or gated under `--approval-mode browser|native`).
119
119
  - `maskera_list_sessions` / `maskera_clear_session` / `maskera_status`: Inspect counts (never raw PII), clear memory, or check model and policy status.
package/dist/cli.js CHANGED
@@ -4,6 +4,7 @@ import { delimiter, join, dirname, resolve, isAbsolute, relative, sep } from 'pa
4
4
  import { createInterface } from 'readline';
5
5
  import { format } from 'util';
6
6
  import { constants } from 'fs';
7
+ import { createRequire } from 'module';
7
8
  import { randomUUID, createHash } from 'crypto';
8
9
  import { MASKERA_SV_NER_MODEL, MASKERA_SV_NER_REVISION, redactFromDetections, hybridDefaultDetectors, runDetectors, clinicalPrecisionFilter, redact, redactWithNer, restore, createNerRecognizer } from 'maskera';
9
10
  import { spawn, spawnSync } from 'child_process';
@@ -993,6 +994,32 @@ var SessionVault = class {
993
994
  knownPlaceholders: Object.keys(session.map).length
994
995
  };
995
996
  }
997
+ /**
998
+ * Picks the session that restores `text` when the caller named none.
999
+ * A candidate must know every placeholder in the text. When several do and
1000
+ * would restore it differently, the choice is ambiguous and refused, so a
1001
+ * missing session_id can never put another document's values into a file.
1002
+ */
1003
+ resolveSessionFor(text) {
1004
+ const tokens = [...new Set(text.match(EXISTING_TOKEN_RE) ?? [])];
1005
+ const candidates = [...this.sessions.values()].filter(
1006
+ (s) => tokens.every((token) => token in s.map)
1007
+ );
1008
+ if (candidates.length === 0) {
1009
+ throw new Error(
1010
+ 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."
1011
+ );
1012
+ }
1013
+ const restorations = new Set(candidates.map((s) => restore(text, s.map)));
1014
+ if (restorations.size > 1) {
1015
+ throw new Error(
1016
+ `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.`
1017
+ );
1018
+ }
1019
+ const latest = candidates[candidates.length - 1];
1020
+ if (!latest) throw new Error("No local session can restore this text.");
1021
+ return latest.id;
1022
+ }
996
1023
  getMap(sessionId) {
997
1024
  const session = this.sessions.get(sessionId.trim());
998
1025
  return session ? { ...session.map } : {};
@@ -1028,7 +1055,7 @@ var SessionVault = class {
1028
1055
 
1029
1056
  // src/server.ts
1030
1057
  var SERVER_NAME = "maskera-mcp";
1031
- var SERVER_VERSION = "0.4.0";
1058
+ var SERVER_VERSION = createRequire(import.meta.url)("../package.json").version;
1032
1059
  var SUPPORTED_PROTOCOLS = ["2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05"];
1033
1060
  var PLACEHOLDER_QUERY_RE = /^\[[A-ZÅÄÖ][A-ZÅÄÖ0-9_]*_\d+\]$/;
1034
1061
  var COUNTS_SCHEMA = {
@@ -1205,14 +1232,14 @@ var TOOLS = [
1205
1232
  },
1206
1233
  session_id: {
1207
1234
  type: "string",
1208
- description: "Session ID containing the local restore map."
1235
+ 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."
1209
1236
  },
1210
1237
  overwrite: {
1211
1238
  type: "boolean",
1212
1239
  description: "Allow overwriting an existing file. Default false."
1213
1240
  }
1214
1241
  },
1215
- required: ["path", "text", "session_id"]
1242
+ required: ["path", "text"]
1216
1243
  },
1217
1244
  outputSchema: {
1218
1245
  type: "object",
@@ -1775,10 +1802,7 @@ function createMaskeraMcpServer(options = {}) {
1775
1802
  if (name === "maskera_write_file") {
1776
1803
  if (typeof args.path !== "string") return finish(toolError("Missing required string: path"));
1777
1804
  if (typeof args.text !== "string") return finish(toolError("Missing required string: text"));
1778
- if (typeof args.session_id !== "string" || !args.session_id.trim()) {
1779
- return finish(toolError("Missing required non-empty string: session_id"));
1780
- }
1781
- const normalizedSessionId = args.session_id.trim();
1805
+ const normalizedSessionId = typeof args.session_id === "string" && args.session_id.trim() ? args.session_id.trim() : vault.resolveSessionFor(args.text);
1782
1806
  telemetrySessionId = normalizedSessionId;
1783
1807
  const { restored, knownPlaceholders } = vault.restore(args.text, {
1784
1808
  sessionId: normalizedSessionId