mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-09 07:09:11 +02:00
Fix static analysis issues and address review feedback
- Fix unused variable in test (settings → _settings) - Add type annotation for __context parameter - Remove unused info parameter from validator - Fix circular import with configure_logging - Add production safety warnings to documentation Co-authored-by: Bill Easton <strawgate@users.noreply.github.com>
This commit is contained in:
parent
b2fbe1a1bb
commit
139801718f
3 changed files with 16 additions and 17 deletions
|
|
@ -362,8 +362,8 @@ print(fastmcp.settings.strict_input_validation) # Default: False
|
|||
|
||||
Common global settings include:
|
||||
- **`log_level`**: Logging level ("DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"), set with `FASTMCP_LOG_LEVEL`
|
||||
- **`debug`**: Global debug mode that sets log level to DEBUG and enables Starlette debug tracebacks for HTTP/SSE transports, set with `FASTMCP_DEBUG`. Provides a convenient way to enable comprehensive debugging. For granular control, use `log_level` and `starlette_debug` separately
|
||||
- **`starlette_debug`**: Enable Starlette debug mode for HTTP/SSE transports only, set with `FASTMCP_STARLETTE_DEBUG`. When enabled, detailed error tracebacks are returned in HTTP responses. Only affects HTTP/SSE transports; has no effect on stdio transport
|
||||
- **`debug`**: Global debug mode that sets log level to DEBUG and enables Starlette debug tracebacks for HTTP/SSE transports, set with `FASTMCP_DEBUG`. Provides a convenient way to enable comprehensive debugging. For granular control, use `log_level` and `starlette_debug` separately. **WARNING**: Only enable in development - debug tracebacks expose detailed internal information
|
||||
- **`starlette_debug`**: Enable Starlette debug mode for HTTP/SSE transports only, set with `FASTMCP_STARLETTE_DEBUG`. When enabled, detailed error tracebacks are returned in HTTP responses. Only affects HTTP/SSE transports; has no effect on stdio transport. **WARNING**: Only enable in development - exposes detailed internal information in HTTP responses
|
||||
- **`mask_error_details`**: Whether to hide detailed error information from clients, set with `FASTMCP_MASK_ERROR_DETAILS`
|
||||
- **`strict_input_validation`**: Controls tool input validation mode (default: False for flexible coercion), set with `FASTMCP_STRICT_INPUT_VALIDATION`. See [Input Validation Modes](/servers/tools#input-validation-modes)
|
||||
- **`env_file`**: Path to the environment file to load settings from (default: ".env"), set with `FASTMCP_ENV_FILE`. Useful when your project uses a `.env` file with syntax incompatible with python-dotenv
|
||||
|
|
|
|||
|
|
@ -290,27 +290,29 @@ class Settings(BaseSettings):
|
|||
|
||||
@field_validator("debug")
|
||||
@classmethod
|
||||
def _update_log_level_for_debug(cls, v: bool, info) -> bool:
|
||||
def _update_log_level_for_debug(cls, v: bool) -> bool:
|
||||
"""When debug is enabled, set log_level to DEBUG."""
|
||||
if v:
|
||||
# When debug is True, we need to ensure log_level is set to DEBUG
|
||||
# This is checked in model_post_init
|
||||
pass
|
||||
return v
|
||||
|
||||
def model_post_init(self, __context) -> None:
|
||||
def model_post_init(self, __context: Any) -> None:
|
||||
"""Post-initialization hook to handle debug mode."""
|
||||
if self.debug and self.log_level != "DEBUG":
|
||||
# When debug is enabled, force log_level to DEBUG
|
||||
self.log_level = "DEBUG"
|
||||
# Reconfigure logging if it's enabled
|
||||
# Only reconfigure if fastmcp module is fully initialized
|
||||
# to avoid AttributeError during import
|
||||
if self.log_enabled:
|
||||
from fastmcp.utilities.logging import configure_logging
|
||||
import fastmcp
|
||||
|
||||
configure_logging(
|
||||
level=self.log_level,
|
||||
enable_rich_tracebacks=self.enable_rich_tracebacks,
|
||||
)
|
||||
# Check if fastmcp.settings exists (module fully initialized)
|
||||
if hasattr(fastmcp, "settings"):
|
||||
from fastmcp.utilities.logging import configure_logging
|
||||
|
||||
configure_logging(
|
||||
level=self.log_level,
|
||||
enable_rich_tracebacks=self.enable_rich_tracebacks,
|
||||
)
|
||||
|
||||
# error handling
|
||||
mask_error_details: Annotated[
|
||||
|
|
|
|||
|
|
@ -2,9 +2,6 @@
|
|||
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
|
||||
from fastmcp import settings as global_settings
|
||||
from fastmcp.settings import Settings
|
||||
from fastmcp.utilities.logging import get_logger
|
||||
|
||||
|
|
@ -47,7 +44,7 @@ class TestDebugSettings:
|
|||
def test_debug_reconfigures_logging(self):
|
||||
"""Test that enabling debug reconfigures logging."""
|
||||
# Create a settings instance with debug enabled
|
||||
settings = Settings(debug=True, log_enabled=True)
|
||||
_settings = Settings(debug=True, log_enabled=True)
|
||||
|
||||
# Verify logging was reconfigured
|
||||
logger = get_logger("test")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue