Repository navigation
Option to not rewrite the logging configuration #420
Description
Is your feature request related to a problem? Please describe.
We are integrating FastMcp into a larger python process that requires a custom logging handler and when initialising the FastMCP server (in our case in sse mode) we see that the logging library configuration changes with a custom configuration of the server itself.
Describe the solution you'd like
Define a configuration parameter that disables the logging configuration performed by the server.
Describe alternatives you've considered
Reviewing the configuration parameters I have seen the existence of the parameter log_level (
| log_level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "INFO" |
Additional context
As far as I have been able to identify, there are two points where this configuration is being made and which should be modified:
- The call to the configure_logging method (), which should be prevented.
python-sdk/src/mcp/server/fastmcp/server.py
Line 138 in c2ca8e0
configure_logging(self.settings.log_level) - The configuration of uvicorn () that if the parameters log_config and log_level are not None also makes the change.
python-sdk/src/mcp/server/fastmcp/server.py
Line 471 in c2ca8e0
config = uvicorn.Config(
Activity
sergioave commentedon May 22, 2025
Hi, any update on this?
olejorgenb commentedon Jun 18, 2025
The cleanest way would be to just reset the logging configuration after the instantiation of the
FastMCPobject, but this is more fun:Note: I tried to simple assign
fast_mcp_logging_module.configure_loggingto an dummy function, but did not work. The variable have likely already been bound somewhere else.FastMCP()overwrites global logging configuration #909 as a duplicate of this issuekulinacs commentedon Jul 9, 2025
This would be great to make configurable - it take a decent amount of troubleshooting to figure out what imported library is adding a logging handler. From the perspective of a developer who has already configured global logging for their application, log messages are suddenly duplicated.
Enumerating handlers and removing them works fine, but global side effects you can't opt out of aren't developer friendly.
mukulmurthy commentedon Aug 6, 2025
We ran into a similar issue attempting to use our structured logging config for FastMCP server logging. We were able to work around the issue by adding a
FastMCPlogger to our log config and callinglogging.config.dictConfig(OUR_LOGGING_CONFIG)to reconfigure the MCP logger to do what we wanted.With that said, agreed that it would be helpful to have an option to not remove other handlers.
lukehsiao commentedon Aug 19, 2025
Can you say more about your workaround? Were you using structlog? If so, care you share some more about how you did it?
ChuckJonas commentedon Sep 5, 2025
Is there any update on this? The FastMCP logs break our ability to cleanly ship JSON formatted logs... The massive multi-line console formatted logs create a ton of noise.
flegelleicht commentedon Sep 24, 2025
Hi, I am also wondering if there is any update on this. The logging output looks weird to me ... and is inconsistent with every other log line in our app:
How do I override this?
nvachhar commentedon Sep 24, 2025
I believe internally MCP uses basicConfig to set up logging (not the only location, but for example
python-sdk/src/mcp/server/fastmcp/utilities/logging.py
Line 39 in 71889d7
Per the documentation:
So the trick is to ensure that you can get a default logger handler installed before MCP does its log initialization (e.g. using dictConfig or an earlier call to basicConfig). Then the MCP calls to basicConfig will be no-ops.
flegelleicht commentedon Sep 24, 2025
Thanks @nvachhar
I tried it with
.dictConfiglike this:... but the result was: no log lines from the code anymore, not even weird looking ones. Just no output 🤷
I’ll try to think of something else, later ...
nvachhar commentedon Sep 24, 2025
Very strange. I do something quite similar (except I don't specifically call out any loggers, I just let the root logger do the logging) and it has worked for me.
laozhangzzz commentedon Jun 25, 2026