Add logging support
A server can send structured logging messages to the client. https://modelcontextprotocol.io/specification/2025-06-18/server/utilities/logging#logging Logging was specified in the 2024-11-05 specification, but since it was not supported in ruby-sdk, I implemented it. https://modelcontextprotocol.io/specification/2024-11-05/server/utilities/logging I also made it possible to output a simple notification message in the examples.
This commit is contained in:
parent
830913be5a
commit
afa2fb4077
1 changed files with 434 additions and 7 deletions
32
lib/mcp/logging_message_notification.rb
Normal file
32
lib/mcp/logging_message_notification.rb
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "json_rpc_handler"
|
||||
|
||||
module MCP
|
||||
class LoggingMessageNotification
|
||||
LOG_LEVEL_SEVERITY = {
|
||||
"debug" => 0,
|
||||
"info" => 1,
|
||||
"notice" => 2,
|
||||
"warning" => 3,
|
||||
"error" => 4,
|
||||
"critical" => 5,
|
||||
"alert" => 6,
|
||||
"emergency" => 7,
|
||||
}.freeze
|
||||
|
||||
def initialize(level:)
|
||||
@level = level
|
||||
end
|
||||
|
||||
def valid_level?
|
||||
LOG_LEVEL_SEVERITY.keys.include?(@level)
|
||||
end
|
||||
|
||||
def should_notify?(log_level)
|
||||
return false unless LOG_LEVEL_SEVERITY.key?(log_level)
|
||||
|
||||
LOG_LEVEL_SEVERITY[log_level] >= LOG_LEVEL_SEVERITY[@level]
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue