[v1.x] Complete the FastMCP Settings model at import time
Settings.lifespan is annotated with FastMCP, which is defined further down mcp/server/fastmcp/server.py, so pydantic leaves the Settings model incomplete at import and only rebuilds it lazily on the first FastMCP() call. pydantic-settings 2.15 added IncompleteFieldDefinitionWarning for exactly this situation, emitted whenever a settings source inspects such a field — i.e. on every FastMCP(...) construction. With filterwarnings = ["error"] that fails the whole test suite on the highest dependency resolution, which is why every open v1.x PR is currently red there.
Motivation and Context
Call Settings.model_rebuild() once FastMCP exists so the model is complete before anything instantiates it. No behaviour change beyond the warning going away; the settings values resolve exactly as before.
main doesn't use pydantic-settings, so this is v1.x only.
How Has This Been Tested?
tests/server/fastmcp/test_server.py::test_settings_model_is_complete_at_import asserts the model is complete after import (fails on v1.x today). Full suite, pyright and ruff pass locally on the locked resolution; the highest CI jobs on this PR are the check against pydantic-settings 2.15.
Breaking Changes
None.
Types of changes
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing functionality to change)
- Documentation update
Checklist
- I am assigned to the linked issue (or it is labeled
help wanted, or I'm a maintainer) - I have disclosed any AI assistance and can explain the change in my own words
- I have read the MCP Documentation
- My code follows the repository's style guidelines
- New and existing tests pass locally
- I have added appropriate error handling
- I have added or updated documentation as needed
Additional context
None.