
    "<i                     V   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z  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 Desktop integration for FastMCP install using Cyclopts.    N)Path)	Annotated)print)StdioMCPServerupdate_config_file)
get_logger)UVEnvironment   )process_common_argsreturnc                     t           j        dk    r$t          t          j                    ddd          } nt           j        dk    r$t          t          j                    ddd          } ndt           j                            d          rCt          t
          j                            d	t          j                    d
z            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)paths    /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/fastmcp/cli/install/claude_desktop.pyget_claude_config_pathr       s    
|wDIKKIx@@		!	!DIKK,A8LL		 	 	)	) JNN,dikkI.EFF
 
 t{{}} 4    )with_editablewith_packagesenv_varspython_versionwith_requirementsprojectfileserver_objectnamer"   r#   r$   r%   r&   r'   c                B   t                      }	|	st          d           dS |	dz  }
t          ||pg dgz   |||          }|r|                                  d| }n!t	          |                                           }|                    dd|g          }t          |d         |d	d
         |pi           }	 |
                                rdd
l}|
	                                
                                }|rW|                    |          }d|v r>||d         v r4|d         |                             di           }|ri ||}n|}||_        t          |
||           t          d| d           dS # t          $ r}t          d| d           Y d
}~dS 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

    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
mcpServersr5   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   r5   r   	Exception)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_desktoprJ   &   s(   8 ())J ~	
 	
 	
 u;;K#)ri[8&  J  *99-99$,,..)) ++Y{,KLLL #Q!""N  M 	3KKK!++--3355G 	3G,,6))df\6J.J.J#),#7#=#A#A%#L#LL 2%A%A%A

%1
(2M% 	;m<<<QQQQRRRt   9999:::uuuuus   9B;E6 6
F FF)server_namer"   r#   r$   env_filer-   r&   r'   rB   rK   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) )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   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                   K   |pg }|pg }|pg }t          | ||||           d{V \  }	}
}}}t          |	|
|||||||	  	        }|st          j        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   rJ   r   exit)rB   rK   r"   r#   r$   rL   r-   r&   r'   r(   r)   r*   env_dictsuccesss                 r   claude_desktop_commandrT   }   s      J "'RM!'RM~2H?R[-8@ @ : : : : : :6D-}h %###+
 
 
G   r!   )__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    r8   listdictboolrJ   	ParameterrT    r!   r   <module>re      s   D D 				 



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