
    "<i                     Z   d Z ddlZddlZddlZddlm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 dd	lmZ  ee          Zd
edz  fdZd
efdZddddddddededz  dedee         dz  dee         dz  deeef         dz  dedz  dedz  dedz  d
efdZddddddddddedeedz   ej        ddgd          f         deee         dz   ej        dd d!"          f         deee         dz   ej        d#d$d!"          f         deee         dz   ej        d%d&d!"          f         d'eedz   ej        d(d)*          f         d+eedz   ej        d,d-*          f         deedz   ej        d.d/*          f         deedz   ej        d0d1*          f         d
dfd2ZdS )3z;Claude Code integration for FastMCP install using Cyclopts.    N)Path)	Annotated)print)
get_logger)UVEnvironment   )process_common_argsreturnc                  4   t          j        d          } | rC	 t          j        | dgddd          }d|j        v r| S n# t          j        t          f$ r Y nw xY wt          j                    dz  dz  dz  t          d          t          j                    d	z  d
z  dz  g}|D ]u}|	                                r_	 t          j        t          |          dgddd          }d|j        v rt          |          c S Y# t          j        t          f$ r Y qw xY wvdS )zFind the Claude Code CLI command.

    Checks common installation locations since 'claude' is often a shell alias
    that doesn't work with subprocess calls.
    claudez	--versionTcheckcapture_outputtextzClaude Codez.claudelocalz/usr/local/bin/claudez.npm-globalbinN)shutilwhich
subprocessrunstdoutCalledProcessErrorFileNotFoundErrorr   homeexistsstr)claude_in_pathresultpotential_pathspaths       /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/fastmcp/cli/install/claude_code.pyfind_claude_commandr"      s}    \(++N 
	^-#	  F --%% .-/@A 	 	 	D	 		i')H4$%%	m#e+h6O    ;;== 	
#YY,#'	   !FM11t99$$$ 213DE   	 4s!   $> AA9>C;;DDc                  "    t                      duS )z&Check if Claude Code CLI is available.N)r"        r!   check_claude_code_availabler&   D   s      ,,r%   )with_editablewith_packagesenv_varspython_versionwith_requirementsprojectfileserver_objectnamer'   r(   r)   r*   r+   r,   c          	      :   t                      }	|	st          d           dS t          ||pg dgz   |||          }
|r|                                  d| }n!t	          |                                           }|
                    dd|g          }|	dd|g}|r6|                                D ]!\  }}|                    d	| d
| g           "|                    d           |                    |           	 t          j
        |ddd           dS # t          j        $ rN}t          d| d|j        r|j                                        nt	          |           d           Y d}~dS d}~wt          $ r!}t          d| d| d           Y d}~dS d}~ww xY w)a  Install FastMCP server in Claude Code.

    Args:
        file: Path to the server file
        server_object: Optional server object name (for :object suffix)
        name: Name for the server in Claude Code
        with_editable: Optional list of directories to install in editable mode
        with_packages: Optional list of additional packages to install
        env_vars: Optional dictionary of environment variables
        python_version: Optional Python version to use
        with_requirements: Optional requirements file to install from
        project: Optional project directory to run within

    Returns:
        True if installation was successful, False otherwise
    z[red]Claude Code CLI not found.[/red]
[blue]Please ensure Claude Code is installed. Try running 'claude --version' to verify.[/blue]Ffastmcp)pythondependenciesrequirementsr,   editable:r   mcpaddz-e=z--Tr   z[red]Failed to install '[bold]z[/bold]' in Claude Code: z[/red]N)r"   r   r   resolver   build_commanditemsextendappendr   r   r   stderrstrip	Exception)r-   r.   r/   r'   r(   r)   r*   r+   r,   
claude_cmd
env_configserver_specfull_command	cmd_partskeyvaluees                    r!   install_claude_coderJ   I   s-   : %&&J m	
 	
 	
 u#)ri[8&  J  *99-99$,,..)) ++Y{,KLLL UE40I  7"..** 	7 	7JCds$4$4U$4$456666 T\"""yTMMMMt(   |T||`a`hLtAHNNL\L\L\nqrsntnt|||	
 	
 	
 uuuuu   WtWWaWWWXXXuuuuus%   :D F#AE,,F9FF)server_namer'   r(   r)   env_filer2   r+   r,   rD   rK   z--namez-nz)Custom name for the server in Claude Code)r/   helpz--with-editablezVDirectory with pyproject.toml to install in editable mode (can be used multiple times) )rM   negativez--withz;Additional packages to install (can be used multiple times)z--envzFEnvironment variables in KEY=VALUE format (can be used multiple times)rL   z
--env-filez)Load environment variables from .env file)rM   r2   z--pythonz(Python version to use (e.g., 3.10, 3.11)z--with-requirementsz.Requirements file to install dependencies fromz	--projectz2Run the command within the given project directoryc                   K   |pg }|pg }|pg }t          | ||||           d{V \  }	}
}}}t          |	|
|||||||	  	        }|rt          d| d           dS t          j        d           dS )zInstall an MCP server in Claude Code.

    Args:
        server_spec: Python file to install, optionally with :object suffix
    N)	r-   r.   r/   r'   r(   r)   r*   r+   r,   z[green]Successfully installed 'z' in Claude Code[/green]r   )r	   rJ   r   sysexit)rD   rK   r'   r(   r)   rL   r2   r+   r,   r-   r.   r/   packagesenv_dictsuccesss                  r!   claude_code_commandrV      s      J "'RM!'RM~2H:M[-8; ; 5 5 5 5 5 51D-x "##+
 
 
G  NNNNOOOOOr%   )__doc__r   r   rQ   pathlibr   typingr   cycloptsrichr   fastmcp.utilities.loggingr   6fastmcp.utilities.mcp_server_config.v1.environments.uvr   sharedr	   __name__loggerr   r"   boolr&   listdictrJ   	ParameterrV   r$   r%   r!   <module>re      s   A A      



                    0 0 0 0 0 0 P P P P P P ' ' ' ' ' '	H		-S4Z - - - -`-T - - - - (,&*&*!%%)M M M
M:M M
 :$M 9t#M 38nt#M $JM d{M D[M 
M M M Mr 	 	 	 	 	 	 	 	{[ [ [[ d
D!<	
 	
 	
	[ T
Ti	
 	
 	
	[$ S	DN	
 	
 	
	%[4 S	DY	
 	
 	
	5[D t<	
 	
 	
	E[R d
;	
 	
 	
	S[` !t!A	
 	
 	
	a[n tE	
 	
 	
	o[| 
}[ [ [ [ [ [r%   