MCP β€” LANGCHAIN

LangChain PII Protection β€” MCP Integration Guide

LangChain vulnerability class: PII leakage in AI model outputs (documented in OWASP Top 10 for LLM Applications) CVSS 9.3 vulnerability. Inject anonym.legal MCP server as PII sanitization layer. Detect & redact PII before LLM processing. Secure Claude, GPT-4, Llama 2 pipelines.

The vulnerability class: PII leakage in AI model outputs (documented in OWASP Top 10 for LLM Applications) Problem

🚨 Vulnerability

LangChain agent tools accept user input directly into vector search, memory, and LLM context. PII like SSN, email, credit card exposed to model training.

πŸ“Š Impact

CVSS 9.3 (Critical). Affects all versions <5.2.0. Customers share financial data, health records, credentials with LLM providers.

βœ… Solution

Inject MCP server before agent execution. Sanitize PII automatically. Deploy anonymize, analyze, decrypt as MCP tools.

No. There is no SDK package. The REST API works with any HTTP client: call it with requests in Python or fetch in Node.js. Code examples are on the Code Examples page.

The MCP Server exposes 9 privacy tools, for example anonym_legal_analyze_text, anonym_legal_anonymize_text and anonym_legal_detokenize_text, that MCP-capable agents can call directly. MCP access is included in Pro and Business. Prevents PII leakage in RAG pipelines and agent workflows.

The API is synchronous. Batch endpoints process arrays of text in a single call. The API runs on EU servers. Document content is not stored after processing, unless you use the optional history.

The API runs on our EU-hosted infrastructure. Document content is not stored after processing, unless you use the optional history. For enterprise self-hosting requirements, contact us.

Yes. Send arrays of text strings in a single API call. The batch endpoint (POST /api/presidio/batch) takes up to 5 texts per request on Basic, 10 on Pro and 50 on Business.

Free tier: 200 tokens per 30 days in the web app (API access starts with Basic). Basic: €3/month (1,000 tokens). Pro: €15/month (4,000 tokens, adds the MCP Server). Business: €29/month (10,000 tokens). What a call costs depends on text length and the entities found, so one call can cost more than one token.

MCP Server Integration

1. Get the MCP Server URL

# Nothing to install or start: the server is hosted.
# URL:  https://anonym.legal/mcp
# Auth: Authorization: Bearer YOUR_API_KEY
# MCP access is included in Pro and Business.

2. Configure LangChain to Use MCP

from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent

# Connect to the hosted MCP server
client = MultiServerMCPClient({
  "anonym-legal": {
    "transport": "streamable_http",
    "url": "https://anonym.legal/mcp",
    "headers": {"Authorization": "Bearer YOUR_API_KEY"},
  }
})

# Load the anonym_legal_* tools
tools = await client.get_tools()

# Create agent with PII protection
agent = create_react_agent(llm, tools)

3. Protect Pipeline

user_input = "My name is John, SSN 123-45-6789"

# Before: VULNERABLE to vulnerability class: PII leakage in AI model outputs (documented in OWASP Top 10 for LLM Applications)
# response = agent.invoke({"input": user_input})

# After: PROTECTED by MCP layer
result = await agent.ainvoke({
  "messages": [("user", f"Anonymize: {user_input}")]
})

# Use the anonymized text downstream
cleaned = result["messages"][-1].content

MCP Tools Available

πŸ” anonym_legal_analyze_text

Detect PII entities in text. Returns entity types, positions, confidence scores. Use for classification.

πŸ”’ anonym_legal_anonymize_text

Replace PII with redactions, masks, hashes, encryption. Safe for LLM input. Preserve text structure.

πŸ”“ anonym_legal_detokenize_text

Restore original values in tokenized text, using the session_id from a tokenize call. Use in retrieval chains. Bearer token auth.

Use Case: Customer Support Chatbot

Vulnerability Chain

Customer: "My order #12345 shipped to 123 Main St, email is jane@ex.com"

# BEFORE: vulnerability class: PII leakage in AI model outputs (documented in OWASP Top 10 for LLM Applications) (VULNERABLE)
agent.invoke(user_input)
# β†’ LangChain stores "jane@ex.com" in vector DB
# β†’ Email sent to OpenAI for embedding
# β†’ Stored in LLM training logs

Protection Applied

Customer: "My order #12345 shipped to 123 Main St, email is jane@ex.com"

# AFTER: MCP Protection
mcp_output = anonymize_tool.invoke({
  "text": user_input,
  "method": "mask"
})
# β†’ "My order #12345 shipped to [ADDRESS], email is [EMAIL]"

# Now safe to send to LLM
response = llm.predict(text=mcp_output)

Watch the API In Action

See PII detection and anonymization via REST API and MCP Server

Secure Your LangChain Pipeline

Patch vulnerability class: PII leakage in AI model outputs (documented in OWASP Top 10 for LLM Applications). Deploy MCP server. Inject PII protection before LLM. Secure Claude, GPT-4, Llama pipelines.

Set Up MCP Server

Frequently Asked Questions

Insert anonym.legal's MCP Server as a preprocessing layer before document ingestion. It detects and anonymizes PII in documents before they're chunked and embedded, ensuring your vector database contains no personally identifiable information.

Yes. The REST API integrates with any Python framework. Use the /api/anonymize endpoint as a document transformer in your LlamaIndex ingestion pipeline. Apply before chunking to ensure embeddings contain no PII.

MCP Server integration works with any AI agent framework. For CrewAI, add anonym.legal as a tool that agents call before processing user data. For AutoGen, call the REST API from a function-calling tool.