From c700dcd1e3ad588f1d56b466341f1937b0e3652d Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Sat, 30 Nov 2024 19:02:01 -0600 Subject: [PATCH 1/3] add rich handler and dotenv loading for settings --- src/fastmcp/cli/cli.py | 6 +++--- src/fastmcp/server.py | 6 +++++- src/fastmcp/utilities/logging.py | 25 +++++++++++++------------ 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/fastmcp/cli/cli.py b/src/fastmcp/cli/cli.py index cab03aab1..63efb1db4 100644 --- a/src/fastmcp/cli/cli.py +++ b/src/fastmcp/cli/cli.py @@ -13,7 +13,7 @@ from typing_extensions import Annotated from ..utilities.logging import get_logger from . import claude -logger = get_logger(__name__) +logger = get_logger("cli") app = typer.Typer( name="fastmcp", @@ -352,7 +352,7 @@ def install( with_packages=with_packages, force=force, ): - print(f"Successfully installed {name} in Claude app") + logger.info(f"Successfully installed {name} in Claude app") else: - print(f"Failed to install {name} in Claude app") + logger.error(f"Failed to install {name} in Claude app") sys.exit(1) diff --git a/src/fastmcp/server.py b/src/fastmcp/server.py index c3ef8884c..71d582f32 100644 --- a/src/fastmcp/server.py +++ b/src/fastmcp/server.py @@ -53,7 +53,11 @@ class Settings(BaseSettings): For example, FASTMCP_DEBUG=true will set debug=True. """ - model_config: SettingsConfigDict = SettingsConfigDict(env_prefix="FASTMCP_") + model_config: SettingsConfigDict = SettingsConfigDict( + env_prefix="FASTMCP_", + env_file=".env", + extra="ignore", + ) # Server settings debug: bool = False diff --git a/src/fastmcp/utilities/logging.py b/src/fastmcp/utilities/logging.py index 604b24e21..75de423ae 100644 --- a/src/fastmcp/utilities/logging.py +++ b/src/fastmcp/utilities/logging.py @@ -1,30 +1,31 @@ -"""Logging utilities for FastMCP.""" +"""logging utilities for fastmcp""" import logging from typing import Literal +from rich.logging import RichHandler + def get_logger(name: str) -> logging.Logger: - """Get a logger nested under FastMCP namespace. + """get a logger nested under fastmcp namespace. - Args: - name: The name of the logger, which will be prefixed with 'FastMCP.' + args: + name: the name of the logger, which will be prefixed with 'fastmcp.' - Returns: - A configured logger instance + returns: + a configured logger instance """ - return logging.getLogger(f"FastMCP.{name}") + return logging.getLogger(f"fastmcp.{name}") def configure_logging( level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "INFO", ) -> None: - """Configure logging for FastMCP. + """configure logging for fastmcp. - Args: - level: The log level to use + args: + level: the log level to use """ logging.basicConfig( - level=level, - format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", + level=level, format="%(message)s", handlers=[RichHandler(rich_tracebacks=True)] ) From 0168c86ae058b9df6ef73880e00900a543d94a00 Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Sat, 30 Nov 2024 19:03:08 -0600 Subject: [PATCH 2/3] rm random diff --- src/fastmcp/utilities/logging.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/fastmcp/utilities/logging.py b/src/fastmcp/utilities/logging.py index 75de423ae..24f98012c 100644 --- a/src/fastmcp/utilities/logging.py +++ b/src/fastmcp/utilities/logging.py @@ -1,4 +1,4 @@ -"""logging utilities for fastmcp""" +"""Logging utilities for FastMCP.""" import logging from typing import Literal @@ -7,12 +7,12 @@ from rich.logging import RichHandler def get_logger(name: str) -> logging.Logger: - """get a logger nested under fastmcp namespace. + """Get a logger nested under fastmcp namespace. - args: + Args: name: the name of the logger, which will be prefixed with 'fastmcp.' - returns: + Returns: a configured logger instance """ return logging.getLogger(f"fastmcp.{name}") @@ -21,9 +21,9 @@ def get_logger(name: str) -> logging.Logger: def configure_logging( level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "INFO", ) -> None: - """configure logging for fastmcp. + """Configure logging for FastMCP. - args: + Args: level: the log level to use """ logging.basicConfig( From 5c117fd4fecb606010d08dfc42791a9bfed75c32 Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Sat, 30 Nov 2024 19:03:50 -0600 Subject: [PATCH 3/3] more --- src/fastmcp/utilities/logging.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fastmcp/utilities/logging.py b/src/fastmcp/utilities/logging.py index 24f98012c..e2dd5f45e 100644 --- a/src/fastmcp/utilities/logging.py +++ b/src/fastmcp/utilities/logging.py @@ -7,15 +7,15 @@ from rich.logging import RichHandler def get_logger(name: str) -> logging.Logger: - """Get a logger nested under fastmcp namespace. + """Get a logger nested under FastMCP namespace. Args: - name: the name of the logger, which will be prefixed with 'fastmcp.' + name: the name of the logger, which will be prefixed with 'FastMCP.' Returns: a configured logger instance """ - return logging.getLogger(f"fastmcp.{name}") + return logging.getLogger(f"FastMCP.{name}") def configure_logging(