o
    i                     @   s   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dZdededB dee dB dee dB dedB deeedB eee eeef dB f fddZdS )z&Shared utilities for install commands.    N)Path)dotenv_values)ValidationError)print)
get_logger)MCPServerConfig)FileSystemSourceenv_varreturnc                 C   sB   d| vrt d|  d t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value r   `/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/fastmcp/cli/install/shared.pyparse_env_var   s   

r   server_specserver_namewith_packagesenv_varsenv_filec              
      s  |pg }|pg }d}|  drt|  }| s'td| d td z@t|}t	|}W d   n1 s<w   Y  d|v rOtd td nt
|}|jjrft|jj}	tt||	 }W n, tjtfy }
 ztd|
 d td W Y d}
~
nd}
~
ww t| d	}t
|d
}t|jj }t|jdr|jjnd}tjdt||||dd |}d}|sz|j I dH }|j}W n" ttfy }
 ztjddt|
id |j}W Y d}
~
nd}
~
ww |rt|dg ng }|rddl }|j!dt"dd tt|| }d}|s|rZi }|rJz|dd t#|$ D O }W n  t%yI }
 ztd|
 d td W Y d}
~
nd}
~
ww |D ]}t&|\}}|||< qL|||||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errordependenciesr   zServer uses deprecated 'dependencies' parameter (deprecated in FastMCP 2.11.4). Please migrate to fastmcp.json configuration file. See https://gofastmcp.com/docs/deployment/server-configuration for details.   )
stacklevelc                 S   s   i | ]\}}|d ur||qS )Nr   ).0kvr   r   r   
<dictcomp>   s    z'process_common_args.<locals>.<dictcomp>z[red]Failed to load .env file: )'endswithr   resolveexistsr   r   r   openjsonloadr   	from_fileenvironmentr#   listsetJSONDecodeErrorr   r   r   r   hasattrr   loggerdebugstrload_servernameImportErrorModuleNotFoundErrorstemgetattrwarningswarnDeprecationWarningr   items	Exceptionr   )r   r   r   r   r   configconfig_pathfdataconfig_packageser   r   r    r:   serverserver_dependenciesr?   env_dictr	   r   r   r   r   r   process_common_args   s   







	
rM   )__doc__r.   r   pathlibr   dotenvr   pydanticr   richr   fastmcp.utilities.loggingr   #fastmcp.utilities.mcp_server_configr   9fastmcp.utilities.mcp_server_config.v1.sources.filesystemr   __name__r6   r8   tupler   r2   dictrM   r   r   r   r   <module>   s2    

$