
    k7i(                        S r SSKrSSKrSSKrSSKJr  SSKJr  SSKrSSK	J
r
  SSKJrJr  SSKJr  SSKJr  S	S
KJr  \" \5      rS\S\S\4S jrS\S\4S jrSSSSSSS.S\S\S-  S\S\S\\   S-  S\\   S-  S\\\4   S-  S\S-  S\S-  S\S-  S\4S jjrSSSSSSSS.S\S\S-  S\S\\   S-  S\\   S-  S\\\4   S-  S\S-  S\S-  S\S-  S\S-  S\4S jjrSSSSSSSSSS .	S!\S\\S-  \R<                  " S"S#/S$S%94   S\\\   S-  \R<                  " S&S'S(S)94   S\\\   S-  \R<                  " S*S+S(S)94   S\\\   S-  \R<                  " S,S-S(S)94   S.\\S-  \R<                  " S/S0S194   S2\\S-  \R<                  " S3S4S194   S\\S-  \R<                  " S5S6S194   S\\S-  \R<                  " S7S8S194   S\\S-  \R<                  " S9S:S194   SS4S; jjrg)<z6Cursor integration for FastMCP install using Cyclopts.    N)Path)	Annotated)print)StdioMCPServerupdate_config_file)
get_logger)UVEnvironment   )process_common_argsserver_nameserver_configreturnc                     UR                  SS9n[        R                  " UR                  5       5      R	                  5       nSU  SU 3nU$ )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_nonez4cursor://anysphere.cursor-deeplink/mcp/install?name=z&config=)model_dump_jsonbase64urlsafe_b64encodeencodedecode)r   r   config_json
config_b64deeplinks        T/home/james-whalen/.local/lib/python3.13/site-packages/fastmcp/cli/install/cursor.pygenerate_cursor_deeplinkr      sV      //T/BK))+*<*<*>?FFHJ Fk]RZ[eZfgHO    r   c                 .    [         R                  S:X  a  [        R                  " SU /SSS9  g[         R                  S:X  a  [        R                  " SSSU /SSS9  g[        R                  " S	U /SSS9  g! [        R                  [
        4 a     g
f = f)zAttempt to open a deeplink URL using the system's default handler.

Args:
    deeplink: The deeplink URL to open

Returns:
    True if the command succeeded, False otherwise
darwinopenT)checkcapture_outputwin32cmdz/cstartzxdg-openF)sysplatform
subprocessrunCalledProcessErrorFileNotFoundError)r   s    r   open_deeplinkr*   -   s    <<8#NNFH-T$O  \\W$NNgx0T
  NNJ1dS))+<= s   ,A7 .A7 A7 7BB)with_editablewith_packagesenv_varspython_versionwith_requirementsprojectfileserver_objectnameworkspace_pathr+   r,   r-   r.   r/   r0   c                r   UR                  5       nUR                  5       (       d  [        SU S35        gUS-  n
U
R                  SS9  U
S-  n[	        UU=(       d    / S/-   UU	US	9nU(       a  U R                  5        S
U 3nO[        U R                  5       5      nUR                  SSU/5      n[        US   USS U=(       d    0 S9n UR                  5       (       d  UR                  S5        [        XU5        [        SU SU S35        g! [         a  n[        SU S35         SnAgSnAff = f)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.cursorT)exist_okzmcp.jsonfastmcppythondependenciesrequirementsr0   editable:r'   r   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   mkdirr	   strbuild_commandr   
write_textr   	Exception)r1   r2   r3   r4   r+   r,   r-   r.   r/   r0   
cursor_dirconfig_file
env_configserver_specfull_commandr   es                    r   install_cursor_workspacerO   D   sb   > $++-N  ""9.9IPQ  )+Jd#z)K#)ri[8&J (-9$,,.) ++Y{,KLL #Q!"NM!!##""#78 	;m<-dV3EnEUU]^	
  <QCvFGs   AD 
D6D11D6)r+   r,   r-   r.   r/   r0   	workspacerP   c                   [        UU=(       d    / S/-   UUUS9n
U(       a  U R                  5        SU 3nO[        U R                  5       5      nU
R                  SSU/5      nU	(       a  [	        U UUU	UUUUUUS9
$ [        US   USS U=(       d    0 S	9n[        X-5      n[        S
U S35        [        U5      (       a  [        S5        g[        SU S35        g)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
r7   r8   r=   r'   )
r1   r2   r3   r4   r+   r,   r-   r.   r/   r0   r   r
   Nr>   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	   rB   rE   rF   rO   r   r   r   r*   )r1   r2   r3   r+   r,   r-   r.   r/   r0   rP   rK   rL   rM   r   r   s                  r   install_cursorrR      s   > #)ri[8&J (-9$,,.) ++Y{,KLL ''$'')/
 	
 #Q!"NM (<H	-dV8
<=XRSBBJ7T	
 r   )	r   r+   r,   r-   env_filer9   r/   r0   rP   rL   z--namez-nz$Custom name for the server in Cursor)r3   helpz--with-editablezVDirectory with pyproject.toml to install in editable mode (can be used multiple times) )rT   negativez--withz;Additional packages to install (can be used multiple times)z--envzFEnvironment variables in KEY=VALUE format (can be used multiple times)rS   z
--env-filez)Load environment variables from .env file)rT   r9   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       	            #    U=(       d    / nU=(       d    / nU=(       d    / n[        XX4U5      I Sh  vN u  ppn[        U
UUUUUUUUU	S9
nU(       d  [        R                  " S5        gg N97f)zpInstall an MCP server in Cursor.

Args:
    server_spec: Python file to install, optionally with :object suffix
N)
r1   r2   r3   r+   r,   r-   r.   r/   r0   rP   r
   )r   rR   r$   exit)rL   r   r+   r,   r-   rS   r9   r/   r0   rP   r1   r2   r3   env_dictsuccesss                  r   cursor_commandr[      s     X "'RM!'RM~2H?R-8@ :6Dh ###+G  #:s   2A0A.:A0) __doc__r   r&   r$   pathlibr   typingr   cycloptsrichr   fastmcp.mcp_configr   r   fastmcp.utilities.loggingr   6fastmcp.utilities.mcp_server_config.v1.environments.uvr	   sharedr   __name__loggerrE   r   boolr*   listdictrO   rR   	Parameterr[    r   r   <module>rl      s   <   
     A 0 P '	H	! 	0C D : (,&*&*!%%)N
N:N N 	N :$N 9t#N 38nt#N $JN d{N D[N 
Nl (,&*&*!%%)!R
R:R R
 :$R 9t#R 38nt#R $JR d{R D[R d{R 
R| 	 	 	 	 	 	 	 	 	Iaa d
D!7	
	a T
Ti	
	a$ S	DN	
	%a4 S	DY	
	5aD t<	
	EaR d
;	
	Sa` !t!A	
	aan tE	
	oa| tl	
	}aJ 
Kar   