Spaces:
Running
Running
Jeremiah Lowin commited on
Update banner and use console.log (#1041)
Browse files* Update banner and use console.log
* Update cli.py
- src/fastmcp/server/server.py +10 -14
- src/fastmcp/utilities/cli.py +18 -25
src/fastmcp/server/server.py
CHANGED
|
@@ -60,7 +60,7 @@ from fastmcp.settings import Settings
|
|
| 60 |
from fastmcp.tools import ToolManager
|
| 61 |
from fastmcp.tools.tool import FunctionTool, Tool, ToolResult
|
| 62 |
from fastmcp.utilities.cache import TimedCache
|
| 63 |
-
from fastmcp.utilities.cli import
|
| 64 |
from fastmcp.utilities.components import FastMCPComponent
|
| 65 |
from fastmcp.utilities.logging import get_logger
|
| 66 |
from fastmcp.utilities.mcp_config import MCPConfig
|
|
@@ -1343,11 +1343,9 @@ class FastMCP(Generic[LifespanResultT]):
|
|
| 1343 |
|
| 1344 |
# Display server banner
|
| 1345 |
if show_banner:
|
| 1346 |
-
|
| 1347 |
-
|
| 1348 |
-
|
| 1349 |
-
transport="stdio",
|
| 1350 |
-
)
|
| 1351 |
)
|
| 1352 |
|
| 1353 |
async with stdio_server() as (read_stream, write_stream):
|
|
@@ -1407,14 +1405,12 @@ class FastMCP(Generic[LifespanResultT]):
|
|
| 1407 |
|
| 1408 |
# Display server banner
|
| 1409 |
if show_banner:
|
| 1410 |
-
|
| 1411 |
-
|
| 1412 |
-
|
| 1413 |
-
|
| 1414 |
-
|
| 1415 |
-
|
| 1416 |
-
path=server_path,
|
| 1417 |
-
)
|
| 1418 |
)
|
| 1419 |
_uvicorn_config_from_user = uvicorn_config or {}
|
| 1420 |
|
|
|
|
| 60 |
from fastmcp.tools import ToolManager
|
| 61 |
from fastmcp.tools.tool import FunctionTool, Tool, ToolResult
|
| 62 |
from fastmcp.utilities.cache import TimedCache
|
| 63 |
+
from fastmcp.utilities.cli import log_server_banner
|
| 64 |
from fastmcp.utilities.components import FastMCPComponent
|
| 65 |
from fastmcp.utilities.logging import get_logger
|
| 66 |
from fastmcp.utilities.mcp_config import MCPConfig
|
|
|
|
| 1343 |
|
| 1344 |
# Display server banner
|
| 1345 |
if show_banner:
|
| 1346 |
+
log_server_banner(
|
| 1347 |
+
server=self,
|
| 1348 |
+
transport="stdio",
|
|
|
|
|
|
|
| 1349 |
)
|
| 1350 |
|
| 1351 |
async with stdio_server() as (read_stream, write_stream):
|
|
|
|
| 1405 |
|
| 1406 |
# Display server banner
|
| 1407 |
if show_banner:
|
| 1408 |
+
log_server_banner(
|
| 1409 |
+
server=self,
|
| 1410 |
+
transport=transport,
|
| 1411 |
+
host=host,
|
| 1412 |
+
port=port,
|
| 1413 |
+
path=server_path,
|
|
|
|
|
|
|
| 1414 |
)
|
| 1415 |
_uvicorn_config_from_user = uvicorn_config or {}
|
| 1416 |
|
src/fastmcp/utilities/cli.py
CHANGED
|
@@ -23,15 +23,15 @@ _ __ ___ /_/ \__,_/____/\__/_/ /_/\____/_/ /_____(_)____/
|
|
| 23 |
""".lstrip("\n")
|
| 24 |
|
| 25 |
|
| 26 |
-
def
|
| 27 |
server: FastMCP[Any],
|
| 28 |
transport: Literal["stdio", "http", "sse", "streamable-http"],
|
| 29 |
*,
|
| 30 |
host: str | None = None,
|
| 31 |
port: int | None = None,
|
| 32 |
path: str | None = None,
|
| 33 |
-
) ->
|
| 34 |
-
"""Creates a formatted banner
|
| 35 |
|
| 36 |
Args:
|
| 37 |
transport: The transport protocol being used
|
|
@@ -39,9 +39,6 @@ def create_server_banner(
|
|
| 39 |
host: Host address (for HTTP transports)
|
| 40 |
port: Port number (for HTTP transports)
|
| 41 |
path: Server path (for HTTP transports)
|
| 42 |
-
|
| 43 |
-
Returns:
|
| 44 |
-
A string representation of the banner.
|
| 45 |
"""
|
| 46 |
|
| 47 |
# Create the logo text
|
|
@@ -49,8 +46,9 @@ def create_server_banner(
|
|
| 49 |
|
| 50 |
# Create the information table
|
| 51 |
info_table = Table.grid(padding=(0, 1))
|
| 52 |
-
info_table.add_column(style="bold
|
| 53 |
-
info_table.add_column(style="
|
|
|
|
| 54 |
|
| 55 |
match transport:
|
| 56 |
case "http" | "streamable-http":
|
|
@@ -60,7 +58,8 @@ def create_server_banner(
|
|
| 60 |
case "stdio":
|
| 61 |
display_transport = "STDIO"
|
| 62 |
|
| 63 |
-
info_table.add_row("
|
|
|
|
| 64 |
|
| 65 |
# Show connection info based on transport
|
| 66 |
if transport in ("http", "streamable-http", "sse"):
|
|
@@ -68,42 +67,36 @@ def create_server_banner(
|
|
| 68 |
server_url = f"http://{host}:{port}"
|
| 69 |
if path:
|
| 70 |
server_url += f"/{path.lstrip('/')}"
|
| 71 |
-
info_table.add_row("Server URL:", server_url)
|
| 72 |
|
| 73 |
# Add documentation link
|
| 74 |
-
info_table.add_row()
|
| 75 |
-
info_table.add_row("Docs:", "https://gofastmcp.com")
|
| 76 |
-
info_table.add_row("
|
| 77 |
|
| 78 |
# Add version information with explicit style overrides
|
| 79 |
-
info_table.add_row()
|
| 80 |
info_table.add_row(
|
|
|
|
| 81 |
"FastMCP version:",
|
| 82 |
Text(fastmcp.__version__, style="dim white", no_wrap=True),
|
| 83 |
)
|
| 84 |
info_table.add_row(
|
|
|
|
| 85 |
"MCP version:",
|
| 86 |
Text(version("mcp"), style="dim white", no_wrap=True),
|
| 87 |
)
|
| 88 |
# Create panel with logo and information using Group
|
| 89 |
panel_content = Group(logo_text, "", info_table)
|
| 90 |
|
| 91 |
-
# Use server name in title if provided
|
| 92 |
-
title = "FastMCP 2.0"
|
| 93 |
-
if server.name != "FastMCP":
|
| 94 |
-
title += f" - {server.name}"
|
| 95 |
-
|
| 96 |
panel = Panel(
|
| 97 |
panel_content,
|
| 98 |
-
title=
|
| 99 |
title_align="left",
|
| 100 |
border_style="dim",
|
| 101 |
padding=(2, 5),
|
| 102 |
expand=False,
|
| 103 |
)
|
| 104 |
|
| 105 |
-
console = Console()
|
| 106 |
-
|
| 107 |
-
console.print(panel)
|
| 108 |
-
rendered = capture.get()
|
| 109 |
-
return f"\n\n{rendered}"
|
|
|
|
| 23 |
""".lstrip("\n")
|
| 24 |
|
| 25 |
|
| 26 |
+
def log_server_banner(
|
| 27 |
server: FastMCP[Any],
|
| 28 |
transport: Literal["stdio", "http", "sse", "streamable-http"],
|
| 29 |
*,
|
| 30 |
host: str | None = None,
|
| 31 |
port: int | None = None,
|
| 32 |
path: str | None = None,
|
| 33 |
+
) -> None:
|
| 34 |
+
"""Creates and logs a formatted banner with server information and logo.
|
| 35 |
|
| 36 |
Args:
|
| 37 |
transport: The transport protocol being used
|
|
|
|
| 39 |
host: Host address (for HTTP transports)
|
| 40 |
port: Port number (for HTTP transports)
|
| 41 |
path: Server path (for HTTP transports)
|
|
|
|
|
|
|
|
|
|
| 42 |
"""
|
| 43 |
|
| 44 |
# Create the logo text
|
|
|
|
| 46 |
|
| 47 |
# Create the information table
|
| 48 |
info_table = Table.grid(padding=(0, 1))
|
| 49 |
+
info_table.add_column(style="bold", justify="center") # Emoji column
|
| 50 |
+
info_table.add_column(style="bold cyan", justify="left") # Label column
|
| 51 |
+
info_table.add_column(style="white", justify="left") # Value column
|
| 52 |
|
| 53 |
match transport:
|
| 54 |
case "http" | "streamable-http":
|
|
|
|
| 58 |
case "stdio":
|
| 59 |
display_transport = "STDIO"
|
| 60 |
|
| 61 |
+
info_table.add_row("π₯οΈ", "Server name:", server.name)
|
| 62 |
+
info_table.add_row("π¦", "Transport:", display_transport)
|
| 63 |
|
| 64 |
# Show connection info based on transport
|
| 65 |
if transport in ("http", "streamable-http", "sse"):
|
|
|
|
| 67 |
server_url = f"http://{host}:{port}"
|
| 68 |
if path:
|
| 69 |
server_url += f"/{path.lstrip('/')}"
|
| 70 |
+
info_table.add_row("π", "Server URL:", server_url)
|
| 71 |
|
| 72 |
# Add documentation link
|
| 73 |
+
info_table.add_row("", "", "")
|
| 74 |
+
info_table.add_row("π", "Docs:", "https://gofastmcp.com")
|
| 75 |
+
info_table.add_row("π", "Deploy:", "https://fastmcp.cloud")
|
| 76 |
|
| 77 |
# Add version information with explicit style overrides
|
| 78 |
+
info_table.add_row("", "", "")
|
| 79 |
info_table.add_row(
|
| 80 |
+
"ποΈ",
|
| 81 |
"FastMCP version:",
|
| 82 |
Text(fastmcp.__version__, style="dim white", no_wrap=True),
|
| 83 |
)
|
| 84 |
info_table.add_row(
|
| 85 |
+
"π€",
|
| 86 |
"MCP version:",
|
| 87 |
Text(version("mcp"), style="dim white", no_wrap=True),
|
| 88 |
)
|
| 89 |
# Create panel with logo and information using Group
|
| 90 |
panel_content = Group(logo_text, "", info_table)
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
panel = Panel(
|
| 93 |
panel_content,
|
| 94 |
+
title="FastMCP 2.0",
|
| 95 |
title_align="left",
|
| 96 |
border_style="dim",
|
| 97 |
padding=(2, 5),
|
| 98 |
expand=False,
|
| 99 |
)
|
| 100 |
|
| 101 |
+
console = Console(stderr=True)
|
| 102 |
+
console.print(Group("\n", panel, "\n"))
|
|
|
|
|
|
|
|
|