mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-23 22:14:18 +02:00
Update banner and use console.log (#1041)
* Update banner and use console.log * Update cli.py
This commit is contained in:
parent
e182231fc8
commit
32890c0b5f
2 changed files with 28 additions and 39 deletions
|
|
@ -60,7 +60,7 @@ from fastmcp.settings import Settings
|
|||
from fastmcp.tools import ToolManager
|
||||
from fastmcp.tools.tool import FunctionTool, Tool, ToolResult
|
||||
from fastmcp.utilities.cache import TimedCache
|
||||
from fastmcp.utilities.cli import create_server_banner
|
||||
from fastmcp.utilities.cli import log_server_banner
|
||||
from fastmcp.utilities.components import FastMCPComponent
|
||||
from fastmcp.utilities.logging import get_logger
|
||||
from fastmcp.utilities.mcp_config import MCPConfig
|
||||
|
|
@ -1343,11 +1343,9 @@ class FastMCP(Generic[LifespanResultT]):
|
|||
|
||||
# Display server banner
|
||||
if 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 banner
|
||||
if 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 {}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 table
|
||||
info_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 column
|
||||
|
||||
match 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 transport
|
||||
if 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 Group
|
||||
panel_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"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue