
    kKj;                     f   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d4dedz  dedz  fdZd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dz  defdZdddddddddd	dedeedz   ej6                  ddgd      f   deee   dz   ej6                  d d!"      f   deee   dz   ej6                  d#d$"      f   deee   dz   ej6                  d%d&"      f   d'eedz   ej6                  d(d)"      f   d*eedz   ej6                  d+d,"      f   deedz   ej6                  d-d."      f   deedz   ej6                  d/d0"      f   deedz   ej6                  d1d2"      f   ddfd3Zy)5z>Claude Desktop integration for FastMCP install using Cyclopts.    N)Path)	Annotated)print)StdioMCPServerupdate_config_file)
get_logger)UVEnvironment   )process_common_argsconfig_pathreturnc                     | r"| j                         st        d|  d       y| S t        j                  dk(  r!t	        t	        j
                         ddd      }nt        j                  dk(  r!t	        t	        j
                         d	d
d      }n`t        j                  j                  d      r@t	        t        j                  j                  dt	        j
                         dz        d      }ny|j                         r|S y)zGet the Claude config directory based on platform.

    Args:
        config_path: Optional custom path to the Claude Desktop config directory
    z/[red]The specified config path does not exist: [/red]Nwin32AppDataRoamingClaudedarwinLibraryzApplication SupportlinuxXDG_CONFIG_HOMEz.config)
existsr   sysplatformr   home
startswithosenvironget)r   paths     s/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/fastmcp/cli/install/claude_desktop.pyget_claude_config_pathr"      s     !!#CK=PVWX
||wDIIKIx@		!DIIK,A8L		 	 	)JJNN,diikI.EF
 {{}    )with_editablewith_packagesenv_varspython_versionwith_requirementsprojectr   fileserver_objectnamer$   r%   r&   r'   r(   r)   c                   t        |	      }
|
s|	st        d       y|
dz  }t        ||xs g dgz   |||      }|r| j                          d| }nt	        | j                               }|j                  dd|g      }t        |d	   |d
d |xs i       }	 |j                         rjd	dl}|j                         j                         }|rF|j                  |      }d|v r1||d   v r*|d   |   j                  di       }|ri ||}n|}||_        t        |||       t        d| d       y# t        $ r}t        d| d       Y d}~yd}~ww xY 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
        config_path: Optional custom path to Claude Desktop config directory

    Returns:
        True if installation was successful, False otherwise
    )r   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
mcpServersr7   z[green]Successfully installed 'z' in Claude Desktop[/green]Tz[red]Failed to install server: r   )r"   r   r	   resolvestrbuild_commandr   r   json	read_textstriploadsr   r7   r   	Exception)r*   r+   r,   r$   r%   r&   r'   r(   r)   r   
config_dirconfig_file
env_configserver_specfull_commandserver_configr<   contentconfigexisting_env
merged_enves                         r!   install_claude_desktoprL   1   s   < (K@JB ;;K#)ri[8&J (-9$,,.) ++Y{,KLL #Q!"NM!++-335GG,6)df\6J.J#),#7#=#A#A%#LL%A%A%A
%1
(2M% 	;m</v5PQR /s&9:s   BD/ /	E8EE)	server_namer$   r%   r&   env_filer/   r(   r)   r   rD   rM   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))rO   z--withz;Additional packages to install (can be used multiple times)z--envzFEnvironment variables in KEY=VALUE format (can be used multiple times)rN   z
--env-filez)Load environment variables from .env filer/   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 directoryz--config-pathz.Custom path to Claude Desktop config directoryc       	            K   |xs g }|xs g }|xs g }t        | ||||       d{   \  }
}}}}t        |
|||||||||	
      }|st        j                  d       yy7 8w)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
   )r   rL   r   exit)rD   rM   r$   r%   r&   rN   r/   r(   r)   r   r*   r+   r,   env_dictsuccesss                  r!   claude_desktop_commandrT      s     P "'RM!'RM~2H?R[-8@ :6D-}h %###+G  #:s   %A"A 9A")N)__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"   r:   listdictboolrL   	ParameterrT    r#   r!   <module>re      s:   D 	 
     A 0 P '	H	t td{ D (,&*&*!%%)#W
W:W W
 :$W 9t#W 38nt#W $JW d{W D[W W 
WF 	 	 	 	 	 	 	 	 	A]] d
D!H	
	] T
Ti	
	]" S	DX	
	#]. S	DY	
	/]< t<	
	=]J d
;	
	K]X !t!A	
	Y]f tE	
	g]t tA	
	u]B 
C]r#   