๐ก๏ธ PII Shield Anonymize documents before Claude sees them. Restore real data after analysis.
๊ฐ์
๐ก๏ธ PII Shield Anonymize documents before Claude sees them. Restore real data after analysis.
README
๐ก๏ธ PII Shield
Anonymize documents before Claude sees them. Restore real data after analysis.
PII Shield reads your documents locally, replaces all personal data with placeholders (, , etc.), and โ when you want analysis โ sends only the anonymized text to an LLM. After analysis, PII Shield restores the original data into the final document โ entirely on your machine. PII never enters the API.
Document โโ> [PII Shield on your machine] โโ> anonymized text โโ> [LLM analyzes] โโ> [PII Shield restores] โโ> Result
John Smith โ โ John Smith
Acme Corp. โ โ Acme Corp.
Two ways to use it, sharing the same engine:
| Form | Who itโs for | Install |
|---|---|---|
Standalone CLI (pii-shield) |
Anyone โ anonymize files locally for any LLM (or just for compliance / GDPR). Pure offline. | npm install -g pii-shield |
Claude Desktop / Code extension (.mcpb + .skill) |
Claude Desktop and Claude Code users โ get tools + skill + in-chat HITL panel. | Drag the .mcpb from a release into Settings โ Extensions, then upload the .skill |
v2 is a complete Node.js rewrite. The original Python product is still available โ see What happened to v1? below.
Features
| Feature | Details | |
|---|---|---|
| ๐ | Zero PII in API | anonymize_file reads the document on your machine and returns only a file path + session id. Claude reads the anonymized file from disk โ PII never enters an API request. |
| ๐ง | GLiNER zero-shot NER | knowledgator/gliner-pii-base-v1.0 over onnxruntime-node + @xenova/transformers (pinned triplet 1.22.0, deterministic npm ci). Handles ALL-CAPS, domain-specific names, multilingual text. No Python, no PyTorch. |
| ๐ค | Human-in-the-Loop review | MCP Apps iframe UI rendered directly in Claude Desktop. Remove false positives, add missed entities โ all occurrences updated automatically, no localhost browser detour. |
| ๐ | PDF + DOCX + plain text | .pdf, .docx (formatting + tracked changes preserved), .txt, .md, .csv. Pure-JS .docx pipeline โ reads, edits, restores without a Word / LibreOffice install. |
| ๐ช๐บ | EU + UK pattern recognizers | UK (NIN, NHS, passport, CRN, driving licence), DE (tax ID, social security), FR (NIR, CNI), IT (fiscal code, VAT), ES (DNI, NIE), CY (TIC, ID card), FI (henkilรถtunnus, Y-tunnus), EU-wide (VAT, passport) โ on top of the generic pack (email, phone, IBAN, credit card, crypto, US IDs, medical licence). 35 entity types in total. |
| ๐ | Entity deduplication | โAcmeโ โ , "Acme Corp." โ , โAcme Corporationโ โ ``. Canonical form picked once; every variant maps back to the same real value on deanonymize. |
| ๐พ | Cross-session deanonymize | Each anonymized .docx carries its session_id in Word custom properties. Weeks later, in a brand new chat, drop the file in and deanonymize_docx restores PII from the embedded id โ nothing to remember. |
| ๐ฆ | Multi-file sessions | Anonymize N related documents under one session_id; identical entities share the same placeholder across files. One deanonymize_text / deanonymize_docx call restores PII everywhere. |
| ๐ค | Team handoff | export_session(passphrase) packs the mapping + anonymized documents into an encrypted .pii-session archive (AES-GCM via scrypt). Colleague runs import_session with the passphrase โ PII never transits. |
| ๐ | Audit logging | Every tool call + response logged locally to ~/.pii_shield/audit/mcp_audit.log. NER bootstrap trace, session lifecycle, dropped stderr โ all on disk, appendable, off-network. |
Standalone CLI โ pii-shield
If you donโt use Claude Desktop / Claude Code, install the CLI globally and run it on any file. Works on 20โ30 documents in one session with shared placeholders across files.
npm install -g pii-shield
pii-shield doctor # health check
pii-shield install-model # download GLiNER (~634 MB, one-off)
# anonymize one file
pii-shield anonymize contract.pdf --no-review
# anonymize a batch โ same session_id, same placeholders for shared entities
pii-shield anonymize contracts/*.pdf attachments/*.docx
# review opens a browser (localhost:6789) with the bulk-mode panel
pii-shield review 2026-04-29_101617_9f40
# restore PII back when you're done
pii-shield deanonymize contract_anonymized.pdf --session 2026-04-29_101617_9f40
| Command | What it does |
|---|---|
pii-shield anonymize |
Anonymize one or many files in one session. Shared placeholders across files. |
pii-shield deanonymize |
Restore PII. Session id read from .docx metadata, --session, or latest. |
pii-shield scan [--json] |
Preview detected entities without writing anything. |
pii-shield review |
Re-open the HITL review panel for a session. |
pii-shield sessions list / show / export / import |
Inspect and hand off sessions across machines. |
pii-shield install-model [--yes] |
Download/extract the GLiNER ONNX model. |
pii-shield doctor [--json] |
Check Node, deps, model, paths. |
The CLI uses the same engine, mappings, and audit log as the MCP variants. Sessions are interchangeable: anonymize on the CLI, deanonymize from Claude Desktop, or vice versa โ the mapping store is shared (~/.pii_shield/mappings/). Requires Node 22+.
Claude Desktop / Claude Code
Prerequisites
- Claude Desktop (any recent version)
- Windows or Linux: Claude Desktop ships a compatible Node runtime. Nothing to install separately.
- macOS: the macOS
.mcpbbelow bundles its own Node 24.15.0. Nothing to install separately.
No terminal commands. No model download upfront. PII Shield handles model install in-chat via a panel that appears the first time you anonymize.
Step 1 โ download the artefacts
Pick the .mcpb for your OS plus the skill bundle:
| File | What | OS |
|---|---|---|
pii-shield-v2.2.0-windows-linux.mcpb |
~700 KB โ uses host Node | Windows / Linux |
pii-shield-v2.2.0-macos.mcpb |
~83 MB โ bundles Node 24.15.0 | macOS (arm64 + x64) |
pii-contract-analyze.skill |
~25 KB โ contract analysis skill | any |
Step 2 โ install the MCP extension
Claude Desktop โ Settings โ Extensions โ Advanced Settings โ Install extension โ select your .mcpb.
On the first tool call PII Shield runs npm ci --ignore-scripts to install a pinned, deterministic set of runtime deps (onnxruntime-node, @xenova/transformers, gliner) into ~/.pii_shield/deps/installs//. 2โ3 minutes once per machine, instant thereafter.
Step 3 โ upload the skill
Claude Desktop โ Customize โ Skills โ + โ Upload a skill โ select pii-contract-analyze.skill.
The skill orchestrates the end-to-end contract anonymization + analysis flow โ Claude uses it to drive anonymize_file โ HITL review โ analysis โ deanonymize_docx without you spelling out each step.
Step 4 โ use it
- Start a new conversation in Claude Desktop
- Select the pii-contract-analyze skill
- Connect a folder containing your document (click the folder icon)
- Tell Claude what you need:
Analyze risks for the purchaser in contract.pdf and prepare a short memo
First-run install panel
The very first time you ask Claude to anonymize anything, PII Shield notices the NER model isnโt on disk yet and opens an in-chat install panel. You see two buttons:
- Download model โ opens your default browser, downloads
gliner-pii-base-v1.0.zip(~634 MB) from the release. Browser handles the transfer (no Defender / SmartScreen issues with unsigned scripts). - Install downloaded ZIP โ PII Shield finds the ZIP in your Downloads / OneDrive / Desktop / Documents folder, validates it, atomic-extracts it into
~/.pii_shield/models/, and re-initializes NER. Anonymization continues automatically.
No terminal, no scripts. Subsequent runs skip the panel entirely.
โ ๏ธ Do NOT attach files directly to anonymize. When you attach a file, Claude Desktop sends its content in the API request โ Claude sees raw data before PII Shield can process it. Connect a folder instead โ Claude only gets the file path and calls
anonymize_filelocally.
Privacy architecture
Only file paths and random session IDs flow through the API. All anonymization and restoration happens locally.
| Stage | What happens | PII in API? |
|---|---|---|
| Anonymize | Server reads file on host, writes anonymized text to disk, returns output_path |
โ |
| Claude reads | Claude reads anonymized .txt โ only sees placeholders |
โ |
| Review | User reviews entities in MCP Apps iframe (rendered in Claude Desktop) | โ |
| Re-anonymize | Server applies user corrections internally | โ |
| Deanonymize | Server writes restored file to disk, returns only the path | โ |
| Deliver | Claude gives user the file path. Never reads the restored file. | โ |
Human-in-the-Loop review
After anonymization, Claude offers a review step rendered directly in Claude Desktop via MCP Apps:
- Claude calls
start_reviewโ Claude Desktop opens a panel inside the conversation - Full document with color-coded entity highlights
- Remove false positives โ click any entity (all occurrences removed)
- Add missed entities โ select text, choose type (all occurrences added)
- Approve โ Claude calls
apply_review_overrides, the server re-anonymizes with your corrections
No localhost web server, no browser detours โ the UI is a Vite single-file iframe served to Claude Desktop as a ui:// MCP resource.
Cross-session deanonymize
Every anonymized .docx PII Shield writes carries its session_id inside Word custom document properties (docProps/custom.xml). Later, in a brand new chat, you can:
- Drop the anonymized
.docxinto a connected folder โ no need to remember the session id, no screenshots of placeholders, nothing. - Ask Claude to โrestore PII in this file.โ
- PII Shieldโs
deanonymize_docxreads the embeddedsession_id, looks up the mapping in~/.pii_shield/mappings/, and writes the restored file next to the input.
Mappings live at ~/.pii_shield/mappings/ โ same root as models/, deps/, and audit/. The root survives plugin upgrades and /plugin remove because itโs in the userโs home dir, not Claude Desktopโs per-plugin CLAUDE_PLUGIN_DATA (which isnโt set for MCPB plugins anyway).
Time-based TTL is controlled by PII_MAPPING_TTL_DAYS (default: 7 days) โ the server cleans up mappings older than that on startup. Bump it for longer-lived matters (PII_MAPPING_TTL_DAYS=90, etc.) via Claude Desktop โ Extensions โ PII Shield โ Settings. If a mapping is missing when you try to deanonymize, deanonymize_docx returns a clean error with a hint to import_session (see Team handoff below) rather than silently skipping entities.
Plain .txt / .md output has no place to embed metadata, so the deanonymize_text tool takes the session_id explicitly as an argument.
Multi-file sessions
Anonymize several related documents under one session_id:
- First call:
anonymize_file(path_A)โ server returnssession_id=SID123. - Second call:
anonymize_file(path_B, session_id="SID123")โ PII Shield extends the same mapping. Identical entities across the two files share the same placeholder (Acme Corp.becomes `` in both). - You write a memo in Claude that mixes placeholders from both files.
- One
deanonymize_text(..., session_id="SID123")call on the memo restores PII everywhere.
The pii-contract-analyze skill drives this automatically when the user uploads N โฅ 2 files and confirms they belong to one matter. See plugin/skills/pii-contract-analyze/references/bulk-mode.md for the full decision tree.
Team handoff โ export / import a session
If a colleague needs to work on the same documents without you re-sharing PII:
- You call
export_session(session_id, passphrase)โ server packs the mapping + anonymized documents into an encrypted.pii-sessionarchive (AES-GCM with a key derived from the passphrase via scrypt). - Send them the
.pii-sessionfile (email, Slack, thumb drive โ itโs useless without the passphrase). - They call
import_session(path, passphrase)on their machine โ the mapping lands under their~/.pii_shield/mappings/and they can nowdeanonymize_docxlocally.
PII never leaves the anonymized documents in transit. The archive format is versioned (.pii-session v1), so future schema changes will stay readable.
MCP tools
| Tool | Description |
|---|---|
anonymize_file |
Anonymize PII in a file (.pdf, .docx, .txt, .md, .csv). Returns output_path and session_id. |
anonymize_next_chunk |
Process next chunk of a large document. Call repeatedly until complete. |
get_full_anonymized_text |
Finalize chunked anonymization. Returns output_path, session_id, docx_output_path. |
start_review |
Open the in-conversation review panel. |
apply_review_overrides |
Apply reviewer corrections and re-anonymize. |
deanonymize_text |
Restore PII โ writes to local file, returns path only. |
deanonymize_docx |
Restore PII in .docx preserving formatting and tracked changes. |
get_mapping |
Get placeholder keys and entity types (no real values). |
list_entities |
Server status, supported entity types, recent sessions. |
resolve_path |
Zero-config path resolution via marker file (maps VM paths to host paths). |
find_file |
Find a file by name in the configured working directory. |
scan_text |
Detect PII without anonymizing (preview mode). |
export_session / import_session |
Portability โ hand a session between hosts. |
Skill modes
The included pii-contract-analyze skill supports:
| Mode | Description |
|---|---|
| MEMO | Legal analysis memo with risk assessment |
| REDLINE | Tracked changes with Word-native revision marks |
| SUMMARY | Brief overview of key terms and obligations |
| COMPARISON | Side-by-side diff of two documents |
| BULK | Process up to 5 files with prefixed placeholders |
| ANONYMIZE-ONLY | Just anonymize, no analysis |
Detected entity types
Authoritative list is nodejs-v2/src/engine/entity-types.ts (SUPPORTED_ENTITIES).
NER-based (GLiNER zero-shot over ONNX Runtime):
PERSON, ORGANIZATION, LOCATION, NRP
Generic pattern-based:
EMAIL_ADDRESS, PHONE_NUMBER, URL, IP_ADDRESS, ID_DOC, CREDIT_CARD, IBAN_CODE, CRYPTO, MEDICAL_LICENSE
US:
US_SSN, US_PASSPORT, US_DRIVER_LICENSE
UK:
UK_NHS, UK_NIN, UK_PASSPORT, UK_CRN, UK_DRIVING_LICENCE
EU-wide:
EU_VAT, EU_PASSPORT
Country-specific:
DE_TAX_ID, DE_SOCIAL_SECURITY, FR_NIR, FR_CNI, IT_FISCAL_CODE, IT_VAT, ES_DNI, ES_NIE, CY_TIC, CY_ID_CARD, FI_HETU, FI_BUSINESS_ID
35 types total (4 NER + 31 pattern-based).
Logs
| Log | Location | Purpose |
|---|---|---|
| Audit | ~/.pii_shield/audit/mcp_audit.log |
Every tool call and response. Proof that only paths and session IDs flow through the API. |
| NER init | ~/.pii_shield/audit/ner_init.log |
Bootstrap trace โ resolved ORT paths for root / transformers / gliner, sanity-check outcome, install timings. |
| Server | ~/.pii_shield/audit/pii_shield_server.log |
stdout/stderr of the Node MCP server process. |
Development
All code lives in nodejs-v2/. From that directory:
# Install exact-pinned dev deps
npm ci --ignore-scripts --legacy-peer-deps
# Type-check
node node_modules/typescript/bin/tsc --noEmit
# Build the thin .mcpb (Windows / Linux + darwin via platform overrides)
npm run build:plugin
# Also build the darwin-universal .mcpb (downloads Node 24.15.0 arm64 + x64)
npm run build:plugin:mac
# MCP protocol smoke test
npm run smoke
# Focused clean-install smoke for the sharp shim + transformers + gliner
npm run smoke:sharp-shim
Troubleshooting
| Problem | Solution |
|---|---|
| First run is slow | First-ever call does npm ci into ~/.pii_shield/deps/ (~2โ3 min). Subsequent runs are instant. |
| Install panel says โZIP not foundโ | Click the panelโs Download model button first. The browser saves to ~/Downloads by default; PII Shield also scans OneDrive variants, Desktop, Documents. If your browser saves elsewhere, set Settings โ Extensions โ PII Shield โ Model Downloads Folder and click Install again. |
| Install panel doesnโt appear at all | The panel needs Claude Desktop โฅ 0.10 (renders ui:// resources). On older hosts, ask Claude to call start_model_setup directly, or check ~/.pii_shield/audit/pii_shield_server.log. |
Unsupported model IR version: 9 |
Old onnxruntime-node cached. Delete ~/.pii_shield/deps/ โ next run reinstalls with the pinned 1.22.0 triplet. |
Cannot find module '../build/Release/sharp-*.node' |
sharp has no native addon for your platform. PII Shieldโs shim intercepts sharp loads (text-only NER doesnโt use it). If you still see this, youโre on an older build โ upgrade to v2.2.0. |
| macOS: server immediately disconnects after install | Make sure you installed pii-shield-v2.2.0-macos.mcpb, not windows-linux. The Mac variant bundles its own Node to dodge a Claude Desktop darwin host-runtime launch bug. |
| Review panel blank | Check ~/.pii_shield/audit/pii_shield_server.log for MCP Apps resource errors. Claude Desktop version < 0.10 doesnโt render ui:// resources. |
| Tools not appearing | Restart Claude Desktop or send any message โ the tool list refreshes on reconnect. |
What happened to v1?
v1.0.0 was a Python MCP server built on presidio + SpaCy + GLiNER/py, shipped as a .dxt bundle. Itโs still available:
- Tag
v1.0.0โ pinned source. - Branch
python-legacyโ full tree before the Node.js rewrite.
v2 is a complete architectural reset โ Node.js, pure-JS .docx, MCP Apps UI, thin .mcpb โ not a drop-in upgrade.
Acknowledgments
PII Shield builds on excellent open-source projects:
- GLiNER +
knowledgator/gliner-pii-base-v1.0โ zero-shot NER backbone. - onnxruntime-node โ the CPU inference engine.
@xenova/transformersโ tokenizer + HF weights loader on top of ONNX Runtime.- docx + jszip + @adeu/core โ pure-JS
.docxread / write / track-changes. - Claude Desktop + the Model Context Protocol โ host runtime and tool surface.
Author
Grigorii Moskalev โ LinkedIn
License
์ค์น
This server does not publish a one-line install command.
Open the repository installation guide