
    k7i7                       S r SSKJr  SSKrSSKrSSKJrJrJ	r	  SSK
Jr  SSKrSSKJrJrJrJrJr  SSKJr  SSKJr  SS	KJrJr  SS
KJr  SSKJr  SSKJr  SSK J!r!  SSK"J#r#  SSK$J%r%J&r&J'r'  \#" \(5      r) S       SS jjr*\\   " \5      r+\,\-  \-\,\4   -  \	\,\-  \-\,\4   -     -  r.\.\\.   -  r/ " S S\%5      r " S S\5      r " S S\5      r0g)z!Base classes for FastMCP prompts.    )annotationsN)	AwaitableCallableSequence)Any)ContentBlockIconPromptMessageRoleTextContent)Prompt)PromptArgument)FieldTypeAdapter)PromptError)get_context)FastMCPComponent)compress_schema)
get_logger)FastMCPBaseModelfind_kwarg_by_typeget_cached_typeadapterc                d    [        U [        5      (       a
  [        SU S9n Uc  Sn[        SXS.UD6$ )z.A user-friendly constructor for PromptMessage.texttyper   user)contentrole )
isinstancestrr   r
   )r   r   kwargss      P/home/james-whalen/.local/lib/python3.13/site-packages/fastmcp/prompts/prompt.pyMessager%      s:     '368|>>v>>    c                  `    \ rS rSr% Sr\" SS9rS\S'   \" SSS	9rS
\S'   \" SSS	9r	S\S'   Sr
g)r   4   z+An argument that can be passed to a prompt.zName of the argument)descriptionr"   nameNz%Description of what the argument doesdefaultr)   
str | Noner)   Fz Whether the argument is requiredboolrequiredr    )__name__
__module____qualname____firstlineno____doc__r   r*   __annotations__r)   r/   __static_attributes__r    r&   r$   r   r   4   sE    5"89D#9#"IK  #EHd r&   r   c                     ^  \ rS rSr% Sr\" SSS9rS\S'   SU 4S jjrSU 4S	 jjr	SS
.     SS jjr
\       S                 SS jj5       r S   SS jjrSrU =r$ )r   @   z7A prompt template that can be rendered with parameters.Nz*Arguments that can be passed to the promptr+   zlist[PromptArgument] | None	argumentsc                x   > [         TU ]  5          [        5       nUR                  5         g ! [         a     g f = fN)superenabler   _queue_prompt_list_changedRuntimeErrorselfcontext	__class__s     r$   r=   Prompt.enableG   s7    	!mG..0 		   , 
99c                x   > [         TU ]  5          [        5       nUR                  5         g ! [         a     g f = fr;   )r<   disabler   r>   r?   r@   s     r$   rG   Prompt.disableO   s7    	!mG..0 		rE   include_fastmcp_metac                  U R                   =(       d    /  Vs/ s H,  n[        UR                  UR                  UR                  S9PM.     nn[        UR                  SU R                  5      UR                  SU R                  5      UUR                  SU R                  5      UR                  SU R                  5      UR                  SU R                  US95      S9$ s  snf )	z$Convert the prompt to an MCP prompt.r*   r)   r/   r*   r)   titleicons_metarI   )r*   r)   r9   rM   rN   rO   )
r9   MCPPromptArgumentr*   r)   r/   	MCPPromptgetrM   rN   get_meta)rA   rJ   	overridesargr9   s        r$   to_mcp_promptPrompt.to_mcp_promptW   s     ~~++
 , XXOO
 , 	 
 vtyy1!mT5E5EF--4--4--<PQ	
 		

s   3C c                6    [         R                  U UUUUUUUS9$ )Create a Prompt from a function.

