Skip to main content
Glama
czangyeob

MCP PII Tools

by czangyeob

mcp_encrypt_text_pii

Detect and encrypt personally identifiable information (PII) in text using GPT-4o-based detection and advanced cryptographic methods for data protection.

Instructions

MCP Tool: 텍스트에서 PII를 탐지하고 암호화

Args:
    text (str): 처리할 텍스트
    
Returns:
    Dict[str, Any]: 암호화 처리 결과

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes

Implementation Reference

  • The core handler function for the 'mcp_encrypt_text_pii' tool. It is registered via the @mcp.tool() decorator. The function detects PII using mcp_detect_pii, encrypts each PII item with PIICrypto, replaces them in the original text, and returns the encrypted text along with mappings and summary.
    @mcp.tool()
    def mcp_encrypt_text_pii(text: str) -> Dict[str, Any]:
        """
        MCP Tool: 텍스트에서 PII를 탐지하고 암호화
        
        Args:
            text (str): 처리할 텍스트
            
        Returns:
            Dict[str, Any]: 암호화 처리 결과
        """
        try:
            start_time = time.time()
            
            # 1. PII 탐지
            detection_result = mcp_detect_pii(text)
            
            if not detection_result["success"]:
                return detection_result
            
            if not detection_result["pii_items"]:
                return {
                    "success": True,
                    "original_text": text,
                    "encrypted_text": text,
                    "pii_items": [],
                    "encrypted_items": {},
                    "count": 0,
                    "processing_time": time.time() - start_time,
                    "summary": {}
                }
            
            # 2. PII 항목들 암호화
            crypto = PIICrypto()
            encrypted_items = {}
            encrypted_text = text
            
            for item in detection_result["pii_items"]:
                pii_type = item["type"]
                pii_value = item["value"]
                
                # 암호화
                encrypted_value = crypto.encrypt_pii_item(pii_value, pii_type)
                encrypted_items[pii_value] = encrypted_value
                
                # 텍스트에서 치환
                encrypted_text = encrypted_text.replace(pii_value, encrypted_value)
            
            processing_time = time.time() - start_time
            
            return {
                "success": True,
                "original_text": text,
                "encrypted_text": encrypted_text,
                "pii_items": detection_result["pii_items"],
                "encrypted_items": encrypted_items,
                "count": len(detection_result["pii_items"]),
                "processing_time": processing_time,
                "summary": detection_result["summary"]
            }
            
        except Exception as e:
            return {
                "success": False,
                "error": str(e),
                "original_text": text,
                "encrypted_text": text,
                "pii_items": [],
                "encrypted_items": {},
                "count": 0,
                "processing_time": 0,
                "summary": {}
            }
  • The JSON schema defining the input parameters for the mcp_encrypt_text_pii tool, part of the MCP_TOOLS dictionary used for tool metadata.
    "encrypt_text_pii": {
        "name": "encrypt_text_pii",
        "description": "텍스트에서 PII를 탐지하고 모든 PII를 암호화합니다. 검색 가능한 암호화된 텍스트를 생성합니다.",
        "parameters": {
            "type": "object",
            "properties": {
                "text": {
                    "type": "string",
                    "description": "처리할 텍스트"
                }
            },
            "required": ["text"]
        }
    },
  • The @mcp.tool() decorator registers the mcp_encrypt_text_pii function with the FastMCP server instance.
    @mcp.tool()
  • Test usage of the tool in the main() function.
    encrypt_text_result = mcp_encrypt_text_pii(test_text)
    if encrypt_text_result['success']:
  • Import of the tool function in the example file.
    mcp_encrypt_text_pii,

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/czangyeob/mcp-pii-tools'

If you have feedback or need assistance with the MCP directory API, please join our Discord server