24
24
from mcp_agent .cli .exceptions import CLIError
25
25
from mcp_agent .cli .mcp_app .api_client import (
26
26
MCPAppClient ,
27
- is_valid_app_id_format ,
28
- is_valid_server_url_format ,
29
27
)
30
28
from mcp_agent .cli .mcp_app .mock_client import MockMCPAppClient
31
29
from mcp_agent .cli .secrets .mock_client import MockSecretsClient
41
39
42
40
43
41
def configure_app (
44
- app_id_or_url : str = typer .Option (
42
+ app_server_url : str = typer .Option (
45
43
None ,
46
44
"--id" ,
47
45
"-i" ,
48
- help = "ID or server URL of the app to configure." ,
46
+ help = "Server URL of the app to configure." ,
49
47
),
50
48
secrets_file : Optional [Path ] = typer .Option (
51
49
None ,
@@ -90,7 +88,7 @@ def configure_app(
90
88
"""Configure an MCP app with the required params (e.g. user secrets).
91
89
92
90
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
94
92
secrets_file: Path to an existing secrets file containing processed user secrets to use for configuring the app
95
93
secrets_output_file: Path to write processed secrets to, if secrets are prompted. Defaults to mcp-agent.configured.secrets.yaml
96
94
dry_run: Don't actually store secrets, just validate
@@ -101,8 +99,8 @@ def configure_app(
101
99
Configured app ID.
102
100
"""
103
101
# 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." )
106
104
107
105
effective_api_key = api_key or settings .API_KEY or load_api_key_credentials ()
108
106
if not effective_api_key :
@@ -122,30 +120,6 @@ def configure_app(
122
120
api_url = api_url or DEFAULT_API_BASE_URL , api_key = effective_api_key
123
121
)
124
122
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
-
149
123
# Cannot provide both secrets_file and secrets_output_file; either must be yaml files
150
124
if secrets_file and secrets_output_file :
151
125
raise CLIError (
@@ -162,20 +136,28 @@ def configure_app(
162
136
163
137
required_params = []
164
138
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
166
146
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
168
150
169
151
requires_secrets = len (required_params ) > 0
170
152
configured_secrets = {}
171
153
172
154
if params :
173
155
if requires_secrets :
174
156
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 )} "
176
158
)
177
159
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." )
179
161
raise typer .Exit (0 )
180
162
181
163
if requires_secrets :
@@ -187,7 +169,7 @@ def configure_app(
187
169
print_configuration_header (secrets_file , secrets_output_file , dry_run )
188
170
189
171
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 )} "
191
173
)
192
174
193
175
try :
@@ -238,10 +220,10 @@ def configure_app(
238
220
raise CLIError (f"{ str (e )} " ) from e
239
221
240
222
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." )
242
224
if secrets_file :
243
225
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 } "
245
227
)
246
228
247
229
if dry_run :
@@ -257,7 +239,9 @@ def configure_app(
257
239
258
240
try :
259
241
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
+ )
261
245
)
262
246
progress .update (task , description = "✅ MCP App configured successfully!" )
263
247
console .print (
@@ -273,4 +257,4 @@ def configure_app(
273
257
274
258
except Exception as e :
275
259
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
0 commit comments