File tree Expand file tree Collapse file tree 3 files changed +43
-2
lines changed Expand file tree Collapse file tree 3 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -445,6 +445,9 @@ async def run(
445445 final_path = path or config .deployment .path
446446 final_log_level = log_level or config .deployment .log_level
447447 final_server_args = server_args or config .deployment .args
448+ # Use CLI override if provided, otherwise use settings
449+ # no_banner CLI flag overrides the show_cli_banner setting
450+ final_no_banner = no_banner if no_banner else not fastmcp .settings .show_cli_banner
448451
449452 logger .debug (
450453 "Running server or client" ,
@@ -481,7 +484,7 @@ async def run(
481484 inner_cmd .extend (["--path" , final_path ])
482485 if final_log_level :
483486 inner_cmd .extend (["--log-level" , final_log_level ])
484- if no_banner :
487+ if final_no_banner :
485488 inner_cmd .append ("--no-banner" )
486489 # Add skip-env flag to prevent infinite recursion
487490 inner_cmd .append ("--skip-env" )
@@ -523,7 +526,7 @@ async def run(
523526 path = final_path ,
524527 log_level = final_log_level ,
525528 server_args = list (final_server_args ) if final_server_args else [],
526- show_banner = not no_banner ,
529+ show_banner = not final_no_banner ,
527530 skip_source = skip_source ,
528531 )
529532 except Exception as e :
Original file line number Diff line number Diff line change @@ -343,6 +343,20 @@ def normalize_log_level(cls, v):
343343 ),
344344 ] = False
345345
346+ show_cli_banner : Annotated [
347+ bool ,
348+ Field (
349+ default = True ,
350+ description = inspect .cleandoc (
351+ """
352+ If True, the server banner will be displayed when running the server via CLI.
353+ This setting can be overridden by the --no-banner CLI flag.
354+ Set to False via FASTMCP_SHOW_CLI_BANNER=false to suppress the banner.
355+ """
356+ ),
357+ ),
358+ ] = True
359+
346360
347361def __getattr__ (name : str ):
348362 """
Original file line number Diff line number Diff line change @@ -372,6 +372,30 @@ def test_run_command_parsing_project_and_skip_source(self):
372372 assert bound .arguments ["project" ] == Path ("./test-env" )
373373 assert bound .arguments ["skip_source" ] is True
374374
375+ def test_show_cli_banner_setting (self ):
376+ """Test that show_cli_banner setting works with environment variable."""
377+ import os
378+ from unittest import mock
379+
380+ from fastmcp .settings import Settings
381+
382+ # Test default (banner shown)
383+ settings = Settings ()
384+ assert settings .show_cli_banner is True
385+
386+ # Test with env var set to false (banner hidden)
387+ with mock .patch .dict (os .environ , {"FASTMCP_SHOW_CLI_BANNER" : "false" }):
388+ settings = Settings ()
389+ assert settings .show_cli_banner is False
390+
391+ # Test CLI precedence logic (simulated)
392+ with mock .patch .dict (os .environ , {"FASTMCP_SHOW_CLI_BANNER" : "true" }):
393+ settings = Settings ()
394+ # CLI --no-banner flag would override
395+ cli_no_banner = True
396+ final = cli_no_banner if cli_no_banner else not settings .show_cli_banner
397+ assert final is True # Banner suppressed by CLI flag
398+
375399
376400class TestWindowsSpecific :
377401 """Test Windows-specific functionality."""
You can’t perform that action at this time.
0 commit comments