Skip to main content
Glama
maskera-mcp

maskera-mcp

by joelhagvall
README.md
<img src="logo.svg" alt="maskera" width="56" align="left" />

# maskera

> **Pasting Swedish customer, patient, or employee text into an LLM leaks personal data, and generic PII tools miss Swedish personnummer, addresses, and lowercase names.** Maskera masks them locally on your device before text leaves, then restores the original values in the reply.

- **On-device, zero telemetry:** text, model weights, and restore maps stay in your browser or Node process.
- **Rules + 68 MB Swedish AI model:** catches personnummer, bankgiro, IBAN, phone numbers, plus free-text names (97% recall, 92.8% lowercase), places (97.3%), and addresses (95.2%).
- **Reversible placeholders:** swaps PII for stable tokens like `[NAMN_1]` and restores them in the model's answer.
- **Three ways to run:** TypeScript/JS packages (`maskera`, `@maskera/core`), local MCP server & HTTP proxy (`@maskera/mcp` with PDF, DOCX, and XLSX redaction), and Chrome/Edge/Firefox extension.
- **Tunable for real workflows:** opt into `profile: "clinical"` for medical text or extend with custom `regexDetector` rules.

<a href="https://maskera.dev"><img src="docs/demo.png" alt="maskera demo: Swedish text with highlighted PII on the left, and the same text with placeholders such as [NAMN_1] on the right" width="100%"></a>

```bash
npm install maskera @huggingface/transformers   # all-in-one: rules + Swedish AI model
```

```ts
import { createNerRecognizer, redactWithNer } from "maskera"

const recognizer = createNerRecognizer() // 68 MB Swedish model, runs locally
const { text, restore } = await redactWithNer(
  "hej jag heter provnamn maskera, personnummer 19900101-2385, och bor i provbyn",
  { recognizer },
)
// text -> "hej jag heter [NAMN_1], personnummer [PERSONNUMMER_1], och bor i [PLATS_1]"
```

Rules only, zero dependencies: `npm install @maskera/core`. **[Live demo: maskera.dev](https://maskera.dev)**

## Three ways to use it

- **Open-source npm packages (MIT):** `@maskera/core` and `maskera` for browser and Node.js apps.
- **AI agents, MCP & CLI ([`@maskera/mcp`](packages/mcp)):** local MCP server, HTTP proxy, and CLI for Claude Code, Codex, OpenCode, and Claude Desktop, including local PDF, DOCX, and XLSX redaction.
- **Browser extension ([maskera.dev/tjanster](https://maskera.dev/tjanster) / [English](https://maskera.dev/en/services)):** masks locally inside ChatGPT, Claude, Gemini, Microsoft Copilot, Perplexity, Mistral and opt-in internal AI sites on Chrome, Edge and Firefox. Free tier included; paid plans via [app.maskera.dev](https://app.maskera.dev).

## Two layers, rules first

<img src="docs/layers.svg" alt="The two-layer design: input text forks into layer 1, deterministic format-aware rules for structured PII like personnummer, and layer 2, a 68 MB Swedish AI model that catches free text like names. Rules win on overlap, and the merged result is the masked output. The restore key stays on your device." width="100%">

1. **`@maskera/core`**: deterministic detectors for structured Swedish PII (personnummer, samordningsnummer, organisationsnummer, phone, email, postnummer, bankgiro, plusgiro, IBAN, cards, IP, URL). Zero dependencies, synchronous, extensible via `regexDetector`.
2. **`maskera`**: everything in core plus [`maskera-sv-ner`](https://huggingface.co/joelhagvall/maskera-sv-ner) (68 MB q4 ONNX). Catches free-text names, places, organisations and street addresses, including all-lowercase chat text and ALL CAPS.

### Use before an LLM call

```ts
const { text: safePrompt, restore } = await redactWithNer(userInput, { recognizer })
const answer = await llm(safePrompt)
const result = restore(answer)
```

Placeholders are stable within a call. For clinical text, pass `profile: "clinical"` to retain common measurements, doses and care terms. Runnable example: [`examples/llm-roundtrip.ts`](examples/llm-roundtrip.ts).

## Benchmarks

Share of values hidden across four public Swedish corpora (measured 2026-11-30): the SUC 3.0 test split (National Library of Sweden), SIC2 Swedish blogs (Språkbanken Text), the MultiCoNER v2 Swedish test split (persons) and the Swedish rows of ai4privacy openpii. Raw results: [`docs/benchmark-independent-v24.json`](docs/benchmark-independent-v24.json).

| System | Names | Lowercase names | Places | Addresses + postcodes | Entity-free sentences with a hit (lower is better) |
| --- | --- | --- | --- | --- | --- |
| **Maskera v24 q4 (68 MB)** | **97%** | **92.8%** | 97.3% | **95.2%** | 4.4% |
| Microsoft Presidio + sv spaCy | 72.3% | 71.4% | 97.1% | 47.0% | **2.5%** |
| swedish-pii 1.2.0 | 55.3% | 0.3% | 82.7% | 77.3% | 7.0% |
| OpenAI Privacy Filter q4 | 52.2% | 10.3% | 33.5% | 63.3% | 3.5% |

Presidio's spaCy model is trained on SUC 3.0, one of the tests. Personnummer, bankgiro and IBAN have no independent Swedish corpus and are not in this table.

Full report and internal release gates: **[docs/BENCHMARKS.md](docs/BENCHMARKS.md)**.

## Packages & docs

| Package / doc | Purpose |
| --- | --- |
| [`@maskera/core`](packages/core) | Zero-dep detectors + redact/restore engine |
| [`maskera`](packages/ner) | Swedish NER model + hybrid pipeline (`@maskera/core` re-exported) |
| [`@maskera/mcp`](packages/mcp) | Local MCP server, HTTP proxy, CLI, and PDF/DOCX/XLSX redaction |
| [`docs/PRODUCTION.md`](docs/PRODUCTION.md) | Self-hosting the model, thresholds, fallback and operational checklist |
| [`docs/TRANSPARENCY.md`](docs/TRANSPARENCY.md) | Privacy boundary and what runs where |
| [`docs/TRAINING_DATA_PROTECTION.md`](docs/TRAINING_DATA_PROTECTION.md) | Synthetic attestation, identifier rejection, KB-BERT boundary |
| **[maskera.dev/whitepaper.pdf](https://maskera.dev/whitepaper.pdf)** | Architecture, privacy model, measurements and GDPR positioning for DPOs/legal |

maskera is **defense in depth, not a compliance guarantee**. The model catches most free-text PII, but can miss edge cases.

## Development

```bash
pnpm install
pnpm demo                  # live demo at http://localhost:5180
pnpm build && pnpm test
pnpm lint                  # biome + benchmark/privacy checks
pnpm smoke                 # pack tarballs, install fresh, test ESM+CJS
pnpm eval                  # grade published model against gold corpus
pnpm eval:domain           # hybrid pipeline on 258-text synthetic domain corpus
pnpm eval:domain:clinical  # same corpus with clinical precision profile
```

Roadmap: [`docs/ROADMAP.md`](docs/ROADMAP.md).

## License

Code: MIT © [Joel Hägvall](https://joelhagvall.com). Model weights: MIT (base model KB-BERT is CC0, National Library of Sweden). See [`packages/ner/NOTICE`](packages/ner/NOTICE).

Maskera is developed and maintained by [Hägvall Labs AB](https://hagvall-labs.com) (Stockholm, Sweden, reg. no. 559598-0110).