Spaces:
Running
Running
Jeremiah Lowin commited on
Only configure logging one time (#1187)
Browse files- src/fastmcp/__init__.py +7 -2
- src/fastmcp/settings.py +1 -12
src/fastmcp/__init__.py
CHANGED
|
@@ -1,10 +1,15 @@
|
|
| 1 |
"""FastMCP - An ergonomic MCP interface."""
|
| 2 |
|
| 3 |
import warnings
|
| 4 |
-
from importlib.metadata import version
|
| 5 |
from fastmcp.settings import Settings
|
|
|
|
| 6 |
|
| 7 |
settings = Settings()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
from fastmcp.server.server import FastMCP
|
| 10 |
from fastmcp.server.context import Context
|
|
@@ -13,7 +18,7 @@ import fastmcp.server
|
|
| 13 |
from fastmcp.client import Client
|
| 14 |
from . import client
|
| 15 |
|
| 16 |
-
__version__ =
|
| 17 |
|
| 18 |
|
| 19 |
# ensure deprecation warnings are displayed by default
|
|
|
|
| 1 |
"""FastMCP - An ergonomic MCP interface."""
|
| 2 |
|
| 3 |
import warnings
|
| 4 |
+
from importlib.metadata import version as _version
|
| 5 |
from fastmcp.settings import Settings
|
| 6 |
+
from fastmcp.utilities.logging import configure_logging as _configure_logging
|
| 7 |
|
| 8 |
settings = Settings()
|
| 9 |
+
_configure_logging(
|
| 10 |
+
level=settings.log_level,
|
| 11 |
+
enable_rich_tracebacks=settings.enable_rich_tracebacks,
|
| 12 |
+
)
|
| 13 |
|
| 14 |
from fastmcp.server.server import FastMCP
|
| 15 |
from fastmcp.server.context import Context
|
|
|
|
| 18 |
from fastmcp.client import Client
|
| 19 |
from . import client
|
| 20 |
|
| 21 |
+
__version__ = _version("fastmcp")
|
| 22 |
|
| 23 |
|
| 24 |
# ensure deprecation warnings are displayed by default
|
src/fastmcp/settings.py
CHANGED
|
@@ -5,7 +5,7 @@ import warnings
|
|
| 5 |
from pathlib import Path
|
| 6 |
from typing import Annotated, Any, Literal
|
| 7 |
|
| 8 |
-
from pydantic import Field, field_validator
|
| 9 |
from pydantic.fields import FieldInfo
|
| 10 |
from pydantic_settings import (
|
| 11 |
BaseSettings,
|
|
@@ -171,17 +171,6 @@ class Settings(BaseSettings):
|
|
| 171 |
),
|
| 172 |
] = None
|
| 173 |
|
| 174 |
-
@model_validator(mode="after")
|
| 175 |
-
def setup_logging(self) -> Self:
|
| 176 |
-
"""Finalize the settings."""
|
| 177 |
-
from fastmcp.utilities.logging import configure_logging
|
| 178 |
-
|
| 179 |
-
configure_logging(
|
| 180 |
-
self.log_level, enable_rich_tracebacks=self.enable_rich_tracebacks
|
| 181 |
-
)
|
| 182 |
-
|
| 183 |
-
return self
|
| 184 |
-
|
| 185 |
# HTTP settings
|
| 186 |
host: str = "127.0.0.1"
|
| 187 |
port: int = 8000
|
|
|
|
| 5 |
from pathlib import Path
|
| 6 |
from typing import Annotated, Any, Literal
|
| 7 |
|
| 8 |
+
from pydantic import Field, field_validator
|
| 9 |
from pydantic.fields import FieldInfo
|
| 10 |
from pydantic_settings import (
|
| 11 |
BaseSettings,
|
|
|
|
| 171 |
),
|
| 172 |
] = None
|
| 173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
# HTTP settings
|
| 175 |
host: str = "127.0.0.1"
|
| 176 |
port: int = 8000
|