Skip to main content

pii-mcp

Pattern-based PII scrubbing for MCP servers (regex + checksums), with an optional NER pass for person names in the Rust backend. Masks emails, IBANs, cards, BICs, MACs, IMEIs, IPs, coordinates, BSNs, US SSNs and ITINs, German tax IDs, Dutch BTW-ids, Dutch passport/ID numbers, phones, street + house number addresses, Dutch and UK postcodes, and Dutch license plates in tool results. Language packs: en, nl, and opt-in de.

PyPI npm CI License: MIT

Example

from pii_mcp import scrub_text

scrub_text(
    "Contact ada@example.com. IBAN NL91 ABNA 0417 1643 00. card 4111111111111111"
)
# Contact [EMAIL]. IBAN [IBAN]. card [CREDIT_CARD]

For runnable scripts including a FastMCP server and payload scrubbing, see the examples/ directory.

Install

pip install "pii-mcp[fastmcp]"   # FastMCP >= 3.0.0
# or
pip install pii-mcp              # core; platform wheels include Rust acceleration
# or
npm install pii-mcp

FastMCP

from fastmcp import FastMCP
from pii_mcp.fastmcp import PiiScrubMiddleware

mcp = FastMCP("MyServer")
mcp.add_middleware(PiiScrubMiddleware())  # languages=["en", "nl"] by default
# mcp.add_middleware(PiiScrubMiddleware(languages=["en", "nl", "de"]))

Results only. On scrub failure or oversize, the result is withheld, never forwarded unmasked.

Core

from pii_mcp import scrub_text, scrub_payload

scrub_text("mail ada@example.com")
scrub_payload({"email": "ada@example.com"}, languages=["en"])

Scope

Aligned with AP: wat zijn persoonsgegevens where pattern/checksum detection can reach them. Person names need the opt-in NER build (below). Free-text health data (allergies), photos/audio/video, and unstructured klant-/personeelsnummers stay out of scope.

AP coverage (pattern layer)

AP example / category Detector Notes
e-mail / contact email, phone Incl. Unicode (EAI/IDN) email
IP-adres ip Indirect identifier
Locatiegegevens location Decimal and DMS lat/lon
Financiële gegevens iban, credit_card, bic, vat_id
BSN / nationaal ID bsn, passport Passport/NIK format (nl pack)
Online / device IDs mac, imei IMEI: grouped forms + Luhn
Adres address Street + number; NL/UK postcode
Kenteken license_plate nl pack
Naam person Opt-in NER build only
Pasfoto, allergieën, koopgedrag, camera Media / free text

Person names (optional NER)

ner=True runs an XLM-R token classifier (Davlan/xlm-roberta-base-ner-hrl, AFL-3.0; EN/NL/DE among its languages) after the pattern detectors and masks person names as [PERSON]. It runs in the Rust core on candle (CPU, fp32) and is off by default: published wheels and the npm package are built without it, and no weights ship with any package.

Build with the ner feature:

maturin develop --release --features ner                  # Python
(cd typescript && npm run build:native -- --features ner) # Node
cargo build -p pii-core --features ner                    # Rust

Download the pinned weights (1.1 GB) and the matching XLM-R tokenizer (MIT) into one directory, and point PII_MCP_NER_MODEL at it:

mkdir -p ner-model && cd ner-model
M=https://huggingface.co/Davlan/xlm-roberta-base-ner-hrl/resolve/253f557bd8249b8515114cfd7f71974fe5fa4d2f
T=https://huggingface.co/FacebookAI/xlm-roberta-base/resolve/e73636d4f797dec63c3081bb6ed5c7b0bb3f2089
curl -fL -O "$M/config.json" -O "$M/model.safetensors" -O "$T/tokenizer.json"
export PII_MCP_NER_MODEL="$PWD"
scrub_text("Mail Ada Lovelace at ada@example.com", ner=True)
# {'text': 'Mail [PERSON] at [EMAIL]', ...}
  • Pattern hits are masked first; the NER pass never re-tags a placeholder, so nothing is counted twice.
  • PII_MCP_NER_THRESHOLD (default 0.9) is the minimum person probability per token. The default favors precision; lower it (for example 0.5) to mask more names at the cost of more false positives.
  • ner=True raises PiiScrubError when the build has no ner feature, the backend is pure Python / TypeScript, or the model directory is missing or invalid. Text is never returned with the NER pass silently skipped.

Cost on macOS arm64 (M4 Pro), scripts/bench_backends.py with PII_MCP_NER_MODEL set:

Case Regex only ner=True
Short mixed PII 0.028 ms 67 ms
2 KiB tool result 0.22 ms 532 ms
16 KiB tool result 2.3 ms 4.6 s

Inference time grows with input length, at about 0.3 s per KiB here: a 1 MiB tool result takes about 5 minutes. Use ner=True for results of a few KiB, not for bulk text. Model load takes 2.0 s once per process; peak RSS is about 2.4 GB. Inference is fp32 only: candle's XLM-R implementation builds its attention mask in F32, so fp16 weights do not run.

On the eval (PII_MCP_NER_MODEL=<dir> python eval/score.py --ner, EN/NL/DE names in 15 contexts), person scores recall 0.987 and precision 0.931. Most false positives are company names such as Albert Heijn. The address generators only produce the street shapes the patterns support, so the address recall of 1.0 covers those shapes only; precision is measured with the en, nl and de packs against bare street names and company names. Words that end in a street suffix and are followed by a number (Keypad 3, Supermarkt 24) are masked on purpose, since dropping those suffixes leaks real addresses such as Nieuwmarkt 4.

