Skip to content

Stop FastMCP from configuring application logging#2532

Open
Genmin wants to merge 5 commits intomodelcontextprotocol:mainfrom
Genmin:fix/fastmcp-library-logging
Open

Stop FastMCP from configuring application logging#2532
Genmin wants to merge 5 commits intomodelcontextprotocol:mainfrom
Genmin:fix/fastmcp-library-logging

Conversation

@Genmin
Copy link
Copy Markdown

@Genmin Genmin commented May 1, 2026

Fixes #1656.

Summary

  • remove process-wide logging configuration from MCPServer.__init__
  • configure logging in the mcp run CLI entrypoint instead, where the process is owned by the SDK CLI
  • preserve server log-level settings for CLI-run servers and fall back to INFO for non-FastMCP server objects

Validation

  • uv run ruff format --check src/mcp/cli/cli.py src/mcp/server/mcpserver/server.py tests/cli/test_utils.py tests/server/mcpserver/test_server.py
  • uv run ruff check src/mcp/cli/cli.py src/mcp/server/mcpserver/server.py tests/cli/test_utils.py tests/server/mcpserver/test_server.py
  • uv run pyright src/mcp/cli/cli.py tests/cli/test_utils.py tests/server/mcpserver/test_server.py
  • uv run pytest tests/cli/test_utils.py tests/server/mcpserver/test_server.py -q
  • git diff --check

@Genmin
Copy link
Copy Markdown
Author

Genmin commented May 1, 2026

Follow-up pushed for the remaining CI coverage gate. The failed matrix jobs were passing tests but reporting two uncovered lines (src/mcp/cli/cli.py:126 and tests/server/mcpserver/test_server.py:54), so I added coverage for the invalid log-level fallback and replaced the local no-op callback with a MagicMock assertion that does not create an uncovered function body.

Local validation on the updated branch:

  • uv run pytest tests/cli/test_utils.py tests/server/mcpserver/test_server.py tests/server/mcpserver/utilities/test_logging.py -q
  • uv run ruff format --check tests/cli/test_utils.py tests/server/mcpserver/test_server.py tests/server/mcpserver/utilities/test_logging.py
  • uv run ruff check src/mcp/cli/cli.py src/mcp/server/mcpserver/utilities/logging.py tests/cli/test_utils.py tests/server/mcpserver/test_server.py tests/server/mcpserver/utilities/test_logging.py
  • uv run pyright src/mcp/cli/cli.py src/mcp/server/mcpserver/utilities/logging.py tests/cli/test_utils.py tests/server/mcpserver/test_server.py tests/server/mcpserver/utilities/test_logging.py
  • git diff --check

@Genmin
Copy link
Copy Markdown
Author

Genmin commented May 1, 2026

One more narrow follow-up pushed: the next Ubuntu run reached 100% coverage, then strict-no-cover correctly reported that the run() pragma was now stale because the CLI path is covered by the new test. I narrowed the pragma to the exception path only.

Additional local validation:

  • uv run pytest tests/cli/test_utils.py tests/server/mcpserver/test_server.py tests/server/mcpserver/utilities/test_logging.py -q
  • uv run ruff format --check src/mcp/cli/cli.py tests/cli/test_utils.py tests/server/mcpserver/test_server.py tests/server/mcpserver/utilities/test_logging.py
  • uv run ruff check src/mcp/cli/cli.py src/mcp/server/mcpserver/utilities/logging.py tests/cli/test_utils.py tests/server/mcpserver/test_server.py tests/server/mcpserver/utilities/test_logging.py
  • uv run pyright src/mcp/cli/cli.py src/mcp/server/mcpserver/utilities/logging.py tests/cli/test_utils.py tests/server/mcpserver/test_server.py tests/server/mcpserver/utilities/test_logging.py
  • git diff --check

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