-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Update FastMCP constructor to respect Pydantic settings configuration #1244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
I would prefer to revert that PR as to have this one merged. It's very annoying that this was build the way it was. We need to deprecate some of those arguments and move to |
@Kludex yeah neither approach is ideal. If you prefer I can just update this PR with the revert of that specific file. #1198 had a handful of other small changes too |
@Kludex please let me know what you'd prefer for this change |
Hi @saqadri thanks for this contribution, will bring up in the maintainer meeting to figure out a path forward. |
Fix environment variable loading in FastMCP by preserving Pydantic Settings behavior
Motivation and Context
PR #1198 introduced a regression where environment variables (e.g.,
FASTMCP_HOST=0.0.0.0
) were no longer being loaded by FastMCP. The issue occurred because the refactored code explicitly passed all settings parameters to the Pydantic Settings constructor, which overrides environment variable values.This fix ensures that only explicitly provided parameters are passed to the Settings constructor, allowing Pydantic's intended priority order to work correctly.
How Has This Been Tested?
Tested the following scenarios:
.env
file values are loaded with correct priorityExample test cases:
Breaking Changes
No breaking changes. This restores the original behavior where environment variables are properly loaded.
Types of changes
Checklist
Additional context
Settings Priority Order
This fix preserves Pydantic Settings' intended priority order (highest to lowest):
FastMCP()
constructorFASTMCP_HOST
).env
file values