Skip to content

Conversation

daamitt
Copy link
Contributor

@daamitt daamitt commented Oct 16, 2025

Low level MCP server now uses log level set by FastMCP(name="My MCP Server", debug=True, log_level='DEBUG')

Motivation and Context

When logging level is set in code at the FastMCP server, this change percolates it to the low lever server by configuring the logging before low level server init.

How Has This Been Tested?

uv run pytest :
Results (18.58s):
653 passed
2 skipped
1 xfailed

Breaking Changes

No

Types of changes

  • [ x] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • [ x] I have read the MCP Documentation
  • [ x] My code follows the repository's style guidelines
  • [ x] New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@felixweinberger felixweinberger added bug Something isn't working needs more work Not ready to be merged yet, needs additional changes. labels Oct 16, 2025
Copy link
Contributor

@felixweinberger felixweinberger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @daamitt thank you for this contribution!

Could you add a small test in tests/server/fastmcp/test_server.py that demonstrates the new logging behavior?

The description suggests this is a bugfix and that FastMCP wasn't receiving the logging level information before. It'd be great to have a regression test for this to prevent this in future.

@maxisbey
Copy link
Contributor

I'd also appreciate some testing evidence showing how it wasn't working before the fix, and how it is working now after the fix (along side the unit tests requested by @felixweinberger )

@daamitt
Copy link
Contributor Author

daamitt commented Oct 16, 2025

Not sure if this can be captured by a test case, its a very small change that only affects the low level server logs (which i found very useful to track down a race condition Merged PR)

@felixweinberger @maxisbey

Here is the before and after of this fix using uv run server fastmcp_quickstart streamable-http with one change to set the log_level

# Create an MCP server
mcp = FastMCP(name="Demo", log_level='DEBUG')

Before

-> uv run server fastmcp_quickstart streamable-http                                                                                              100% █ [19:38]
[10/16/25 19:38:22] DEBUG    Using selector: KqueueSelector                                                                                selector_events.py:54
INFO:     Started server process [90895]
INFO:     Waiting for application startup.
                    INFO     StreamableHTTP session manager started                                                               streamable_http_manager.py:110
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)

After

-> uv run server fastmcp_quickstart streamable-http                                                                                              100% █ [19:47]
[10/16/25 19:47:38] DEBUG    Initializing server 'Demo'                                                                                            server.py:157
                    DEBUG    Registering handler for ListToolsRequest                                                                              server.py:414
                    DEBUG    Registering handler for CallToolRequest                                                                               server.py:486
                    DEBUG    Registering handler for ListResourcesRequest                                                                          server.py:281
                    DEBUG    Registering handler for ReadResourceRequest                                                                           server.py:316
                    DEBUG    Registering handler for PromptListRequest                                                                             server.py:243
                    DEBUG    Registering handler for GetPromptRequest                                                                              server.py:265
                    DEBUG    Registering handler for ListResourceTemplatesRequest                                                                  server.py:301
                    DEBUG    Using selector: KqueueSelector                                                                                selector_events.py:54
INFO:     Started server process [91391]
INFO:     Waiting for application startup.
                    INFO     StreamableHTTP session manager started                                                               streamable_http_manager.py:110
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)

@felixweinberger
Copy link
Contributor

Not sure if this can be captured by a test case, its a very small change that only affects the low level server logs (which i found very useful to track down a race condition Merged PR)

@felixweinberger @maxisbey

Here is the before and after of this fix using uv run server fastmcp_quickstart streamable-http with one change to set the log_level

# Create an MCP server
mcp = FastMCP(name="Demo", log_level='DEBUG')

##Before

-> uv run server fastmcp_quickstart streamable-http                                                                                              100% █ [19:38]
[10/16/25 19:38:22] DEBUG    Using selector: KqueueSelector                                                                                selector_events.py:54
INFO:     Started server process [90895]
INFO:     Waiting for application startup.
                    INFO     StreamableHTTP session manager started                                                               streamable_http_manager.py:110
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)

##After

-> uv run server fastmcp_quickstart streamable-http                                                                                              100% █ [19:47]
[10/16/25 19:47:38] DEBUG    Initializing server 'Demo'                                                                                            server.py:157
                    DEBUG    Registering handler for ListToolsRequest                                                                              server.py:414
                    DEBUG    Registering handler for CallToolRequest                                                                               server.py:486
                    DEBUG    Registering handler for ListResourcesRequest                                                                          server.py:281
                    DEBUG    Registering handler for ReadResourceRequest                                                                           server.py:316
                    DEBUG    Registering handler for PromptListRequest                                                                             server.py:243
                    DEBUG    Registering handler for GetPromptRequest                                                                              server.py:265
                    DEBUG    Registering handler for ListResourceTemplatesRequest                                                                  server.py:301
                    DEBUG    Using selector: KqueueSelector                                                                                selector_events.py:54
INFO:     Started server process [91391]
INFO:     Waiting for application startup.
                    INFO     StreamableHTTP session manager started                                                               streamable_http_manager.py:110
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)

There are already tests in there that assert on logging - you could take inspiration from those for example?

with patch("mcp.server.session.ServerSession.send_log_message") as mock_log:

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

Labels

bug Something isn't working needs more work Not ready to be merged yet, needs additional changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants