
    "<inF                       d Z ddlmZ ddlZddlmZ ddlmZ ddl	m
Z
mZmZ ddlZddlmZ ddlZddlmZ ddlmZ e G d	 d
                      Ze G d d                      Ze G d d                      Ze G d d                      Ze G d d                      Zd%dZd&dZd'dZ G d dee          Zd(dZd)d Z	 d*d+d$Z dS ),z+Utilities for inspecting FastMCP instances.    )annotationsN)	dataclass)Enum)AnyLiteralcast)FastMCP)Clientc                      e Zd ZU dZded<   ded<   ded<   ded<   d	Zd
ed<   d	Zd
ed<   d	Zded<   d	Zded<   d	Z	ded<   d	Z
ded<   d	Zd
ed<   d	S )ToolInfozInformation about a tool.strkeyname
str | Nonedescriptiondict[str, Any]input_schemaNdict[str, Any] | Noneoutput_schemar   list[str] | Nonetagsbool | Noneenabledtitlelist[dict[str, Any]] | Noneiconsmeta)__name__
__module____qualname____doc____annotations__r   r   r   r   r   r   r        /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/fastmcp/utilities/inspect.pyr   r      s         ##HHHIII    +/M////)-K----!D!!!!GE)-E----"&D&&&&&&r$   r   c                      e Zd ZU dZded<   ded<   ded<   dZded	<   dZd
ed<   dZded<   dZded<   dZ	ded<   dZ
ded<   dS )
PromptInfozInformation about a prompt.r   r   r   r   r   Nr   	argumentsr   r   r   r   r   r   r   r   )r   r   r    r!   r"   r(   r   r   r   r   r   r#   r$   r%   r'   r'   #   s         %%HHHIII-1I1111!D!!!!GE)-E----"&D&&&&&&r$   r'   c                      e Zd ZU dZded<   ded<   ded<   ded<   dZded	<   dZd
ed<   dZded<   dZded<   dZ	ded<   dZ
ded<   dZd
ed<   dS )ResourceInfozInformation about a resource.r   r   urir   r   r   N	mime_typer   r   r   r   r   r   r   r   r   r   )r   r   r    r!   r"   r,   r   r   r   r   r   r   r#   r$   r%   r*   r*   2   s         ''HHHHHH I    )-K----!D!!!!GE)-E----"&D&&&&&&r$   r*   c                      e Zd ZU dZded<   ded<   ded<   ded<   dZded	<   dZd
ed<   dZd
ed<   dZded<   dZ	ded<   dZ
ded<   dZded<   dZd
ed<   dS )TemplateInfoz&Information about a resource template.r   r   uri_templater   r   r   Nr,   r   
parametersr   r   r   r   r   r   r   r   r   )r   r   r    r!   r"   r,   r0   r   r   r   r   r   r   r#   r$   r%   r.   r.   C   s         00HHH I    (,J,,,,)-K----!D!!!!GE)-E----"&D&&&&&&r$   r.   c                      e Zd ZU dZded<   ded<   ded<   ded<   ded	<   ded
<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   dS )FastMCPInfoz.Information extracted from a FastMCP instance.r   r   r   instructionsversionwebsite_urlr   r   fastmcp_versionmcp_versionintserver_generationzlist[ToolInfo]toolszlist[PromptInfo]promptszlist[ResourceInfo]	resourceszlist[TemplateInfo]	templatesr   capabilitiesN)r   r   r    r!   r"   r#   r$   r%   r2   r2   U   s         88III&&&&!!!!!!!!      r$   r2   mcpFastMCP[Any]returnc                F  K   |                                   d{V }|                                  d{V }|                                  d{V }|                                  d{V }g }|D ]}|                    |j                  }|                    t          |j        |j        p|j        |j	        |j
        r|j
        ni |j        |j        r|j                                        nd|j        rt          |j                  nd|j        |j        |j        rd |j        D             nd|j                             g }|D ]}	|                    t)          |	j        |	j        p|	j        |	j	        |	j        rd |	j        D             nd|	j        rt          |	j                  nd|	j        |	j        |	j        rd |	j        D             nd|	j        	  	                   g }
