
    kKjD                    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<   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titlelist[dict[str, Any]] | Noneiconsmeta)__name__
__module____qualname____doc____annotations__r   r   r   r   r   r        j/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/fastmcp/utilities/inspect.pyr   r      s\    #	H
I  +/M(/)-K&-!D
!E:)-E&-"&D
&r"   r   c                  v    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<   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%   "   sK    %	H
I-1I*1!D
!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<   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(   0   s[    '	H	H
 Iz )-K&-!D
!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)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   r   r   r   r   r!   r"   r#   r,   r,   @   sg    0	H
 Iz (,J%,)-K&-!D
!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#   r0   r0   Q   sR    8
I&&!!!!  r"   r0   c                t  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"                  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"                  r(|
j"                  D cg c]  }|j                          c}nd|
j$                                g }|D ]  }|j                  t+        |j                  t-        |j.                        |j
                  |j                  |j0                  |j                  r|j                  j                         nd|j                  rt        |j                        nd|j                   |j"                  r(|j"                  D cg c]  }|j                          c}nd|j$                  
              g }|D ]  }|j                  t3        |j                  |j4                  |j
                  |j                  |j0                  |j6                  |j                  r|j                  j                         nd|j                  rt        |j                        nd|j                   |j"                  r(|j"                  D cg c]  }|j                          c}nd|j$                                ddid	d	d
dd	ii d}t9        | j:                  d      rH| j:                  j"                  r2| j:                  j"                  D cg c]  }|j                          c}nd}t9        | j:                  d      r| j:                  j<                  nd}t?        | j
                  | j@                  t9        | d      r| jB                  n| j:                  jB                  ||tD        jF                  tH        jJ                  jC                  d      d||	|||      S 7 x7 c7 N7 9c 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   r   r   r   listChangedTF	subscriberB   r8   r:   r9   loggingr   r3   r2   mcp   r   r1   r2   r3   r   r4   r5   r7   r8   r9   r:   r;   r<   )&
list_toolslist_promptslist_resourceslist_resource_templatesto_mcp_toolr   appendr   r   r   inputSchemar   r   
model_dumpr   listr   r   r   r%   r&   r(   r   r)   r*   r,   r-   r.   hasattr_mcp_serverr3   r0   r1   r2   fastmcp__version__	importlibmetadata)rG   
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_v2rj   d   s     ~~''J))++L--//N6688N J###3HHYY*$(( ,,5=5I5IX11r"00=A=M=MD,,779SW(,		T$))_tjj:: 6:ZZ@ZTt(Z@YY	
 ( LJJ[[.FJJ"..## 8>7G7GH7G3>>+7GH*0++T&++&4ll<< 6<\\B\Tt(\B[[	
 & N"LL%]]$00",,'' %00;;=,4MMT(--(tnn>> 6>^^D^Tt(^D]]	
 #* N"LL%22]]$00",,#..'' %00;;=,4MMT(--(tnn>> 6>^^D^Tt(^D]]	
 #.  &#(?!5)	L 3??G,1F1F (+'<'<='<t	'<=  (/s'N##TX  XX%% 'Y 7S__=T=T&++&&..u5  ! [ (+/8  A I
 C, E. E" 	>s   V8VV8VV8VV8VC9V8V/A<V8+VAV8V$$C V8V)C"V8=V. A-V8V3B7V8V8V8V8V8c                `	  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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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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              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 F7 17 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&   r?   r@   rA   rB   TFrC   rE   
websiteUrlrG      rI   )!r
   rJ   rK   rL   rM   	ExceptionrO   r   r   r   rP   rS   r   rQ   r&   r%   r(   r   r)   mimeTyper,   uriTemplateinitialize_result
serverInforl   r0   rT   r1   r2   rU   rV   rW   rX   )rG   client	mcp_toolsmcp_promptsmcp_resourcesmcp_templatesr]   r_   r`   ra   
mcp_promptr&   rc   rd   mcp_resourcerf   mcp_templater<   server_inforh   ri   s                        r#   inspect_fastmcp_v1r|      sM     c{{f ++--	"//11$3355	"("@"@"BBM
 
!H ! ( 4 49A9M9M!5!5SU"& $x1hnn :BH4??,H "& %JIz;/J4H4H9C9M9MN9M#S^^-9M	N"# * 6 6'z73
8H8H :D9I9IJ9I4??,9IJ &, )L!!L,,-L,,-%** , 8 8*33 $|W5,:L:L :F9K9KL9K4??,9KL *& )L!!L445!$\%=%=!>%** , 8 8*33# $|W5,:L:L :F9K9KL9K4??,9KL ** $T*',UC%u-	
 ..99 {G,1B1B ,7+<+<=+<4T__+<= 	 '.k<&HK""d 	 %%55OO++*#//!**2259 $$%
g {{-15 C 	M	  I O K( M* M$ >W {{{s   R.QR.RQRQRQ!R Q'3Q$4Q'8A;R3Q9 
A R
Q>!AR=RBR.R BR R"7ARR)BRR.RR.RR!R$Q''Q62R5Q66!RR.R+R" R+'R.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|   rj   r   r	   r   )rG   s    r#   inspect_fastmcpr   z  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.rU   rG   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   r1   r2   r3   r   
generationr<   rU   rG   )serverenvironmentr8   r9   r:   r;   rH   indent)r   r1   r2   r3   r   r7   r<   r4   r5   r8   r9   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.
    NrG   r   )r   rr   r<   r8   r9   r:   resourceTemplatesrH   r   )r
   list_tools_mcplist_prompts_mcplist_resources_mcplist_resource_templates_mcprq   rr   rU   rV   rW   rX   r2   r8   r9   r:   r   r   r   )rG   rs   tools_resultprompts_resultresources_resulttemplates_resultr{   r   s           r#   format_mcp_infor     s      c{{f#2244%6688!'!:!:!<<!'!C!C!EE ..99
 #.. ))11%8 &!''%--)33!1!C!C
 $$VA61 {{48<E {{{s   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)rG   formatr   s      r#   format_infor     s       &#v&"""$S)))	=((	( <(--D"4((+F8455 *
 .s"   =B	B 'B	'B(B	B	)rG   zFastMCP[Any]returnr0   )rG   r   r   r0   )rG   FastMCP[Any] | FastMCP1xr   r0   )r   r0   r   bytes)rG   r   r   r   )N)rG   r   r   z)InspectFormat | Literal['fastmcp', 'mcp']r   zFastMCPInfo | Noner   r   )!r   
__future__r   importlib.metadatarW   dataclassesr   enumr   typingr   r   r   r   mcp.server.fastmcpr	   r   rU   r
   fastmcp.server.serverr   r%   r(   r,   r0   rj   r|   r   r   r   r   r   r   r!   r"   r#   <module>r      s   1 "  !  % %  3   ) ' ' ' 
' 
' 
' ' ' ' ' ' '  ! ! !$EPK
\A$C 3:7H  $6	!656 6 	6r"   