
    k7i                        S r SSKrSSKrSSKrSSKJr  SSKJrJr  SSK	J
r  SSKJ
r
  SSKJr  SSKJr  SSKJr  \" S	5      r\S
   r\S   rS\S\4S jrS\S\4S jrS\S\
S   4S jrS\S\4S jr         S!S\S\S-  S\S-  S\S-  S\S-  S\S-  S\\   S-  S\S\S\SS4S jjr   S"S\S\S-  S\S-  S\S-  SS4
S  jjrg)#z<FastMCP run command implementation with enhanced type hints.    N)Path)AnyLiteralFastMCP)
get_logger)MCPServerConfig)FileSystemSourcezcli.run)stdiohttpssestreamable-http)DEBUGINFOWARNINGERRORCRITICALpathreturnc                 b    [         R                  " S5      n[        UR                  U 5      5      $ )zCheck if a string is a URL.z
^https?://)recompileboolmatch)r   url_patterns     I/home/james-whalen/.local/lib/python3.13/site-packages/fastmcp/cli/run.pyis_urlr      s&    **]+K!!$'((    urlc                      SSK nUR                  U 5      nUR                  R                  U5      nU$ ! [         a;  n[
        R                  SU  SU 35        [        R                  " S5         SnAgSnAff = f)zyCreate a FastMCP server from a client URL.

Args:
    url: The URL to connect to

Returns:
    A FastMCP server instance
r   Nz Failed to create client for URL z:    )	fastmcpClientr   as_proxy	Exceptionloggererrorsysexit)r   r"   clientserveres        r   create_client_serverr-      sh    $))&1 7uBqcBCs   14 
A91A44A9mcp_config_pathc                     SSK Jn  U R                  5        n[        R                  " U5      nSSS5        UR
                  " W5      nU$ ! , (       d  f       N"= f)z)Create a FastMCP server from a MCPConfig.r   r   N)r"   r   openjsonloadr$   )r.   r   src
mcp_configr+   s        r   create_mcp_config_serverr5   3   sE    				3YYs^
 
  j)FM	 
 	s   A


Aconfig_pathc                 h    [         R                  " U 5      nUR                  R                  U 5        U$ )zLoad a FastMCP configuration from a fastmcp.json file.

Args:
    config_path: Path to fastmcp.json file

Returns:
    MCPServerConfig object
)r	   	from_file
deploymentapply_runtime_settings)r6   configs     r   load_mcp_server_configr<   >   s/     &&{3F ,,[9Mr   server_spec	transporthostport	log_levelserver_argsshow_banneruse_direct_importskip_sourcec
                 p  #    [        U 5      (       a%  [        U 5      n
[        R                  SU  35        GOgU R	                  S5      (       Ga  [        U 5      n[        U5       n[        R                  " U5      nSSS5        SW;   a  [        U5      n
GO[        U5      nU=(       d    UR                  R                  nU=(       d    UR                  R                  nU=(       d    UR                  R                  nU=(       d    UR                  R                  nU=(       d    UR                  R                   nUb  UOUR                  R"                  nU	(       d  UR%                  5       I Sh  vN OS  SSKJn  SSKJn  U(       a  U" U5      OU" 5       nU   UR.                  R1                  5       I Sh  vN n
SSS5        [        R                  SW
R2                   S	U 35        O[5        U S
9n[7        US9nU	(       d  UR%                  5       I Sh  vN OS  SSKJn  SSKJn  U(       a  U" U5      OU" 5       nU   UR.                  R1                  5       I Sh  vN n
SSS5        [        R                  SW
R2                   SUR                   35        [9        U
[:        5      (       a  [=        XX1S9I Sh  vN   g0 nU(       a  UUS'   U(       a  UUS'   U(       a  UUS'   U(       a  UUS'   U(       a  UUS'   U(       d  SUS'    U
R>                  " S0 UD6I Sh  vN   g! , (       d  f       GN= f GN GN! , (       d  f       GN= f GN= N! , (       d  f       N= f N NG! [@         a8  n[        RC                  SU 35        [D        RF                  " S5         SnAgSnAff = f7f)aW  Run a MCP server or connect to a remote one.

Args:
    server_spec: Python file, object specification (file:obj), config file, or URL
    transport: Transport protocol to use
    host: Host to bind to when using http transport
    port: Port to bind to when using http transport
    path: Path to bind to when using http transport
    log_level: Log level
    server_args: Additional arguments to pass to the server
    show_banner: Whether to show the server banner
    use_direct_import: Whether to use direct import instead of subprocess
    skip_source: Whether to skip source preparation step
z Created client proxy server for z.jsonN
mcpServersr   )nullcontext)	with_argvzFound server "z" from config )r   )sourcez" in )r?   r@   r>   r>   r?   r@   r   rA   FrC   zFailed to run server: r!    )$r   r-   r&   debugendswithr   r0   r1   r2   r5   r<   r9   r>   r?   r@   r   rA   argsprepare_source
contextlibrH   fastmcp.cli.clirI   rJ   load_servernamer
   r	   
isinstance	FastMCP1xrun_v1_server_async	run_asyncr%   r'   r(   r)   )r=   r>   r?   r@   r   rA   rB   rC   rD   rE   r+   r6   fdatar;   rH   rI   argv_contextrJ   kwargsr,   s                        r   run_commandr\   O   s    6 k%k27}EF			g	&	&;'+!99Q<D  4-k:F ,K8F "@V%6%6%@%@I16,,11D16,,11D16,,11D!@V%6%6%@%@I*6F<M<M<R<R 
 2=&'')))$ /1 6A9[1kmL%}}88::  LL>&++n[MRS "{3 / .9f##%%%d 	+- 2=y-+-!==4466F  	~fkk]%}EF
 &)$$!&$TTTF'{vvv'{ %}((((a , * ;  	& 7 \ 	U& 	) -aS12s   A#N6%L-<C6N62L?3*N6M;M<M AN6M*N6M#M$M(AN6M-AN6M1 'M/(M1 ,N6-
L<7	N6M
M	N6M
M*&N6/M1 1
N3;.N.)N6.N33N6r+   c                 R  #    U(       a  XR                   l        U(       a  X R                   l        U=S:X  a    U R                  5       I Sh  vN   g==S:X  a  O=S:X  a  O=c  O  O    U R	                  5       I Sh  vN   gS:X  a  U R                  5       I Sh  vN   gg NT N& N
7f)zRun a FastMCP 1.x server using async methods.

Args:
    server: FastMCP 1.x server instance
    host: Host to bind to
    port: Port to bind to
    transport: Transport protocol to use
r   Nr   r   r   )settingsr?   r@   run_stdio_asyncrun_streamable_http_asyncrun_sse_async)r+   r?   r@   r>   s       r   rV   rV      s}      ##
((***.V'$.22444&&(((  +4(s6   A
B'B!/B'<B#=B'B%B'#B'%B')	NNNNNNTFF)NNN) __doc__r1   r   r(   pathlibr   typingr   r   mcp.server.fastmcpr   rU   fastmcp.server.serverfastmcp.utilities.loggingr   #fastmcp.utilities.mcp_server_configr	   9fastmcp.utilities.mcp_server_config.v1.sources.filesystemr
   r&   TransportTypeLogLevelTypestrr   r   r-   r5   r<   intlistr\   rV   rK   r   r   <module>ro      s   B  	 
   3 ) 0 W	I	 ABFG) ) )c c (d wt}   & '+%)$(#vvt#v *v *	v
 *v d"v cT!v v v v 
vv &*	))
*) *) t#	)
 
)r   