|D ]}|
                    t-          |j        |j        |j        |j	        |j        |j        r|j                                        nd|j        rt          |j                  nd|j        |j        |j        rd |j        D             nd|j        	                     g }|D ]}|                    t1          |j        |j        |j        |j	        |j        |j        |j        r|j                                        nd|j        rt          |j                  nd|j        |j        |j        rd
 |j        D             nd|j                             ddidddddii d}t5          | j        d          r"| j        j        rd | j        j        D             nd}t5          | j        d          r| j        j        nd}t;          | j        | j        t5          | d          r| j        n| j        j        ||t@          j!        tD          j#                            d          d|||
||          S )zExtract information from a FastMCP v2.x instance.

    Args:
        mcp: The FastMCP v2.x instance to inspect

    Returns:
        FastMCPInfo dataclass containing the extracted information
    N)r   c                6    g | ]}|                                 S r#   
model_dump.0icons     r%   
<listcomp>z&inspect_fastmcp_v2.<locals>.<listcomp>   s"    @@@Tt((@@@r$   r   r   r   r   r   r   r   r   r   r   r   c                6    g | ]}|                                 S r#   rD   rG   args     r%   rI   z&inspect_fastmcp_v2.<locals>.<listcomp>   s"    HHH3>>++HHHr$   c                6    g | ]}|                                 S r#   rD   rF   s     r%   rI   z&inspect_fastmcp_v2.<locals>.<listcomp>   s"    BBBTt((BBBr$   	r   r   r   r(   r   r   r   r   r   c                6    g | ]}|                                 S r#   rD   rF   s     r%   rI   z&inspect_fastmcp_v2.<locals>.<listcomp>   "    DDDTt((DDDr$   r   r+   r   r   r,   r   r   r   r   r   r   c                6    g | ]}|                                 S r#   rD   rF   s     r%   rI   z&inspect_fastmcp_v2.<locals>.<listcomp>   rQ   r$   r   r/   r   r   r,   r0   r   r   r   r   r   r   listChangedTF	subscriberU   r:   r<   r;   loggingr   c                6    g | ]}|                                 S r#   rD   rF   s     r%   rI   z&inspect_fastmcp_v2.<locals>.<listcomp>   s"    ===t		===r$   r5   r4   r?      r   r3   r4   r5   r   r6   r7   r9   r:   r;   r<   r=   r>   )$_list_tools_middleware_list_prompts_middleware_list_resources_middleware#_list_resource_templates_middlewareto_mcp_toolr   appendr   r   r   inputSchemar   r   rE   r   listr   r   r   r   r'   r(   r*   r,   r.   r0   hasattr_mcp_serverr5   r2   r3   r4   fastmcp__version__	importlibmetadata)r?   
tools_listprompts_listresources_listtemplates_list
tool_infostoolmcp_toolprompt_infospromptresource_infosresourcetemplate_infostemplater>   server_iconsserver_website_urls                    r%   inspect_fastmcp_v2rz   h   s       1133333333J5577777777L99;;;;;;;;NBBDDDDDDDDN J 
 
###22HY*$( ,5=5IQX11r"0=A=MWD,77999SW(,	;T$)___tj:@@TZ@@@@Y  	
 	
 	
 	
& L 
 
J[.FJ".#HHv7GHHHH*0+?T&+&&&4l<BBV\BBBB[  	
 	
 	
 	
& N" 
 
LL]$0",'H0;;===,4MCT(-(((t (n>DDX^DDDD]  	
 	
 	
 	
* N" 
 
L%\]$0",#.'H0;;===,4MCT(-(((t (n>DDX^DDDD]!  	
 	
 	
 	
.  &#(??!5)	 L 3?G,,	141F	==s'<====  (/s'N'NX##TX  X% 'Y 7 7TS_=T&+&..u55  !   r$   	FastMCP1xc                F  K   t          |           4 d{V }|                                 d{V }|                                 d{V }|                                 d{V }	 |                                 d{V }n# t
          $ r g }Y nw xY wg }|D ]t}|                    t          |j        |j        |j	        |j
        r|j
        ni dddddt          |d          r|j        rd |j        D             ndd                     ug }|D ]}	d}
