
    {h
                         d Z ddl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Zdedz  fdZde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_loggerzmcp[cli]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    O/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/mcp/cli/claude.pyget_claude_config_pathr      s    
||wDIIKIx@		!DIIK,A8L		 	 	)BJJNN#4diikI6MNPXY{{}    c                  `    t        j                  d      } | st        j                  d       y| S )z'Get the full path to the uv executable.uvzeuv executable not found in PATH, falling back to 'uv'. Please ensure uv is installed and in your PATH)shutilwhichloggererror)uv_paths    r   get_uv_pathr#   !   s,    ll4 Gs	
 Nr   )with_editablewith_packagesenv_vars	file_specserver_namer$   r%   r&   c                f   t               }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}
t        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}|r||d	<   ||d   |<   |j	                  t        j&                  |d             t        j)                  d| ddt        |      i       y# t
        $ r% t        j                  ddt        |      i       Y yw xY w# t
        $ r% t        j                  ddt        |      i       Y y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config_file)extraF
mcpServersenvrunc              3   &   K   | ]	  }|s|  y w)N ).0pkgs     r   	<genexpr>z'update_claude_config.<locals>.<genexpr>k   s     @CCC@s   z--withz--with-editable:   mcp)commandargs   )indentzAdded server 'z' to Claude configTzFailed to update Claude config)r   r#   RuntimeErrorr   
write_text	Exceptionr    	exceptionstrjsonloads	read_textMCP_PACKAGEupdatesortedextendrsplitr   resolvedumpsinfo)r'   r(   r$   r%   r&   
config_dirr"   r*   configexisting_envr8   packagesr2   	file_pathserver_objectserver_configs                   r   update_claude_configrR   ,   s   , ()JmGU
 	

 ;;K		""4(=K1134v%#%F<  &..5F<<PQ\<]3]!,/<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 	UE9-.4;T(J #+M% ,9|[)tzz&;<[M);< #k"23 	 	
 }  	5!3{#3   	~  ,s;/ 	 	
 s$   G 
FH +G?>G?+H0/H0)__doc__r@   r   r   r   pathlibr   typingr   $mcp.server.fastmcp.utilities.loggingr   __name__r    rC   r   r?   r#   listdictboolrR   r0   r   r   <module>r[      s    '  	  
   ;	H	t  S  "&&*&*hhh $;	h
 9t#h 38nt#h 
hr   