Skip to content

allow passing full uvicorn config #504

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

Merged
merged 5 commits into from
May 19, 2025
Merged

allow passing full uvicorn config #504

merged 5 commits into from
May 19, 2025

Conversation

zzstoatzz
Copy link
Collaborator

@zzstoatzz zzstoatzz commented May 19, 2025

closes #438

Previously, users could not customize the format of Uvicorn's initial startup logs as FastMCP only passed a log_level string. This change allows users to provide a complete log_config dictionary via uvicorn_config when running an HTTP server. If log_config is present, it's passed directly to uvicorn.Config, giving full control over Uvicorn's logging, and FastMCP's log_level parameter is correctly omitted for Uvicorn's configuration.

@github-actions github-actions bot added the tests label May 19, 2025
@zzstoatzz zzstoatzz marked this pull request as ready for review May 19, 2025 20:09
@zzstoatzz zzstoatzz requested review from Copilot and jlowin May 19, 2025 20:09
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables passing a full Uvicorn configuration dictionary to run_http_async, merging it with default parameters and only injecting log_level when no custom log_config is provided.

  • Refactored run_http_async to build and merge a uvicorn_config dict before instantiating uvicorn.Config.
  • Added new tests in test_logging.py to verify default log levels, custom log_config, and precedence when both are provided.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tests/server/test_logging.py Add tests for default log level, custom log_config, and precedence with both set
src/fastmcp/server/server.py Change run_http_async to accept and merge a full uvicorn_config dict
Comments suppressed due to low confidence (2)

src/fastmcp/server/server.py:778

  • [nitpick] Spreading the entire uvicorn_config into config_kwargs may unintentionally override essential parameters (app, host, port). Consider restricting which keys can be merged or documenting the merge order to prevent surprises.
"**uvicorn_config,

src/fastmcp/server/server.py:778

  • The new merge logic for uvicorn_config and log_level isn’t covered by a test where uvicorn_config contains log_level but no log_config. Add a test to assert intended precedence in that scenario.
"**uvicorn_config,

@zzstoatzz zzstoatzz merged commit 6697a16 into main May 19, 2025
5 checks passed
@zzstoatzz zzstoatzz deleted the uvicorn-config branch May 19, 2025 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can not reformat uvicorn log which is using logging.getLogger("uvicorn.error")
2 participants