Skip to content

FastMCP configures logging on init, which messes up application-level logging #1656

@pfaion

Description

@pfaion

Initial Checks

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions