modelcontextprotocol / modelcontextprotocol/python-sdk

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

Aperta
#1,656 7 commenti 6 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug P2 ready for work
Lingua principale
Python
Stelle
24.3k
Fork
4k
Merge medio
1g 1h
PR unite (30g)
31

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia individuando la configurazione del logging di FastMCP init e confrontala con la guida di Python "Configuring Logging for a Library". Il lavoro è completato quando l'inizializzazione della libreria non configura più il logging dell'applicazione, mentre qualsiasi logging rich specifico del quickstart rimane separato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
developer-experience
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.