+
    Q(iE                       ^ RI Ht ^ RIHt ^ RIHt ^ RIHtHtH	t	H
t
Ht ^ RIHtHt ^ RIHt ^ RIHtHt ^ RIHt ^ R	IHt ^ R
IHt ^ RIHt ^ RIHt . R,Ot]! ]4      t ]! R]R7      t! ! R R]4      t" ! R R]]]!,          4      t#] ! R R]]!,          4      4       t$] ! R R4      4       t%R R lt&R R lt'R R lt(R R lt)R R  lt*R! R" lt+R# R$ lt,R-R% R& llt-R' R( lt.R) R* lt/R+# ).    )annotations)	dataclass)Enum)AnyGenericLiteralcast
get_origin)CancelledElicitationDeclinedElicitation)	BaseModel)GenerateJsonSchemaJsonSchemaValue)core_schema)TypeVar)compress_schema)
get_logger)get_cached_typeadapterAcceptedElicitationElicitConfigScalarElicitationTypeT)defaultc                  V   a  ] tR t^$tRtR V 3R lltR V 3R lltR V 3R lltRtV ;t	# )	ElicitationJsonSchemaa%  Custom JSON schema generator for MCP elicitation that always inlines enums.

MCP elicitation requires inline enum schemas without $ref/$defs references.
This generator ensures enums are always generated inline for compatibility.
Optionally adds enumNames for better UI display when available.
c                    V ^8  d   QhRRRR/# )   schemazcore_schema.CoreSchemareturnr    )formats   "`/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/fastmcp/server/elicitation.py__annotate__"ElicitationJsonSchema.__annotate__,   s     . .%; . .    c                   < VR,          R8X  d   V P                  V4      # VR,          R8X  d   V P                  V4      # \        SV `  V4      # )zEOverride to prevent ref generation for enums and handle list schemas.typeenumlist)enum_schemalist_schemasupergenerate_innerselfr   	__class__s   &&r"   r-   $ElicitationJsonSchema.generate_inner,   sQ     &>V# ##F++&>V###F++w%f--r%   c                    V ^8  d   QhRRRR/# )r   r   zcore_schema.ListSchemar   r   r    )r!   s   "r"   r#   r$   9   s     #+ #+"8 #+_ #+r%   c                Z  < VP                  R4      pV'       d@   VP                  R4      R8X  d*   V P                  V4      pRV9   d   RVR,          /pRRRV/# V'       d=   \        SV `  V4      pRV9   g   RV9   g   RV9   d   RV9   d   RVR,          /pRRRV/# \        SV `  V4      # )	zFGenerate schema for list types, detecting enum items for multi-select.items_schemar'   r(   oneOfanyOfarrayitemsconst)getr*   r,   r-   r+   )r/   r   r4   r8   items_resultr0   s   &&   r"   r+   !ElicitationJsonSchema.list_schema9   s    zz.1 L,,V4>$$\2E% %.1   71,?L <'\)l* l*$+\'-B#CLG\  w"6**r%   c                    V ^8  d   QhRRRR/# )r   r   zcore_schema.EnumSchemar   r   r    )r!   s   "r"   r#   r$   ^   s     + +"8 +_ +r%   c                "   < \         SV `  V4      # )zGenerate inline enum schema.

Always generates enum pattern: `{"enum": [value, ...]}`
Titled enums are handled separately via dict-based syntax in ctx.elicit().
)r,   r*   r.   s   &&r"   r*   !ElicitationJsonSchema.enum_schema^   s     w"6**r%   r    )
__name__
__module____qualname____firstlineno____doc__r-   r+   r*   __static_attributes____classcell__)r0   s   @r"   r   r   $   s'    . .#+ #+J+ +r%   r   c                  4    ] tR t^it$ RtRtR]R&   R]R&   RtR# )	r   z)Result when user accepts the elicitation.acceptzLiteral['accept']actionr   datar    N)r@   rA   rB   rC   rD   rI   __annotations__rE   r    r%   r"   r   r   i   s    3 (F(
Gr%   c                  "    ] tR t^pt$ R]R&   RtR# )r   r   valuer    N)r@   rA   rB   rC   rK   rE   r    r%   r"   r   r   p   s    Hr%   c                  :    ] tR t^ut$ RtR]R&   R]R&   R]R&   RtR	# )
r   a  Configuration for an elicitation request.

