Skip to main content
Glama
czangyeob

MCP PII Tools

by czangyeob

mcp_decrypt_text_pii

Decrypt personally identifiable information from encrypted text using a mapping of original values to encrypted values within the MCP PII Tools server.

Instructions

MCP Tool: 암호화된 텍스트에서 PII 복호화

Args:
    encrypted_text (str): 암호화된 텍스트
    encrypted_items (Dict[str, str]): 원본값 -> 암호화값 매핑
    
Returns:
    Dict[str, Any]: 복호화 결과

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
encrypted_textYes
encrypted_itemsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function decorated with @mcp.tool() that implements the decryption logic for PII in encrypted text. It reverses the encryption using PIICrypto and mapping provided.
    @mcp.tool()
    def mcp_decrypt_text_pii(encrypted_text: str, encrypted_items: Dict[str, str]) -> Dict[str, Any]:
        """
        MCP Tool: 암호화된 텍스트에서 PII 복호화
        
        Args:
            encrypted_text (str): 암호화된 텍스트
            encrypted_items (Dict[str, str]): 원본값 -> 암호화값 매핑
            
        Returns:
            Dict[str, Any]: 복호화 결과
        """
        try:
            start_time = time.time()
            
            # 암호화값 -> 원본값 매핑 생성
            decrypted_items = {}
            decrypted_text = encrypted_text
            
            crypto = PIICrypto()
            
            for original_value, encrypted_value in encrypted_items.items():
                # PII 유형 추정 (암호화된 값을 기준으로)
                pii_type = _guess_pii_type(encrypted_value)
                
                # Base64 패턴인 경우 (결정론적 암호화) 여러 유형 시도
                if re.match(r'^[A-Za-z0-9+/=]+$', encrypted_value) and len(encrypted_value) > 20:
                    # 이름, 주소, 이메일 순서로 시도
                    decrypted_value = None
                    for try_type in ["이름", "주소", "이메일"]:
                        try:
                            result = crypto.decrypt_pii_item(encrypted_value, try_type)
                            if not (result.startswith("[복호화실패:") or result.startswith("[FPE복호화실패:")):
                                decrypted_value = result
                                pii_type = try_type
                                break
                        except:
                            continue
                    
                    if decrypted_value is None:
                        decrypted_value = f"[복호화실패:{encrypted_value[:20]}...]"
                else:
                    # FPE 암호화 또는 다른 패턴
                    decrypted_value = crypto.decrypt_pii_item(encrypted_value, pii_type)
                
                decrypted_items[encrypted_value] = decrypted_value
                
                # 텍스트에서 복호화
                decrypted_text = decrypted_text.replace(encrypted_value, decrypted_value)
            
            processing_time = time.time() - start_time
            
            return {
                "success": True,
                "encrypted_text": encrypted_text,
                "decrypted_text": decrypted_text,
                "decrypted_items": decrypted_items,
                "count": len(encrypted_items),
                "processing_time": processing_time
            }
            
        except Exception as e:
            return {
                "success": False,
                "error": str(e),
                "encrypted_text": encrypted_text,
                "decrypted_text": encrypted_text,
                "decrypted_items": {},
                "count": 0,
                "processing_time": 0
            }
  • The JSON schema defining the input parameters and description for the decrypt_text_pii tool (function named mcp_decrypt_text_pii).
    "decrypt_text_pii": {
        "name": "decrypt_text_pii",
        "description": "암호화된 텍스트에서 PII를 복호화합니다.",
        "parameters": {
            "type": "object",
            "properties": {
                "encrypted_text": {
                    "type": "string",
                    "description": "암호화된 텍스트"
                },
                "encrypted_items": {
                    "type": "object",
                    "description": "원본값 -> 암호화값 매핑 딕셔너리"
                }
            },
            "required": ["encrypted_text", "encrypted_items"]
        }
  • Helper function used by the handler to guess PII type from encrypted values to aid decryption.
    def _guess_pii_type(value: str) -> str:
        """PII 값으로부터 유형을 추정하는 헬퍼 함수 (암호화된 값도 고려)"""
        import re
        
        # 이메일 패턴
        if re.match(r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$', value):
            return "이메일"
        
        # 전화번호 패턴 (한국) - 하이픈 포함
        if re.match(r'^\d{3}-\d{4}-\d{4}$', value) or re.match(r'^\d{2,3}-\d{3,4}-\d{4}$', value):
            return "전화번호"
        
        # 신용카드번호 패턴 - 하이픈 포함
        if re.match(r'^\d{4}-\d{4}-\d{4}-\d{4}$', value):
            return "신용카드번호"
        
        # 여권번호 패턴 - 알파벳 + 숫자 (암호화된 경우도 고려)
        if re.match(r'^[A-Z]\d{8,9}$', value) or re.match(r'^[A-Z]\d{7,10}$', value):
            return "여권번호"
        
        # 주민등록번호 패턴 - 하이픈 포함
        if re.match(r'^\d{6}-\d{7}$', value):
            return "주민등록번호"
        
        # 주소 패턴 (한국) - 한글 키워드 포함
        if any(keyword in value for keyword in ["시", "구", "로", "동", "번지"]):
            return "주소"
        
        # Base64 패턴 (결정론적 암호화 결과) - 이름, 주소, 이메일만 사용
        if re.match(r'^[A-Za-z0-9+/=]+$', value):
            # Base64는 결정론적 암호화 결과이므로 이름, 주소, 이메일 중 하나
            # 길이로 대략적인 구분 (정확하지 않을 수 있음)
            if len(value) < 50:
                return "이름"  # 짧은 Base64는 보통 이름
            elif len(value) < 70:
                return "이메일"  # 중간 길이 Base64는 보통 이메일
            else:
                return "주소"  # 긴 Base64는 보통 주소
        
        # 기본적으로 이름으로 추정
        return "이름"
  • Registration of the mcp_decrypt_text_pii tool in the MCP server tools list in the example file.
        mcp_encrypt_text_pii,
        mcp_decrypt_text_pii,
        MCP_TOOLS
    )
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool decrypts PII from encrypted text but doesn't cover critical aspects like authentication requirements, rate limits, error handling, or whether it's a read-only or mutative operation. This is a significant gap for a tool handling sensitive PII data.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured with a clear purpose statement followed by Args and Returns sections. It avoids unnecessary fluff and is appropriately sized for the tool's complexity. However, the use of Korean might reduce clarity for some agents, and the Returns section could be more descriptive.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (handling PII decryption with two parameters and nested objects), the description is minimally adequate. It covers the basic purpose and parameters but lacks behavioral details and usage guidelines. The presence of an output schema helps, but without annotations, the description should do more to explain security implications and error cases.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description lists both parameters (encrypted_text and encrypted_items) with brief explanations, adding some semantic value beyond the schema's 0% description coverage. However, it doesn't fully compensate for the coverage gap—details like the format of encrypted_items mapping or examples are missing. The baseline is 3 since it provides basic parameter context.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '암호화된 텍스트에서 PII 복호화' (Decrypt PII from encrypted text). It specifies both the verb (decrypt) and the resource (PII from encrypted text), making the function unambiguous. However, it doesn't explicitly differentiate from sibling tools like mcp_decrypt_pii_item, which might handle individual items rather than text.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like mcp_decrypt_pii_item or mcp_anonymize_text, nor does it specify prerequisites or contexts for usage. This leaves the agent without clear direction on tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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