t          |	d          r|	j        rd |	j        D             }
|                    t          |	j        |	j        |	j	        |
dddt          |	d          r|	j        rd |	j        D             ndd	  	                   g }|D ]}|                    t          t!          |j                  t!          |j                  |j        |j	        |j        ddddt          |d          r|j        rd	 |j        D             ndd
                     g }|D ]}|                    t'          t!          |j                  t!          |j                  |j        |j	        |j        dddddt          |d          r|j        rd |j        D             ndd                     ddidddddii d}|j        j        }t          |d          r|j        rd |j        D             nd}t          |d          r|j        nd}t1          | j        j        | j        j        | j        j        ||t8          j        t<          j                            d          d|||||          cddd          d{V  S # 1 d{V swxY w Y   dS )zExtract information from a FastMCP v1.x instance using a Client.

    Args:
        mcp: The FastMCP v1.x instance to inspect

    Returns:
        FastMCPInfo dataclass containing the extracted information
    Nr   c                6    g | ]}|                                 S r#   rD   rF   s     r%   rI   z&inspect_fastmcp_v1.<locals>.<listcomp>  s"    HHH4??,,HHHr$   rJ   r(   c                6    g | ]}|                                 S r#   rD   rL   s     r%   rI   z&inspect_fastmcp_v1.<locals>.<listcomp>%  s"    NNN#S^^--NNNr$   c                6    g | ]}|                                 S r#   rD   rF   s     r%   rI   z&inspect_fastmcp_v1.<locals>.<listcomp>0  s"    JJJ4??,,JJJr$   rO   c                6    g | ]}|                                 S r#   rD   rF   s     r%   rI   z&inspect_fastmcp_v1.<locals>.<listcomp>E  "    LLL4??,,LLLr$   rR   c                6    g | ]}|                                 S r#   rD   rF   s     r%   rI   z&inspect_fastmcp_v1.<locals>.<listcomp>[  r   r$   rT   rU   TFrV   rX   c                6    g | ]}|                                 S r#   rD   rF   s     r%   rI   z&inspect_fastmcp_v1.<locals>.<listcomp>m  s"    ===4T__===r$   
websiteUrlr?      r\   ) r
   