Packages

Runtime Path Install
Python src/pii_mcp pip install pii-mcp
TypeScript typescript/ npm install pii-mcp
Rust core crates/pii-core shared by both (PyO3 / N-API)

Rust core (Python)

Published platform wheels ship pii_mcp._native (PyO3 over pii-core). Pip prefers those on supported OS/arch; elsewhere (or with --no-binary) you get the pure-Python hatchling wheel/sdist and the same scrub API.

When _native is importable, scrub_text / scrub_payload use it. Force the Python path with PII_MCP_BACKEND=python; require native with PII_MCP_BACKEND=native.

Local development from a clone (optional):

pip install -e ".[native]"
maturin develop --release --manifest-path crates/pii-mcp-native/Cargo.toml

Performance (Python vs Rust release)

Medians from scripts/bench_backends.py on macOS arm64 / CPython 3.14.7 (release native build; debug builds are not representative):

Case Python Rust Speedup
Short clean text 0.234 ms 0.023 ms 10.2x
Short mixed PII 0.058 ms 0.007 ms 8.9x
100 KiB sparse PII 20.4 ms 2.0 ms 10.2x
1 MiB sparse PII 203 ms 20.4 ms 10.0x
Nested JSON payload 12.4 ms 1.2 ms 10.3x
1k x tiny scrub_text 54.3 ms 6.8 ms 8.0x
python scripts/bench_backends.py

Metadata

Release files for pii-mcp 1.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pii-mcp 1.9.1
File Size Uploaded
pii_mcp-1.9.1.tar.gz 221.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pii-mcp 1.9.1
File
pii_mcp-1.9.1-py3-none-any.whl Python 3 none any Details
pii_mcp-1.9.1-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
pii_mcp-1.9.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
pii_mcp-1.9.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
pii_mcp-1.9.1-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
pii_mcp-1.9.1-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 4.7 MB

Release files / pii_mcp-1.9.1.tar.gz

Download URL pii_mcp-1.9.1.tar.gz
Size 221.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5a412d7614696f53c0d5ebb2460131a733de38c17efff64040a61228e152dbd8
BLAKE2b-256 checksum
How to use checksums
81804e6ad9782d0addb41bcd89c6cbfbef964c46472881911a701f0287a8c687
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release files / pii_mcp-1.9.1-py3-none-any.whl

Download URL pii_mcp-1.9.1-py3-none-any.whl
Size 29.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1ea0e5d7ebc68bac5a7414f04887361959118fbd246f90ec4d8f7e6ccfbb961b
BLAKE2b-256 checksum
How to use checksums
9f6835cc89649c12013d69eb7e18be38944a54fe23a07b7b090d1459e6d11cb8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release files / pii_mcp-1.9.1-cp310-abi3-win_amd64.whl

Download URL pii_mcp-1.9.1-cp310-abi3-win_amd64.whl
Size 805.8 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
c853344d52e5a464603a84a41abe00db968dfbfaf09dbfef66450018ce41940d
BLAKE2b-256 checksum
How to use checksums
000ec52551d06e3213590eefe3f660b8f36493efe281831410ada1f038ebff0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release files / pii_mcp-1.9.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pii_mcp-1.9.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 957.5 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
a9916da30528836c0e61d9a6d849a05e983d8769fb69297a26621054a38bb0df
BLAKE2b-256 checksum
How to use checksums
2fedf9f42e4e3a3950692f3af06574695de5e64adf90c69fe9137472baca0624
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release files / pii_mcp-1.9.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL pii_mcp-1.9.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 928.7 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
e0ee8bea24f1aad5bfd2d585e36942a2d7545fa1e72afc391a3a9e0664b5a9de
BLAKE2b-256 checksum
How to use checksums
2049072cb8e0bde2f22f2a5d16e9a6cac8cc0cad72b194060ea9556011ef891c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release files / pii_mcp-1.9.1-cp310-abi3-macosx_11_0_arm64.whl

Download URL pii_mcp-1.9.1-cp310-abi3-macosx_11_0_arm64.whl
Size 836.2 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
aff7ef08737ed6498afcb75acbafa5879b593e85790d8c1e0e6d577084f5a8cf
BLAKE2b-256 checksum
How to use checksums
e4dae5f1bcbcb070f921417c1eba94389999bbf1fc10d564d832061071871817
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release files / pii_mcp-1.9.1-cp310-abi3-macosx_10_12_x86_64.whl

Download URL pii_mcp-1.9.1-cp310-abi3-macosx_10_12_x86_64.whl
Size 881.8 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
b502eec7d0dc825f3eb7f9e7bae8ff0bc92f0acf7a5e0a94cd9cde35cc07727c
BLAKE2b-256 checksum
How to use checksums
848d17c2fbdb9b2f7cd5d07193a90556855267ca88bd50ef4f8e9100c623632f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release history Release notifications | RSS feed

1.10.0

7 release files

This release

1.9.1 This release

7 release files

1.9.0

7 release files

1.8.1

7 release files

1.8.0

7 release files

1.7.1

7 release files

1.7.0

7 release files

1.6.0

7 release files

1.5.5

7 release files

1.5.4

7 release files

1.5.3

7 release files

1.5.2

7 release files

1.5.1

7 release files

1.5.0

7 release files

1.4.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page