+
    wi1                     Z    R t ^ RIHt ^ RIHtHtHtHtHtH	t	 R R lt
R R ltR R ltR	# )
z
Shared validation functions for server requests.

This module provides validation logic for sampling and elicitation requests
that is shared across normal and task-augmented code paths.
)McpError)INVALID_PARAMSClientCapabilities	ErrorDataSamplingMessageTool
ToolChoicec                >    V ^8  d   QhR\         R,          R\        /# )   client_capsNreturn)r   bool)formats   "I/home/ubuntu/.local/lib/python3.14/site-packages/mcp/server/validation.py__annotate__r      s       1Cd1J t     c                f    V f   R# V P                   f   R# V P                   P                  f   R# R# )z
Check if the client supports sampling tools capability.

Args:
    client_caps: The client's declared capabilities

Returns:
    True if client supports sampling.tools, False otherwise
FT)samplingtools)r   s   &r   check_sampling_tools_capabilityr      s4     #!!)r   c                    V ^8  d   QhR\         R,          R\        \        ,          R,          R\        R,          RR/# )r
   r   Nr   tool_choicer   )r   listr   r   )r   s   "r   r   r   &   sC      #d*: d" 
	r   c                p    Vf   Ve.   \        V 4      '       g   \        \        \        RR7      4      hR# R# )a<  
Validate that the client supports sampling tools if tools are being used.

Args:
    client_caps: The client's declared capabilities
    tools: The tools list, if provided
    tool_choice: The tool choice setting, if provided

Raises:
    McpError: If tools/tool_choice are provided but client doesn't support them
Nz1Client does not support sampling tools capability)codemessage)r   r   r   r   )r   r   r   s   &&&r   validate_sampling_toolsr   &   s?      K3.{;;'O  < 4r   c                >    V ^8  d   QhR\         \        ,          RR/# )r
   messagesr   N)r   r   )r   s   "r   r   r   @   s#     (q (q_0E (q$ (qr   c                ^   V '       g   R# V R,          P                   p\        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      p\        V 4      ^8  d   V R,          P                   MRpT;'       d5    \        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      pV'       dh   \        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d   \        R4      hVf   \        R4      hV'       g   \        R	4      hV'       dx   V'       dn   V Uu0 uF!  qUP                  R
8X  g   K  VP
                  kK#  	  ppV Uu0 uF!  qUP                  R8X  g   K  VP                  kK#  	  ppWg8w  d   \        R4      hR# R# R# u upi u upi )a  
Validate tool_use/tool_result message structure per SEP-1577.

This validation ensures:
1. Messages with tool_result content contain ONLY tool_result content
2. tool_result messages are preceded by a message with tool_use
3. tool_result IDs match the tool_use IDs from the previous message

See: https://github.com/modelcontextprotocol/modelcontextprotocol/issues/1577

Args:
    messages: The list of sampling messages to validate

Raises:
    ValueError: If the message structure is invalid
Nc              3   >   "   T F  qP                   R 8H  x  K  	  R# 5itool_resultNtype.0cs   & r   	<genexpr>4validate_tool_use_result_messages.<locals>.<genexpr>U   s     ILq66]2L   TFc              3   >   "   T F  qP                   R 8H  x  K  	  R# 5i)tool_useNr#   r%   s   & r   r(   r)   X   s     4dScaVVz5IScr*   c              3   >   "   T F  qP                   R 8g  x  K  	  R# 5ir!   r#   r%   s   & r   r(   r)   ]   s     =1vv&r*   zHThe last message must contain only tool_result content if any is presentz;tool_result requires a previous message containing tool_usezDtool_result blocks do not match any tool_use in the previous messager,   r"   zPids of tool_result blocks and tool_use blocks from previous message do not match)content_as_listanylen
ValueErrorr$   id	toolUseId)r   last_contenthas_tool_resultsprevious_contenthas_previous_tool_user'   tool_use_idstool_result_idss   &       r   !validate_tool_use_result_messagesr<   @   sH   " B<//LsILIsssILII7:8}7Ix|33t,dd4dSc4d4dSc4d1d 3==333====ghh#Z[[$cdd!1&6O&6&&J:N&6O0<X1-@W;1;;X*opp + "2OXs   8F%F%%F*<F*N)__doc__mcp.shared.exceptionsr   	mcp.typesr   r   r   r   r   r   r   r   r<    r   r   <module>rA      s)    + &4(qr   