
    kKjS                     r   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 dd	lmZmZ  ee      Zd
edefdZddd
ededee   dedef
dZddddededz  dee   dz  dee   fdZddddededz  d
edee   dz  dedz  defdZdddddddedeedz   e	j4                  ddgd !      f   deee   dz   e	j4                  d"d#$      f   d%eee   dz   e	j4                  d&d'$      f   d(eedz   e	j4                  d)d*$      f   d+eedz   e	j4                  d,d-$      f   ddfd.Zy)/z5Goose integration for FastMCP install using Cyclopts.    N)Path)	Annotatedquote)print)
get_logger   )open_deeplinkprocess_common_argsnamereturnc                 v    t        j                  dd| j                               j                  d      }|xs dS )zConvert a display name to a URL-safe identifier.

    Lowercases, replaces non-alphanumeric runs with hyphens,
    and strips leading/trailing hyphens.
    z
[^a-z0-9]+-zfastmcp-server)resublowerstrip)r   slugs     j/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/fastmcp/cli/install/goose.py_slugifyr      s3     66-djjl399#>D###    z MCP server installed via FastMCP)descriptioncommandargsr   c                L   t        |       }dt        |d       g}|j                  d |D               |j                  dt        |d              |j                  dt        | d              |j                  dt        |d              dd	j	                  |       S )
aW  Generate a Goose deeplink for installing an MCP extension.

    Args:
        name: Human-readable display name for the extension.
        command: The executable command (e.g. "uv").
        args: Arguments to the command.
        description: Short description shown in Goose.

    Returns:
        A goose://extension?... deeplink URL.
    zcmd= safec              3   <   K   | ]  }d t        |d         yw)zarg=r   r   Nr   ).0args     r   	<genexpr>z*generate_goose_deeplink.<locals>.<genexpr>2   s      ?$3Ds,-.$s   zid=zname=zdescription=zgoose://extension?&)r   r   extendappendjoin)r   r   r   r   extension_idparamss         r   generate_goose_deeplinkr)      s    $ D>LgB 789:F
MM?$??
MMCl4567
MME%2./01
MML{!< =>? 0122r   python_versionwith_packagesserver_specr+   r,   c                    dg}|r|j                  d|g       t        t        |xs g             D ]  }|dk7  s	|j                  d|g        |j                  dd| g       |S )a/  Build a uvx command for running a FastMCP server.

    Goose requires uvx (not uv run) as the command. The uvx format is:
        uvx [--with pkg] [--python X] fastmcp run <spec>

    uvx automatically infers that the `fastmcp` command comes from the
    `fastmcp` package, so --from is not needed.
    uvx--pythonfastmcp--withrun)r$   sortedset)r-   r+   r,   r   pkgs        r   _build_uvx_commandr7   :   sj     gDZ01c--2./)KK3( 0 	KKE;/0Kr   )r,   r+   fileserver_objectc                   |r| j                          d| }nt        | j                               }t        |||      }t        ||d   |dd       }t	        d| d       t        |d	
      rt	        d       yt	        d| d       y)a  Install FastMCP server in Goose via deeplink.

    Args:
        file: Path to the server file.
        server_object: Optional server object name (for :object suffix).
        name: Name for the extension in Goose.
        with_packages: Optional list of additional packages to install.
        python_version: Optional Python version to use.

    Returns:
        True if installation was successful, False otherwise.
    :r*   r   r	   N)r   r   r   z [blue]Opening Goose to install 'z'[/blue]goose)expected_schemezA[green]Goose should now open with the installation dialog[/green]Tza[red]Could not open Goose automatically.[/red]
[blue]Please copy this link and open it in Goose: z[/blue]F)resolvestrr7   r)   r   r
   )r8   r9   r   r,   r+   r-   full_commanddeeplinks           r   install_gooserB   U   s    ( (-9$,,.)%%#L 'Q!"H 
,TF(
;<Xw7QRAAI
'S	
 r   )server_namer,   env_varsenv_filepythonrC   z--namez-nz&Custom name for the extension in Goose)r   helpr2   z;Additional packages to install (can be used multiple times))rG   rD   z--envzFEnvironment variables in KEY=VALUE format (can be used multiple times)rE   z
--env-filez)Load environment variables from .env filerF   r0   z(Python version to use (e.g., 3.10, 3.11)c                   K   |xs g }|xs g }|s|r t        d       t        j                  d       t        | ||||       d{   \  }}}}}	t	        |||||      }
|
st        j                  d       yy7 3w)a.  Install an MCP server in Goose.

    Uses uvx to run the server. Environment variables are not included
    in the deeplink; use `fastmcp install mcp-json` to generate a full
    config for manual installation.

    Args:
        server_spec: Python file to install, optionally with :object suffix
    a  [red]Goose deeplinks cannot include environment variables.[/red]
[yellow]Use `fastmcp install mcp-json` to generate a config, then add it to your Goose config file with env vars: https://block.github.io/goose/docs/getting-started/using-extensions/#config-entry[/yellow]r	   N)r8   r9   r   r,   r+   )r   sysexitr   rB   )r-   rC   r,   rD   rE   rF   r8   r9   r   	_env_dictsuccesss              r   goose_commandrM      s     ` "'RM~2H8i	
 	@S[-8A ;7D-}i ##G  ;s   AA;A94A;)__doc__r   rI   pathlibr   typingr   urllib.parser   cycloptsrichr   fastmcp.utilities.loggingr   sharedr
   r   __name__loggerr?   r   listr)   r7   boolrB   	ParameterrM    r   r   <module>r\      sX   ; 	 
      0 6	H	$3 $3 $ :3
33 s)3
 3 	3@ "&&*	 $J 9t#	
 
#Y@ '+!%/
/:/ /
 9t#/ $J/ 
/v 	 	 	 	 	KII d
D!9	
	I S	DN	
	I" S	DY	
	#I0 t<	
	1I> d
;	
	?IL 
MIr   