From 6ef77b58ae9e4e3fe3a3f62a0ab555dcde6b720b Mon Sep 17 00:00:00 2001 From: b3nw Date: Tue, 5 May 2026 02:43:23 +0000 Subject: [PATCH] fix: handle rate limiting with backoff, fix auth error detection --- src/monarch_mcp_custom/auth.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/monarch_mcp_custom/auth.py b/src/monarch_mcp_custom/auth.py index 0b82ff0..edf1a3b 100644 --- a/src/monarch_mcp_custom/auth.py +++ b/src/monarch_mcp_custom/auth.py @@ -123,8 +123,15 @@ def retry_on_auth_error(max_retries: int = 1): "401" in error_str or "unauthorized" in error_str or "authentication" in error_str - or isinstance(e, (RequestFailedException, LoginFailedException)) + or isinstance(e, LoginFailedException) ) + is_rate_limit = "429" in error_str or "rate limit" in error_str + + if is_rate_limit and attempt < max_retries: + import asyncio + logger.warning(f"Rate limited in {func.__name__}, waiting 15s before retry...") + await asyncio.sleep(15) + continue if is_auth_error and attempt < max_retries: logger.warning(