Skip to content

πŸš€ The fast, Pythonic way to build MCP servers and clients.

add rich handler and dotenv loading for settings

zzstoatzzc700dcd1e3ad
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)]
)