2727
2828logger = get_logger (__name__ )
2929
30+
3031def is_pending_auth_event (event : Event ) -> bool :
3132 """Check if an ADK event represents a pending authentication request.
3233
@@ -154,29 +155,30 @@ def generate_headers(credential: AuthCredential) -> Optional[dict[str, str]]:
154155
155156 return headers
156157
158+
157159def retry_on_errors (func ):
158- """Decorator to automatically retry action when MCP session errors occur.
159-
160- When MCP session errors occur, the decorator will automatically retry the
161- action once. The create_session method will handle creating a new session
162- if the old one was disconnected.
163-
164- Args:
165- func: The function to decorate.
166-
167- Returns:
168- The decorated function.
169- """
170-
171- @functools .wraps (func ) # Preserves original function metadata
172- async def wrapper (self , * args , ** kwargs ):
173- try :
174- return await func (self , * args , ** kwargs )
175- except Exception as e :
176- # If an error is thrown, we will retry the function to reconnect to the
177- # server. create_session will handle detecting and replacing disconnected
178- # sessions.
179- logger .info (' Retrying %s due to error: %s' , func .__name__ , e )
180- return await func (self , * args , ** kwargs )
181-
182- return wrapper
160+ """Decorator to automatically retry action when MCP session errors occur.
161+
162+ When MCP session errors occur, the decorator will automatically retry the
163+ action once. The create_session method will handle creating a new session
164+ if the old one was disconnected.
165+
166+ Args:
167+ func: The function to decorate.
168+
169+ Returns:
170+ The decorated function.
171+ """
172+
173+ @functools .wraps (func ) # Preserves original function metadata
174+ async def wrapper (self , * args , ** kwargs ):
175+ try :
176+ return await func (self , * args , ** kwargs )
177+ except Exception as e :
178+ # If an error is thrown, we will retry the function to reconnect to the
179+ # server. create_session will handle detecting and replacing disconnected
180+ # sessions.
181+ logger .info (" Retrying %s due to error: %s" , func .__name__ , e )
182+ return await func (self , * args , ** kwargs )
183+
184+ return wrapper
0 commit comments