
    Ki                        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j4                  ddgd      f   deee   dz   ej4                  dd d!"      f   deee   dz   ej4                  d#d$d!"      f   deee   dz   ej4                  d%d&d!"      f   d'eedz   ej4                  d(d)*      f   d+eedz   ej4                  d,d-*      f   deedz   ej4                  d.d/*      f   deedz   ej4                  d0d1*      f   d
dfd2Zy)3z;Claude Code integration for FastMCP install using Cyclopts.    N)Path)	Annotated)print)
get_logger)UVEnvironment   )process_common_argsreturnc                  @   t        j                  d      } | r-	 t        j                  | dgddd      }d|j                  v r| S 	 t        j                         dz  dz  dz  t        d      t        j                         d	z  d
z  dz  g}|D ]S  }|j                         s	 t        j                  t        |      dgddd      }d|j                  v rt        |      c S U y# t        j
                  t        f$ r Y w xY w# t        j
                  t        f$ r Y w xY w)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       k/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/fastmcp/cli/install/claude_code.pyfind_claude_commandr"      s7    \\(+N
	^^-#	F -%% . 			i')H4$%		m#e+h6O   ;;=
#Y,#'	 !FMM1t9$ 2 7 --/@A 		0 113DE s#   *C"  <D"C>=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       yt        ||xs g dgz   |||      }
|r| j                          d| }nt	        | j                               }|
j                  dd|g      }|	dd|g}|r0|j                         D ]  \  }}|j                  d	| d
| g        |j                  d       |j                  |       	 t        j                  |ddd       y# t        j                  $ rK}t        d| d|j                  r|j                  j                         n
t	        |       d       Y d}~yd}~wt        $ r}t        d| d| d       Y d}~y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	
 #)ri[8&J (-9$,,.) ++Y{,KLL UE40I "..* 	7JCdse1UG$456	7 T\"yTM(( ,TF2K`a`h`hAHHNNL\nqrsntKuu{|	
  .tf4MaSPVWXs%   C+ +E,>AEE,E''E,)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   |xs g }|xs g }|xs g }t        | ||||       d{   \  }	}
}}}t        |	|
|||||||	      }|rt        d| d       yt        j                  d       y7 Fw)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1D-x "##+
G /v5MNO'5s   %A0A.AA0)__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   
     0 P '	H	-S4Z -`-T - (,&*&*!%%)M
M:M M
 :$M 9t#M 38nt#M $JM d{M D[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%   