[JsonRpc] Improved middleware registration