`logging/setLevel` from one session changes the log level of other sessions
維護者通常 1 天內回覆
評估
- 難度
- 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 內容生成。
描述
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 小時
- 30 天內合併 PR
- 47
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
modelcontextprotocol/ruby-sdk 的其他 Issue
-
Invalid UTF-8 in `MCP-Protocol-Version`, `Mcp-Method` or `Mcp-Name` gives 500 instead of 400可能已有人在做 @atesgoral 今天認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 78/100
modelcontextprotocol/ruby-sdk#663 ·
維護者通常 1 天內回覆
-
`Client::Stdio` passes the whole parent environment to the server process可能已有人在做 @atesgoral 今天認領。 未關閉bug
難度 4/5 3-5 天 新手友好度 55/100
modelcontextprotocol/ruby-sdk#662 ·
維護者通常 1 天內回覆
-
Elicitation results are not checked against `requested_schema`, but the docs say they match it可能已有人在做 @atesgoral 今天認領。 未關閉bug
難度 3/5 1-2 天 新手友好度 35/100
modelcontextprotocol/ruby-sdk#661 ·
維護者通常 1 天內回覆
-
HTTP client sends handler exception messages back to the server可能已有人在做 @atesgoral 今天認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 35/100
modelcontextprotocol/ruby-sdk#660 ·
維護者通常 1 天內回覆
-
`JWTVerifier` answers 500 instead of 401 for a PS256 token when it verifies with an EC key (jwt < 3.3.0)可能已有人在做 @atesgoral 今天認領。 未關閉bug
難度 3/5 1-2 天 新手友好度 35/100
modelcontextprotocol/ruby-sdk#659 ·
維護者通常 1 天內回覆
查看 modelcontextprotocol/ruby-sdk 的全部 Issue
相似的 Issue
-
bug javascript
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 88/100
yegor256/netbout.rb#69 ·
-
難度 2/5 1-3 小時 新手友好度 84/100
yegor256/iccq.github.io#161 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
palladius/rails8-app-on-gcp#198 ·
-
bug
難度 1/5 1 小時以內 新手友好度 95/100
WikiEducationFoundation/WikiEduDashboard#7258 ·
維護者通常 1 天內回覆