Repository navigation
mcp: map custom slog levels to the nearest lower MCP level in LoggingHandler - #1446
Open
kaankucukx wants to merge 2 commits into
Open
kaankucukx wants to merge 2 commits into
kaankucukx wants to merge 2 commits into
Conversation
…Handler slogLevelToMCP returned "debug" for any slog.Level that is not one of the eight MCP level constants. LoggingHandler.Enabled compares the raw slog level, so a record at slog.LevelInfo+1 passed it when the client level was "info", but ServerSession.Log then compared the mapped "debug" against "info" and discarded the record. Custom levels were silently dropped, and when the client level was "debug" they were delivered mislabeled. Map an unknown level to the highest MCP level that does not exceed it, so both filters agree. Levels below LevelDebug still map to "debug". Fixes modelcontextprotocol#1445
kaankucukx
force-pushed
the
mcp/logging-custom-slog-levels
branch
from
October 24, 2026 13:07
dd1f6b0 to
e34e9c9
Compare
Contributor
|
@kaankucukx please fix the tests |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1445
slogLevelToMCPreturned"debug"for anyslog.Levelthat is not one of the eight MCP level constants.LoggingHandler.Enabledcompares the raw slog level, so a record atslog.LevelInfo+1passed it when the client level wasinfo, butServerSession.Logthen compared the mapped"debug"against"info"and discarded the record. Custom levels were silently dropped, and when the client level wasdebugthey were delivered mislabeled asdebug.This maps an unknown level to the highest MCP level that does not exceed it (
INFO+1→info,WARN+1→warning,ERROR+2→error, aboveLevelEmergency→emergency), so both filters agree. Levels belowLevelDebugstill map todebug. The exact-match path is unchanged.Tests:
TestSlogLevelToMCPCustomLevelscovers the mapping table, andTestLoggingHandlerCustomLevelruns a record atINFO+1through an in-memory client/server with the client level set toinfoand checks it arrives asinfo. Both fail onmainand pass with this change;go test ./mcpis green.Logging is deprecated by SEP-2577 but remains functional during the deprecation window, so this keeps the existing behavior correct rather than adding to the API.