
    kKj                      	   U d Z ddlZddlZddlZddlZddlmZ ddlmZm	Z	m
Z
 ddl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mZmZ dd	lmZ dd
lmZ ddlmZ ddl m!Z! ddl"m#Z# ddl$m%Z%  e%d      Z& e       Z'ddddddddZ(e)e*e*f   e+d<   dddde*dz  de*dz  de*dz  de*e)e*e	f   z  ez  fdZ,de*de#fd Z-d!ede*e)e*e	f   z  fd"Z.d#e*e)e*e	f   z  ez  de/fd$Z0d%e*d&e1e	   dz  d'e	d(e	dee)e*e	f      f
d)Z2ddd*d#e*e)e*e	f   z  ez  d+e3dz  d,e*dz  defd-Z4d.e*d/e)e*e	f   de	fd0Z5d1e6e*d2f   d3e*dz  d4e)e*e	f   de)e*e	f   fd5Z7d/e)e*e	f   de*fd6Z8d7ejr                  jt                  de*fd8Z;d9e*d/e)e*e	f   ddfd:Z<d;e*de*fd<Z=d=eddfd>Z>d?ejr                  j~                  de)e*e	f   fd@Z@d=ede)e*e	f   fdAZAdBeBejr                  jt                     deBe)e*e	f      fdCZCdDedEe*dFe6e*d2f   d3e*dz  dGe/ddfdHZDdDedIe*dGe/ddfdJZEdDedKe*dFe6e*d2f   d3e*dz  dGe/ddfdLZF	 dydddMdMdMdMdMdddN	dee*dz   ej                  dOP      f   dee*dz   ej                  dQdRP      f   dee
dS   dz   ej                  dTdUgdVW      f   dXee/ ej                  dYdZP      f   d[ee/ ej                  d\d]P      f   d4ee/ ej                  d^d_P      f   d`ee/ ej                  dadbP      f   dGee/ ej                  dcddP      f   d+ee3dz   ej                  dedfP      f   d,ee*dz   ej                  dgdhP      f   ddfdiZH	 	 dzdddMddMdddjdee*dz   ej                  dOP      f   dkee* ej                  dlP      f   dFe*dee*dz   ej                  dQdRP      f   dee
dS   dz   ej                  dTdUgdVW      f   dmee/ ej                  dndoP      f   d3ee*dz   ej                  dpdqP      f   dGee/ ej                  dcdrP      f   d+ee3dz   ej                  dedfP      f   d,ee*dz   ej                  dgdhP      f   ddfdsZIddMdtdueeBe*   dz   ej                  dvdwP      f   dGee/ ej                  dcddP      f   ddfdxZJy){z?Client-side CLI commands for querying and invoking MCP servers.    N)Path)	AnnotatedAnyLiteral)Console)escape)DiscoveredServerdiscover_serversresolve_name)CallToolResultClient)ElicitResult)ClientTransport)StreamableHttpTransport)SSETransport)StdioTransport)
get_loggerz
cli.clientstrintfloatboollistdictNone)stringintegernumberbooleanarrayobjectnull_JSON_SCHEMA_TYPE_MAPcommand	transportserver_specr$   r%   returnc                d   |,| *t         j                  d       t        j                  d       |t	        |      S | *t         j                  d       t        j                  d       t        | t              sJ | }|j                  d      r;|dk(  r4|j                  d      j                  d      s|j                  d      dz   }|S t        |      }|j                         xs$ |j                          xr |j                  d	      }|rX|j                  d
      rt        |      S |j                  d      r)|j                         }t        ddt        |      dg      S |S 	 t!        |      S # t"        $ r7}t         j                  d|        t        j                  d       Y d}~yd}~ww xY w)ur  Turn CLI inputs into something ``Client()`` accepts.

    Exactly one of ``server_spec`` or ``command`` should be provided.

    Resolution order for ``server_spec``:
    1. URLs (``http://``, ``https://``) — passed through as-is.
       If ``--transport`` is ``sse``, the URL is rewritten to end with ``/sse``
       so ``infer_transport`` picks the right transport.
    2. Existing file paths, or strings ending in ``.py``/``.js``/``.json``.
    3. Anything else — name-based resolution via ``resolve_name``.

    When ``command`` is provided, the string is shell-split into a
    ``StdioTransport(command, args)``.
    NzG[bold red]Error:[/bold red] Cannot use both a server spec and --command   zB[bold red]Error:[/bold red] Provide a server spec or use --commandzhttp://zhttps://sse/z/sse).pyz.js.jsonr.   r-   fastmcprunz--no-bannerr$   args[bold red]Error:[/bold red] )consoleprintsysexit_build_stdio_from_command
isinstancer   
startswithrstripendswithr   is_fileis_dir_resolve_json_specresolver   r   
ValueError)r&   r$   r%   specpathr=   resolved_pathexcs           c/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/fastmcp/cli/client.pyresolve_server_specrG   +   s   * {6U	
 	(11P	
 	k3'''D ./dkk#&6&?&?&G;;s#f,D :Dlln KKMDdmm,CD  ==!%d++== LLNM!!S/? 
 D!! 4SE:;s   $
E/ /	F/8-F**F/command_strc                 2   	 t        j                  |       }s*t        j	                  d       t        j                  d       t        |d   |dd       S # t        $ r7}t        j	                  d|        t        j                  d       Y d}~zd}~ww xY w)z7Shell-split a command string into a ``StdioTransport``.z-[bold red]Error:[/bold red] Invalid command: r)   Nz+[bold red]Error:[/bold red] Empty --commandr   r1   )shlexsplitrA   r4   r5   r6   r7   r   )rH   partsrE   s      rF   r8   r8   s   s|    K(
 CD%(qr;;  EcUKLs   A 	B-BBrC   c                    | j                         s.t        j                  d|  d       t        j                  d       	 t        j                  | j                               }t        t              rd|v r|S t        j                  d|  d	|  d
       t        j                  d       y# t
        j                  $ r:}t        j                  d|  d|        t        j                  d       Y d}~d}~ww xY w)z%Disambiguate a ``.json`` server spec.z2[bold red]Error:[/bold red] File not found: [cyan][/cyan]r)   z,[bold red]Error:[/bold red] Invalid JSON in : N
mcpServersz"[bold red]Error:[/bold red] [cyan]zl[/cyan] is a FastMCP server config, not an MCPConfig.
Start the server first, then query it:

  fastmcp run z*
  fastmcp list http://localhost:8000/mcp
)existsr4   r5   r6   r7   jsonloads	read_textJSONDecodeErrorr9   r   )rC   datarE   s      rF   r?   r?      s     ;;=@gN	
 	zz$..*+
 $,$"6 MM
,TF 3 5	6 HHQK  DTF"SERSs    #B+ +C8>0C33C8resolvedc                 p    t        | t              r| j                  d      S t        | t        t        f      S )zReturn True if the resolved target will use an HTTP-based transport.

    MCPConfig dicts are excluded because ``MCPConfigTransport`` manages
    individual server transports internally and does not support top-level auth.
    r*   )r9   r   r:   r   r   )rW   s    rF   _is_http_targetrY      s3     (C ""#:;;h!8, GHH    messageresponse_typeparamscontextc                 v  K   ddl m} t        j                  d|         t	        ||      s|t        j                  d      }|j                         j                         dk(  rt        d      S |j                         j                         dk(  rt        d      S t        di 	      S |j                  }|j                  d
i       }t        |j                  dg             }|s|t        j                  d      }|j                         j                         dk(  rt        d      S |j                         j                         dk(  rt        d      S t        di 	      S i }	|j                         D ]  \  }
}|j                  dd      }|
|v rdnd}d|
 d| d| d}t        j                  |      }|j                         j                         dk(  rt        d      c S |j                         j                         dk(  rt        d      c S |dk(  r|
|vrt        ||      |	|
<    t        d|		      S w)zPrompt the user on the terminal for elicitation responses.

    Prints the server's message and prompts for each field in the schema.
    The user can type 'decline' or 'cancel' instead of a value to abort.
    r   )ElicitRequestFormParamsz)
[bold yellow]Server asks:[/bold yellow] z7[dim](press Enter to accept, or type 'decline'):[/dim] decline)actioncancelaccept)rb   content
propertiesrequiredtyper   z [red]*[/red]   [cyan]z	[/cyan] ()rO   )	mcp.typesr`   r4   r5   r9   inputstriplowerr   requestedSchemagetsetitemscoerce_value)r[   r\   r]   r^   r`   answerschemarf   rg   result
field_namefield_schema	type_hint
req_markerprompt_textraws                   rF   _terminal_elicitation_handlerr~      s     2MM>wiHIf56E
 <<>!Y.y11<<>!X-x008R88##FL"-J6::j"-.HE
 <<>!Y.y11<<>!X-x008R88F$.$4$4$6 
L $$VX6	(2h(>_B
 Ii[*RPmmK(99;)+y1199;(*x00"983)#|<z %7  x88s   H7H9timeoutauthr   r   c                b    |dk(  rd}n||}nt        |       rd}nd}t        | ||t              S )a'  Build a ``Client`` from a resolved server spec.

    Applies ``auth='oauth'`` automatically for HTTP-based targets unless
    the caller explicitly passes ``--auth none`` to disable it.

    ``auth=None`` means "not specified" (use default), ``auth="none"``
    means "explicitly disabled".
    noneNoauth)r   r   elicitation_handler)rY   r   r~   )rW   r   r   effective_auths       rF   _build_clientr      sF     v~%)				" 9	 rZ   r}   rv   c                    |j                  dd      }|dk(  r	 t        |       S |dk(  r	 t        |       S |dk(  r4| j	                         d	v ry
| j	                         dv ryt        d|       |dv r	 t        j                  |       S | S # t        $ r t        d|       dw xY w# t        $ r t        d|       dw xY w# t
        j                  $ r t        d| d|       dw xY w)z?Coerce a string CLI value according to a JSON-Schema type hint.rh   r   r   zExpected integer, got Nr   zExpected number, got r   )true1yesT)false0noFzExpected boolean, got )r   r    zExpected JSON z, got )rq   r   rA   r   ro   rR   rS   rU   )r}   rv   schema_types      rF   rt   rt     s+    **VX.Ki	Is8O h	H: i99;..99;..1#9::))	T::c?"
 J/  	I5cW=>DH	I  	H4SG<=4G	H ## 	T~k]&HItS	Ts"   
B
 
B& 3C 
B#&B?&C(raw_args.
input_jsoninput_schemac                 R   t        |       dk(  r| d   j                  d      r	|| d   }d} i }|a	 t        j                  |      }t        t              s*t
        j                  d       t        j                  d       |j                  |       |j                  di       }| D ]k  }d	|vr.t
        j                  d
| d       t        j                  d       |j                  d	d      \  }}	|j                  |i       }
	 t        |	|
      ||<   m |S # t        j                  $ r8}t
        j                  d|        t        j                  d       Y d}~d}~ww xY w# t        $ r:}t
        j                  d| d|        t        j                  d       Y d}~d}~ww xY w)a  Build a tool-call argument dict from CLI inputs.

    A single JSON object argument is treated as the full argument dict.
    ``--input-json`` provides the base dict; ``key=value`` pairs override.
    Values are coerced using the tool's ``inputSchema``.
    r)   r   {N z2[bold red]Error:[/bold red] Invalid --input-json: z>[bold red]Error:[/bold red] --input-json must be a JSON objectrf   =z3[bold red]Error:[/bold red] Invalid argument [cyan]u   [/cyan] — expected key=valuez+[bold red]Error:[/bold red] Argument [cyan]z	[/cyan]: )lenr:   rR   rS   rU   r4   r5   r6   r7   r9   r   updaterq   rK   rt   rA   )r   r   r   rw   parsedrE   rf   argkeyvalueprop_schemas              rF   parse_tool_argumentsr   *  s    8}hqk44S9j>Pa[
F	ZZ
+F &$'MMP HHQKf!!,3Jc>MMEcUJhi HHQKYYsA&
U nnS"-	&uk:F3K   M9 ## 	MMNseTUHHQKK	,  	MM=cU)C5Q HHQKK		s/   D E#E (-EE #	F&,0F!!F&c                    d| v r,| d   D cg c]  }t        |       }}dj                  |      S | j                  dd      }t        |t              rdj                  d |D              S t
        j                  ||      S c c}w )zEProduce a short Python-style type string from a JSON-Schema fragment.anyOfz | rh   anyc              3   H   K   | ]  }t         j                  ||        y wN)r"   rq   ).0ts     rF   	<genexpr>z+_json_schema_type_to_str.<locals>.<genexpr>m  s     O;a/33Aq9;s    ")_json_schema_type_to_strjoinrq   r9   r   r"   )rv   srL   r   s       rF   r   r   d  s     &6<WoFo)!,oFzz%  **VU+K+t$zzO;OOO $$[+>> Gs   Btoolc                    g }| j                   }|j                  di       }t        |j                  dg             }|j                         D ]d  \  }}t	        |      }||v r|j                  | d|        ,|j                  d      }|t        |      nd}	|j                  | d| d|	        f | j                   ddj                  |       d	}
| j                  rt	        | j                        }|
d
| z  }
|
S )zKBuild ``name(param: type, ...) -> return_type`` from a tool's JSON schemas.rf   rg   rO   defaultz...z = (, rk   z -> )
inputSchemarq   rr   rs   r   appendreprnamer   outputSchema)r   r]   rv   rf   rg   	prop_namer   type_strr   default_reprsigrets               rF   format_tool_signaturer   r  s    FFL"-J6::j"-.H","2"2"4	;+K8 MMYKr(45!ooi0G,3,?4=ULMMYKr(3|nEF #5 YYKq6*+1
-C&t'8'89cU|JrZ   labelc                     |j                  di       }|syt        j                  d|  dt        j                  |       d       y)z!Print a JSON schema with a label.rf   Nz	    [dim]rO   [/dim])rq   r4   r5   rR   dumps)r   rv   rf   s      rF   _print_schemar     s=    L"-JMMIeWBtzz&'9&:&ABrZ   r   c                 H    t        |       }dj                  d |D              S )zEEscape rich markup and encode control chars for terminal-safe output.ri   c              3      K   | ]=  }|d v s$dt        |      cxk  rdk  sn t        |      dkD  r|ndt        |      d ? yw)>   	
          z\x02xN)ord)r   chs     rF   r   z+_sanitize_untrusted_text.<locals>.<genexpr>  sU       B $#b'"8D"8SWt^ 	3r73- 	! s   AA)escape_rich_markupr   )r   	sanitizeds     rF   _sanitize_untrusted_textr     s,    "5)I77  	  rZ   rw   c           	      Z   | j                   r| j                  D ]|  }t        |t        j                  j
                        r,t        j                  dt        |j                                St        j                  dt        t        |                    ~ y| j                  3t        j                  t        j                  | j                               y| j                  D ]D  }t        |t        j                  j
                        r)t        j                  t        |j                               Qt        |t        j                  j                        rBt!        |j"                        dz  dz  }t        j                  d|j$                   d| d       t        |t        j                  j&                        rCt!        |j"                        dz  dz  }t        j                  d|j$                   d| d       t        j                  t        t        |                   G y)	z/Pretty-print a tool call result to the console.r3   N      z[dim][Image: , ~ bytes][/dim]z[dim][Audio: )is_errorre   r9   mcptypesTextContentr4   r5   r   textr   structured_content
print_jsonrR   r   ImageContentr   rV   mimeTypeAudioContent)rw   blocksizes      rF   _format_call_result_textr     s    ^^E%!6!6723KEJJ3W2XY 23KCPUJ3W2XY $ 	  ,4::f&?&?@AeSYY223MM25::>?syy556uzz?Q&!+DMMM%..)9TF-PQsyy556uzz?Q&!+DMMM%..)9TF-PQMM23u:>?  rZ   r   c                 |   t        | t        j                  j                        rd| j                  dS t        | t        j                  j
                        rd| j                  | j                  dS t        | t        j                  j                        rd| j                  | j                  dS dt        |       dS )z5Serialize a single content block to a JSON-safe dict.r   )rh   r   image)rh   r   rV   audiounknown)rh   r   )
r9   r   r   r   r   r   r   rV   r   r   )r   s    rF   _content_block_to_dictr     s    %../

33%//0U^^UZZPP%//0U^^UZZPPE
33rZ   c                     | j                   D cg c]  }t        |       }}|| j                  d}| j                  | j                  |d<   |S c c}w )z3Serialize a ``CallToolResult`` to a JSON-safe dict.)re   r   r   )re   r   r   r   )rw   r   content_listouts       rF   _call_result_to_dictr     sZ     @F~~N~e*51~LN&2PC  ,$*$=$= !J	 Os   Atoolsc                     | D cg c]B  }|j                   |j                  |j                  d|j                  rd|j                  ini D c}S c c}w )z-Serialize a list of tools to JSON-safe dicts.)r   descriptionr   r   )r   r   r   r   )r   r   s     rF   _tools_to_jsonr     s_      A FF====	
 45>>/r		
   s   AAclient	tool_name	argumentsjson_outputc                 N  K   | j                          d{   }|D ci c]  }|j                  | }}||vr}t        j                  ||j	                         dd      }d| d}	|r!dj                  d |D              }
|	d	|
 d
z  }	t        j                  d|	        t        j                  d       ||   }t        |||j                        }t        |j                  j                  dg             }t        |j	                               }||z
  }|rdj                  d t        |      D              }t        j                  d|        t        j                          t        |      }t        j                  d| d       t        j                  d       | j!                  ||d       d{   }|r2t        j#                  t%        j&                  t)        |                   nt+        |       |j,                  rt        j                  d       yy7 c c}w 7 nw)z1Handle a tool call within an open client session.Nr         ?ncutoffzTool [cyan][/cyan] not found.r   c              3   (   K   | ]
  }d | d  ywz[cyan]rN   Nr   r   ms     rF   r   z$_handle_tool_call.<locals>.<genexpr>       #OAfQCw$7    Did you mean: ?r3   r)   rg   c              3   (   K   | ]
  }d | d  ywr   r   r   s     rF   r   z$_handle_tool_call.<locals>.<genexpr>	  s     M_&7 3_r   z8[bold red]Error:[/bold red] Missing required arguments: z  [dim]r   F)raise_on_error)
list_toolsr   difflibget_close_matcheskeysr   r4   r5   r6   r7   r   r   rr   rq   sortedr   	call_toolr   rR   r   r   r   r   )r   r   r   r   r   r   r   tool_mapclose_matchesmsgsuggestionsr   parsed_argsrg   providedmissingmissing_strr   rw   s                      rF   _handle_tool_callr    s     ##%%E#()5a	5H) 11x}}!C
 I;&89))#O#OOK_[M33C4SE:;ID&y*d>N>NOK4##''
B78H;##%&H!GiiMVG_MMF{mT	
 	#D)uF+,##I{5#QQF4::&:6&BCD ( K &): Rs-   H%HH%HFH%4H#5A'H%H%uric                   K   | j                  |       d{   }|rg }|D ]  }t        |t        j                  j                        r=|j                  t        |j                        |j                  |j                  d       dt        |t        j                  j                        s|j                  t        |j                        |j                  |j                  d        t        j                  t        j                  |             y|D ]  }t        |t        j                  j                        r)t        j!                  t#        |j                               Pt        |t        j                  j                        sut%        |j                        dz  dz  }t        j!                  d|j                   d| d        y7 w)	z5Handle a resource read within an open client session.N)r  r   r   )r  r   blobr   r   z[dim][Blob: r   r   )read_resourcer9   r   r   TextResourceContentsr   r   r  r   r   BlobResourceContentsr  r4   r   rR   r   r5   r   r   )r   r  r   contentsrV   r   r   s          rF   _handle_resourcer    sK     ))#..HE%!?!?@"599~$)NN %

 E399#A#AB"599~$)NN %

 " 	4::d+,eSYY;;<MM25::>?syy==>uzz?Q&!+DMML(8D6OP 1 /s   GGBG+CG	AGprompt_namec           	        K   t        ||ddi      }| j                          d{   }|D ci c]  }|j                  | }}||vr}t        j                  ||j                         dd      }	d| d}
|	r!d	j                  d
 |	D              }|
d| dz  }
t        j                  d|
        t        j                  d       | j                  ||xs d       d{   }|ri }|j                  r|j                  |d<   |j                  D 
cg c]$  }
|
j                  t        |
j                         d& c}
|d<   t        j#                  t%        j&                  |             y|j                  D ]_  }
t        j                  dt)        |
j                         d       t+        |
j                   t,        j.                  j0                        r6t        j                  dt)        |
j                   j2                                nt+        |
j                   t,        j.                  j4                        rVt7        |
j                   j8                        dz  dz  }t        j                  d|
j                   j:                   d| d       n4t        j                  dt)        t=        |
j                                       t        j                          b y7 c c}w 7 c c}
w w)z2Handle a prompt get within an open client session.rh   r    Nr   r   r   zPrompt [cyan]r   r   c              3   (   K   | ]
  }d | d  ywr   r   r   s     rF   r   z!_handle_prompt.<locals>.<genexpr>Y  r   r   r   r   r3   r)   r   )rolere   messagesz[bold]z:[/bold]z  r   z  [dim][Image: r   r   )r   list_promptsr   r   r  r  r   r4   r5   r6   r7   
get_promptr   r  r  r   re   r   rR   r   r   r9   r   r   r   r   r   r   rV   r   r   )r   r  r   r   r   r	  promptsp
prompt_mapr  r  r  rw   rV   r   s                  rF   _handle_promptr   C  sl     'y*vx>PQK''))G%,-W!&&!)WJ-*$11*a
 k]*<=))#O#OOK_[M33C4SE:;$$[+2EFFF!"("4"4D 

 ' 1#++> '
Z 	4::d+,7AB(KLckk399#8#89MMB78H8HIJKLSYY%;%;<s{{''(1,1DMM!#++"6"6!7s4&N MMB7CKK8HIJKL = *- G
s@   #K(KK(KBK(K 1K()K#9F K(K(#K(F)	r$   r%   	resourcesr  r   output_schemar   r   r   z4Server URL, Python file, MCPConfig JSON, or .js file)helpz	--commandz7Stdio command to connect to (e.g. 'npx -y @mcp/server'))httpr+   z--transportz-tz2Force transport type for URL targets (http or sse))r   r#  r!  z--resourceszAlso list resourcesr  z	--promptszAlso list promptsz--input-schemazShow full input schemasr"  z--output-schemazShow full output schemasz--jsonzOutput as JSONz	--timeoutzConnection timeout in secondsz--authzAAuth method: 'oauth', a bearer token string, or 'none' to disablec       	         
  K   t        | ||      }
t        |
||	      }	 |4 d{    |j                          d{   }|rdt        |      i}|ra|j	                          d{   }|D cg c]:  }t        |j                        |j                  |j                  |j                  d< c}|d<   |ro|j                          d{   }|D cg c]F  }|j                  |j                  |j                  xs g D cg c]  }|j                          c}dH c}}|d<   t        j                  t        j                   |             	 ddd      d{    y|st        j#                  d	       nt        j#                  d
t%        |       d       t        j#                          |D ]  }t'        |      }t        j#                  dt)        |       d       |j                  r+t        j#                  dt)        |j                                |rt+        d|j,                         |r"|j.                  rt+        d|j.                         t        j#                           |r|j	                          d{   }t        j#                  dt%        |       d       t        j#                          |st        j#                  d       |D ]  }t        j#                  dt)        t        |j                               d       |j                  xs d|j                  xs dg}dj1                  d |D              }|sst        j#                  dt)        |               t        j#                          |r-|j                          d{   }t        j#                  dt%        |       d       t        j#                          |st        j#                  d       |D ]  }d}|j                  r8|j                  D cg c]  }|j                   }}ddj1                  |       d}t        j#                  dt)        |j                  |z          d       |j                  st        j#                  dt)        |j                                 t        j#                          ddd      d{    y7 7 7 ]c c}w 7 c c}w c c}}w 7 7 ^7 Mc c}w 7 /# 1 d{  7  sw Y   yxY w# t2        $ r7}t        j#                  d|        t5        j6                  d       Y d}~yd}~ww xY ww)a$  List tools available on an MCP server.

    Examples:
        fastmcp list http://localhost:8000/mcp
        fastmcp list server.py
        fastmcp list mcp.json --json
        fastmcp list --command 'npx -y @mcp/server' --resources
        fastmcp list http://server/mcp --transport sse
    r#   r   Nr   )r  r   r   r   r!  )r   r   r   r  z[dim]No tools found.[/dim]z[bold]Tools (z)[/bold]rj   rN   z    InputOutputz[bold]Resources (z   [dim]No resources found.[/dim]ri   u    — c              3   &   K   | ]	  }|s|  y wr   r   )r   r  s     rF   r   zlist_command.<locals>.<genexpr>   s     'C:a:s   z[bold]Prompts (z  [dim]No prompts found.[/dim]r   r   rk   r3   r)   )rG   r   r   r   list_resourcesr   r  r   r   r   r  r   
model_dumpr4   r   rR   r   r5   r   r   r   r   r   r   r   	Exceptionr6   r7   )r&   r$   r%   r!  r  r   r"  r   r   r   rW   r   r   rV   resrprmr  ar   r   
desc_partsdescargs_strrL   rE   s                             rF   list_commandr3    sP    @ #;9UH8W4@FU6 ++--E(/1F'G & 5 5 77C "%) "%A $'quu:$%FF+,==()

	 "%)D%  & 3 3 55C "%' "%A	 %&FF+,==CD;;CTRTCT)VCTQ!,,.CT)V
 "%'DO ""4::d#347 66< :;c%j\BC!D/5CMMH-Ec-J,K7"ST''"#;D<L<L#M"NO $%gt/?/?@$):):%h0A0ABMMO " "1133 1#c(8DEMM"DEAMM"#;CJ#G"HP #$&&,B0C!DJ"<<'C:'CCD-Ed-K,L&MN  "//11CzBCMM"BCA!H{{12 =A =%&tyy'7&8#:MM"#;AFFX<M#N"OwW }}-Eamm-T,U&VW  a 66-
 8) 6
 *W	'% b 4  2 !>S 666d  4SE:;sO  UT  R?T  S+S)S+(S)S+1?S0S+S	S+-SSS 0S+T  ST   U!DS+ SCS+AS+S!A2S+S$AS+-AS+.T  9S):T  >U?T  S+S+S+SS+T  S+!S+$S+)T  +S=1S42S=9T  <U=T   	U 	-T;6U;U  U)r$   r%   promptr   r   r   r   targetz7Tool name, resource URI, or prompt name (with --prompt)r4  z--promptzTreat target as a prompt namez--input-jsonz5JSON string of arguments (merged with key=value args)zOutput raw JSON resultc                .  K   |s*t         j                  d       t        j                  d       t	        | ||      }
t        |
||      }	 |4 d{    |rt        |||	||       d{    n1d|v rt        |||       d{    nt        |||	||       d{    ddd      d{    y7 `7 I7 17 7 # 1 d{  7  sw Y   yxY w# t        $ r7}t         j                  d|        t        j                  d       Y d}~yd}~ww xY ww)as  Call a tool, read a resource, or get a prompt on an MCP server.

    By default the target is treated as a tool name. If the target
    contains ``://`` it is treated as a resource URI. Pass ``--prompt``
    to treat it as a prompt name.

    Arguments are passed as key=value pairs. Use --input-json for complex
    or nested arguments.

    Examples:
        ```
        fastmcp call server.py greet name=World
        fastmcp call server.py resource://docs/readme
        fastmcp call server.py analyze --prompt data='[1,2,3]'
        fastmcp call http://server/mcp create --input-json '{"tags": ["a","b"]}'
        ```
    z[bold red]Error:[/bold red] Missing target.

Usage: fastmcp call <server> <target> [key=value ...]

  target can be a tool name, a resource URI, or a prompt name (with --prompt).

Use [cyan]fastmcp list <server>[/cyan] to see available tools.r)   r#   r   Nz://r3   )
r4   r5   r6   r7   rG   r   r   r  r  r+  )r&   r5  r$   r%   r4  r   r   r   r   r   rW   r   rE   s                rF   call_commandr7    s     R M	
 	";9UH8W4@F6$VVY
KXXX&&vv{CCC'FIz;   66XC 666  4SE:;s   A	DC B3C B=+B5,B=B7B=B9B="C -B;.C 2D3C 5B=7B=9B=;C =CCCC DC 	D-DDDD)sourcer   r8  z--sourcezGOnly show servers from these sources (e.g. claude-code, cursor, gemini)c           
      l  K   t               }| r|D cg c]  }|j                  | v s| }}|ry|D cg c]E  }|j                  |j                  |j                  |j                  t        |j                        dG }}t        j                  t        j                  |             y|st        j                  d       t        j                          t        j                  d       t        j                  d       t        j                  d       t        j                  d       t        j                  d       t        j                  d	       t        j                  d
       yddlm} i }|D ]-  }|j                  |j                  g       j                  |       / |j!                         D ]  \  }}t        j                          t        j                  d|        t        j                  d|d   j                   d       t        j                           |dddddd      }	|	j#                  dd       |	j#                  dd       |D ](  }|	j%                  |j                  |j                         * t        j                  |	       t        j                           yc c}w c c}w w)aB  Discover MCP servers configured in editor and project configs.

    Scans Claude Desktop, Claude Code, Cursor, Gemini CLI, Goose, and
    project-level mcp.json files for MCP server definitions.

    Discovered server names can be used directly with ``fastmcp list``
    and ``fastmcp call`` instead of specifying a URL or file path.

    Examples:
        fastmcp discover
        fastmcp discover --source claude-code
        fastmcp discover --source cursor --source gemini --json
        fastmcp list weather
        fastmcp call cursor:weather get_forecast city=London
    )r   r8  qualified_nametransport_summaryconfig_pathNz [dim]No MCP servers found.[/dim]z	Searched:u     • Claude Desktop configu"     • ~/.claude.json (Claude Code)u+     • .cursor/mcp.json (walked up from cwd)u*     • ~/.gemini/settings.json (Gemini CLI)u)     • ~/.config/goose/config.yaml (Goose)u     • ./mcp.jsonr   )Tablez[bold]Source:[/bold]  z[bold]Config:[/bold]  [dim]r   TboldF)r      )show_headerheader_style	show_edgepad_edgeboxpaddingServercyan)style	Transportdim)r
   r8  r   r:  r;  r   r<  r4   r   rR   r   r5   
rich.tabler=  
setdefaultr   rs   
add_columnadd_row)
r8  r   serversr   rV   r=  	by_sourcesource_namegrouptables
             rF   discover_commandrT    s5    <  G%<gV);1g< 	&
  (("#"2"2%&%8%8"1==1  	 	&
 	4::d+,89k"34:;CDBCAB()  46IQXXr*11!4  (oo/U.{m<=3E!H4H4H3IPQ
 	0E2AMM!&&!"5"56  	e+ 0G =	&
s!   J4J*J*J4A
J/=H7J4r   )Nri   )K__doc__r   rR   rJ   r6   pathlibr   typingr   r   r   cycloptsrl   r   rich.consoler   rich.markupr   r   fastmcp.cli.discoveryr	   r
   r   fastmcp.client.clientr   r   fastmcp.client.elicitationr   fastmcp.client.transports.baser   fastmcp.client.transports.httpr   fastmcp.client.transports.sser   fastmcp.client.transports.stdior   fastmcp.utilities.loggingr   loggerr4   r"   r   r   __annotations__rG   r8   r?   r   rY   rh   r~   r   r   rt   tupler   r   r   Toolr   r   r   r   ContentBlockr   r   r   r   r  r  r   	Parameterr3  r7  rT  r   rZ   rF   <module>ri     s   E    
  * *     4 R R 8 3 : B 6 : 0	L	!
) ) tCH~   	EtE 4ZE Tz	E
 	4S>O+EP<3 <> <T cDcN&: 8IcDcN2_D I I89899t#89 89 	89
 $sCx.!89| !	DcN"_4 T\ *	
 Hc 4S> c D2CHo2d
2 sCx.2 
#s(^	2t?T#s(^ ? ?		 3 >C Cd38n C CC C @^ @ @@4#))"8"8 4T#s(^ 4 DcN $syy~~. 4S#X3G &... S#X. d
	.
 . 
.b#Q#Q	#Q #Q 
	#QL666 S#X6 d
	6
 6 
6H 	X 	 	 	 	 	 	 	 	 	iXd
G	
	X d
J	
	X %&E	
	X, =/DE	G-X4 ;-@A	C5X< +2KL	N=XD ,3MN	PEXL 8*:;	=MXT ;-LM	OUX\ d
T	
	]Xj 
kXB 	 	b( 	 	 	 	 	 	 	kbd
G	
	b J	
	b b d
J	
	b* %&E	
	+b8 :,KL	N9b@ d
H	
	AbN 8*BC	EObV ;-LM	OWb^ d
T	
	_bl 
mbZ 	 	YS	DZ	
	Y 8*:;	=Y 
YrZ   