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.
This commit is contained in:
Koichi ITO 2026-03-13 18:16:29 +09:00
commit 9d9a1347d9

View file

@ -263,25 +263,18 @@ module MCP
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