
    kKj'                        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	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 d
dlmZ  ee      ZdededefdZdedefdZddddddddededz  de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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dz  defd!Zd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)*      f   deee   dz   e	j@                  d+d,*      f   deee   dz   e	j@                  d-d.*      f   d/eedz   e	j@                  d0d1*      f   d2eedz   e	j@                  d3d4*      f   deedz   e	j@                  d5d6*      f   deedz   e	j@                  d7d8*      f   d eedz   e	j@                  d9d:*      f   ddfd;Z!y)<z6Cursor integration for FastMCP install using Cyclopts.    N)Path)	Annotated)quote)print)StdioMCPServerupdate_config_file)
get_logger)UVEnvironment   )open_deeplink)process_common_argsserver_nameserver_configreturnc                     |j                  d      }t        j                  |j                               j	                         }t        | d      }d| d| }|S )zGenerate a Cursor deeplink for installing the MCP server.

    Args:
        server_name: Name of the server
        server_config: Server configuration

    Returns:
        Deeplink URL that can be clicked to install the server
    T)exclude_none )safez4cursor://anysphere.cursor-deeplink/mcp/install?name=z&config=)model_dump_jsonbase64urlsafe_b64encodeencodedecoder   )r   r   config_json
config_b64encoded_namedeeplinks         k/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/fastmcp/cli/install/cursor.pygenerate_cursor_deeplinkr      sa      //T/BK))+*<*<*>?FFHJ 2.LEl^S[\f[ghHO    r   c                     t        | d      S )zAttempt to open a Cursor deeplink URL using the system's default handler.

    Args:
        deeplink: The deeplink URL to open

    Returns:
        True if the command succeeded, False otherwise
    cursor)expected_scheme)_shared_open_deeplink)r   s    r   r   r   /   s     !8DDr    )with_editablewith_packagesenv_varspython_versionwith_requirementsprojectfileserver_objectnameworkspace_pathr%   r&   r'   r(   r)   r*   c                   |j                         }|j                         st        d| d       y|j                         st        d| d       y|dz  }
|
j	                  d       |
dz  }t        ||xs g d	gz   ||	|
      }|r| j                          d| }nt        | j                               }|j                  d	d|g      }t        |d   |dd |xs i       }	 |j                         s|j                  d       t        |||       t        d| d| d       y# t        $ r}t        d| d       Y d}~yd}~ww xY w)a  Install FastMCP server to workspace-specific Cursor configuration.

    Args:
        file: Path to the server file
        server_object: Optional server object name (for :object suffix)
        name: Name for the server in Cursor
        workspace_path: Path to the workspace directory
        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]Workspace directory does not exist: z[/red]Fz([red]Workspace path is not a directory: z.cursorT)exist_okzmcp.jsonfastmcppythondependenciesrequirementsr*   editable:runr   r   Ncommandargsenvz{"mcpServers": {}}z[green]Successfully installed 'z' to workspace at z[/green]z,[red]Failed to install server to workspace: )resolveexistsr   is_dirmkdirr
   strbuild_commandr   
write_textr   	Exception)r+   r,   r-   r.   r%   r&   r'   r(   r)   r*   
cursor_dirconfig_file
env_configserver_specfull_commandr   es                    r   install_cursor_workspacerK   ;   s   > $++-N  "9.9IPQ  "88HOP  )+Jd#z)K#)ri[8&J (-9$,,.) ++Y{,KLL #Q!"NM!!#""#78 	;m<-dV3EnEUU]^	
  <QCvFGs   #A D$ $	E-EE)r%   r&   r'   r(   r)   r*   	workspacerL   c                   t        ||xs g dgz   |||      }
|r| j                          d| }nt        | j                               }|
j                  dd|g      }|	rt	        | |||	||||||
      S t        |d   |dd |xs i 	      }t        ||      }t        d
| d       t        |      rt        d       yt        d| d       y)a  Install FastMCP server in Cursor.

    Args:
        file: Path to the server file
        server_object: Optional server object name (for :object suffix)
        name: Name for the server in Cursor
        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
        workspace: Optional workspace directory for project-specific installation

    Returns:
        True if installation was successful, False otherwise
    r1   r2   r7   r8   )
r+   r,   r-   r.   r%   r&   r'   r(   r)   r*   r   r   Nr9   z![blue]Opening Cursor to install 'z'[/blue]zB[green]Cursor should now open with the installation dialog[/green]Tzc[red]Could not open Cursor automatically.[/red]
[blue]Please copy this link and open it in Cursor: z[/blue]F)	r
   r=   rA   rB   rK   r   r   r   r   )r+   r,   r-   r%   r&   r'   r(   r)   r*   rL   rG   rH   rI   r   r   s                  r   install_cursorrN      s   > #)ri[8&J (-9$,,.) ++Y{,KLL ''$'')/
 	
 #Q!"NM (m<H	-dV8
<=XRSBBJ7T	
 r    )	r   r%   r&   r'   env_filer3   r)   r*   rL   rH   z--namez-nz$Custom name for the server in Cursor)r-   helpz--with-editablezVDirectory with pyproject.toml to install in editable mode (can be used multiple times))rP   z--withz;Additional packages to install (can be used multiple times)z--envzFEnvironment variables in KEY=VALUE format (can be used multiple times)rO   z
--env-filez)Load environment variables from .env filer3   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 directoryz--workspacezYInstall to workspace directory (will create .cursor/ inside it) instead of using deeplinkc       	            K   |xs g }|xs g }|xs g }t        | ||||       d{   \  }
}}}}t        |
|||||||||	
      }|st        j                  d       yy7 8w)z|Install an MCP server in Cursor.

    Args:
        server_spec: Python file to install, optionally with :object suffix
    N)
r+   r,   r-   r%   r&   r'   r(   r)   r*   rL   r   )r   rN   sysexit)rH   r   r%   r&   r'   rO   r3   r)   r*   rL   r+   r,   r-   env_dictsuccesss                  r   cursor_commandrV      s     P "'RM!'RM~2H?R[-8@ :6D-}h ###+G  #:s   %A"A 9A")"__doc__r   rR   pathlibr   typingr   urllib.parser   cycloptsrichr   fastmcp.mcp_configr   r   fastmcp.utilities.loggingr	   6fastmcp.utilities.mcp_server_config.v1.environments.uvr
   sharedr   r$   r   __name__loggerrA   r   boollistdictrK   rN   	ParameterrV    r    r   <module>rh      s   <  
      A 0 P : '	H	! 	2	EC 	ED 	E$ (,&*&*!%%)Q
Q:Q Q 	Q :$Q 9t#Q 38nt#Q $JQ d{Q D[Q 
Qr (,&*&*!%%)!R
R:R R
 :$R 9t#R 38nt#R $JR d{R D[R d{R 
R| 	 	 	 	 	 	 	 	 	A]] d
D!7	
	] T
Ti	
	]" S	DX	
	#]. S	DY	
	/]< t<	
	=]J d
;	
	K]X !t!A	
	Y]f tE	
	g]t tl	
	u]B 
C]r    