Attributes:
    schema: The JSON schema to send to the client
    response_type: The type to validate responses with (None for raw schemas)
    is_raw: True if schema was built directly (extract "value" from response)
dict[str, Any]r   ztype | Noneresponse_typeboolis_rawr    N)r@   rA   rB   rC   rD   rK   rE   r    r%   r"   r   r   u   s     Lr%   c                    V ^8  d   QhRRRR/# r   rP   r   r   r   r    )r!   s   "r"   r#   r#      s     & &c &l &r%   c                T   V f   \        RRR/ /RRR7      # \        V \        4      '       d   \        V 4      # \        V \        4      '       d   \        V 4      # \        V 4      \        J d   \        V 4      # \        V 4      '       d   \        V 4      # \        \        V 4      V RR7      # )a  Parse response_type into schema and handling configuration.

Supports multiple syntaxes:
- None: Empty object schema, expect empty response
- dict: `{"low": {"title": "..."}}` -> single-select titled enum
- list patterns:
    - `[["a", "b"]]` -> multi-select untitled
    - `[{"low": {...}}]` -> multi-select titled
    - `["a", "b"]` -> single-select untitled
- `list[X]` type annotation: multi-select with type
- Scalar types (bool, int, float, str, Literal, Enum): single value
- Other types (dataclass, BaseModel): use directly
Nr'   object
propertiesFr   rP   rR   )r   
isinstancedict_parse_dict_syntaxr)   _parse_list_syntaxr
   _parse_generic_list_is_scalar_type_parse_scalar_typeget_elicitation_schemarP   s   &r"   parse_elicit_response_typerb      s     HlB7
 	
 -&&!-00-&&!-00- D("=11}%%!-00 %m4# r%   c                    V ^8  d   QhRRRR/# )r   rP   r   r   rQ   r    )r!   s   "r"   r#   r#      s      3 4 r%   c                    V \         \        \        \        09   ;'       gB    \	        V 4      \
        J ;'       g)    \        V \        4      ;'       d    \        V \        4      # )z<Check if response_type is a scalar type that needs wrapping.)
rQ   intfloatstrr
   r   rY   r'   
issubclassr   ra   s   &r"   r^   r^      sX     	$UC00 	Q 	Qm$/	Q 	Q}d+OO
=$0Or%   c                    V ^8  d   QhRRRR/# )r   drO   r   r   r    )r!   s   "r"   r#   r#      s      . \ r%   c                p    V '       g   \        R4      h\        V RR7      p\        RRRRV/RR./R	R
R7      # )zEParse dict syntax: {"low": {"title": "..."}} -> single-select titled.z#Dict response_type cannot be empty.Fmulti_selectr'   rV   rW   rM   requiredNTrX   )
ValueError_dict_to_enum_schemar   )rj   r*   s   & r"   r[   r[      sM    >??&qu=KH7K0	

  r%   c                    V ^8  d   QhRRRR/# )r   lstz	list[Any]r   r   r    )r!   s   "r"   r#   r#      s     ,L ,LI ,L, ,Lr%   c                n   \        V 4      ^8X  d   \        V ^ ,          \        4      '       d|   V ^ ,          '       dm   \        ;QJ d#    R V ^ ,           4       F  '       d   K   RM	  RM! R V ^ ,           4       4      '       d%   \	        RRRRRRR	R
V ^ ,          ///RR./RRR7      # \        V 4      ^8X  d\   \        V ^ ,          \
        4      '       d?   V ^ ,          '       d0   \        V ^ ,          RR7      p\	        RRRRRRR	V//RR./RRR7      # V '       d   \        ;QJ d    R V  4       F  '       d   K   RM	  RM! R V  4       4      '       dT   \        \        \        ,          \        \        V 4      ,          4      p\        V,          p\	        \        V4      VRR7      # \        RV  24      h)z0Parse list patterns: [[...]], [{...}], or [...].c              3  B   "   T F  p\        V\        4      x  K  	  R # 5iNrY   rg   .0items   & r"   	<genexpr>%_parse_list_syntax.<locals>.<genexpr>   s     9&$