The function can return:
- A string (converted to a message)
- A Message object
- A dict (converted to a message)
- A sequence of any of the above
fnr*   rM   r)   rN   tagsenabledmeta)FunctionPromptfrom_functionrZ   s           r$   r`   Prompt.from_functionr   s4    & ++# , 	
 		
r&   c                    #    [        S5      e7f)zRender the prompt with arguments.

This method is not implemented in the base Prompt class and must be
implemented by subclasses.
z"Subclasses must implement render())NotImplementedError)rA   r9   s     r$   renderPrompt.render   s      ""FGGs   r    )returnNone)rJ   bool | NonerT   r   rf   rQ   NNNNNNNr[   5Callable[..., PromptResult | Awaitable[PromptResult]]r*   r-   rM   r-   r)   r-   rN   zlist[Icon] | Noner\   zset[str] | Noner]   rh   r^   dict[str, Any] | Nonerf   r_   r;   r9   rl   rf   zlist[PromptMessage])r0   r1   r2   r3   r4   r   r9   r5   r=   rG   rV   staticmethodr`   rd   r6   __classcell__)rC   s   @r$   r   r   @   s    A-2"N.I*  -1
 *
 	

 

6    "&#' $#&*
A

 
  	

 !
 
 
 $
 

 
> ,0	H(	H 
	H 	Hr&   r   c                      \ rS rSr% SrS\S'   \       S
                 SS jj5       rSS jr S   SS jjr	S	r
g)r_      zA prompt that is a function.rk   r[   Nc	                   SSK Jn	  U=(       d*    [        USS5      =(       d    UR                  R                  n
U
S:X  a  [        S5      e[        R                  " U5      nUR                  R                  5        Hi  nUR                  [        R                  R                  :X  a  [        S5      eUR                  [        R                  R                  :X  d  M`  [        S5      e   U=(       d    [        R                  " U5      n[        R                  " U5      (       d  UR                   n[#        U[$        5      (       a  UR&                  n[)        U5      nUR+                  5       n[-        XS	9nU(       a  U/OSn[/        UUS
9n/ nSU;   Ga  US   R1                  5        H  u  nnUR3                  S5      nUUR                  ;   a  UR                  U   nUR4                  [        R                  R6                  :w  ak  UR4                  [8        LaX  UU:w  aR   [)        UR4                  5      nUR+                  5       n[:        R<                  " USS9nSU 3nU(       a  U SU 3nOUn URA                  [C        UUUUR3                  S/ 5      ;   S95        M     U " U
UUUUU=(       d
    [E        5       Ub  UOSUUS9	$ ! [>         a     Naf = f)rY   r   Contextr0   Nz<lambda>z,You must provide a name for lambda functionsz1Functions with *args are not supported as promptsz4Functions with **kwargs are not supported as prompts
kwarg_type)prune_params
propertiesr)   ),:)
separatorsz8Provide as a JSON string matching the following schema: z

r/   rL   T)	r*   rM   r)   rN   r9   r\   r]   r[   r^   )#fastmcp.server.contextrt   getattrrC   r0   
ValueErrorinspect	signature
parametersvalueskind	ParameterVAR_POSITIONALVAR_KEYWORDgetdoc	isroutine__call__r!   rn   __func__r   json_schemar   r   itemsrR   
annotationemptyr"   jsondumps	Exceptionappendr   set)clsr[   r*   rM   r)   rN   r\   r]   r^   rt   	func_namesigparamtype_adapterr   context_kwargrw   r9   
param_namearg_description	sig_paramparam_adapterparam_schema
schema_strschema_notes                            r$   r`   FunctionPrompt.from_function   s   ( 	3RGB
D9RR\\=R=R	
"KLL#^^**,EzzW..=== !TUUzzW..::: !WXX	 - "7W^^B%7   $$Bb,''B-b1!--/
 +2B*7T$ZlK
 +-	:%%/%=%C%C%E!
E"'))M": / #z :I!,,0A0A0G0GG%00;&-7!,B9CWCW,XM+8+D+D+FL *.LZ)XJ -eeodp*qK.5D4ET+2W2=
   "'$3!+z~~j"/M!M= &FL #&2G

 
	
  ) ! !s   AK+K
KKc                   SSK Jn  [        R                  " U R                  5      n0 n[        U R                  US9nUR                  5        H  u  pgXcR                  ;   a  UR                  U   nXe:X  a  XtU'   M.  UR                  [        R                  R                  :X  d(  UR                  [        L d  [        U[        5      (       d  XtU'   M   [        UR                  5      n	 U	R                  U5      XF'   M  XtU'   M     U$ ! [        [         ["        R$                  4 a    U	R'                  U5      XF'    M  f = f! [        [         ["        R$                  4 a'  n
[)        SU SU SUR                   SU
 35      U
eSn
A
ff = f)	zGConvert string arguments to expected types based on function signature.r   rs   ru   zCould not convert argument 'z' with value 'z' to expected type z	. Error: N)r|   rt   r   r   r[   r   r   r   r   r   r   r"   r!   r   validate_jsonr~   	TypeErrorpydantic_coreValidationErrorvalidate_pythonr   )rA   r#   rt   r   converted_kwargscontext_param_namer   param_valuer   adapteres              r$   _convert_string_arguments(FunctionPrompt._convert_string_arguments  s   2( 0GL'-||~#J^^+z2 33>Z0 $$(9(9(?(??''3.#K553>Z0!"89I9I"J;B;P;P +<,8  0;,K (6N   !+I}7T7TU ;B;R;R +<,8
 '	=3P3PQ !)::,nU`Ta b0050@0@/A1#O  !!!s6   E (D2D=9E <D==E  F"FFc                  #    SSK Jn  U R                  (       ae  U R                   Vs1 s H!  o3R                  (       d  M  UR                  iM#     nn[        U=(       d    0 5      nXE-
  nU(       a  [        SU 35      e U(       a  UR                  5       O0 n[        U R                  US9nU(       a  X;  a  [        5       Xx'   U R                  U5      nU R                  " S0 UD6n	[        R                  " U	5      (       a
  U	I Sh  vN n	[        U	[        [         -  5      (       d  U	/n	/ n
U	 H  n [        U["        5      (       a  U
R%                  U5        M,  [        U[&        5      (       a#  U
R%                  [#        S[)        SUS9S	95        Md  [*        R,                  " U[&        S
9R/                  5       nU
R%                  [#        S[)        SUS9S	95        M     U
$ s  snf  N! [0         a  n[3        S5      UeSnAff = f! [0         aA  n[4        R7                  SU R                   35        [3        SU R                   S35      UeSnAff = f7f)z!Render the prompt with arguments.r   rs   zMissing required arguments: ru   Nr   r   r   )r   r   )fallbackz+Could not convert prompt result to message.zError rendering prompt .r    )r|   rt   r9   r/   r*   r   r~   copyr   r[   r   r   r   isawaitabler!   listtupler
   r   r"   r   r   to_jsondecoder   r   logger	exception)rA   r9   rt   rU   r/   providedmissingr#   r   resultmessagesmsgr   r   s                 r$   rd   FunctionPrompt.render>  s
    
 	3 >>,0NNKNSllNHK9?+H)G #?y!IJJ0	M)2Y^^%F.tww7KM!<(3% 33F;F WW&v&F""6**% fdUl33  -/H!#}55 ,#C-- )%+(3c(J #0"7"7c"J"Q"Q"S )%+(3g(N 0 Og L& &6 ! %E  	M6tyykBC 7		{!DE1L	Ms   &IG" G"/I BH G'	*H 4&G)H 6G)H AG)H !I'H )
H3G??HH 
I<IIIr    ri   rj   )r#   dict[str, Any]rf   r   r;   rm   )r0   r1   r2   r3   r4   r5   classmethodr`   r   rd   r6   r    r&   r$   r_   r_      s    &==   "&#' $#&*g
Ag
 g
 	g

  g
 !g
 g
 g
 $g
 
g
 g
R1 j ,0?M(?M 
?M ?Mr&   r_   r;   )r   zstr | ContentBlockr   zRole | Noner#   r   rf   r
   )1r4   
__future__r   _annotationsr   r   collections.abcr   r   r   typingr   r   	mcp.typesr   r	   r
   r   r   r   rQ   r   rP   pydanticr   r   fastmcp.exceptionsr   fastmcp.server.dependenciesr   fastmcp.utilities.componentsr   fastmcp.utilities.json_schemar   fastmcp.utilities.loggingr   fastmcp.utilities.typesr   r   r   r0   r   r%   message_validatorr"   dictSyncPromptResultPromptResultr_   r    r&   r$   <module>r      s   ' 2   9 9   J J ) 9 ' * 3 9 9 0  
H	 6:??'2?EH??  .}=  
38n s]"T#s(^345   ),<"==	% 	YH YHxaMV aMr&   