-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
The current constructor of FastMCP
creates the Settings
object from kwargs during init. This erases type information on what can be passed and any help from the IDE. For example, the lifetime callable can be passed (contrary to what is currently claimed in the readme, where it is advised to use low-level interfaces for that), but I had to click through the code to discover that fact.
class FastMCP:
def __init__(
self, name: str | None = None, instructions: str | None = None, **settings: Any
):
self.settings = Settings(**settings)
Apart from generally violating the principle of dependency injection, this actually decreases usability and type-safety, and does that for no reason whatsoever IMO
Instead, the interface should have been
class FastMCP:
def __init__(
self, name: str | None = None, instructions: str | None = None, settings: Settings | None = None
):
self.settings = settings or Settings()
Since now it is too late, and I suppose you want to keep it backwards compatible, one could change to something like
class FastMCP:
def __init__(
self, name: str | None = None, instructions: str | None = None, settings: Settings | None = None, **settings_kwargs: Any
):
if settings and settings_kwargs:
raise ...
if settings_kwargs:
log.warning("Deprecated ...")
self.settings = settings or Settings(**settings_kwargs)
If you are interested, I could make a quick PR for that, maybe also improve the documentation in the readme while I'm at it