Skip to content

Stop FastMCP from configuring application logging - #2532

Closed
Genmin wants to merge 5 commits into
modelcontextprotocol:mainfrom
Genmin:fix/fastmcp-library-logging
Closed

Genmin wants to merge 5 commits into
modelcontextprotocol:mainfrom
Genmin:fix/fastmcp-library-logging

Conversation

@Genmin

@Genmin Genmin commented May 1, 2026

Copy link
Copy Markdown

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

Genmin commented May 1, 2026 •

Copy link
Copy Markdown
Author

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

Genmin commented May 1, 2026

Copy link
Copy Markdown
Author

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

@m-u-xyz

m-u-xyz commented Jun 16, 2026

Copy link
Copy Markdown

Thank you. Is there anything that blocks this PR? I'd really like to remove the required monkeypatching of logging.basicConfig from my code …

@maxisbey

maxisbey commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR, and sorry it sat here without a proper review.

We're closing most of the open PR backlog. v2 is out and changed a lot of the SDK, so many older PRs no longer apply as written, and we're a small team that realistically doesn't have the capacity to work through the rest.

If this still matters to you on v2, the most useful thing you can do is open an issue (or comment on the existing one) with your use case and a repro. Hearing why it matters to you is what we use to decide what to prioritise.

AI Disclaimer

@maxisbey maxisbey closed this Oct 5, 2026
@maxisbey maxisbey added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Oct 5, 2026
@m-u-xyz

m-u-xyz commented Oct 5, 2026

Copy link
Copy Markdown

Sigh Yes it still matters! A lot, in fact. See my comment on the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants