-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
Initial Checks
- I confirm that I'm using the latest version of MCP Python SDK
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Description
Hi everyone, thanks for maintaining the Python SDK for MCP!
I've noticed that the FastMCP class configures the logging ecosystem on __init__(), both by adding custom handlers and calling logging.basicConfig(...). This will conflict with any logging setup that any application using the MCP SDK will use.
Please note that the best practice for logging is:
- library code should never configure logging behavior
- application entrypoints should configure logging behavior
Please refer to the official logging HowTo, section "Configuring Logging for a Library":
It is strongly advised that you do not add any handlers other than NullHandler to your library’s loggers. This is because the configuration of handlers is the prerogative of the application developer who uses your library. The application developer knows their target audience and what handlers are most appropriate for their application: if you add handlers ‘under the hood’, you might well interfere with their ability to carry out unit tests and deliver logs which suit their requirements.
For the sake of easy quickstarts, I'd advice to create some module specifically meant for quickstarts that runs a FastMCP server, taking care of setting up the rich logging as well before. But keep it separated from the main library usage of FastMCP server, so applications using it don't get their logging config messed up.
Example Code
Python & MCP Python SDK
1.22.0