
    "<i_                     2   d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ  ee          Zd
edeeef         fdZdededz  dee         dz  dee         dz  dedz  deeedz  eee         eeef         dz  f         fdZdS )z&Shared utilities for install commands.    N)Path)dotenv_values)ValidationError)print)
get_logger)MCPServerConfig)FileSystemSourceenv_varreturnc                     d| vr't          d|  d           t          j        d           |                     dd          \  }}|                                |                                fS )z6Parse environment variable string in format KEY=VALUE.=z1[red]Invalid environment variable format: '[bold]z![/bold]'. Must be KEY=VALUE[/red]   )r   sysexitsplitstrip)r
   keyvalues      /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/fastmcp/cli/install/shared.pyparse_env_varr      sn    
'jjjj	
 	
 	
 	sA&&JC99;;%%    server_specserver_namewith_packagesenv_varsenv_filec                 v  K   |pg }|pg }d}|                      d          rct          |                                           }|                                s't	          d| d           t          j        d           	 t          |          5 }t          j	        |          }ddd           n# 1 swxY w Y   d|v r$t	          d           t          j        d           nXt          j        |          }|j        j        r8t          |j        j                  }	t          t          ||	z                       }nj# t          j        t"          f$ r1}
t	          d|
 d           t          j        d           Y d}
~
n(d}
~
ww xY wt%          | 	          }t          |
          }t          |j        j                                                  }t+          |j        d          r|j        j        nd}t.                              dt3          |          |||d           |}d}|sx	 |j                                         d{V }|j        }nP# t8          t:          f$ r<}
t.                              ddt3          |
          i           |j        }Y d}
~
nd}
~
ww xY wd}|s|ri }|rn	 |d t?          |                                           D             z  }n># tB          $ r1}
t	          d|
 d           t          j        d           Y d}
~
nd}
~
ww xY w|D ]}tE          |          \  }}|||<   |||||fS )zProcess common arguments shared by all install commands.

    Handles both fastmcp.json config files and traditional file.py:object syntax.
    Nz.jsonz#[red]Configuration file not found: z[/red]r   
mcpServersz=[red]MCPConfig files are not supported for installation[/red]z![red]Invalid configuration file: )path)source
entrypointzInstalling server)filer   server_objectr   )extrazFCould not import server (likely missing dependencies), using file nameerrorc                     i | ]
\  }}|||S )N ).0kvs      r   
<dictcomp>z'process_common_args.<locals>.<dictcomp>s   s&       !QAqr   z[red]Failed to load .env file: )#endswithr   resolveexistsr   r   r   openjsonloadr   	from_fileenvironmentdependencieslistsetJSONDecodeErrorr   r	   r    r   hasattrr!   loggerdebugstrload_servernameImportErrorModuleNotFoundErrorstemr   items	Exceptionr   )r   r   r   r   r   configconfig_pathfdataconfig_packageser    r"   r#   r=   serverenv_dictr
   r   r   s                       r   process_common_argsrK      s      "'RM~2HFG$$ 0;''//11!!## 	KKKKLLLHQKKK	k"" $ay||$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ t##UVVV )2;?? %2 O&*6+=+J&K&KO$(]_-L)M)M$N$NM$o6 	 	 	?a???@@@HQKKKKKKKK	
 "{333 /// "##++--D$+FM<$H$HR  d  LLII&**	
 
     DF 		!=4466666666F;DD01 	 	 	LLXA'     9DDDDDD	 '+H "8 " 	  %28%<%<%B%B%D%D       AAAABBB
   	" 	"G&w//JC!HSMMmX==sm    D< B0$D< 0B44D< 7B48BD< <F'E>>F)&I J!2JJ+.K 
L$'LL)__doc__r0   r   pathlibr   dotenvr   pydanticr   richr   fastmcp.utilities.loggingr   #fastmcp.utilities.mcp_server_configr   9fastmcp.utilities.mcp_server_config.v1.sources.filesystemr	   __name__r9   r;   tupler   r5   dictrK   r'   r   r   <module>rW      su   , ,  



                   $ $ $ $ $ $       0 0 0 0 0 0 ? ? ? ? ? ? V V V V V V	H		&3 &5c? & & & &b>b>tb> 9t#b> 3i$	b>
 Tkb> 4tS$s)T#s(^d-BBCb> b> b> b> b> b>r   