Skip to content

cli

foo(param1=typer.Argument(..., help='Primeiro parâmetro do comando FOO.'), param2=typer.Argument(..., help='Segundo parâmetro do comando FOO.'))

Executes the FOO command with two required parameters.

Parameters:

Name Type Description Default
param1 str

First parameter for the FOO command.

Argument(..., help='Primeiro parâmetro do comando FOO.')
param2 str

Second parameter for the FOO command.

Argument(..., help='Segundo parâmetro do comando FOO.')

Returns:

Name Type Description
None None

This function does not return any value.

Source code in src/mcpgateway_client/cli.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
@app.command(help="Executa o comando FOO com dois parâmetros obrigatórios.")
def foo(
    param1: str = typer.Argument(..., help="Primeiro parâmetro do comando FOO."),
    param2: str = typer.Argument(..., help="Segundo parâmetro do comando FOO."),
) -> None:
    """
    Executes the FOO command with two required parameters.

    Args:
        param1 (str): First parameter for the FOO command.
        param2 (str): Second parameter for the FOO command.

    Returns:
        None: This function does not return any value.
    """
    typer.echo(f"Executando FOO com param1={param1} e param2={param2}")

main_callback(ctx, version=typer.Option(None, '--version', help='Exibe a versão do pacote e sai.', is_eager=True, callback=lambda value: show_version_and_exit() if value else None))

Main callback for the CLI application. Displays the main panel if no subcommand is invoked.

Parameters:

Name Type Description Default
ctx Context

The Typer context object for the CLI invocation.

required

Returns:

Name Type Description
None None

This function does not return any value.

Source code in src/mcpgateway_client/cli.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
@app.callback(invoke_without_command=True)
def main_callback(
    ctx: typer.Context,
    version: bool = typer.Option(
        None,
        "--version",
        help="Exibe a versão do pacote e sai.",
        is_eager=True,
        callback=lambda value: show_version_and_exit() if value else None,
    ),
) -> None:
    """
    Main callback for the CLI application. Displays the main panel if no subcommand is invoked.

    Args:
        ctx (typer.Context): The Typer context object for the CLI invocation.

    Returns:
        None: This function does not return any value.
    """
    if ctx.invoked_subcommand is None and not version:
        console.print(
            Panel.fit(
                "[bold cyan]mcpgateway-client CLI[/bold cyan]\n\n"
                "[white]Use um dos comandos abaixo:[/white]\n"
                "[green]- foo[/green]: executa ação foo com dois argumentos obrigatórios\n"
                "[green]- bar[/green]: executa ação bar com dois argumentos obrigatórios\n\n"
                "[yellow]Dica:[/yellow] use '--help' após qualquer comando para mais detalhes.",
                title="[bold blue]SnapEnv CLI[/bold blue]",
                border_style="bright_blue",
            )
        )

register(gateway_url=typer.Option(..., '--gateway-url', '-g', help='Gateway URL to connect to. Ex: ws://localhost:8765/mcp/register'), gateway_auth_token=typer.Option(None, '--auth-token', '-a', help='Set the auth token for the gateway. Ex: Bearer abcdef123456'), stdio=typer.Option(..., '--stdio', '-i', help='Subprocess command to start. Ex: npx -y @modelcontextprotocol/server-filesystem ./'), server_name=typer.Option(..., '--server-name', '-n', help='Server name for registration. Ex: local-mcpserver-001'), header=HEADER_OPTION, log_level=LOG_LEVEL, dry_run=DRY_RUN)

Executes the REGISTER command with required and optional parameters.

Parameters:

Name Type Description Default
gateway_url str

URL do gateway para conexão.

Option(..., '--gateway-url', '-g', help='Gateway URL to connect to. Ex: ws://localhost:8765/mcp/register')
gateway_auth_token str

Token de autenticação.

Option(None, '--auth-token', '-a', help='Set the auth token for the gateway. Ex: Bearer abcdef123456')
stdio str

Comando subprocesso.

Option(..., '--stdio', '-i', help='Subprocess command to start. Ex: npx -y @modelcontextprotocol/server-filesystem ./')
server_name str

Nome do servidor.

Option(..., '--server-name', '-n', help='Server name for registration. Ex: local-mcpserver-001')
header str

Headers HTTP.

HEADER_OPTION
Usage Examples

