pii-mcp
Pattern-based PII redaction for MCP servers (regex + checksums). Masks emails,
IBANs, cards, BICs, MACs, IMEIs, IPs, coordinates, BSNs, US SSNs and ITINs, UK
National Insurance and NHS numbers, 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.
If pii-mcp saves you time, a ⭐ helps others find it.
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
Pattern Tier 1 only: structured identifiers that regex and checksums can reach. Aligned with AP: wat zijn persoonsgegevens where that layer applies. Free-text health data (allergies), photos/audio/ video, and unstructured klant-/personeelsnummers stay out of scope.
person is pattern / key-aware when available (issue #52); until then the
count stays 0. Prose name NER is out of band — this package does not ship
an in-process NER model. Decimal/DMS location coordinates stay here;
free-text place names do not.
Using with foro / Presidio
| Layer | Owner |
|---|---|
| Pattern / checksum / language packs / MCP middleware | this package (Tier 1) |
| PERSON / LOCATION NER on API paths | Presidio or another NER sidecar (Tier 2) |
Live MCP gates in user containers should run Tier 1 only (no model). On platforms such as foro, keep NER in one Presidio sidecar on API paths — do not stack a second in-process NER beside it.
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 |
NL BTW / DE USt-IdNr |
| BSN / nationaal ID | bsn, passport |
Passport/NIK format (nl pack) |
| Nationaal ID (US / UK) | ssn, tax_id |
US SSN/ITIN, UK NINO (en pack) |
| Gezondheidsgegevens (health ID) | ssn |
UK NHS number, grouped (en) |
| Online / device IDs | mac, imei |
IMEI: grouped forms + Luhn |
| Adres | address |
Street + number; NL/UK postcode |
| Kenteken | license_plate |
nl pack |
| Naam | person |
Pattern/key-aware when available (#52); prose NER out of band |
| Pasfoto, allergieën, koopgedrag, camera | Media / free text |
Packages
| Runtime | Path | Install |
|---|---|---|
| Python | src/pii_mcp |
pip install pii-mcp |
| TypeScript | typescript/ |
npm install pii-mcp |
| Gate (JS) | typescript/gate/ |
COPY pii-gate.mjs (zero npm deps) |
| Rust core | crates/pii-core |
shared by both (PyO3 / N-API) |
Tier 1 gate contract for foro user containers (caps, placeholders, binary skip):
docs/tier1-gate.md.
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
Contributing
See CONTRIBUTING.md for setup, how to add a detector, and the checks a PR must pass.
Metadata
Release files for pii-mcp 1.10.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pii_mcp-1.10.0.tar.gz | 251.5 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| pii_mcp-1.10.0-py3-none-any.whl | Python 3 | none | any | Details |
| pii_mcp-1.10.0-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| pii_mcp-1.10.0-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.10.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| pii_mcp-1.10.0-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
| pii_mcp-1.10.0-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.10.0.tar.gz
| Download URL | pii_mcp-1.10.0.tar.gz |
|---|---|
| Size | 251.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b1fe3cee8ebaf10060cb62ee7073d8596041458842e7e841f17d7344c57adf46
|
|
BLAKE2b-256 checksum How to use checksums |
773c19c870a3964af541d2578fc00ae15e3fa149aebe81ffcf553c9a0037ae72
|
| 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 15, 2026.
Transparency logRelease files / pii_mcp-1.10.0-py3-none-any.whl
| Download URL | pii_mcp-1.10.0-py3-none-any.whl |
|---|---|
| Size | 31.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0cf72e3b5e492700c6059f715b276e2a195d7bb5213bc88dad47b9b8ed21c82f
|
|
BLAKE2b-256 checksum How to use checksums |
de9fe61ae4d4b0c4f4cb328b134055e6cfed0ef013d0cd36df769947936d0eaf
|
| 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 15, 2026.
Transparency logRelease files / pii_mcp-1.10.0-cp310-abi3-win_amd64.whl
| Download URL | pii_mcp-1.10.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 815.7 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
92f5b021c4ee9cd36f708199b781e88c5236f3b8a36eb10f71ff5d972010fd8e
|
|
BLAKE2b-256 checksum How to use checksums |
471029cb851a46350bae1a383f2e355ef77ac3c5fda09a285c6d18c6129df695
|
| 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 15, 2026.
Transparency logRelease files / pii_mcp-1.10.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | pii_mcp-1.10.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 966.0 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
e609503364a78d1a2fa5219a4a27302b3a092adf6e486102d6e93b31ecbeed59
|
|
BLAKE2b-256 checksum How to use checksums |
5c667a382825572c0337ff627c77ba3b2e33c512c47b156dc4cfe1d76f899484
|
| 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 15, 2026.
Transparency logRelease files / pii_mcp-1.10.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | pii_mcp-1.10.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 936.8 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
9c49e4433d28763d378fb30ccdaf726e7498ccd23f0d5c5b1208ded0cf0fd666
|
|
BLAKE2b-256 checksum How to use checksums |
2015f69a5f30a6e41522115dd7cd2e88f05bd823408eba02a3a3cab00af3d27e
|
| 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 15, 2026.
Transparency logRelease files / pii_mcp-1.10.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | pii_mcp-1.10.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 845.7 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
7ad5496a5e1a253bf995e1ab03f19bdf4b7a679166c2946e804e8d966c09e6eb
|
|
BLAKE2b-256 checksum How to use checksums |
32b36fa09b2cc7abbe21d2b0a9b49f8f95b894528564c2e109ba55a7251949d5
|
| 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 15, 2026.
Transparency logRelease files / pii_mcp-1.10.0-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | pii_mcp-1.10.0-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 890.9 kB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
c60e65a4d14f6396fa80e048de2ab89b8516db205fe7ec1c33de7b267c5c7746
|
|
BLAKE2b-256 checksum How to use checksums |
f8e1b83759f2889c3fedd4a426139b480a97b06c760ea9e835e63d64e55ce801
|
| 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 15, 2026.
Transparency log