modelcontextprotocol / modelcontextprotocol/python-sdk

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

Aberta
#1,656 7 comentários 6 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

bug P2 ready for work
Linguagem predominante
Python
Estrelas
24.3k
Forks
4k
Merge médio
1d 1h
PRs com merge (30d)
31

Descrição

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

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece localizando a configuração de logging de FastMCP init e compare-a com a orientação do Python "Configuring Logging for a Library". Considera-se concluído quando a inicialização da biblioteca não configurar mais o logging da aplicação, enquanto qualquer logging rich específico do quickstart permanecer separado.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python
Domínio
developer-experience
Tipo de issue
Bug
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Pouca atividade
Clareza
Razoavelmente clara
Facilidade para iniciantes
45/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.