o
    i                     @   s  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B fddZd
efddZddddddddededB dedee dB dee dB deeef dB dedB dedB dedB d
efddZddddddddddedeedB ejddgd d!f deee dB ejd"d#d$d%f deee dB ejd&d'd$d%f deee dB ejd(d)d$d%f d*eedB ejd+d,d-f d.eedB ejd/d0d-f deedB ejd1d2d-f deedB ejd3d4d-f d
dfd5d6ZdS )7z;Claude Code integration for FastMCP install using Cyclopts.    N)Path)	Annotated)print)
get_logger)UVEnvironment   )process_common_argsreturnc               
   C   s   t d} | r)ztj| dgdddd}d|jv r| W S W n tjtfy(   Y nw t d d d tdt d	 d
 d g}|D ].}|	 rpztjt
|dgdddd}d|jv rbt
|W   S W qB tjtfyo   Y qBw qBd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path r   e/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/fastmcp/cli/install/claude_code.pyfind_claude_command   sH   

	

r!   c                   C   s
   t  duS )z&Check if Claude Code CLI is available.N)r!   r   r   r   r    check_claude_code_availableD   s   
r"   )with_editablewith_packagesenv_varspython_versionwith_requirementsprojectfileserver_objectnamer#   r$   r%   r&   r'   r(   c             
   C   sZ  t  }	|	std dS t||pg dg |||d}
|r%|   d| }nt|  }|
dd|g}|	dd|g}|rP| D ]\}}|d	| d
| g q?|d || zt	j
|dddd W dS  t	jy } ztd| d|jr||j nt| d W Y d}~dS d}~w ty } ztd| d| d W Y d}~dS d}~w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er   r   r    install_claude_codeI   sJ   	

$rE   )server_namer#   r$   r%   env_filer-   r'   r(   r?   rF   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) )rH   negativez--withz;Additional packages to install (can be used multiple times)z--envzFEnvironment variables in KEY=VALUE format (can be used multiple times)rG   z
--env-filez)Load environment variables from .env file)rH   r-   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                   sz   |pg }|pg }|pg }t | ||||I dH \}	}
}}}t|	|
|||||||d	}|r6td| d dS t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   rE   r   sysexit)r?   rF   r#   r$   r%   rG   r-   r'   r(   r)   r*   r+   packagesenv_dictsuccessr   r   r    claude_code_command   s*   E
rP   )__doc__r   r   rK   pathlibr   typingr   cycloptsrichr   fastmcp.utilities.loggingr   6fastmcp.utilities.mcp_server_config.v1.environments.uvr   sharedr   __name__loggerr   r!   boolr"   listdictrE   	ParameterrP   r   r   r   r    <module>   s   0


	

Y



")07>