
    "<i                        d 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 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d
         Zed         ZdedefdZdedefdZdede
d         fdZdedefdZ	 	 	 	 	 	 	 	 	 d#dededz  dedz  dedz  dedz  dedz  dee         dz  dedededdfd Z	 	 	 d$d!ededz  dedz  dedz  ddf
d"ZdS )%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                 n    t          j        d          }t          |                    |                     S )zCheck if a string is a URL.z
^https?://)recompileboolmatch)r   url_patterns     /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/fastmcp/cli/run.pyis_urlr      s-    *]++K!!$''(((    urlc                    	 ddl }|                    |           }|j                            |          }|S # t          $ r?}t
                              d|  d|            t          j        d           Y d}~dS d}~ww xY w)zCreate 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-      s    $$))&11   BBBqBBCCCs   47 
B 4A;;B mcp_config_pathc                     ddl m} |                                 5 }t          j        |          }ddd           n# 1 swxY w Y    |j        |          }|S )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   s    					 $3Ys^^
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ Wj))FMs   <A A config_pathc                 b    t          j        |           }|j                            |            |S )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<   >   s2     &{33F ,,[999Mr   TFserver_spec	transporthostport	log_levelserver_argsshow_banneruse_direct_importskip_sourcec
                 r  K   t          |           r.t          |           }
t                              d|             n>|                     d          rdt          |           }t          |          5 }t          j        |          }ddd           n# 1 swxY w Y   d|v rt          |          }
nt          |          }|p|j        j        }|p|j        j        }|p|j        j        }|p|j        j        }|p|j        j        }||n|j        j        }|	s|                                 d{V nd ddlm} ddlm} |r ||          n	 |            }|5  |j                                         d{V }
ddd           n# 1 swxY w Y   t                              d|
j         d	|            nt5          | 
          }t7          |          }|	s|                                 d{V nd ddlm} ddlm} |r ||          n	 |            }|5  |j                                         d{V }
ddd           n# 1 swxY w Y   t                              d|
j         d|j                    t9          |
t:                    rt=          |
|||           d{V  dS i }|r||d<   |r||d<   |r||d<   |r||d<   |r||d<   |sd|d<   	  |
j        di | d{V  dS # t@          $ r<}t          !                    d|            tE          j#        d           Y d}~dS d}~ww xY w)a  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 ?G%k22EEEFFFF			g	&	& :G;''+ 	 !9Q<<D	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  4-k::FF ,K88F "@V%6%@I16,1D16,1D16,1D!@V%6%@I*6F<M<R 
 2=F&'')))))))))$ /.....111111 6AS99[111kkmmL ; ;%}88::::::::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; LLR&+RR[RRSSSS "{333 /// .9Bf##%%%%%%%%%d 	+*****------ 2=Oyy---++-- 	7 	7!=4466666666F	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	EfkEEEEFFF
 &)$$ !&t$)TTTTTTTTTTF ('{ v v v ('{ & %}f(((((((((((((   1a11222sN   4BBB F		FF I		IIK0 0
L6:1L11L6r+   c                 0  K   |r|| j         _        |r|| j         _        |xdk    r |                                  d{V  dS xxdk    rnxdk    rnxn n  |                                  d{V  dS dk    r|                                  d{V  dS dS )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        $# $#
WWWW((***********.VVVVV'''''$$$$$$$2244444444444UU&&((((((((((( Ur   )	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 B  				 



               3 3 3 3 3 3 ) ) ) ) ) ) 0 0 0 0 0 0      W V V V V V	I		 ABFG) ) ) ) ) )c c    (d wt}         & '+%)$(#v vvt#v *v *	v
 *v d"v cT!v v v v 
v v v vv &*	) ))
*) *) t#	)
 
) ) ) ) ) )r   