
    Ch~:                         S r SSKrSSK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r SS	KJr  SS
KJr   SSKr\" S5      r\R4                  " SSSSS9rS rS\S\\\4   4S jr  S<S\S\S-  S\ \   S-  S\ \   4S jjr!S\S\\\S-  4   4S jr"S=S\S\S-  4S jjr#\RI                  5       S>S j5       r%\RI                  5       \RL                  " SS S!9S/ 4S\S\
\S-  \RN                  " S"S#S$SSSS%94   S\
\ \   \RN                  " S&S'S!94   SS4S( jj5       r(\RI                  5       \RL                  " SS S!9S4S\S)\
\S-  \RN                  " S*S+S,S!94   SS4S- jj5       r)\RI                  5       \RL                  " SS S!9SS/ / S4S\S.\
\S-  \RN                  " S/S0S1S!94   S\
\S-  \RN                  " S"S#S$SSSS%94   S\
\ \   \RN                  " S&S'S!94   S2\
\ \   \RN                  " S3S4S5S!94   S6\
\S-  \RN                  " S7S8S9SSSSS:94   SS4S; jj5       r*g! \ a    \" S5        \R&                  " S5         GN f = f! \ a    \" S5        \R&                  " S5         GN:f = f! \ a    Sr GNDf = f)?zMCP CLI tools.    N)Path)	AnnotatedAny)FastMCP)Serverz=Error: typer is required. Install with 'pip install mcp[cli]'   )claude)
get_loggerz?Error: mcp.server.fastmcp is not installed or not in PYTHONPATHclimcpzMCP development toolsFT)namehelpadd_completionno_args_is_helpc                      [         R                  S:X  a&  S H  n  [        R                  " U S/SSSS9  U s  $    gg! [        R                   a     M<  f = f)z5Get the correct npx command for the current platform.win32)znpx.cmdznpx.exenpxz	--versionT)checkcapture_outputshellNr   )sysplatform
subprocessrunCalledProcessError)cmds    E/home/james-whalen/.local/lib/python3.13/site-packages/mcp/cli/cli.py_get_npx_commandr   *   s\    
||w0C[1dZ^_
 1  00 s   <AAenv_varreturnc                     SU ;  a/  [         R                  SU  S35        [        R                  " S5        U R	                  SS5      u  pUR                  5       UR                  5       4$ )z6Parse environment variable string in format KEY=VALUE.=z%Invalid environment variable format: z. Must be KEY=VALUEr   )loggererrorr   exitsplitstrip)r   keyvalues      r   _parse_env_varr*   8   sU    
'<WIEXYZsA&JC99;%%    	file_specwith_editablewith_packagesc                     S/nUR                  / SQ5        U(       a  UR                  S[        U5      /5        U(       a%  U H  nU(       d  M  UR                  SU/5        M!     UR                  SSU /5        U$ )z@Build the uv run command that runs a MCP server through mcp run.uv)r   --withr   --with-editabler1   r   r   )extendstr)r,   r-   r.   r   pkgs        r   _build_uv_commandr6   A   sn     &CJJ'(

%s='9:; Cs

Hc?+ !
 JJui()Jr+   c                    [        U 5      S:  =(       a    U S   S:H  nSU(       a  U SS OU ;   a  U R                  SS5      u  p#OU Sp2[        U5      R                  5       R	                  5       nUR                  5       (       d.  [        R                  SU 35        [        R                  " S5        UR                  5       (       d.  [        R                  SU 35        [        R                  " S5        XC4$ )zParse a file path that may include a server object specification.

Args:
    file_spec: Path to file, optionally with :object suffix

Returns:
    Tuple of (file_path, server_object)
r   :   NzFile not found: zNot a file: )lenrsplitr   
expanduserresolveexistsr#   r$   r   r%   is_file)r,   has_windows_drivefile_strserver_object	file_paths        r   _parse_file_pathrD   X   s     I*By|s/B  1y}yA"+"2"23":-"+T- X))+335I'	{34|I;/0##r+   filerB   c                 ,   [        U R                  5      nU[        R                  ;  a   [        R                  R	                  SU5        [
        R                  R                  SU 5      nU(       a  UR                  (       d5  [        R                  SS[        U 5      0S9  [        R                  " S5        [
        R                  R                  U5      nUR                  R                  U5        S[        S[         4S	 jnU(       d  S
 HZ  n[        XF5      (       d  M  U" [!        XF5      U  SU 35      (       d  [        R                  SU  SU S35        MO  [!        XF5      s  $    [        R                  SU  S3S[        U 5      0S9  [        R                  " S5        SU;   a8  UR#                  SS5      u  px [
        R$                  " U5      n	[!        XS5      n
O[!        XAS5      n
W
c9  [        R                  SU S3S[        U 5      0S9  [        R                  " S5        U" X5      (       d  [        R                  " S5        U
$ ! [&         a<    [        R                  SU S3S[        U 5      0S9  [        R                  " S5         Nf = f)zImport a MCP server from a file.

Args:
    file: Path to the file
    server_object: Optional object name in format "module:object" or just "object"

Returns:
    The server object
r   server_modulezCould not load modulerE   extrar   rB   object_namec           	          [        U [        5      (       dW  [        R                  SU S[	        U 5       S[         S35        [        U [
        5      (       a  [        R                  S5        gg)zHelper function to check that the server object is supported

Args:
    server_object: The server object to check.

Returns:
    True if it's supported.
zThe server object z is of type z (expecting z).zXNote that only FastMCP server is supported. Low level Server class is not yet supported.FT)
isinstancer   r#   r$   typeLowLevelServerwarning)rB   rJ   s     r   _check_server_object,_import_server.<locals>._check_server_object   sa     -11LL-k],tMGZF[[ghogpprst-88n r+   )r   serverappr8   zIgnoring object 'z#' as it's not a valid server objectzNo server object found in a  . Please either:
1. Use a standard variable name (mcp, server, or app)
2. Specify the object name with file:object syntax3. If the server creates the FastMCP object within main()    or another function, refactor the FastMCP object to be a    global variable named mcp, server, or app.NzCould not import module ''zServer object 'z' not found)r4   parentr   pathinsert	importlibutilspec_from_file_locationloaderr#   r$   r%   module_from_specexec_moduler   hasattrgetattrr&   import_moduleImportError)rE   rB   file_dirspecmodulerP   r   module_namerJ   rG   rR   s              r   _import_serverrf   w   s;    4;;Hsxx8$ >>11/4HDt{{,VSY4GH^^,,T2FKKF#C c & ,Dv$$+GF,AdV1TFCSTTLL#4TF!D6Ad!efv,, - 	( /< < 3t9% 	 	
 	 m#0#6#6sA#> 	%33K@M]>F 5~m_K83t9% 	 	
 	66M)  	LL+K=:s4y)   HHQK	s   ="I AJJc                       [         R                  R                  S5      n [        SU  35        g! [         R                  R                   a$    [        S5        [
        R                  " S5         gf = f)zShow the MCP version.r   zMCP version z+MCP version unknown (package not installed)r   N)rX   metadataversionprintPackageNotFoundErrorr   r%   )ri   s    r   ri   ri      s[    $$,,U3WI&'22 ;<s   -0 ?A21A2.z2Python file to run, optionally with :object suffix)r   r2   z-ez?Directory containing pyproject.toml to install in editable mode)r   r>   	file_okayresolve_pathr1   zAdditional packages to installc           	         [        U 5      u  p4[        R                  S[        U5      UU(       a  [        U5      OSUS.S9   [	        X45      n[        US5      (       a   [        [        X%R                  -   5      5      n[        XU5      n[        5       nU(       d+  [        R                  S5        [        R                  " S5        [        R                  S:H  n[        R                   " US	/U-   S
U[#        [$        R&                  R)                  5       5      S9n	[        R                  " U	R*                  5        g! [        R,                   a^  n
[        R                  S[        U5      [        U
5      U
R*                  S.S9  [        R                  " U
R*                  5         Sn
A
gSn
A
f[.         a8    [        R                  SS[        U5      0S9  [        R                  " S5         gf = f)z(Run a MCP server with the MCP Inspector.zStarting dev serverN)rE   rB   r-   r.   rH   dependencieszbnpx not found. Please ensure Node.js and npm are properly installed and added to your system PATH.r   r   z@modelcontextprotocol/inspectorT)r   r   envzDev server failed)rE   r$   
returncodeznpx not found. Please ensure Node.js and npm are properly installed and added to your system PATH. You may need to restart your terminal after installation.rE   )rD   r#   debugr4   rf   r^   listsetro   r6   r   r$   r   r%   r   r   r   dictosenvironitemsrq   r   FileNotFoundError)r,   r-   r.   rE   rB   rR   uv_cmdnpx_cmdr   processes              r   devr~      s   4 +95D
LLI*3@S/d*	
  *46>** ]5H5H%H!IJM"9]K #$LLt HHQK '..786ARZZ%%'(	
 	##$(( 	D	Qll 	 	
 	 " 3t9%	 	 	
 	s!   C8D< <G.AF))AG.-G.	transportz--transportz-tz(Transport protocol to use (stdio or sse)c                 @   [        U 5      u  p#[        R                  S[        U5      UUS.S9   [	        X#5      n0 nU(       a  XS'   UR
                  " S	0 UD6  g! [         a8    [        R                  SS[        U5      0S9  [        R                  " S5         gf = f)
a  Run a MCP server.

The server can be specified in two ways:

1. Module approach: server.py - runs the module directly, expecting a server.run() call.

2. Import approach: server.py:app - imports and runs the specified server object.



Note: This command runs the server directly. You are responsible for ensuring
all dependencies are available.

For dependency management, use `mcp install` or `mcp dev` instead.
zRunning server)rE   rB   r   rH   r   zFailed to run serverrE   r   N )
rD   r#   rr   r4   rf   r   	Exception	exceptionr   r%   )r,   r   rE   rB   rR   kwargss         r   r   r   1  s    2 +95D
LLI*"
  4 "+;

V "D	 	 	
 	s   *A ?BBserver_namez--namez-nzMCustom name for the server (defaults to server's name attribute or file name)env_varsz	--env-varz-vz)Environment variables in KEY=VALUE formatenv_filez
--env-filez-fz+Load environment variables from a .env file)r   r>   rl   dir_okayrm   c           	         [        U 5      u  pg[        R                  S[        U5      UUU(       a  [        U5      OSUS.S9  [        R
                  " 5       (       d+  [        R                  S5        [        R                  " S5        UnSn	U(       d   [        Xg5      n	U	R                  nU	(       a  [        U	S	/ 5      O/ nU(       a  [        [!        X;-   5      5      nSnU(       d  U(       a  0 nU(       ay  ["        (       aC   U["        R$                  " U5      R'                  5        VVs0 s H  u  pUc  M
  X_M     snn-  nO+[        R                  S5        [        R                  " S5        U H  n[/        U5      u  nnUUU'   M     [        R0                  " U UUUUS9(       a  [        R3                  SU S35        g[        R                  SU S35        [        R                  " S5        g! [        [        4 a6  n
[        R                  SS[        U
5      0S9  UR                  n Sn
A
GNSn
A
ff = fs  snnf ! [(        [*        4 a/    [        R-                  S
5        [        R                  " S5         GNf = f)zInstall a MCP server in the Claude desktop app.

Environment variables are preserved once added and only updated if new values
are explicitly provided.
zInstalling serverN)rE   r   rB   r-   r.   rH   zClaude app not foundr   zFCould not import server (likely missing dependencies), using file namer$   ro   zFailed to load .env filez6python-dotenv is not installed. Cannot load .env file.)r-   r.   r   zSuccessfully installed z in Claude appzFailed to install )rD   r#   rr   r4   r	   get_claude_config_pathr$   r   r%   rf   r   ra   ModuleNotFoundErrorstemr_   rs   rt   dotenvdotenv_valuesrx   OSError
ValueErrorr   r*   update_claude_configinfo)r,   r   r-   r.   r   r   rE   rB   r   rR   r}   server_dependenciesenv_dictkvr   r(   r)   s                     r   installr   j  s%   t +95D
LLI&*3@S/d*
  	 ((**+, DF	#D8F;;D BH'&."=RS!DEF '+H8v &2F2Fx2P2V2V2X j2X$!\]2X jjH
 UV  G'0JC!HSM   ""## 	-dV>BC)$~>?W 01 	LLXA'   99D	( !k,  $$%?@HHQK sB   G3 (I +	H<8H<>I 3H9+H44H9<I ;J J)NN)N)r    N)+__doc__importlib.metadatarX   importlib.utilrv   r   r   pathlibr   typingr   r   
mcp.serverr   r   rN   typerra   rj   r%   mcp.clir	   $mcp.server.fastmcp.utilities.loggingr
   r   r#   TyperrS   r   r4   tupler*   rs   r6   rD   rf   commandri   ArgumentOptionr~   r   r   r   r+   r   <module>r      s      	  
  !  /
?
 
E	kk		 	&C &E#s(O & "&&*$; 9t# 
#Y	.$ $dC$J.>(? $>Y YcDj Yx   ^^A 	 	-OO
 tR	
	
O  S	1	
	!O. 
/O Od ^^A 	55
 d
;	
	5 
5 5p ^^A 	 	 	 	 	e}}
 d
`	
	} tR	
	
}0 S	1	
	1}> S	<	
	?}N t>	
		O}f 
g} }w
  	
IJHHQK  	
KLHHQK  Fs4   H3 I J 3 II I>=I>JJ