Skip to content

Avoid configuring logging during MCPServer initialization#2503

Open
fungi8 wants to merge 1 commit intomodelcontextprotocol:mainfrom
fungi8:fix-mcpserver-logging-side-effect
Open

Avoid configuring logging during MCPServer initialization#2503
fungi8 wants to merge 1 commit intomodelcontextprotocol:mainfrom
fungi8:fix-mcpserver-logging-side-effect

Conversation

@fungi8
Copy link
Copy Markdown

@fungi8 fungi8 commented Apr 25, 2026

Summary

  • remove the configure_logging() call from MCPServer.__init__() so constructing a server does not mutate application-level logging
  • add a regression test that verifies MCPServer() does not call logging.basicConfig()
  • add direct coverage for the MCPServer logging utilities now that logging is no longer configured as an initialization side effect

Fixes #1656

Tests

  • uv run --frozen pytest tests/server/mcpserver/test_server.py::test_create_server_does_not_configure_logging tests/server/mcpserver/test_server.py::TestServer::test_create_server tests/server/mcpserver/utilities/test_logging.py -q
  • uv run --frozen ruff check src/mcp/server/mcpserver/server.py tests/server/mcpserver/test_server.py tests/server/mcpserver/utilities/test_logging.py
  • uv run --frozen ruff format --check src/mcp/server/mcpserver/server.py tests/server/mcpserver/test_server.py tests/server/mcpserver/utilities/test_logging.py
  • uv run --frozen coverage erase && uv run --frozen coverage run -m pytest tests/server/mcpserver/test_server.py::test_create_server_does_not_configure_logging tests/server/mcpserver/test_server.py::TestServer::test_create_server tests/server/mcpserver/utilities/test_logging.py && uv run --frozen coverage combine && uv run --frozen coverage report --include='src/mcp/server/mcpserver/server.py,src/mcp/server/mcpserver/utilities/logging.py' --fail-under=0 && UV_FROZEN=1 uv run --frozen strict-no-cover
  • uv run --frozen pyright src/mcp/server/mcpserver/server.py tests/server/mcpserver/test_server.py tests/server/mcpserver/utilities/test_logging.py

@fungi8 fungi8 force-pushed the fix-mcpserver-logging-side-effect branch from 570ec6e to 57b9340 Compare April 25, 2026 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant