@maskera/mcp 0.4.3 → 0.4.5

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
@@ -54,6 +54,8 @@ type MaskMode = "auto" | "rules";
54
54
  interface ModelLoadEvent {
55
55
  phase: "loading" | "ready" | "error";
56
56
  model: string;
57
+ /** The quantization being loaded (`"q8"` on Node by default, `"q4"` for a local model path). */
58
+ dtype?: string;
57
59
  elapsedMs?: number;
58
60
  error?: string;
59
61
  }
@@ -118,12 +120,6 @@ declare function normalizeMixedScriptHomoglyphs(text: string): {
118
120
  */
119
121
  declare function buildCustomTermsDetector(rawTerms: readonly string[]): Detector | null;
120
122
  declare function createMaskeraEngine(options?: EngineOptions): MaskeraEngine;
121
- /**
122
- * Returns an `onModelStatus` handler that prints a concise progress line on
123
- * stderr only when model loading takes longer than `delayMs` (default 350ms),
124
- * keeping warm/cached runs quiet while reassuring users during the initial
125
- * 43 MB ONNX download.
126
- */
127
123
  declare function createModelProgressLogger(write?: (line: string) => void, delayMs?: number): (event: ModelLoadEvent) => void;
128
124
 
129
125
  type DoctorCheckStatus = "ok" | "warn" | "fail";
@@ -273,6 +269,8 @@ interface InspectedRequest {
273
269
  counts: Record<string, number>;
274
270
  /** Redacted snippets sent upstream (never raw PII). */
275
271
  redactedPreview: string[];
272
+ /** Optional non-PII upstream error summary when status >= 400. */
273
+ errorDetail?: string;
276
274
  /** Optional non-PII security warnings (e.g. uninspectable binary attachments). */
277
275
  warnings?: string[];
278
276
  }
@@ -502,13 +500,13 @@ declare class StreamingRestorer {
502
500
  flush(): string;
503
501
  private drain;
504
502
  }
505
- type RedactFieldKind = "message" | "system" | "tool_description";
503
+ type RedactFieldKind = "message" | "system" | "tool_description" | "reasoning";
506
504
  /**
507
- * Returns `true` when a `system` prompt block is clearly long English agent
508
- * boilerplate (e.g. Claude Code / Codex / OpenCode system instructions) with
509
- * zero Swedish characters or domain words. Those blocks still run deterministic
510
- * structured PII rules + `customTerms`, avoiding hundreds of false Swedish NER
511
- * hits on English keywords while keeping full NER on Swedish or short prompts.
505
+ * Returns `true` when a `system` prompt block is clearly English agent
506
+ * boilerplate (e.g. Claude Code / Codex / OpenCode system instructions,
507
+ * billing headers, or CLAUDE.md/MEMORY.md rules) rather than Swedish text.
508
+ * Multi-paragraph blocks return `true` only when every paragraph is English
509
+ * boilerplate, so mixed blocks split cleanly per paragraph.
512
510
  */
513
511
  declare function isLikelyEnglishSystemPrompt(text: string): boolean;
514
512
  /**
@@ -533,12 +531,15 @@ declare function redactLlmRequestBody(body: Record<string, unknown>, redactStrin
533
531
  */
534
532
  declare function restoreLlmResponseBody(body: unknown, map: Readonly<Record<string, string>>, options?: {
535
533
  mutate?: boolean;
534
+ reasoningExcludedTokens?: ReadonlySet<string>;
536
535
  }): unknown;
537
536
  /**
538
537
  * Transforms an SSE (`text/event-stream`) stream from Anthropic or OpenAI,
539
538
  * incrementally restoring Maskera placeholders even when split across chunks.
540
539
  */
541
- declare function createSseRestorer(map: Readonly<Record<string, string>>): {
540
+ declare function createSseRestorer(map: Readonly<Record<string, string>>, options?: {
541
+ reasoningExcludedTokens?: ReadonlySet<string>;
542
+ }): {
542
543
  push(chunk: string): string;
543
544
  flush(): string;
544
545
  };
@@ -667,7 +668,7 @@ declare const MASKERA_STATUS_URI = "maskera://status";
667
668
  * prompts so connected clients get the full operating guide without a separate
668
669
  * skill install step. Kept in sync with `skills/maskera/SKILL.md` by unit test.
669
670
  */
670
- declare const MASKERA_SKILL_MARKDOWN = "---\nname: maskera\ndescription: Redact Swedish personal data (names, personnummer, addresses, phones, emails, IBAN, org numbers) locally before text or files reach an AI model, and restore answers locally. Use when working with Swedish client files, HR/CVs, legal or municipal cases, healthcare notes, support transcripts, or when setting up @maskera/mcp (local LLM proxy, Streamable HTTP or stdio MCP server, guard) or the maskera npm SDK.\n---\n\n# Maskera: local Swedish PII redaction\n\nMaskera runs 100% locally on-device using deterministic Swedish rules plus the 43 MB Swedish ONNX NER model (`joelhagvall/maskera-sv-ner`). Raw PII and restore maps stay local so cloud LLMs only see placeholders such as `[NAMN_1]` and `[PERSONNUMMER_1]`.\n\n## Choose the right mode\n\nPick by where the text comes from: **proxy for text typed straight into the chat**, **MCP for files the agent reads with the Maskera tools**. Before the user sends real personal data, verify the setup with made-up data (a fictional address) and confirm a placeholder in the local inspector at `http://127.0.0.1:8787/_maskera`, or run `npx -y @maskera/mcp doctor`.\n\n1. **Local LLM proxy + warm Streamable HTTP MCP (`maskera-mcp wrap` / `proxy` / `service`):**\n Use when no prompt, history or tool output may leave the machine unredacted, or when multiple clients should share one warm ONNX model and session vault.\n ```bash\n # Single-command launch (starts local proxy, verifies 0 leaks, injects env vars, prints session receipt on exit):\n npx -y @maskera/mcp wrap -- claude\n # Or run a persistent local proxy (+ Streamable HTTP /mcp + live inspector with self-test button):\n npx -y @maskera/mcp proxy --root /path/to/workspace --open\n # Or install as a background service (launchd on macOS, systemd --user on Linux):\n npx -y @maskera/mcp service install --root /path/to/workspace --no-raw-restore\n # Point any harness or SDK at the loopback proxy:\n ANTHROPIC_BASE_URL=http://127.0.0.1:8787 claude\n OPENAI_BASE_URL=http://127.0.0.1:8787/v1 codex # API key mode; ChatGPT-login Codex requires HTTPS so use MCP below\n # Same warm process also serves Streamable HTTP MCP:\n # http://127.0.0.1:8787/mcp (supports ?no_raw_restore=1&read_only=1&approval_mode=browser)\n ```\n - Claude Desktop: Help -> Troubleshooting -> Enable Developer Mode, then Developer -> Configure Third-Party Inference. Set Inference provider to **Gateway**, Credential kind **Static API key**, Gateway base URL `http://127.0.0.1:8787` (no `/v1`), Gateway API key = the user's Anthropic API key, Gateway auth scheme **x-api-key**. Apply Changes, then Save & Restart. Full guide: `https://maskera.dev/docs/guides`.\n - Routes Anthropic (`/v1/messages`) and OpenAI (`/v1/chat/completions`, `/v1/responses`) automatically, or set `--upstream <url>`.\n - Restores placeholders transparently in JSON, tool arguments and chunk-split SSE streams.\n - Fails closed (`502`) if local redaction fails. Inspect counts only at `http://127.0.0.1:8787/_maskera/status`.\n\n2. **Working with sensitive local Swedish files (MCP stdio or Streamable HTTP):**\n Auto-detect or install automatically with `npx -y @maskera/mcp install [client|all]` (`claude-code`, `claude-desktop`, `codex`, `cursor`, `opencode`, `t3-code`; pass `--apply` to run `claude`/`codex mcp add`, `--with-hook` to install a `guard` hook). It verifies local Swedish PII masking (and any running `/mcp` server) automatically and prints a zero-PII setup receipt (`--receipt <file.json>` to save it, `--no-verify` to skip). Or configure manually:\n - Claude Code / Cursor (`mcpServers`):\n ```json\n {\n \"mcpServers\": {\n \"maskera\": {\n \"command\": \"npx\",\n \"args\": [\"-y\", \"@maskera/mcp\", \"--root\", \"/path/to/workspace\", \"--no-raw-restore\"]\n }\n }\n }\n ```\n - Codex CLI:\n ```bash\n codex mcp add maskera -- npx -y @maskera/mcp --root /path/to/workspace --no-raw-restore\n ```\n - OpenCode v2:\n ```bash\n opencode mcp add maskera -- npx -y @maskera/mcp --root /path/to/workspace --no-raw-restore\n ```\n Workflow rules when the Maskera MCP tools are available:\n - List and search sensitive Swedish directories with `maskera_list_files` and `maskera_search_files` instead of raw `grep`/`rg` so matched lines are redacted before entering context.\n - Read sensitive Swedish files with `maskera_read_file` instead of raw file-reading tools. Reuse one `session_id` across related files so `[NAMN_1]` stays consistent.\n - Pass `custom_terms` for client codenames, project names or case references not covered by built-in rules.\n - Pass `profile: \"clinical\"` for Swedish medical or care notes so diagnoses, doses and measurements stay intact while personal data is masked.\n - Write finished drafts directly to disk with `maskera_write_file` so placeholders are restored locally without echoing raw PII back into the conversation.\n - Use `--no-raw-restore` (or `--approval-mode browser`) when the agent should never pull raw PII back into chat via `maskera_restore` or `include_map: true`.\n - Clear the in-memory restore map with `maskera_clear_session` once the task is done.\n\n3. **Hooks and Unix pipes (guard):**\n ```bash\n # Block prompts or JSON hook payloads containing PII (exits 2, prints counts only):\n npx -y @maskera/mcp guard\n # Redact text locally in a pipeline:\n cat input.txt | npx -y @maskera/mcp guard --redact\n ```\n\n4. **Embedding in application code (browser or Node 18+):**\n ```bash\n npm install maskera @huggingface/transformers\n ```\n Reuse one `createNerRecognizer()` instance across calls and run `await redactWithNer(text, { recognizer })` (or `redact(text)` from `@maskera/core` for zero-dependency structured rules only).\n\n## Boundaries\n\n- A skill guides agent behaviour; for hard enforcement that cannot be bypassed by raw shell or file tools, use `maskera-mcp proxy` or restrict file access to `maskera-mcp` with `--no-raw-restore`.\n- Automated masking reduces exposure risk but is not a zero-leak guarantee. Never log restore maps or write them next to redacted outputs.\n- Reference docs and machine-readable details: `https://maskera.dev/docs` and `https://maskera.dev/llms.txt`.\n";
671
+ declare const MASKERA_SKILL_MARKDOWN = "---\nname: maskera\ndescription: Redact Swedish personal data (names, personnummer, addresses, phones, emails, IBAN, org numbers) locally before text or files reach an AI model, and restore answers locally. Use when working with Swedish client files, HR/CVs, legal or municipal cases, healthcare notes, support transcripts, or when setting up @maskera/mcp (local LLM proxy, Streamable HTTP or stdio MCP server, guard) or the maskera npm SDK.\n---\n\n# Maskera: local Swedish PII redaction\n\nMaskera runs 100% locally on-device using deterministic Swedish rules plus the Swedish ONNX NER model (`joelhagvall/maskera-sv-ner`). Raw PII and restore maps stay local so cloud LLMs only see placeholders such as `[NAMN_1]` and `[PERSONNUMMER_1]`.\n\n## Choose the right mode\n\nPick by where the text comes from: **proxy for text typed straight into the chat**, **MCP for files the agent reads with the Maskera tools**. Before the user sends real personal data, verify the setup with made-up data (a fictional address) and confirm a placeholder in the local inspector at `http://127.0.0.1:8787/_maskera`, or run `npx -y @maskera/mcp doctor`.\n\n1. **Local LLM proxy + warm Streamable HTTP MCP (`maskera-mcp wrap` / `proxy` / `service`):**\n Use when no prompt, history or tool output may leave the machine unredacted, or when multiple clients should share one warm ONNX model and session vault.\n ```bash\n # Single-command launch (starts local proxy, verifies 0 leaks, injects env vars, prints session receipt on exit):\n npx -y @maskera/mcp wrap -- claude\n # Or run a persistent local proxy (+ Streamable HTTP /mcp + live inspector with self-test button):\n npx -y @maskera/mcp proxy --root /path/to/workspace --open\n # Or install as a background service (launchd on macOS, systemd --user on Linux):\n npx -y @maskera/mcp service install --root /path/to/workspace --no-raw-restore\n # Point any harness or SDK at the loopback proxy:\n ANTHROPIC_BASE_URL=http://127.0.0.1:8787 claude\n OPENAI_BASE_URL=http://127.0.0.1:8787/v1 codex # API key mode; ChatGPT-login Codex requires HTTPS so use MCP below\n # Same warm process also serves Streamable HTTP MCP:\n # http://127.0.0.1:8787/mcp (supports ?no_raw_restore=1&read_only=1&approval_mode=browser)\n ```\n - Claude Desktop: Help -> Troubleshooting -> Enable Developer Mode, then Developer -> Configure Third-Party Inference. Set Inference provider to **Gateway**, Credential kind **Static API key**, Gateway base URL `http://127.0.0.1:8787` (no `/v1`), Gateway API key = the user's Anthropic API key, Gateway auth scheme **x-api-key**. Apply Changes, then Save & Restart. Full guide: `https://maskera.dev/en/docs/clients#claude-desktop`.\n - Routes Anthropic (`/v1/messages`) and OpenAI (`/v1/chat/completions`, `/v1/responses`) automatically, or set `--upstream <url>`.\n - Restores placeholders transparently in JSON, tool arguments and chunk-split SSE streams.\n - Fails closed (`502`) if local redaction fails. Inspect counts only at `http://127.0.0.1:8787/_maskera/status`.\n\n2. **Working with sensitive local Swedish files (MCP stdio or Streamable HTTP):**\n Auto-detect or install automatically with `npx -y @maskera/mcp install [client|all]` (`claude-code`, `claude-desktop`, `codex`, `cursor`, `opencode`, `t3-code`; pass `--apply` to run `claude`/`codex mcp add`, `--with-hook` to install a `guard` hook). It verifies local Swedish PII masking (and any running `/mcp` server) automatically and prints a zero-PII setup receipt (`--receipt <file.json>` to save it, `--no-verify` to skip). Or configure manually:\n - Claude Code / Cursor (`mcpServers`):\n ```json\n {\n \"mcpServers\": {\n \"maskera\": {\n \"command\": \"npx\",\n \"args\": [\"-y\", \"@maskera/mcp\", \"--root\", \"/path/to/workspace\", \"--no-raw-restore\"]\n }\n }\n }\n ```\n - Codex CLI:\n ```bash\n codex mcp add maskera -- npx -y @maskera/mcp --root /path/to/workspace --no-raw-restore\n ```\n - OpenCode v2:\n ```bash\n opencode mcp add maskera -- npx -y @maskera/mcp --root /path/to/workspace --no-raw-restore\n ```\n Workflow rules when the Maskera MCP tools are available:\n - List and search sensitive Swedish directories with `maskera_list_files` and `maskera_search_files` instead of raw `grep`/`rg` so matched lines are redacted before entering context.\n - Read sensitive Swedish files with `maskera_read_file` instead of raw file-reading tools. Reuse one `session_id` across related files so `[NAMN_1]` stays consistent.\n - Pass `custom_terms` for client codenames, project names or case references not covered by built-in rules.\n - Pass `profile: \"clinical\"` for Swedish medical or care notes so diagnoses, doses and measurements stay intact while personal data is masked.\n - Write finished drafts directly to disk with `maskera_write_file` so placeholders are restored locally without echoing raw PII back into the conversation.\n - Use `--no-raw-restore` (or `--approval-mode browser`) when the agent should never pull raw PII back into chat via `maskera_restore` or `include_map: true`.\n - Clear the in-memory restore map with `maskera_clear_session` once the task is done.\n\n3. **Hooks and Unix pipes (guard):**\n ```bash\n # Block prompts or JSON hook payloads containing PII (exits 2, prints counts only):\n npx -y @maskera/mcp guard\n # Redact text locally in a pipeline:\n cat input.txt | npx -y @maskera/mcp guard --redact\n ```\n\n4. **Embedding in application code (browser or Node 18+):**\n ```bash\n npm install maskera @huggingface/transformers\n ```\n Reuse one `createNerRecognizer()` instance across calls and run `await redactWithNer(text, { recognizer })` (or `redact(text)` from `@maskera/core` for zero-dependency structured rules only).\n\n## Boundaries\n\n- A skill guides agent behaviour; for hard enforcement that cannot be bypassed by raw shell or file tools, use `maskera-mcp proxy` or restrict file access to `maskera-mcp` with `--no-raw-restore`.\n- Automated masking reduces exposure risk but is not a zero-leak guarantee. Never log restore maps or write them next to redacted outputs.\n- Reference docs and machine-readable details: `https://maskera.dev/docs` and `https://maskera.dev/llms.txt`.\n";
671
672
  interface McpPromptDefinition {
672
673
  name: string;
673
674
  description: string;