-
Notifications
You must be signed in to change notification settings - Fork 56
Add logging
support
#103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dak2
wants to merge
1
commit into
modelcontextprotocol:main
Choose a base branch
from
dak2:support-logging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+161
−7
Open
Add logging
support
#103
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require "json_rpc_handler" | ||
|
||
module MCP | ||
class LoggingMessageNotification | ||
LOG_LEVELS = ["debug", "info", "notice", "warning", "error", "critical", "alert", "emergency"].freeze | ||
attr_reader :level | ||
|
||
class InvalidLevelError < StandardError | ||
def initialize | ||
super("Invalid log level provided. Valid levels are: #{LOG_LEVELS.join(", ")}") | ||
@code = JsonRpcHandler::ErrorCode::InvalidParams | ||
end | ||
end | ||
|
||
class NotSpecifiedLevelError < StandardError | ||
def initialize | ||
super("Log level not specified. Please set a valid log level.") | ||
@code = JsonRpcHandler::ErrorCode::InternalError | ||
end | ||
end | ||
|
||
def initialize(level:) | ||
@level = level | ||
end | ||
|
||
def valid_level? | ||
LOG_LEVELS.include?(level) | ||
end | ||
end | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
module MCP | ||
class LoggingMessageNotificationTest < ActiveSupport::TestCase | ||
test "valid_level? returns true for valid levels" do | ||
LoggingMessageNotification::LOG_LEVELS.each do |level| | ||
logging_message_notification = LoggingMessageNotification.new(level: level) | ||
assert logging_message_notification.valid_level?, "#{level} should be valid" | ||
end | ||
end | ||
|
||
test "valid_level? returns false for invalid levels" do | ||
invalid_levels = ["invalid", 1, "", nil, :fatal] | ||
invalid_levels.each do |level| | ||
logging_message_notification = LoggingMessageNotification.new(level: level) | ||
assert_not logging_message_notification.valid_level?, "#{level} should be invalid" | ||
end | ||
end | ||
|
||
test "InvalidLevelError has correct error code" do | ||
error = LoggingMessageNotification::InvalidLevelError.new | ||
assert_equal(-32602, error.instance_variable_get(:@code)) | ||
end | ||
|
||
test "InvalidLevelError message format" do | ||
error = LoggingMessageNotification::InvalidLevelError.new | ||
expected_levels = LoggingMessageNotification::LOG_LEVELS.join(", ") | ||
expected_message = "Invalid log level provided. Valid levels are: #{expected_levels}" | ||
|
||
assert_equal expected_message, error.message | ||
end | ||
|
||
test "NotSpecifiedLevelError has correct error code" do | ||
error = LoggingMessageNotification::NotSpecifiedLevelError.new | ||
assert_equal(-32603, error.instance_variable_get(:@code)) | ||
end | ||
|
||
test "NotSpecifiedLevelError has correct message" do | ||
error = LoggingMessageNotification::NotSpecifiedLevelError.new | ||
expected_message = "Log level not specified. Please set a valid log level." | ||
|
||
assert_equal expected_message, error.message | ||
end | ||
end | ||
end |
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, the Python SDK uses "info" level as the default. What do you think about doing the same?
https://github.com/modelcontextprotocol/python-sdk/blob/v1.12.3/src/mcp/server/fastmcp/server.py#L132
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's necessary to set a default value, but what do you think?
The log_level literal specified in the MCP spec appears to be defined in mcp/types.py, and it seems that no default value has been set.
https://github.com/modelcontextprotocol/python-sdk/blob/68e25d478b3b6a026b2d9a30b3e5f34f3b1290de/src/mcp/types.py#L905
The log_level in fastmcp/server.py#L132 appears to set the default value for uvicorn's log_level.
However, if this literal is the same as the one specified in the MCP spec, I don't think it meets the logging specifications, as levels such as
emergency
andnotice
are not defined.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true. There's no need to set something that's not explicitly specified in the specification.
Your current suggestion makes sense to me.