cli register \ --gateway-url https://gateway.snapby.com \ --auth-token "Bearer abcdef123456" \ --stdio "/usr/local/bin/mcpserve" \ --server-name "snapby-server-001"

cli register -g https://localhost:8080 -i ./run.sh -n dev-env \ -h "Authorization: Bearer devtoken" -h "X-Custom-Header: test"

Returns:

Name Type Description
None None

Esta função não retorna valor.

Source code in src/mcpgateway_client/cli.py
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
@app.command(help="Register your MCP Server to the Gateway.")
def register(
    gateway_url: str = typer.Option(
        ...,
        "--gateway-url",
        "-g",
        help="Gateway URL to connect to. Ex: ws://localhost:8765/mcp/register",
    ),
    gateway_auth_token: str = typer.Option(
        None,
        "--auth-token",
        "-a",
        help="Set the auth token for the gateway. Ex: Bearer abcdef123456",
    ),
    stdio: str = typer.Option(
        ...,
        "--stdio",
        "-i",
        help="Subprocess command to start. Ex: npx -y @modelcontextprotocol/server-filesystem ./",
    ),
    server_name: str = typer.Option(
        ...,
        "--server-name",
        "-n",
        help="Server name for registration. Ex: local-mcpserver-001",
    ),
    header: list[str] = HEADER_OPTION,
    log_level: str = LOG_LEVEL,
    dry_run: bool = DRY_RUN,
) -> None:
    """
    Executes the REGISTER command with required and optional parameters.

    Args:
        gateway_url (str): URL do gateway para conexão.
        gateway_auth_token (str, optional): Token de autenticação.
        stdio (str): Comando subprocesso.
        server_name (str): Nome do servidor.
        header (str, optional): Headers HTTP.

    Usage Examples:
        > cli register \\
            --gateway-url https://gateway.snapby.com \\
            --auth-token "Bearer abcdef123456" \\
            --stdio "/usr/local/bin/mcpserve" \\
            --server-name "snapby-server-001"

        > cli register -g https://localhost:8080 -i ./run.sh -n dev-env \\
            -h "Authorization: Bearer devtoken" -h "X-Custom-Header: test"

    Returns:
        None: Esta função não retorna valor.
    """
    setup_logger(level=log_level)
    headers = {}
    if header:
        for item in header:
            if ":" not in item:
                msg = f"Invalid header: '{item}'."
                raise ValueError(msg)
            key, value = item.split(":", 1)
            headers[key.strip()] = value.strip()

    ws_args = StdioToWsArgs(
        gateway_url=gateway_url,
        gateway_auth_token=gateway_auth_token,
        # port=args.port,
        # enable_cors=args.enable_cors,
        # health_endpoints=args.health_endpoint,
        server_name=server_name,
        # server_id=args.server_id,
        # require_gateway=args.require_gateway,
        headers=headers,
        stdio_cmd=stdio,
        # ssl_verify=args.ssl_verify,
        # ssl_ca_cert=args.ssl_ca_cert,
        log_level=log_level,
    )

    # config_panel = Panel(
    #     Pretty(ws_args.__dict__, expand_all=True),
    #     title="📦 Client Register Settings",
    #     # subtitle="Objeto Python formatado",
    #     border_style="cyan",
    #     expand=True,
    # )
    # console.print(config_panel)

    tree = Tree("📦 [bold cyan]Settings[/]")

    for key, value in ws_args.__dict__.items():
        if isinstance(value, dict):
            branch = tree.add(f"[bold yellow]{key}[/]:")
            for sub_key, sub_value in value.items():
                branch.add(f"[green]{sub_key}[/]: {sub_value}")
        else:
            tree.add(f"[bold yellow]{key}[/]: {value}")

    console.print(Panel(tree, title="Client Register", border_style="magenta", expand=True))

    if not dry_run:
        client_main(ws_args)

show_version_and_exit()

Exibe versão usando Rich e sai.

Source code in src/mcpgateway_client/cli.py
47
48
49
50
51
52
53
54
55
56
57
def show_version_and_exit() -> None:
    """Exibe versão usando Rich e sai."""
    console.print(
        Panel.fit(
            f"[bold green]SnapBy MCP Gateway:[/bold green] [cyan]CLIENT v{VERSION}[/cyan]\n\n"
            f"[bold red]https://snapby.com[/bold red]",
            title="[bold blue]Version[/bold blue]",
            border_style="green",
        )
    )
    raise typer.Exit()