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

オープン
#658 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@atesgoral がすでに取り組んでいます。

2026年11月6日 から。

  • #667 @atesgoral による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
ruby

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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=.

主要言語
Ruby
スター
940
フォーク
143
平均マージ
1日 3時間
マージ済み PR(30日)
47

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

modelcontextprotocol/ruby-sdk のほかの issue

modelcontextprotocol/ruby-sdk の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。