Skip to content

Commit df6fa89

Browse files
authored
Port over cli changes (#421)
1 parent c944af6 commit df6fa89

File tree

7 files changed

+314
-246
lines changed

7 files changed

+314
-246
lines changed

src/mcp_agent/cli/cloud/commands/configure/main.py

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
from mcp_agent.cli.exceptions import CLIError
2525
from mcp_agent.cli.mcp_app.api_client import (
2626
MCPAppClient,
27-
is_valid_app_id_format,
28-
is_valid_server_url_format,
2927
)
3028
from mcp_agent.cli.mcp_app.mock_client import MockMCPAppClient
3129
from mcp_agent.cli.secrets.mock_client import MockSecretsClient
@@ -41,11 +39,11 @@
4139

4240

4341
def configure_app(
44-
app_id_or_url: str = typer.Option(
42+
app_server_url: str = typer.Option(
4543
None,
4644
"--id",
4745
"-i",
48-
help="ID or server URL of the app to configure.",
46+
help="Server URL of the app to configure.",
4947
),
5048
secrets_file: Optional[Path] = typer.Option(
5149
None,
@@ -90,7 +88,7 @@ def configure_app(
9088
"""Configure an MCP app with the required params (e.g. user secrets).
9189
9290
Args:
93-
app_id_or_url: ID or server URL of the MCP App to configure
91+
app_server_url: Server URL of the MCP App to configure
9492
secrets_file: Path to an existing secrets file containing processed user secrets to use for configuring the app
9593
secrets_output_file: Path to write processed secrets to, if secrets are prompted. Defaults to mcp-agent.configured.secrets.yaml
9694
dry_run: Don't actually store secrets, just validate
@@ -101,8 +99,8 @@ def configure_app(
10199
Configured app ID.
102100
"""
103101
# Check what params the app requires (doubles as an access check)
104-
if not app_id_or_url:
105-
raise CLIError("You must provide an app ID or server URL to configure.")
102+
if not app_server_url:
103+
raise CLIError("You must provide a server URL to configure.")
106104

107105
effective_api_key = api_key or settings.API_KEY or load_api_key_credentials()
108106
if not effective_api_key:
@@ -122,30 +120,6 @@ def configure_app(
122120
api_url=api_url or DEFAULT_API_BASE_URL, api_key=effective_api_key
123121
)
124122

125-
app_id = app_server_url = None
126-
if is_valid_app_id_format(app_id_or_url):
127-
app_id = app_id_or_url
128-
elif is_valid_server_url_format(app_id_or_url):
129-
app_server_url = app_id_or_url
130-
131-
try:
132-
app = client.get_app(app_id=app_id, server_url=app_server_url)
133-
app = run_async(client.get_app(app_id=app_id, server_url=app_server_url))
134-
135-
if not app:
136-
raise CLIError(f"App with ID or URL '{app_id_or_url}' not found.")
137-
138-
app_id = app.appId
139-
140-
except UnauthenticatedError as e:
141-
raise CLIError(
142-
"Invalid API key. Run 'mcp-agent login' or set MCP_API_KEY environment variable with new API key."
143-
) from e
144-
except Exception as e:
145-
raise CLIError(
146-
f"Error retrieving app to configure with ID or URL {app_id_or_url}",
147-
) from e
148-
149123
# Cannot provide both secrets_file and secrets_output_file; either must be yaml files
150124
if secrets_file and secrets_output_file:
151125
raise CLIError(
@@ -162,20 +136,28 @@ def configure_app(
162136

163137
required_params = []
164138
try:
165-
required_params = run_async(client.list_config_params(app_id=app_id))
139+
required_params = run_async(
140+
client.list_config_params(app_server_url=app_server_url)
141+
)
142+
except UnauthenticatedError as e:
143+
raise CLIError(
144+
"Invalid API key. Run 'mcp-agent login' or set MCP_API_KEY environment variable with new API key."
145+
) from e
166146
except Exception as e:
167-
raise CLIError(f"Failed to retrieve required secrets for app {app_id}: {e}")
147+
raise CLIError(
148+
f"Failed to retrieve required secrets for app {app_server_url}: {e}"
149+
) from e
168150

169151
requires_secrets = len(required_params) > 0
170152
configured_secrets = {}
171153

172154
if params:
173155
if requires_secrets:
174156
print_info(
175-
f"App {app_id} requires the following ({len(required_params)}) user secrets: {', '.join(required_params)}"
157+
f"App {app_server_url} requires the following ({len(required_params)}) user secrets: {', '.join(required_params)}"
176158
)
177159
else:
178-
print_info(f"App {app_id} does not require any user secrets.")
160+
print_info(f"App {app_server_url} does not require any user secrets.")
179161
raise typer.Exit(0)
180162

181163
if requires_secrets:
@@ -187,7 +169,7 @@ def configure_app(
187169
print_configuration_header(secrets_file, secrets_output_file, dry_run)
188170

189171
print_info(
190-
f"App {app_id} requires the following ({len(required_params)}) user secrets: {', '.join(required_params)}"
172+
f"App {app_server_url} requires the following ({len(required_params)}) user secrets: {', '.join(required_params)}"
191173
)
192174

193175
try:
@@ -238,10 +220,10 @@ def configure_app(
238220
raise CLIError(f"{str(e)}") from e
239221

240222
else:
241-
print_info(f"App {app_id} does not require any parameters.")
223+
print_info(f"App {app_server_url} does not require any parameters.")
242224
if secrets_file:
243225
raise CLIError(
244-
f"App {app_id} does not require any parameters, but a secrets file was provided: {secrets_file}"
226+
f"App {app_server_url} does not require any parameters, but a secrets file was provided: {secrets_file}"
245227
)
246228

247229
if dry_run:
@@ -257,7 +239,9 @@ def configure_app(
257239

258240
try:
259241
config = run_async(
260-
client.configure_app(app_id=app_id, config_params=configured_secrets)
242+
client.configure_app(
243+
app_server_url=app_server_url, config_params=configured_secrets
244+
)
261245
)
262246
progress.update(task, description="✅ MCP App configured successfully!")
263247
console.print(
@@ -273,4 +257,4 @@ def configure_app(
273257

274258
except Exception as e:
275259
progress.update(task, description="❌ MCP App configuration failed")
276-
raise CLIError(f"Failed to configure app {app_id}: {str(e)}") from e
260+
raise CLIError(f"Failed to configure app {app_server_url}: {str(e)}") from e

src/mcp_agent/cli/cloud/commands/logger/configure/main.py

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ def configure_logger(
3333
),
3434
) -> None:
3535
"""Configure OTEL endpoint and headers for log collection.
36-
36+
3737
This command allows you to configure the OpenTelemetry endpoint and headers
3838
that will be used for collecting logs from your deployed MCP apps.
39-
39+
4040
Examples:
4141
mcp-agent cloud logger configure https://otel.example.com:4318/v1/logs
4242
mcp-agent cloud logger configure https://otel.example.com --headers "Authorization=Bearer token,X-Custom=value"
@@ -45,17 +45,19 @@ def configure_logger(
4545
if not endpoint and not test:
4646
print_error("Must specify endpoint or use --test")
4747
raise typer.Exit(1)
48-
48+
4949
config_path = _find_config_file()
50-
50+
5151
if test:
5252
if config_path and config_path.exists():
5353
config = _load_config(config_path)
5454
otel_config = config.get("otel", {})
5555
endpoint = otel_config.get("endpoint")
5656
headers_dict = otel_config.get("headers", {})
5757
else:
58-
console.print("[yellow]No configuration file found. Use --endpoint to set up OTEL configuration.[/yellow]")
58+
console.print(
59+
"[yellow]No configuration file found. Use --endpoint to set up OTEL configuration.[/yellow]"
60+
)
5961
raise typer.Exit(1)
6062
else:
6163
headers_dict = {}
@@ -67,52 +69,64 @@ def configure_logger(
6769
except ValueError:
6870
print_error("Headers must be in format 'key=value,key2=value2'")
6971
raise typer.Exit(1)
70-
72+
7173
if endpoint:
7274
console.print(f"[blue]Testing connection to {endpoint}...[/blue]")
73-
75+
7476
try:
7577
with httpx.Client(timeout=10.0) as client:
7678
response = client.get(
77-
endpoint.replace("/v1/logs", "/health") if "/v1/logs" in endpoint else f"{endpoint}/health",
78-
headers=headers_dict
79+
endpoint.replace("/v1/logs", "/health")
80+
if "/v1/logs" in endpoint
81+
else f"{endpoint}/health",
82+
headers=headers_dict,
7983
)
80-
81-
if response.status_code in [200, 404]: # 404 is fine, means endpoint exists
84+
85+
if response.status_code in [
86+
200,
87+
404,
88+
]: # 404 is fine, means endpoint exists
8289
console.print("[green]✓ Connection successful[/green]")
8390
else:
84-
console.print(f"[yellow]⚠ Got status {response.status_code}, but endpoint is reachable[/yellow]")
85-
91+
console.print(
92+
f"[yellow]⚠ Got status {response.status_code}, but endpoint is reachable[/yellow]"
93+
)
94+
8695
except httpx.RequestError as e:
8796
print_error(f"✗ Connection failed: {e}")
8897
if not test:
89-
console.print("[yellow]Configuration will be saved anyway. Check your endpoint URL and network connection.[/yellow]")
90-
98+
console.print(
99+
"[yellow]Configuration will be saved anyway. Check your endpoint URL and network connection.[/yellow]"
100+
)
101+
91102
if not test:
92103
if not config_path:
93104
config_path = Path.cwd() / "mcp_agent.config.yaml"
94-
105+
95106
config = _load_config(config_path) if config_path.exists() else {}
96-
107+
97108
if "otel" not in config:
98109
config["otel"] = {}
99-
110+
100111
config["otel"]["endpoint"] = endpoint
101112
config["otel"]["headers"] = headers_dict
102-
113+
103114
try:
104115
config_path.parent.mkdir(parents=True, exist_ok=True)
105116
with open(config_path, "w") as f:
106117
yaml.dump(config, f, default_flow_style=False, sort_keys=False)
107-
108-
console.print(Panel(
109-
f"[green]✓ OTEL configuration saved to {config_path}[/green]\n\n"
110-
f"Endpoint: {endpoint}\n"
111-
f"Headers: {len(headers_dict)} configured" + (f" ({', '.join(headers_dict.keys())})" if headers_dict else ""),
112-
title="Configuration Saved",
113-
border_style="green"
114-
))
115-
118+
119+
console.print(
120+
Panel(
121+
f"[green]✓ OTEL configuration saved to {config_path}[/green]\n\n"
122+
f"Endpoint: {endpoint}\n"
123+
f"Headers: {len(headers_dict)} configured"
124+
+ (f" ({', '.join(headers_dict.keys())})" if headers_dict else ""),
125+
title="Configuration Saved",
126+
border_style="green",
127+
)
128+
)
129+
116130
except Exception as e:
117131
raise CLIError(f"Error saving configuration: {e}")
118132

@@ -134,4 +148,4 @@ def _load_config(config_path: Path) -> dict:
134148
with open(config_path, "r") as f:
135149
return yaml.safe_load(f) or {}
136150
except Exception as e:
137-
raise CLIError(f"Failed to load config from {config_path}: {e}")
151+
raise CLIError(f"Failed to load config from {config_path}: {e}")

0 commit comments

Comments
 (0)