list_toolslist_promptslist_resourceslist_resource_templates	Exceptionrb   r   r   r   rc   re   r   r(   r'   r*   r   r+   mimeTyper.   uriTemplateinitialize_result
serverInfor   r2   rf   r3   r4   rg   rh   ri   rj   )r?   client	mcp_toolsmcp_promptsmcp_resourcesmcp_templatesro   rq   rr   
mcp_promptr(   rt   mcp_resourcerv   mcp_templater>   server_inforx   ry   s                      r%   inspect_fastmcp_v1r      s      c{{ E
 E
 E
 E
 E
 E
 E
f ++--------	"//11111111$3355555555	"("@"@"B"BBBBBBBMM 	 	 	MMM	 
! 	 	H ! ( 49A9M!U!5!5SU"& $ x116>nHHHHHH     & % 	 	JIz;// OJ4H ONN9MNNN	"# * 6' z7338B8HJJ9IJJJJ     " ) 	 	L!!L,--L,--%* , 8*3 $ |W55:F:LLL9KLLLL     & ) 	 	L!!L455!$\%=!>!>%* , 8*3# $ |W55:F:LLL9KLLLL     * $T*',UCC%u-	
 
 .9 {G,,1<1B==;+<==== 	 '.k<&H&HRK""d 	 %5O+*#/!*22599 $$%
 
 
oE
 E
 E
 E
 E
 E
 E
 E
 E
 E
 E
 E
 E
 E
 E
 E
 E
 E
 E
 E
 E
 E
 E
 E
 E
 E
 E
 E
 E
 E
s7   AN(BNBNBK+N
NNFastMCP[Any] | FastMCP1xc                   K   t          | t                    rt          |            d{V S t          t	          t
          t                   |                      d{V S )a`  Extract information from a FastMCP instance into a dataclass.

    This function automatically detects whether the instance is FastMCP v1.x or v2.x
    and uses the appropriate extraction method.

    Args:
        mcp: The FastMCP instance to inspect (v1.x or v2.x)

    Returns:
        FastMCPInfo dataclass containing the extracted information
    N)
isinstancer{   r   rz   r   r	   r   )r?   s    r%   inspect_fastmcpr     si       #y!! A',,,,,,,,,'WS\3(?(?@@@@@@@@@r$   c                      e Zd ZdZdZdZdS )InspectFormatz"Output format for inspect command.rg   r?   N)r   r   r    r!   FASTMCPMCPr#   r$   r%   r   r     s        ,,G
CCCr$   r   infobytesc                    | j         | j        | j        | j        | j        | j        | j        d| j        | j        d| j	        | j
        | j        | j        d}t          j        |d          S )zFormat FastMCPInfo as FastMCP-specific JSON.

    This includes FastMCP-specific fields like tags, enabled, annotations, etc.
    )r   r3   r4   r5   r   
generationr>   rg   r?   )serverenvironmentr:   r;   r<   r=   r[   indent)r   r3   r4   r5   r   r9   r>   r6   r7   r:   r;   r<   r=   pydantic_coreto_json)r   results     r%   format_fastmcp_infor     s     I -|+Z0 -
 
 +#
 
 <^^# F(  2222r$   c           	        K   t          |           4 d{V }|                                 d{V }|                                 d{V }|                                 d{V }|                                 d{V }|j        j        }t          j        t          j
                            d          d|i |j        |j        |j        |j        d}t!          j        |d          cddd          d{V  S # 1 d{V swxY w Y   dS )zFormat server info as standard MCP protocol JSON.

    Uses Client to get the standard MCP protocol format with camelCase fields.
    Includes version metadata at the top level.
    Nr?   r   )r   r   r>   r:   r;   r<   resourceTemplatesr[   r   )r
   list_tools_mcplist_prompts_mcplist_resources_mcplist_resource_templates_mcpr   r   rg   rh   ri   rj   r4   r:   r;   r<   r   r   r   )r?   r   tools_resultprompts_resultresources_resulttemplates_resultr   r   s           r%   format_mcp_infor     s      c{{ 7 7 7 7 7 7 7f#2244444444%6688888888!'!:!:!<!<<<<<<<!'!C!C!E!EEEEEEE .9
 #. )11%88  &!'%-)3!1!C
 
 $VA66617 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7s   CC==
D
Dformat)InspectFormat | Literal['fastmcp', 'mcp']FastMCPInfo | Nonec                (  K   t          |t                    rt          |          }|t          j        k    rt	          |            d{V S |t          j        k    r&|t          |            d{V }t          |          S t          d|           )a0  Format server information according to the specified format.

    Args:
        mcp: The FastMCP instance
        format: Output format ("fastmcp" or "mcp")
        info: Pre-extracted FastMCPInfo (optional, will be extracted if not provided)

    Returns:
        JSON bytes in the requested format
    NzUnknown format: )	r   r   r   r   r   r   r   r   
ValueError)r?   r   r   s      r%   format_infor     s        &# 'v&&"""$S)))))))))	=(	(	( <(--------D"4(((4F44555r$   )r?   r@   rA   r2   )r?   r{   rA   r2   )r?   r   rA   r2   )r   r2   rA   r   )r?   r   rA   r   )N)r?   r   r   r   r   r   rA   r   )!r!   
__future__r   importlib.metadatari   dataclassesr   enumr   typingr   r   r   r   mcp.server.fastmcpr	   r{   rg   r
   fastmcp.server.serverr   r'   r*   r.   r2   rz   r   r   r   r   r   r   r   r#   r$   r%   <module>r      s   1 1 " " " " " "     ! ! ! ! ! !       % % % % % % % % % %     3 3 3 3 3 3        ) ) ) ) ) ) ' ' ' ' ' ' ' '  ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '  ' ' ' ' ' ' ' '" ! ! ! ! ! ! ! !$I I I IXO
 O
 O
 O
dA A A A$    C   3 3 3 3:7 7 7 7H  $6 6 6 6 6 6 6r$   