FastPII Docs
Integrations

MCP

Model Context Protocol integration for AI agents.

MCP

FastPII provides an MCP (Model Context Protocol) server integration with three built-in tools for PII detection, validation, and listing detectors.

Creating an MCP server

With an explicit engine

from fastpii import FastPII, DEFAULT_PRIORITY, DEFAULT_CONFIDENCE_SCORES, DEFAULT_CONTEXT_BOOST
from fastpii.core.confidence import ConfidenceScorer
from fastpii.integrations.mcp import MCPServer
from fastpii.countries.cz import CzechPack

scorer = ConfidenceScorer(
    base_scores=DEFAULT_CONFIDENCE_SCORES,
    context_boost=DEFAULT_CONTEXT_BOOST,
)
engine = FastPII(priority=DEFAULT_PRIORITY, confidence_scorer=scorer)
engine.register(CzechPack())

server = MCPServer(engine)

With regions list

from fastpii.integrations.mcp import MCPServer

server = MCPServer.from_regions(["cz", "pl", "de", "fr"])

Available tools

detect_pii

Detect PII in text. Returns list of detected identifiers with type, value, position, and confidence.

Input schema:

ParameterTypeRequiredDescription
textstringYesText to analyze for PII
detector_namesarray of stringsNoSpecific detectors to use

Example:

result = server.call_tool("detect_pii", {
    "text": "Email: jan.novak@example.cz, RČ: 8001011238",
})

Response:

{
    "text": "Email: jan.novak@example.cz, RČ: 8001011238",
    "findings": [
        {
            "type": "email",
            "value": "jan.novak@example.cz",
            "start": 7,
            "end": 27,
            "confidence": 0.95,
            "region": "cz",
            "metadata": {}
        },
        {
            "type": "rodne_cislo",
            "value": "8001011238",
            "start": 33,
            "end": 43,
            "confidence": 1.0,
            "region": "cz",
            "metadata": {"checksum_valid": true, "birth_date": "1980-01-01", "gender": "male"}
        }
    ],
    "detector_names": ["email", "rodne_cislo"],
    "processing_time_ms": 2
}

validate_identifier

Validate a specific identifier. Returns validation result with metadata.

Input schema:

ParameterTypeRequiredDescription
valuestringYesValue to validate
detector_namestringYesDetector name (e.g., rodne_cislo, ico, pesel)

Example:

result = server.call_tool("validate_identifier", {
    "value": "8001011238",
    "detector_name": "rodne_cislo",
})

Response:

{
    "detector": "rodne_cislo",
    "value": "8001011238",
    "is_valid": true,
    "metadata": {
        "checksum_valid": true,
        "birth_date": "1980-01-01",
        "gender": "male"
    }
}

list_detectors

List all available PII detectors for the configured regions.

Input schema: No parameters required.

Example:

result = server.call_tool("list_detectors", {})

Response:

{
    "detectors": [
        {"name": "rodne_cislo", "region": "cz", "description": "Czech birth number"},
        {"name": "ico", "region": "cz", "description": "Czech company ID"}
    ]
}

Integration with Claude Desktop

Add to your Claude Desktop configuration:

{
    "mcpServers": {
        "fastpii": {
            "command": "python",
            "args": ["-m", "fastpii.integrations.mcp"],
            "env": {
                "FASTPII_REGIONS": "cz,pl,de,fr"
            }
        }
    }
}

Tool boundaries

A common pattern is to sanitize text at tool boundaries:

  1. Before sending to backend services: Detect and anonymize user input
  2. Before returning to user: Detect and redact any PII in agent responses
# Sanitize before sending
sanitized = server.call_tool("detect_pii", {"text": user_input})
# Process sanitized text through your AI pipeline
# Redact before returning
redacted = engine.redact(agent_response)

On this page