
    Ch6                       S r SSKJr  SSKrSSKJrJrJr  SSKJ	r	J
r
Jr  SSKrSSKJrJrJrJr  SSKJrJr  SSKJr  SS	KJrJrJr  \	(       a  SS
KJr  SSKJr  SSKJ r J!r!   " S S\5      r" " S S\"5      r# " S S\"5      r$\\#\$-     " \#\$-  5      r%\&\"-  \'\&\
4   -  \\&\"-  \'\&\
4   -     -  r(\(\\(   -  r) " S S\5      r* " S S\5      r+g)z!Base classes for FastMCP prompts.    )annotationsN)	AwaitableCallableSequence)TYPE_CHECKINGAnyLiteral)	BaseModelFieldTypeAdaptervalidate_call)find_context_parameterinject_context)func_metadata)ContentBlockIconTextContent)Context)ServerSessionT)LifespanContextTRequestTc                  F   ^  \ rS rSr% SrS\S'   S\S'   S	U 4S jjrSrU =r$ )
Message   z#Base class for all prompt messages.Literal['user', 'assistant']roler   contentc                h   > [        U[        5      (       a
  [        SUS9n[        TU ]  " SSU0UD6  g )Ntexttyper   r    )
isinstancestrr   super__init__selfr   kwargs	__class__s      Y/home/james-whalen/.local/lib/python3.13/site-packages/mcp/server/fastmcp/prompts/base.pyr&   Message.__init__   s1    gs##!vG<G33F3    r"   r   zstr | ContentBlockr)   r   )	__name__
__module____qualname____firstlineno____doc____annotations__r&   __static_attributes____classcell__r*   s   @r+   r   r      s    -
&&4 4r-   r   c                  @   ^  \ rS rSr% SrSrS\S'   SU 4S jjrSrU =r	$ )	UserMessage"   zA message from the user.userr   r   c                *   > [         TU ]  " SSU0UD6  g Nr   r"   r%   r&   r'   s      r+   r&   UserMessage.__init__'       33F3r-   r"   r.   
r/   r0   r1   r2   r3   r   r4   r&   r5   r6   r7   s   @r+   r9   r9   "   s    ")/D
&/4 4r-   r9   c                  @   ^  \ rS rSr% SrSrS\S'   SU 4S jjrSrU =r	$ )	AssistantMessage+   zA message from the assistant.	assistantr   r   c                *   > [         TU ]  " SSU0UD6  g r=   r>   r'   s      r+   r&   AssistantMessage.__init__0   r@   r-   r"   r.   rA   r7   s   @r+   rC   rC   +   s    ')4D
&44 4r-   rC   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)PromptArgument:   z+An argument that can be passed to a prompt.zName of the argumentdescriptionr$   nameNz%Description of what the argument does
str | NonerL   Fz Whether the argument is requireddefaultrL   boolrequiredr"   )r/   r0   r1   r2   r3   r   rM   r4   rL   rR   r5   r"   r-   r+   rI   rI   :   s9    5"89D#9#D6]^K^56XYHdYr-   rI   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SS9r
S\S'   \" SS9rS\S'   \" SSS9rS\S'   \" SSSS9rS	\S'   \     S             SS jj5       r  S      S!S jjrSrg)"PromptB   z7A prompt template that can be rendered with parameters.zName of the promptrK   r$   rM   Nz"Human-readable title of the promptrN   titlez#Description of what the prompt doesrL   z*Arguments that can be passed to the promptzlist[PromptArgument] | None	argumentsT)exclude5Callable[..., PromptResult | Awaitable[PromptResult]]fnz&Optional list of icons for this promptrO   list[Icon] | Noneiconsz-Name of the kwarg that should receive context)rL   rX   context_kwargc           
        U=(       d    UR                   nUS:X  a  [        S5      eUc  [        U5      n[        UUb  U/O/ S9nUR                  R                  5       n	/ n
SU	;   aY  U	S   R                  5        HB  u  pXR                  S/ 5      ;   nU
R                  [        UUR                  S5      US95        MD     [        U5      nU " UUU=(       d    UR                  =(       d    SU
UUUS	9$ )
zCreate 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
z<lambda>z,You must provide a name for lambda functions)
skip_names
propertiesrR   rL   )rM   rL   rR    )rM   rV   rL   rW   rZ   r\   r]   )r/   
ValueErrorr   r   	arg_modelmodel_json_schemaitemsgetappendrI   r   r3   )clsrZ   rM   rV   rL   r\   r]   	func_namefunc_arg_metadata
parametersrW   
param_nameparamrR   s                 r+   from_functionPrompt.from_functionM   s   $ 'BKK	
"KLL  226M **7*C
 '00BBD
 +-	:%%/%=%C%C%E!
