o
    i                     @   s  d 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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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.d/d,f deedB ejd0d1d,f deedB ejd2d3d,f ddfd4d5ZdS )6z>Claude Desktop integration for FastMCP install using Cyclopts.    N)Path)	Annotated)print)StdioMCPServerupdate_config_file)
get_logger)UVEnvironment   )process_common_argsreturnc                  C   sz   t jdkrtt ddd} n&t jdkrtt ddd} nt jdr3ttjd	t d
 d} ndS |  r;| S dS )z2Get the Claude config directory based on platform.win32AppDataRoamingClaudedarwinLibraryzApplication SupportlinuxXDG_CONFIG_HOMEz.configN)	sysplatformr   home
startswithosenvirongetexists)path r   h/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/fastmcp/cli/install/claude_desktop.pyget_claude_config_path   s   

r   )with_editablewith_packagesenv_varspython_versionwith_requirementsprojectfileserver_objectnamer    r!   r"   r#   r$   r%   c             
   C   sT  t  }	|	std dS |	d }
t||pg dg |||d}|r)|   d| }nt|  }|dd|g}t|d |d	d
 |pCi d}zH|
 r~dd
l}|
	 
 }|r~||}d|v r~||d v r~|d | di }|ryi ||}n|}||_t|
|| td| d W dS  ty } ztd| d W Y d
}~dS d
}~ww )a  Install FastMCP server in Claude Desktop.

    Args:
        file: Path to the server file
        server_object: Optional server object name (for :object suffix)
        name: Name for the server in Claude's config
        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 Desktop config directory not found.[/red]
[blue]Please ensure Claude Desktop is installed and has been run at least once to initialize its config.[/blue]Fzclaude_desktop_config.jsonfastmcp)pythondependenciesrequirementsr%   editable:runr   r	   N)commandargsenv
mcpServersr2   z[green]Successfully installed 'z' in Claude Desktop[/green]Tz[red]Failed to install server: z[/red])r   r   r   resolvestrbuild_commandr   r   json	read_textstriploadsr   r2   r   	Exception)r&   r'   r(   r    r!   r"   r#   r$   r%   
config_dirconfig_file
env_configserver_specfull_commandserver_configr7   contentconfigexisting_env
merged_enver   r   r   install_claude_desktop&   sV   

rG   )server_namer    r!   r"   env_filer*   r$   r%   r?   rH   z--namez-nz5Custom name for the server in Claude Desktop's config)r(   helpz--with-editablezVDirectory with pyproject.toml to install in editable mode (can be used multiple times) )rJ   negativez--withz;Additional packages to install (can be used multiple times)z--envzFEnvironment variables in KEY=VALUE format (can be used multiple times)rI   z
--env-filez)Load environment variables from .env file)rJ   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                   sj   |pg }|pg }|pg }t | ||||I dH \}	}
}}}t|	|
|||||||d	}|s3td dS dS )zInstall an MCP server in Claude Desktop.

    Args:
        server_spec: Python file to install, optionally with :object suffix
    N)	r&   r'   r(   r    r!   r"   r#   r$   r%   r	   )r
   rG   r   exit)r?   rH   r    r!   r"   rI   r*   r$   r%   r&   r'   r(   env_dictsuccessr   r   r   claude_desktop_command}   s*   E
rP   )__doc__r   r   pathlibr   typingr   cycloptsrichr   fastmcp.mcp_configr   r   fastmcp.utilities.loggingr   6fastmcp.utilities.mcp_server_config.v1.environments.uvr   sharedr
   __name__loggerr   r5   listdictboolrG   	ParameterrP   r   r   r   r   <module>   s    

	

`

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