`logging/setLevel` from one session changes the log level of other sessions

Đang mở
#658 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@atesgoral đang làm issue này rồi.

Từ ngày 6/11/2026.

  • #667 của @atesgoral — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
ruby
Lĩnh vực
backend-api-design

Hướng nghiên cứu

Start with lib/mcp/server.rb:1386, lib/mcp/server_session.rb:310-314, and lib/mcp/server.rb:448-450 to trace how session and server log levels are applied. The issue suggests updating the server-wide value only when session is nil; check existing logging specs and add coverage for two legacy sessions. Done means setting a level in one session does not change notifications sent to another session that never set a level. An open linked pull request (#667) is already addressing this issue.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug

Server#configure_logging_level sets the level on the calling session, then always sets the server-wide @logging_message_notification too (server.rb:1386).

Legacy sessions that did not set their own level fall back to that server-wide value (server_session.rb:310-314), and Server#notify_log_message uses it for broadcasts (server.rb:448-450). So when one client calls logging/setLevel, every other legacy session without its own level starts to get notifications/message at that level. This includes sessions created later.

The spec treats the log level as a preference of the connection that sets it. The modern lifecycle is not affected, because it uses the per-request logLevel from the envelope.

Repro

Run from the repository root with bundle exec ruby -I lib repro.rb:

require "mcp"

class RecordingTransport
  attr_reader :log_messages

  def initialize
    @log_messages = []
  end

  def send_notification(method, params = nil, session_id: nil, **)
    @log_messages << [session_id, params["data"]] if method == "notifications/message"
    true
  end
end

log_tool = MCP::Tool.define(name: "log_tool") do |server_context:|
  server_context.notify_log_message(data: "debug detail", level: "debug")
  MCP::Tool::Response.new([{ type: "text", text: "ok" }])
end
transport = RecordingTransport.new
server = MCP::Server.new(name: "example", tools: [log_tool])
server.transport = transport

initialize_request = {
  jsonrpc: "2.0", id: 1, method: "initialize",
  params: { protocolVersion: "2025-11-25", capabilities: {}, clientInfo: { name: "client", version: "1" } },
}
session_a = MCP::ServerSession.new(server: server, transport: transport, session_id: "A")
session_b = MCP::ServerSession.new(server: server, transport: transport, session_id: "B")
session_a.handle(initialize_request)
session_b.handle(initialize_request)

session_a.handle({ jsonrpc: "2.0", id: 2, method: "logging/setLevel", params: { level: "debug" } })
session_b.handle({ jsonrpc: "2.0", id: 3, method: "tools/call", params: { name: "log_tool", arguments: {} } })

p transport.log_messages

Expected: []. Session B never called logging/setLevel.

Actual: [["B", "debug detail"]]

Suggested fix

Set the server-wide value only on the session-less path (session is nil). With a session, change only that session's level. Applications can still set a server-wide default with Server#logging_message_notification=.

Ngôn ngữ chính
Ruby
Star
940
Fork
143
Merge trung bình
1 ngày 5 giờ
Pull request đã merge (30 ngày)
48

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của modelcontextprotocol/ruby-sdk

Tất cả issue của modelcontextprotocol/ruby-sdk

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.