%
B)GG  "'$)IIm$<!) &F 2#7rzz7R'
 	
r-   c                p  #    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 R                  U=(       d    0 X R                  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                  [         R#                  U
5      5        Mg  [        U
[$        5      (       a$  ['        SU
S9nU	R                  [)        US95        M  [*        R,                  " U
[$        SS9R/                  5       nU	R                  [        SUS	95        M     U	$ s  snf  GN! [0         a    [	        S
U
 35      ef = f! [0         a   n[	        SU R                   SU 35      eSnAff = f7f)z!Render the prompt with arguments.zMissing required arguments: Nr   r    )r      )fallbackindentr;   )r   r   z,Could not convert prompt result to message: zError rendering prompt z: r"   )rW   rR   rM   setrb   r   rZ   r]   inspectiscoroutiner#   listtupler   rg   dictmessage_validatorvalidate_pythonr$   r   r9   pydantic_coreto_jsondecode	Exception)r(   rW   contextargrR   providedmissing	call_argsresultmessagesmsgr   es                r+   renderPrompt.render   s     >>,0NNKNSllNHK9?+H)G #?y!IJJ 	I&tww	RJ\J\]I WW)y)F""6**% fdUl33  ')H[!#w// ,#C.. (9(I(I#(NO#C--"-6"D G(DE"/"7"7cRS"T"["["] VW(MN  OI L &( ! [$'STWSX%YZZ[  	I6tyykA3GHH	Is    H6G%G%
/H6:AH	 G**H	 &G-(H	 *9G-#H	 %7G-H	 AG-H	 $H6*H	 -HH	 	
H3H..H33H6r"   )NNNNN)rZ   rY   rM   rN   rV   rN   rL   rN   r\   r[   r]   rN   returnrT   )NN)rW   zdict[str, Any] | Noner   z:Context[ServerSessionT, LifespanContextT, RequestT] | Noner   zlist[Message])r/   r0   r1   r2   r3   r   rM   r4   rV   rL   rW   rZ   r\   r]   classmethodrn   r   r5   r"   r-   r+   rT   rT   B   s    A"67D#7d0TUE:U#D6[\K\-24Eq-rI*r@Ed@SB=S$T?ghEh %d8gqu vM:v   "&#'$(9
A9
 9
 	9

  9
 !9
 "9
 
9
 9
z ,0NR.I(.I L.I 
	.I .Ir-   rT   ),r3   
__future__r   ru   collections.abcr   r   r   typingr   r   r	   r|   pydanticr
   r   r   r   .mcp.server.fastmcp.utilities.context_injectionr   r   *mcp.server.fastmcp.utilities.func_metadatar   	mcp.typesr   r   r   mcp.server.fastmcp.serverr   mcp.server.sessionr   mcp.shared.contextr   r   r   r9   rC   rz   r$   ry   SyncPromptResultPromptResultrI   rT   r"   r-   r+   <module>r      s    ' "  9 9 . .  A A a D 5 511=	4i 	44' 44w 4  .> >?N^@^_ =4S>1HS7]TRUWZRZ^=[4\\ ),<"==ZY ZuIY uIr-   