4%%&   FTr'   rV   rW   rM   r7   r8   r(   rn   NrX   rl   c              3  B   "   T F  p\        V\        4      x  K  	  R # 5iru   rv   rw   s   & r"   rz   r{      s     9ST:dC((Sr|   z-Invalid list response_type format. Received: )lenrY   r)   allr   rZ   rp   r	   r'   r   r   tupler   r`   ro   )rr   r*   choice_literalwrappeds   &   r"   r\   r\      s}    	CAs1vt$$FFC9#a&9CCC9#a&999w'FCPQFCS(TUWI
 
 	
 3x1}CFD11c!ff*3q6Ew';(OPWI
 
 	
 ss9S9sss9S999 %)cGE#J4G$H'7)'2!
 	
 DSEJ
KKr%   c                    V ^8  d   QhRRRR/# rT   r    )r!   s   "r"   r#   r#      s      s | r%   c                J    \         V ,          p\        \        V4      VRR7      # )z.Parse list[X] type annotation -> multi-select.FrX   r   r   r`   rP   r   s   & r"   r]   r]      '    #M2G%g. r%   c                    V ^8  d   QhRRRR/# rT   r    )r!   s   "r"   r#   r#      s      c l r%   c                J    \         V ,          p\        \        V4      VRR7      # )z:Parse scalar types (bool, int, float, str, Literal, Enum).FrX   r   r   s   & r"   r_   r_      r   r%   c               $    V ^8  d   QhRRRRRR/# )r   configr   contentr   r   zAcceptedElicitation[Any]r    )r!   s   "r"   r#   r#   	  s$     8 88#&88r%   c                :   V P                   '       dH   \        V\        4      '       d   RV9  d   \        R4      h\        \
        ,          ! VR,          R7      # V P                  ew   \        V P                  4      pVP                  V4      p\        V\        4      '       d#   \        \
        ,          ! VP                  R7      # \        \
        ,          ! VR7      # V'       d   \        RV 24      h\        \        \        \
        3,          ,          ! / R7      # )zHandle an accepted elicitation response.

Args:
    config: The elicitation configuration from parse_elicit_response_type
    content: The response content from the client

Returns:
    AcceptedElicitation with the extracted/validated data
rM   z4Elicitation response missing required 'value' field.)rJ   z6Elicitation expected an empty response, but received: )rR   rY   rZ   ro   r   r   rP   r   validate_pythonr   rM   rg   )r   r   type_adaptervalidated_datas   &&  r"   handle_elicit_acceptr   	  s     }}}'4((G7,BSTT"3'WW-=>> '-f.B.BC%55g>n&;<<&s+1E1EFF"3'^<< DWIN
 	
 tCH~.B77r%   c               $    V ^8  d   QhRRRRRR/# )r   	enum_dictzdict[str, dict[str, str]]rm   rQ   r   rO   r    )r!   s   "r"   r#   r#   +  s$      (8<r%   c                    V'       d   RMRp. pV P                  4        F,  w  rEVP                  RV4      pVP                  RVRV/4       K.  	  W#/pV'       g   RVR&   V# )ab  Convert dict enum to SEP-1330 compliant schema pattern.

Args:
    enum_dict: {"low": {"title": "Low Priority"}, "medium": {"title": "Medium Priority"}}
    multi_select: If True, use anyOf pattern; if False, use oneOf pattern

Returns:
    {"type": "string", "oneOf": [...]} for single-select
    {"anyOf": [...]} for multi-select (used as array items)
r6   r5   titler9   stringr'   )r8   r:   append)r   rm   pattern_keypatternrM   metadatar   results   &&      r"   rp   rp   +  se     *'wKG$??,We,78 - *3F!vMr%   c                    V ^8  d   QhRRRR/# )r   rP   ztype[T]r   rO   r    )r!   s   "r"   r#   r#   D  s      ' n r%   c                p    \        V 4      P                  \        R7      p\        V4      p\	        V4       V# )z_Get the schema for an elicitation response.

Args:
    response_type: The type of the response
)schema_generator)r   json_schemar   r    validate_elicitation_json_schema)rP   r   s   & r"   r`   r`   D  s<     $M2>>. ? F V$F %V,Mr%   c                    V ^8  d   QhRRRR/# )r   r   rO   r   Noner    )r!   s   "r"   r#   r#   W  s     y y^ y yr%   c                   0 R mpV P                  R4      R8w  d   \        RV P                  R4       R24      hV P                  R/ 4      pVP                  4        EF  w  r4VP                  R4      p\        V\        4      '       d;   RV9   d3   V Uu. uF  qfR8w  g   K  VNK  	  pp\        V4      ^8X  d
   V^ ,          pMVP                  RR4      '       d   K  R	V9   d   K  R
