ruby-sdk/lib/mcp/logging_message_notification.rb
dak2 afa2fb4077 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.
2026-01-26 22:23:46 +09:00

32 lines
629 B
Ruby

# 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