
    ~h                         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m	Z	  e	e
      Zdedz  fdZddddd	ed
ededz  dee   dz  deeef   dz  defdZy)z!Claude app integration utilities.    N)Path)Any)
get_loggerreturnc                     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)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    N/opt/mcp/mcp-sentiment/venv/lib/python3.12/site-packages/fastmcp/cli/claude.pyget_claude_config_pathr      s    
||wDIIKIx@		!DIIK,A8L		 	 	)JJNN,diikI.EF
 {{}    )with_editablewith_packagesenv_vars	file_specserver_namer   r   r   c                   t               }|st        d      |dz  }|j                         s	 |j                  d       	 t        j                  |j                               }d	|vri |d	<   ||d	   v r d
|d	   |   v r|d	   |   d
   }	|ri |	|}n|	}dg}
dh}|r|j                  d |D               t        |      D ]  }|
j                  d|g        |r|
j                  dt        |      g       d| v r4| j                  dd      \  }}t        |      j!                          d| } n"t        t        |       j!                               } |
j                  dd| g       d|
d}|r||d
<   ||d	   |<   |j                  t        j"                  |d             t
        j%                  d| ddt        |      i       y# t        $ r6}t
        j                  dt        |      t        |      d       Y d}~yd}~ww xY w# t        $ r6}t
        j                  dt        |      t        |      d       Y d}~yd}~ww xY w)a  Add or update a FastMCP server in Claude's configuration.

    Args:
        file_spec: Path to the server file, optionally with :object suffix
        server_name: Name for the server in Claude's config
        with_editable: Optional directory to install in editable mode
        with_packages: Optional list of additional packages to install
        env_vars: Optional dictionary of environment variables. These are merged with
            any existing variables, with new values taking precedence.

    Raises:
        RuntimeError: If Claude Desktop's config directory is not found, indicating
            Claude Desktop may not be installed or properly set up.
    zClaude Desktop config directory not found. Please ensure Claude Desktop is installed and has been run at least once to initialize its config.zclaude_desktop_config.jsonz{}z#Failed to create Claude config file)errorconfig_file)extraNF
mcpServersenvrunfastmcpc              3   &   K   | ]	  }|s|  y w)N ).0pkgs     r   	<genexpr>z'update_claude_config.<locals>.<genexpr>b   s     @CCC@s   z--withz--with-editable:   uv)commandargs   )indentzAdded server 'z' to Claude configr#   TzFailed to update Claude config)r   RuntimeErrorr   
write_text	Exceptionloggerr"   strjsonloads	read_textupdatesortedextendrsplitr   resolvedumpsinfo)r   r    r   r   r   
config_dirr#   econfigexisting_envr2   packagesr,   	file_pathserver_objectserver_configs                   r   update_claude_configrL       s   , ()JU
 	

 ;;K
	""4(AK1134v%#%F<  6,//-k::!,/<UCL7l7h7' w ;OO@=@@ (# 	)CKK3(	) KK*C,>?@ )'0'7'7Q'?$I}	?2245Q}oFIDO3356I 	Yy1248$(G #+M% ,9|[)tzz&;<[M);< #k"23 	 	
 E  	LL5 V#&{#3   	F  ,Q";/ 	 	
 s0   G  FH 	H,G==H	I,H??I)__doc__r:   r   r   pathlibr   typingr   fastmcp.utilities.loggingr   __name__r8   r   r9   listdictboolrL   r*   r   r   <module>rU      s    '  	 
   0	H	t , "&&*&*lll $;	l
 9t#l 38nt#l 
lr   