Fix context logging methods to accept Any type per MCP spec#2427
Closed
Christian-Sidak wants to merge 1 commit intomodelcontextprotocol:mainfrom
Closed
Fix context logging methods to accept Any type per MCP spec#2427Christian-Sidak wants to merge 1 commit intomodelcontextprotocol:mainfrom
Christian-Sidak wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
…MCP spec The MCP spec defines the logging data field as 'unknown' (any JSON serializable type), but Context.log() and convenience methods (debug, info, warning, error) only accepted str. This changes the parameter from 'message: str' to 'data: Any' to match the spec and the existing ServerSession.send_log_message signature. Also removes the 'extra' parameter which was a workaround for the str-only limitation and caused confusion (as noted in the issue). Fixes modelcontextprotocol#397
Author
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.
Summary
Fixes #397
The MCP spec defines the logging notification
datafield asunknown(any JSON serializable type), butContext.log()and the convenience methods (debug,info,warning,error) only acceptedstr. This was inconsistent with both the spec and the existingServerSession.send_log_message(data: Any)signature.Changes:
message: strtodata: AnyinContext.log()and all convenience methodsextraparameter, which was a workaround for thestr-only limitation and caused confusion (calling withextra=kwargs raisedTypeErrorsinceContext.log()did not accept them)Before (broken):
After (fixed):
Backward compatible -- all existing code passing strings continues to work unchanged since the positional argument just changed name from
messagetodata.Test plan
test_context_loggingpasses (string messages)test_context_logging_structured_datapasses (dict, list, int, None)test_logging_callbackpasses with new API