π The fast, Pythonic way to build MCP servers and clients.
Update banner and use console.log (#1041)
Jeremiah Lowin32890c0b5f9b
diff --git a/src/fastmcp/server/server.py b/src/fastmcp/server/server.pyindex f61c5cb64..541533d6e 100644--- a/src/fastmcp/server/server.py+++ b/src/fastmcp/server/server.py@@ -60,7 +60,7 @@ from fastmcp.settings import Settingsfrom fastmcp.tools import ToolManagerfrom fastmcp.tools.tool import FunctionTool, Tool, ToolResultfrom fastmcp.utilities.cache import TimedCache-from fastmcp.utilities.cli import create_server_banner+from fastmcp.utilities.cli import log_server_bannerfrom fastmcp.utilities.components import FastMCPComponentfrom fastmcp.utilities.logging import get_loggerfrom fastmcp.utilities.mcp_config import MCPConfig@@ -1343,11 +1343,9 @@ class FastMCP(Generic[LifespanResultT]):# Display server bannerif show_banner:- logger.info(- create_server_banner(- server=self,- transport="stdio",- )+ log_server_banner(+ server=self,+ transport="stdio",)async with stdio_server() as (read_stream, write_stream):@@ -1407,14 +1405,12 @@ class FastMCP(Generic[LifespanResultT]):# Display server bannerif show_banner:- logger.info(- create_server_banner(- server=self,- transport=transport,- host=host,- port=port,- path=server_path,- )+ log_server_banner(+ server=self,+ transport=transport,+ host=host,+ port=port,+ path=server_path,)_uvicorn_config_from_user = uvicorn_config or {}diff --git a/src/fastmcp/utilities/cli.py b/src/fastmcp/utilities/cli.pyindex 0c9b9970e..4c488ffde 100644--- a/src/fastmcp/utilities/cli.py+++ b/src/fastmcp/utilities/cli.py@@ -23,15 +23,15 @@ _ __ ___ /_/ \__,_/____/\__/_/ /_/\____/_/ /_____(_)____/""".lstrip("\n")-def create_server_banner(+def log_server_banner(server: FastMCP[Any],transport: Literal["stdio", "http", "sse", "streamable-http"],*,host: str | None = None,port: int | None = None,path: str | None = None,-) -> str:- """Creates a formatted banner (as a string) with server information and logo.+) -> None:+ """Creates and logs a formatted banner with server information and logo.Args:transport: The transport protocol being used@@ -39,9 +39,6 @@ def create_server_banner(host: Host address (for HTTP transports)port: Port number (for HTTP transports)path: Server path (for HTTP transports)-- Returns:- A string representation of the banner."""# Create the logo text@@ -49,8 +46,9 @@ def create_server_banner(# Create the information tableinfo_table = Table.grid(padding=(0, 1))- info_table.add_column(style="bold cyan", justify="left")- info_table.add_column(style="white", justify="left")+ info_table.add_column(style="bold", justify="center") # Emoji column+ info_table.add_column(style="bold cyan", justify="left") # Label column+ info_table.add_column(style="white", justify="left") # Value columnmatch transport:case "http" | "streamable-http":@@ -60,7 +58,8 @@ def create_server_banner(case "stdio":display_transport = "STDIO"- info_table.add_row("Transport:", display_transport)+ info_table.add_row("π₯οΈ", "Server name:", server.name)+ info_table.add_row("π¦", "Transport:", display_transport)# Show connection info based on transportif transport in ("http", "streamable-http", "sse"):@@ -68,42 +67,36 @@ def create_server_banner(server_url = f"http://{host}:{port}"if path:server_url += f"/{path.lstrip('/')}"- info_table.add_row("Server URL:", server_url)+ info_table.add_row("π", "Server URL:", server_url)# Add documentation link- info_table.add_row()- info_table.add_row("Docs:", "https://gofastmcp.com")- info_table.add_row("Hosting:", "https://fastmcp.cloud")+ info_table.add_row("", "", "")+ info_table.add_row("π", "Docs:", "https://gofastmcp.com")+ info_table.add_row("π", "Deploy:", "https://fastmcp.cloud")# Add version information with explicit style overrides- info_table.add_row()+ info_table.add_row("", "", "")info_table.add_row(+ "ποΈ","FastMCP version:",Text(fastmcp.__version__, style="dim white", no_wrap=True),)info_table.add_row(+ "π€","MCP version:",Text(version("mcp"), style="dim white", no_wrap=True),)# Create panel with logo and information using Grouppanel_content = Group(logo_text, "", info_table)- # Use server name in title if provided- title = "FastMCP 2.0"- if server.name != "FastMCP":- title += f" - {server.name}"-panel = Panel(panel_content,- title=title,+ title="FastMCP 2.0",title_align="left",border_style="dim",padding=(2, 5),expand=False,)- console = Console()- with console.capture() as capture:- console.print(panel)- rendered = capture.get()- return f"\n\n{rendered}"+ console = Console(stderr=True)+ console.print(Group("\n", panel, "\n"))