@maskera/mcp 0.4.3 → 0.4.4

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
@@ -273,6 +273,8 @@ interface InspectedRequest {
273
273
  counts: Record<string, number>;
274
274
  /** Redacted snippets sent upstream (never raw PII). */
275
275
  redactedPreview: string[];
276
+ /** Optional non-PII upstream error summary when status >= 400. */
277
+ errorDetail?: string;
276
278
  /** Optional non-PII security warnings (e.g. uninspectable binary attachments). */
277
279
  warnings?: string[];
278
280
  }
@@ -502,13 +504,13 @@ declare class StreamingRestorer {
502
504
  flush(): string;
503
505
  private drain;
504
506
  }
505
- type RedactFieldKind = "message" | "system" | "tool_description";
507
+ type RedactFieldKind = "message" | "system" | "tool_description" | "reasoning";
506
508
  /**
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.
509
+ * Returns `true` when a `system` prompt block is clearly English agent
510
+ * boilerplate (e.g. Claude Code / Codex / OpenCode system instructions,
511
+ * billing headers, or CLAUDE.md/MEMORY.md rules) rather than Swedish text.
512
+ * Multi-paragraph blocks return `true` only when every paragraph is English
513
+ * boilerplate, so mixed blocks split cleanly per paragraph.
512
514
  */
513
515
  declare function isLikelyEnglishSystemPrompt(text: string): boolean;
514
516
  /**
@@ -533,12 +535,15 @@ declare function redactLlmRequestBody(body: Record<string, unknown>, redactStrin
533
535
  */
534
536
  declare function restoreLlmResponseBody(body: unknown, map: Readonly<Record<string, string>>, options?: {
535
537
  mutate?: boolean;
538
+ reasoningExcludedTokens?: ReadonlySet<string>;
536
539
  }): unknown;
537
540
  /**
538
541
  * Transforms an SSE (`text/event-stream`) stream from Anthropic or OpenAI,
539
542
  * incrementally restoring Maskera placeholders even when split across chunks.
540
543
  */
541
- declare function createSseRestorer(map: Readonly<Record<string, string>>): {
544
+ declare function createSseRestorer(map: Readonly<Record<string, string>>, options?: {
545
+ reasoningExcludedTokens?: ReadonlySet<string>;
546
+ }): {
542
547
  push(chunk: string): string;
543
548
  flush(): string;
544
549
  };
@@ -667,7 +672,7 @@ declare const MASKERA_STATUS_URI = "maskera://status";
667
672
  * prompts so connected clients get the full operating guide without a separate
668
673
  * skill install step. Kept in sync with `skills/maskera/SKILL.md` by unit test.
669
674
  */
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";
675
+ 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/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
676
  interface McpPromptDefinition {
672
677
  name: string;
673
678
  description: string;