From 9d9a1347d9f99403e7b164854bfeb98548c2aaa3 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Fri, 13 Mar 2026 18:16:29 +0900 Subject: [PATCH] Remove dead code in `handle_regular_request` Notifications never reach `handle_regular_request` because `handle_post` checks `notification?(body)` first and returns 202 via `handle_accepted`. Since only notifications cause `handle_json` to return `nil`, `response` is always non-`nil` here. --- lib/mcp/server/transports/streamable_http_transport.rb | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/mcp/server/transports/streamable_http_transport.rb b/lib/mcp/server/transports/streamable_http_transport.rb index ff9977d..1285cc2 100644 --- a/lib/mcp/server/transports/streamable_http_transport.rb +++ b/lib/mcp/server/transports/streamable_http_transport.rb @@ -263,25 +263,18 @@ def handle_regular_request(body_string, session_id) end end - response = @server.handle_json(body_string) || "" + response = @server.handle_json(body_string) # Stream can be nil since stateless mode doesn't retain streams stream = get_session_stream(session_id) if session_id if stream send_response_to_stream(stream, response, session_id) - elsif response.nil? && notification_request?(body_string) - [202, { "Content-Type" => "application/json" }, [response]] else [200, { "Content-Type" => "application/json" }, [response]] end end - def notification_request?(body_string) - body = parse_request_body(body_string) - body.is_a?(Hash) && body["method"].start_with?("notifications/") - end - def get_session_stream(session_id) @mutex.synchronize { @sessions[session_id]&.fetch(:stream, nil) } end