V9   d   K  RV9   d   VR,          pVP                  R4      '       dO   VR,          pV P                  R/ 4      P                  V/ 4      p	R
V	9   d   K  V	P                  R4      p
W9   d   EK  \        RV RV R24      hRV9   g   RV9   dr   VP                  R. 4      VP                  R. 4      ,           pV F?  pR	V9   g   R
V9   d   K  VP                  R4      pW9  g   K,  \        RV RV RV R24      h	  EK  VR8X  d   VP                  R/ 4      pVP                  R4      R8X  d   \        RV R24      hR
V9   d   EK  RV9   g   RV9   do   VP                  R. 4      VP                  R. 4      ,           pV'       d>   \        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       d   EK]  \        RV R24      hVR8X  d   \        RV R24      hWQ9  g   EK  \        RV RV RV R24      h	  R# u upi )!a5  Validate that a JSON schema follows MCP elicitation requirements.

This ensures the schema is compatible with MCP elicitation requirements:
- Must be an object schema
- Must only contain primitive field types (string, number, integer, boolean)
- Must be flat (no nested objects or arrays of objects)
- Allows const fields (for Literal types) and enum fields (for Enum types)
- Only primitive types and their nullable variants are allowed

Args:
    schema: The JSON schema to validate

Raises:
    TypeError: If the schema doesn't meet MCP elicitation requirements
r'   rV   z7Elicitation schema must be an object schema, got type 'zR'. Elicitation schemas are limited to flat objects with primitive properties only.rW   nullnullableFr9   r(   z$refz#/$defs/:   NNz$defszElicitation schema field 'z' contains a reference 'z\' that could not be validated. Only references to enum types or primitive types are allowed.r5   r6   z' has union type 'z&' which is not a primitive type. Only z$ are allowed in elicitation schemas.r7   r8   z' is an array of objects, but arrays of objects are not allowed. Elicitation schemas must be flat objects with primitive properties only.c              3  ,   "   T F
  pR V9   x  K  	  R# 5i)r9   Nr    )rx   ss   & r"   rz   3validate_elicitation_json_schema.<locals>.<genexpr>  s     (M}!A}s   Tz' is an array, but arrays are only allowed when items are enums (for multi-select). Only enum arrays are supported in elicitation schemas.z|' is an object, but nested objects are not allowed. Elicitation schemas must be flat objects with primitive properties only.z' has type 'N>   numberr   booleaninteger)r:   	TypeErrorr8   rY   r)   r~   
startswithr   )r   ALLOWED_TYPESrW   	prop_nameprop_schema	prop_typetref_pathdef_nameref_defref_typeunion_schemasunion_schema
union_typer4   s   &              r"   r   r   W  si     ?M zz&X%EfjjQWFXEY Z^ ^
 	

 L"-J","2"2"4	OOF+	 i&&"(1A	1&[QQ		Ay>Q& )!I__Z// k! [  [ "6*H"":..#B< **Wb155hCW$";;v.,,YK7OPXz Zm m  k!W%;'OOGR8;??7TV;WWM -l*f.D)--f5
2#4YK?QR\Q] ^22?@df  !.  &??7B7L'830 <_ _  % ,&'\*A , 0 0" =@P@PRA ! !SS(M}(MSSS(M}(M%M%M ,YK 8r r   ,YK 8[ [  ),YK|I; O**78\^ w #5 Bs   K? K?N)r   r   r   r   r   r`   r   rb   )F)0
__future__r   dataclassesr   r(   r   typingr   r   r   r	   r
   mcp.server.elicitationr   r   pydanticr   pydantic.json_schemar   r   pydantic_corer   typing_extensionsr   fastmcp.utilities.json_schemar   fastmcp.utilities.loggingr   fastmcp.utilities.typesr   __all__r@   loggerr   r   r   r   r   rb   r^   r[   r\   r]   r_   r   rp   r`   r   r    r%   r"   <module>r      s    " !  : :  D % % 9 0 :	 
H	CA+. A+J)WQZ  GAJ     &R ,L^8D2&yr%   