o
    *ºi³  ã                   @  s|   d Z ddlmZ ddlZddlZddlmZmZ e e	¡Z
e d¡ZdZeG dd„ dƒƒZddd„Zddd„Zddd„ZdS )a»  Tool name validation utilities according to SEP-986.

Tool names SHOULD be between 1 and 128 characters in length (inclusive).
Tool names are case-sensitive.
Allowed characters: uppercase and lowercase ASCII letters (A-Z, a-z),
digits (0-9), underscore (_), dash (-), and dot (.).
Tool names SHOULD NOT contain spaces, commas, or other special characters.

See: https://modelcontextprotocol.io/specification/2025-11-25/server/tools#tool-names
é    )ÚannotationsN)Ú	dataclassÚfieldz^[A-Za-z0-9._-]{1,128}$zPhttps://modelcontextprotocol.io/specification/2025-11-25/server/tools#tool-namesc                   @  s0   e Zd ZU dZded< edd„ dZded< d	S )
ÚToolNameValidationResultzÆResult of tool name validation.

    Attributes:
        is_valid: Whether the tool name conforms to SEP-986 requirements.
        warnings: List of warning messages for non-conforming aspects.
    ÚboolÚis_validc                   C  s   g S ©N© r	   r	   r	   ú\/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/mcp/shared/tool_name_validation.pyÚ<lambda>%   s    z!ToolNameValidationResult.<lambda>)Údefault_factoryú	list[str]ÚwarningsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r   r	   r	   r	   r
   r      s   
 r   ÚnameÚstrÚreturnc                 C  s$  g }| st ddgdS t| ƒdkrt ddt| ƒ› dgdS d| v r'| d¡ d	| v r0| d
¡ |  d¡s:|  d¡r?| d¡ |  d¡sI|  d¡rN| d¡ t | ¡sŒg }tƒ }| D ]}t d|¡sp||vrp| |¡ | 	|¡ qZ| dd 
dd„ |D ƒ¡› ¡ | d¡ t d|dS t d|dS )zÓValidate a tool name according to the SEP-986 specification.

    Args:
        name: The tool name to validate.

    Returns:
        ToolNameValidationResult containing validation status and any warnings.
    FzTool name cannot be empty)r   r   é€   z=Tool name exceeds maximum length of 128 characters (current: ú)ú z9Tool name contains spaces, which may cause parsing issuesú,z9Tool name contains commas, which may cause parsing issuesú-zUTool name starts or ends with a dash, which may cause parsing issues in some contextsÚ.zTTool name starts or ends with a dot, which may cause parsing issues in some contextsz[A-Za-z0-9._-]z'Tool name contains invalid characters: z, c                 s  s    | ]}t |ƒV  qd S r   )Úrepr)Ú.0Úcr	   r	   r
   Ú	<genexpr>Y   s   € z%validate_tool_name.<locals>.<genexpr>zLAllowed characters are: A-Z, a-z, 0-9, underscore (_), dash (-), and dot (.)T)r   ÚlenÚappendÚ
startswithÚendswithÚTOOL_NAME_REGEXÚmatchÚsetÚreÚaddÚjoin)r   r   Úinvalid_charsÚseenÚcharr	   r	   r
   Úvalidate_tool_name(   s>   	þþ






€ 
r.   r   r   ÚNonec                 C  s^   |sdS t  d| › d¡ |D ]
}t  d|› ¡ qt  d¡ t  d¡ t  dt› d¡ dS )	z§Log warnings for non-conforming tool names.

    Args:
        name: The tool name that triggered the warnings.
        warnings: List of warning messages to log.
    Nz"Tool name validation warning for "z":z  - zHTool registration will proceed, but this may cause compatibility issues.zKConsider updating the tool name to conform to the MCP tool naming standard.zSee SEP-986 (z) for more details.)ÚloggerÚwarningÚSEP_986_URL)r   r   r1   r	   r	   r
   Úissue_tool_name_warninga   s   

r3   r   c                 C  s   t | ƒ}t| |jƒ |jS )aC  Validate a tool name and issue warnings for non-conforming names.

    This is the primary entry point for tool name validation. It validates
    the name and logs any warnings via the logging module.

    Args:
        name: The tool name to validate.

    Returns:
        True if the name is valid, False otherwise.
    )r.   r3   r   r   )r   Úresultr	   r	   r
   Úvalidate_and_warn_tool_names   s   r5   )r   r   r   r   )r   r   r   r   r   r/   )r   r   r   r   )r   Ú
__future__r   Úloggingr(   Údataclassesr   r   Ú	getLoggerr   r0   Úcompiler%   r2   r   r.   r3   r5   r	   r	   r	   r
   Ú<module>   s    



9