
    inF                    l   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 y)"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<   y	)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        /home/jay/workspace/.worktrees/task-2116-dev1/scripts/.codegraph-venv/lib/python3.12/site-packages/fastmcp/utilities/inspect.pyr   r      sf    #	H
I  +/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<   y)
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'   #   sU    %	H
I-1I*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<   y)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   se    '	H	H
 Iz )-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<   y)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   sq    0	H
 Iz (,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<   y)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   sR    8
I&&!!!!  r$   r2   c                  K   | j                          d{   }| j                          d{   }| j                          d{   }| j                          d{   }g }|D ]+  }|j	                  |j
                        }|j                  t        |j
                  |j                  xs |j
                  |j                  |j                  r|j                  ni |j                  |j                  r|j                  j                         nd|j                  rt        |j                        nd|j                   |j"                  |j$                  r(|j$                  D cg c]  }|j                          c}nd|j&                               . g }	|D ]  }
|	j                  t)        |
j
                  |
j                  xs |
j
                  |
j                  |
j*                  r(|
j*                  D cg c]  }|j                          c}nd|
j                  rt        |
j                        nd|
j                   |
j"                  |
j$                  r(|
j$                  D cg c]  }|j                          c}nd|
j&                  	              g }|D ]  }|j                  t-        |j
                  |j
                  |j                  |j                  |j.                  |j                  r|j                  j                         nd|j                  rt        |j                        nd|j                   |j"                  |j$                  r(|j$                  D cg c]  }|j                          c}nd|j&                                g }|D ]  }|j                  t1        |j
                  |j
                  |j                  |j                  |j.                  |j2                  |j                  r|j                  j                         nd|j                  rt        |j                        nd|j                   |j"                  |j$                  r(|j$                  D cg c]  }|j                          c}nd|j&                                ddid	d	d
dd	ii d}t5        | j6                  d      rH| j6                  j$                  r2| j6                  j$                  D cg c]  }|j                          c}nd}t5        | j6                  d      r| j6                  j8                  nd}t;        | j                  | j<                  t5        | d      r| j>                  n| j6                  j>                  ||t@        jB                  tD        jF                  j?                  d      d||	|||      S 7 7 7 q7 \c c}w c c}w c c}w c c}w c c}w c c}w w)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   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   r   r   r   r   r   r   r/   r   r   r,   r0   r   r   r   r   r   r   listChangedTF	subscriberD   r:   r<   r;   loggingr   r5   r4   mcp   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   
model_dumpr   listr   r   r   r   r'   r(   r*   r,   r.   r0   hasattr_mcp_serverr5   r2   r3   r4   fastmcp__version__	importlibmetadata)rI   
tools_listprompts_listresources_listtemplates_list
tool_infostoolmcp_tooliconprompt_infospromptargresource_infosresourcetemplate_infostemplater>   server_iconsserver_website_urls                      r%   inspect_fastmcp_v2rl   h   s     1133J5577L99;;NBBDDN J 
###2HHYY*$(( ,,5=5I5IX11r"00=A=M=MD,,779SW(,		T$))_tjj:: 6:ZZ@Tt(@YY	

* L 
JJ[[.FJJ"..## 8>7G7GH3>>+H*0++T&++&4ll<< 6<\\BTt(B[[	

( N" 
LLLL]]$00",,'' %00;;=,4MMT(--(t ((nn>> 6>^^DTt(D]]	

, N" 
LL%\\]]$00",,#..'' %00;;=,4MMT(--(t ((nn>> 6>^^DTt(D]]!	

0  &#(?!5)	L 3??G,1F1F (+'<'<=t	=  (/s'N##TX  XX%% 'Y 7S__=T=T&++&&..u5  ! c 47;D" A I C. E0 E" 	>s   WV1WV4WV7WV:DW#V= :A<W6WAW#W:C"WW 3C-W W"7A-W$W;B7W4W7W:W=Wc                h	  K   t        |       4 d{   }|j                          d{   }|j                          d{   }|j                          d{   }	 |j	                          d{   }g }|D ]  }|j                  t        |j                  |j                  |j                  |j                  r|j                  ni dddddt        |d      r4|j                  r(|j                  D cg c]  }|j                          c}ndd              g }	|D ]  }
d}t        |
d      r3|
j                  r'|
j                  D cg c]  }|j                          }}|	j                  t        |
j                  |
j                  |
j                  |dddt        |
d      r4|
j                  r(|
j                  D cg c]  }|j                          c}ndd	              g }|D ]  }|j                  t!        t#        |j$                        t#        |j$                        |j                  |j                  |j&                  ddddt        |d      r4|j                  r(|j                  D cg c]  }|j                          c}ndd              g }|D ]  }|j                  t)        t#        |j*                        t#        |j*                        |j                  |j                  |j&                  dddddt        |d      r4|j                  r(|j                  D cg c]  }|j                          c}ndd              dd	id
d
ddd
ii d}|j,                  j.                  }t        |d      r4|j                  r(|j                  D cg c]  }|j                          c}nd}t        |d      r|j0                  nd}t3        | j4                  j                  | j4                  j6                  | j4                  j8                  ||t:        j<                  t>        j@                  j9                  d      d||	|||      cddd      d{    S 7 J7 57  7 7 # t
        $ r g }Y w xY wc c}w c c}w c c}w c c}w c c}w c c}w 7 D# 1 d{  7  sw Y   yxY ww)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   r@   r(   rA   rB   rC   rD   TFrE   rG   
