@maskera/mcp 0.4.4 → 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/README.md +1 -1
- package/dist/cli.js +9 -4
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +3 -7
- package/dist/index.js +9 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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";
|
|
@@ -672,7 +668,7 @@ declare const MASKERA_STATUS_URI = "maskera://status";
|
|
|
672
668
|
* prompts so connected clients get the full operating guide without a separate
|
|
673
669
|
* skill install step. Kept in sync with `skills/maskera/SKILL.md` by unit test.
|
|
674
670
|
*/
|
|
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
|
|
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";
|
|
676
672
|
interface McpPromptDefinition {
|
|
677
673
|
name: string;
|
|
678
674
|
description: string;
|
package/dist/index.js
CHANGED
|
@@ -310,7 +310,7 @@ function createMaskeraEngine(options = {}) {
|
|
|
310
310
|
if (!recognizer) {
|
|
311
311
|
const dtype = options.nerOptions?.dtype ?? (options.nerOptions?.localModelPath ? "q4" : "q8");
|
|
312
312
|
const loadStartedAt = Date.now();
|
|
313
|
-
options.onModelStatus?.({ phase: "loading", model });
|
|
313
|
+
options.onModelStatus?.({ phase: "loading", model, dtype });
|
|
314
314
|
recognizer = createNerRecognizer({
|
|
315
315
|
...options.nerOptions,
|
|
316
316
|
model,
|
|
@@ -521,6 +521,11 @@ function createMaskeraEngine(options = {}) {
|
|
|
521
521
|
}
|
|
522
522
|
};
|
|
523
523
|
}
|
|
524
|
+
var MODEL_DOWNLOAD_MB = { q4: 43, q8: 59 };
|
|
525
|
+
function downloadSize(dtype) {
|
|
526
|
+
const mb = dtype ? MODEL_DOWNLOAD_MB[dtype] : void 0;
|
|
527
|
+
return mb ? `, ~${mb} MB on first run` : "";
|
|
528
|
+
}
|
|
524
529
|
function createModelProgressLogger(write = (line) => process.stderr.write(`${line}
|
|
525
530
|
`), delayMs = 350) {
|
|
526
531
|
let timer = null;
|
|
@@ -532,7 +537,7 @@ function createModelProgressLogger(write = (line) => process.stderr.write(`${lin
|
|
|
532
537
|
timer = setTimeout(() => {
|
|
533
538
|
announcedLoading = true;
|
|
534
539
|
write(
|
|
535
|
-
`[maskera] Loading Swedish ONNX model (${event.model},
|
|
540
|
+
`[maskera] Loading Swedish ONNX model (${event.model}${downloadSize(event.dtype)}, cached locally)...`
|
|
536
541
|
);
|
|
537
542
|
}, delayMs);
|
|
538
543
|
timer.unref?.();
|
|
@@ -874,7 +879,7 @@ description: Redact Swedish personal data (names, personnummer, addresses, phone
|
|
|
874
879
|
|
|
875
880
|
# Maskera: local Swedish PII redaction
|
|
876
881
|
|
|
877
|
-
Maskera runs 100% locally on-device using deterministic Swedish rules plus the
|
|
882
|
+
Maskera 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]\`.
|
|
878
883
|
|
|
879
884
|
## Choose the right mode
|
|
880
885
|
|
|
@@ -1282,7 +1287,7 @@ var COUNTS_SCHEMA = {
|
|
|
1282
1287
|
var TOOLS = [
|
|
1283
1288
|
{
|
|
1284
1289
|
name: "maskera_redact",
|
|
1285
|
-
description: "Redact Swedish PII (names, personnummer, addresses, emails, phones, IBAN, etc.) locally on-device using Maskera's
|
|
1290
|
+
description: "Redact Swedish PII (names, personnummer, addresses, emails, phones, IBAN, etc.) locally on-device using Maskera's Swedish NER model and deterministic rules. Stores the restore map locally under session_id so placeholders stay consistent across calls and can be restored later without exposing raw PII to the LLM.",
|
|
1286
1291
|
annotations: {
|
|
1287
1292
|
title: "Redact Swedish PII locally",
|
|
1288
1293
|
readOnlyHint: true,
|