Skip to content

Commit 2355cbb

Browse files
Use context var to define unconditional verbose logger
1 parent 0316066 commit 2355cbb

File tree

12 files changed

+96
-42
lines changed

12 files changed

+96
-42
lines changed

LLMS.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ Example usage:
14061406

14071407
### src/mcp_agent/cli/main.py
14081408

1409-
**Function:** `main(verbose: bool = typer.Option(False, '--verbose', '-v', help='Enable verbose mode'), quiet: bool = typer.Option(False, '--quiet', '-q', help='Disable output'), color: bool = typer.Option(True, '--color/--no-color', help='Enable/disable color output'))`
1409+
**Function:** `main(verbose: bool = typer.Option(False, '--verbose', '-v', help='Enable verbose mode'), color: bool = typer.Option(True, '--color/--no-color', help='Enable/disable color output'))`
14101410

14111411
- **Description**: Main entry point for the MCP Agent CLI.
14121412
- **Parameters**

docs/cli-reference.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Available for all commands:
2626
| Option | Description |
2727
| :----- | :---------- |
2828
| `--verbose, -v` | Enable verbose output |
29-
| `--quiet, -q` | Minimize output |
3029
| `--format <type>` | Output format (`text`, `json`, `yaml`) |
3130
| `--color/--no-color` | Enable/disable colored output |
3231
| `--version` | Show version and exit |

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
print_configuration_header,
3636
print_info,
3737
print_success,
38+
LOG_VERBOSE,
3839
)
3940

4041

@@ -85,6 +86,12 @@ def configure_app(
8586
help="API key for authentication. Defaults to MCP_API_KEY environment variable.",
8687
envvar=ENV_API_KEY,
8788
),
89+
verbose: bool = typer.Option(
90+
False,
91+
"--verbose",
92+
"-v",
93+
help="Enable verbose output for this command",
94+
),
8895
) -> str:
8996
"""Configure an MCP app with the required params (e.g. user secrets).
9097
@@ -99,6 +106,9 @@ def configure_app(
99106
Returns:
100107
Configured app ID.
101108
"""
109+
if verbose:
110+
LOG_VERBOSE.set(True)
111+
102112
# Check what params the app requires (doubles as an access check)
103113
if not app_server_url:
104114
raise CLIError("You must provide a server URL to configure.")
@@ -214,7 +224,7 @@ def configure_app(
214224
print_success("User secrets processed successfully")
215225

216226
except Exception as e:
217-
if ctx.obj.get("verbose", False):
227+
if LOG_VERBOSE.get():
218228
import traceback
219229

220230
typer.echo(traceback.format_exc())

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
print_error,
3232
print_info,
3333
print_success,
34+
LOG_VERBOSE,
35+
print_verbose,
3436
)
3537
from mcp_agent.cli.utils.git_utils import (
3638
get_git_metadata,
@@ -130,6 +132,12 @@ def deploy_config(
130132
file_okay=True,
131133
resolve_path=True,
132134
),
135+
verbose: bool = typer.Option(
136+
False,
137+
"--verbose",
138+
"-v",
139+
help="Enable verbose output for this command",
140+
),
133141
) -> str:
134142
"""Deploy an mcp-agent using the specified configuration.
135143
@@ -152,6 +160,9 @@ def deploy_config(
152160
Returns:
153161
Newly-deployed MCP App ID
154162
"""
163+
if verbose:
164+
LOG_VERBOSE.set(True)
165+
155166
try:
156167
if config_dir is None:
157168
resolved_config_dir = working_dir
@@ -209,15 +220,13 @@ def deploy_config(
209220
retriable=False,
210221
)
211222

212-
if ctx.obj.get("verbose", False):
213-
print_info(f"Using API at {effective_api_url}")
223+
print_verbose(f"Using API at {effective_api_url}")
214224

215225
mcp_app_client = MCPAppClient(
216226
api_url=effective_api_url, api_key=effective_api_key
217227
)
218228

219-
if ctx.obj.get("verbose", False):
220-
print_info(f"Checking for existing app ID for '{app_name}'...")
229+
print_verbose(f"Checking for existing app ID for '{app_name}'...")
221230

222231
try:
223232
app_id = run_async(mcp_app_client.get_app_id_by_name(app_name))
@@ -232,8 +241,7 @@ def deploy_config(
232241
)
233242
app_id = app.appId
234243
print_success(f"Created new app '{app_name}'")
235-
if ctx.obj.get("verbose", False):
236-
print_info(f"New app id: `{app_id}`")
244+
print_verbose(f"New app id: `{app_id}`")
237245
else:
238246
short_id = f"{app_id[:8]}…"
239247
print_success(f"Found existing app '{app_name}' (ID: `{short_id}`)")
@@ -243,8 +251,7 @@ def deploy_config(
243251
default=True,
244252
)
245253
if use_existing:
246-
if ctx.obj.get("verbose", False):
247-
print_info(f"Will deploy an update to app ID: `{app_id}`")
254+
print_verbose(f"Will deploy an update to app ID: `{app_id}`")
248255
else:
249256
print_error(
250257
"Cancelling deployment. Please choose a different app name."
@@ -261,8 +268,7 @@ def deploy_config(
261268
update_payload["unauthenticated_access"] = unauthenticated_access
262269

263270
if update_payload:
264-
if ctx.obj.get("verbose", False):
265-
print_info("Updating app settings before deployment...")
271+
print_verbose("Updating app settings before deployment...")
266272
run_async(
267273
mcp_app_client.update_app(
268274
app_id=app_id,
@@ -280,10 +286,9 @@ def deploy_config(
280286
# If a deployed secrets file already exists, determine if it should be used or overwritten
281287
if deployed_secrets_file:
282288
if secrets_file:
283-
if ctx.obj.get("verbose", False):
284-
print_info(
285-
f"Both '{MCP_SECRETS_FILENAME}' and '{MCP_DEPLOYED_SECRETS_FILENAME}' found in {config_dir}."
286-
)
289+
print_verbose(
290+
f"Both '{MCP_SECRETS_FILENAME}' and '{MCP_DEPLOYED_SECRETS_FILENAME}' found in {config_dir}."
291+
)
287292
if non_interactive:
288293
print_info(
289294
"Running in non-interactive mode — reusing previously deployed secrets."
@@ -320,10 +325,9 @@ def deploy_config(
320325
)
321326

322327
print_success("Secrets file processed successfully")
323-
if ctx.obj.get("verbose", False):
324-
print_info(
325-
f"Transformed secrets file written to {secrets_transformed_path}"
326-
)
328+
print_verbose(
329+
f"Transformed secrets file written to {secrets_transformed_path}"
330+
)
327331

328332
else:
329333
print_info("Skipping secrets processing...")
@@ -367,7 +371,6 @@ def deploy_config(
367371
mcp_app_client=mcp_app_client,
368372
retry_count=retry_count,
369373
ignore=ignore_path,
370-
verbose=ctx.obj.get("verbose", False),
371374
)
372375
)
373376

@@ -390,7 +393,7 @@ def deploy_config(
390393
return app_id
391394

392395
except Exception as e:
393-
if ctx.obj.get("verbose", False):
396+
if LOG_VERBOSE.get():
394397
import traceback
395398

396399
typer.echo(traceback.format_exc())
@@ -404,7 +407,6 @@ async def _deploy_with_retry(
404407
mcp_app_client: MCPAppClient,
405408
retry_count: int,
406409
ignore: Optional[Path],
407-
verbose: bool = False,
408410
):
409411
"""Execute the deployment operations with retry logic.
410412
@@ -425,7 +427,6 @@ async def _deploy_with_retry(
425427
api_key=api_key,
426428
project_dir=project_dir,
427429
ignore_file=ignore,
428-
verbose=verbose,
429430
)
430431
except Exception as e:
431432
raise CLIError(f"Bundling failed: {str(e)}") from e
@@ -485,8 +486,7 @@ async def _perform_api_deployment():
485486
raise
486487

487488
if retry_count > 1:
488-
if verbose:
489-
print_info(f"Deployment API configured with up to {retry_count} attempts")
489+
print_verbose(f"Deployment API configured with up to {retry_count} attempts")
490490

491491
try:
492492
return await retry_async_with_exponential_backoff(

src/mcp_agent/cli/cloud/commands/deploy/wrangler_wrapper.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111

1212
from mcp_agent.cli.config import settings
1313
from mcp_agent.cli.core.constants import MCP_SECRETS_FILENAME
14-
from mcp_agent.cli.utils.ux import console, print_error, print_warning, print_info
14+
from mcp_agent.cli.utils.ux import (
15+
console,
16+
print_error,
17+
print_warning,
18+
print_info,
19+
print_verbose,
20+
)
1521
from mcp_agent.cli.utils.git_utils import (
1622
get_git_metadata,
1723
compute_directory_fingerprint,
@@ -116,7 +122,6 @@ def wrangler_deploy(
116122
api_key: str,
117123
project_dir: Path,
118124
ignore_file: Path | None = None,
119-
verbose: bool = False,
120125
) -> None:
121126
"""Bundle the MCP Agent using Wrangler.
122127
@@ -188,8 +193,7 @@ def wrangler_deploy(
188193
else:
189194
print_info(f"Using ignore patterns from {ignore_file}")
190195
else:
191-
if verbose:
192-
print_info("No ignore file provided; applying default excludes only")
196+
print_verbose("No ignore file provided; applying default excludes only")
193197

194198
# Copy the entire project to temp directory, excluding unwanted directories and the live secrets file
195199
def ignore_patterns(path_str, names):
@@ -299,10 +303,9 @@ def ignore_patterns(path_str, names):
299303
},
300304
)
301305
meta_vars.update({"MCP_DEPLOY_WORKSPACE_HASH": bundle_hash})
302-
if verbose:
303-
print_info(
304-
f"Deploying from non-git workspace (hash {bundle_hash[:12]}…)"
305-
)
306+
print_verbose(
307+
f"Deploying from non-git workspace (hash {bundle_hash[:12]}…)"
308+
)
306309

307310
# Write a breadcrumb file into the project so it ships with the bundle.
308311
# Use a Python file for guaranteed inclusion without renaming.

src/mcp_agent/cli/commands/build.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from rich.panel import Panel
2020
from rich.progress import Progress, SpinnerColumn, TextColumn
2121

22+
from mcp_agent.cli.utils.ux import LOG_VERBOSE
2223
from mcp_agent.config import get_settings, Settings
2324

2425

@@ -200,6 +201,9 @@ def build(
200201
),
201202
) -> None:
202203
"""Run comprehensive preflight checks and generate build manifest."""
204+
if verbose:
205+
LOG_VERBOSE.set(True)
206+
verbose = LOG_VERBOSE.get()
203207

204208
console.print("\n[bold cyan]🔍 MCP-Agent Build Preflight Checks[/bold cyan]\n")
205209

src/mcp_agent/cli/commands/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from rich.prompt import Prompt, Confirm
1818
from rich.progress import Progress, SpinnerColumn, TextColumn
1919

20+
from mcp_agent.cli.utils.ux import LOG_VERBOSE
2021
from mcp_agent.config import Settings, get_settings
2122

2223

@@ -126,6 +127,10 @@ def check(
126127
),
127128
) -> None:
128129
"""Check and summarize configuration status."""
130+
if verbose:
131+
LOG_VERBOSE.set(True)
132+
verbose = LOG_VERBOSE.get()
133+
129134
cfg = _find_config_file()
130135
sec = _find_secrets_file()
131136

src/mcp_agent/cli/commands/keys.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from rich.prompt import Prompt, Confirm
1919
from rich.progress import Progress, SpinnerColumn, TextColumn
2020

21+
from mcp_agent.cli.utils.ux import LOG_VERBOSE
2122

2223
app = typer.Typer(help="Manage provider API keys")
2324
console = Console()
@@ -172,6 +173,10 @@ def show(
172173
"""Show configured API keys and their status."""
173174
from mcp_agent.config import get_settings
174175

176+
if verbose:
177+
LOG_VERBOSE.set(True)
178+
verbose = LOG_VERBOSE.get()
179+
175180
console.print("\n[bold cyan]🔑 API Key Status[/bold cyan]\n")
176181

177182
settings = get_settings()
@@ -451,6 +456,10 @@ def test(
451456

452457
console.print("\n[bold cyan]🧪 Testing API Keys[/bold cyan]\n")
453458

459+
if verbose:
460+
LOG_VERBOSE.set(True)
461+
verbose = LOG_VERBOSE.get()
462+
454463
settings = get_settings()
455464

456465
# Determine which providers to test

src/mcp_agent/cli/commands/server.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from rich.table import Table
1313
from rich.prompt import Confirm
1414

15+
from mcp_agent.cli.utils.ux import LOG_VERBOSE
1516
from mcp_agent.config import Settings, MCPServerSettings, MCPSettings, get_settings
1617
from mcp_agent.cli.utils.importers import import_servers_from_mcp_json
1718
from mcp_agent.core.context import cleanup_context
@@ -694,6 +695,10 @@ def test(
694695
from mcp_agent.app import MCPApp
695696
from mcp_agent.agents.agent import Agent
696697

698+
if verbose:
699+
LOG_VERBOSE.set(True)
700+
verbose = LOG_VERBOSE.get()
701+
697702
async def _probe():
698703
app_obj = MCPApp(name="server-test")
699704
async with app_obj.run():

src/mcp_agent/cli/config/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
ENV_API_BASE_URL,
1111
ENV_API_KEY,
1212
)
13+
from mcp_agent.cli.utils.ux import LOG_VERBOSE
1314

1415

1516
class Settings(BaseSettings):
@@ -38,3 +39,6 @@ class Settings(BaseSettings):
3839

3940
# Create a singleton settings instance
4041
settings = Settings()
42+
43+
# Set LOG_VERBOSE context var based on VERBOSE setting
44+
LOG_VERBOSE.set(settings.VERBOSE)

0 commit comments

Comments
 (0)