websiteUrlrI      rK   )!r
   
list_toolslist_promptslist_resourceslist_resource_templates	ExceptionrQ   r   r   r   rR   rU   r   rS   r(   r'   r*   r   r+   mimeTyper.   uriTemplateinitialize_result
serverInforn   r2   rV   r3   r4   rW   rX   rY   rZ   )rI   client	mcp_toolsmcp_promptsmcp_resourcesmcp_templatesr_   ra   rb   rc   
mcp_promptr(   re   rf   mcp_resourcerh   mcp_templater>   server_inforj   rk   s                        r%   inspect_fastmcp_v1r      sn     c{ E
 E
f ++--	"//11$3355	"("@"@"BBM
 
! 	H ! ( 4 49A9M9M!5!5SU"& $ x1hnn :BH4??,H	( % 	JIz;/J4H4H9C9M9MN#S^^-N	N"# * 6 6' z73
8H8H :D9I9IJ4??,J	. ) 	L!!L,,-L,,-%** , 8 8*33 $ |W5,:L:L :F9K9KL4??,L	( ) 	L!!L445!$\%=%=!>%** , 8 8*33# $ |W5,:L:L :F9K9KL4??,L	, $T*',UC%u-	
 ..99 {G,1B1B ,7+<+<=4T__= 	 '.k<&HK""d 	 %%55OO++*#//!**2259 $$%
oE
 E
 E
-15 C 	M	" I O K* M, M$ >_E
 E
 E
 E
s   R2QR2RQRQ"RQ%R Q+3Q(4Q+8A<R4Q="A RR"AR?RBR1R"BR$R$;ARR-BR
R2RR2R"R%R(Q++Q:6R9Q::!RR2R/#R&$R/+R2c                   K   t        | t              rt        |        d{   S t        t	        t
        t           |              d{   S 7 ,7 w)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)
isinstance	FastMCP1xr   rl   r   r	   r   )rI   s    r%   inspect_fastmcpr     sB      #y!',,,'WS\3(?@@@ -@s!   AA'A	A
AAc                      e Zd ZdZdZdZy)InspectFormatz"Output format for inspect command.rW   rI   N)r   r   r    r!   FASTMCPMCPr#   r$   r%   r   r     s    ,G
Cr$   r   c                \   | 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>   rW   rI   )serverenvironmentr:   r;   r<   r=   rJ   indent)r   r3   r4   r5   r   r9   r>   r6   r7   r:   r;   r<   r=   pydantic_coreto_json)inforesults     r%   format_fastmcp_infor     s     II --||++ZZ00 --
 ++##
 <<^^^^#F(   22r$   c           	     r  K   t        |       4 d{   }|j                          d{   }|j                          d{   }|j                          d{   }|j	                          d{   }|j
                  j                  }t        j                  t        j                  j                  d      d|i |j                  |j                  |j                  |j                  d}t!        j"                  |d      cddd      d{    S 7 7 7 7 7 7 # 1 d{  7  sw Y   yxY ww)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.
    NrI   r   )r   rx   r>   r:   r;   r<   resourceTemplatesrJ   r   )r
   list_tools_mcplist_prompts_mcplist_resources_mcplist_resource_templates_mcprw   rx   rW   rX   rY   rZ   r4   r:   r;   r<   r   r   r   )rI   ry   tools_resultprompts_resultresources_resulttemplates_resultr   r   s           r%   format_mcp_infor     s     c{ 7 7f#2244%6688!'!:!:!<<!'!C!C!EE ..99
 #.. ))11%8 &!''%--)33!1!C!C
 $$VA617 7 748<E7 7 7 7s   D7DD7D"DD"DD"DD"2D3BD"D7D D7D"D"D"D" D7"D4(D+)D40D7c                  K   t        |t              rt        |      }|t        j                  k(  rt	        |        d{   S |t        j
                  k(  r |t        |        d{   }t        |      S t        d|       7 E7 w)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)rI   formatr   s      r%   format_infor     s       &#v&"""$S)))	=((	( <(--D"4((+F8455 *
 .s"   =B	B 'B	'B(B	B	)rI   zFastMCP[Any]returnr2   )rI   r   r   r2   )rI   FastMCP[Any] | FastMCP1xr   r2   )r   r2   r   bytes)rI   r   r   r   )N)rI   r   r   z)InspectFormat | Literal['fastmcp', 'mcp']r   zFastMCPInfo | Noner   r   )!r!   
__future__r   importlib.metadatarY   dataclassesr   enumr   typingr   r   r   r   mcp.server.fastmcpr	   r   rW   r
   fastmcp.server.serverr   r'   r*   r.   r2   rl   r   r   r   r   r   r   r   r#   r$   r%   <module>r      s   1 "  !  % %  3   ) ' ' '  ' ' ' ' ' '  ' ' '" ! ! !$IXO
dA$C 3:7H  $6	!656 6 	6r$   