fix_start_google_auth
This commit is contained in:
@@ -12,6 +12,7 @@ from typing import Any, Dict, List, Optional
|
||||
from googleapiclient.errors import HttpError # type: ignore
|
||||
from mcp import Resource
|
||||
|
||||
from auth.oauth_config import is_oauth21_enabled, is_external_oauth21_provider
|
||||
from auth.service_decorator import require_google_service
|
||||
from core.server import server
|
||||
from core.utils import handle_http_errors
|
||||
@@ -23,6 +24,27 @@ LIST_TASKS_MAX_RESULTS_MAX = 10_000
|
||||
LIST_TASKS_MAX_POSITION = "99999999999999999999"
|
||||
|
||||
|
||||
def _format_reauth_message(error: Exception, user_google_email: str) -> str:
|
||||
base = f"API error: {error}. You might need to re-authenticate."
|
||||
if is_oauth21_enabled():
|
||||
if is_external_oauth21_provider():
|
||||
hint = (
|
||||
"LLM: Ask the user to provide a valid OAuth 2.1 bearer token in the "
|
||||
"Authorization header and retry."
|
||||
)
|
||||
else:
|
||||
hint = (
|
||||
"LLM: Ask the user to authenticate via their MCP client's OAuth 2.1 "
|
||||
"flow and retry."
|
||||
)
|
||||
else:
|
||||
hint = (
|
||||
"LLM: Try 'start_google_auth' with the user's email "
|
||||
f"({user_google_email}) and service_name='Google Tasks'."
|
||||
)
|
||||
return f"{base} {hint}"
|
||||
|
||||
|
||||
class StructuredTask:
|
||||
def __init__(self, task: Dict[str, str], is_placeholder_parent: bool) -> None:
|
||||
self.id = task["id"]
|
||||
@@ -116,7 +138,7 @@ async def list_task_lists(
|
||||
return response
|
||||
|
||||
except HttpError as error:
|
||||
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
||||
message = _format_reauth_message(error, user_google_email)
|
||||
logger.error(message, exc_info=True)
|
||||
raise Exception(message)
|
||||
except Exception as e:
|
||||
@@ -162,7 +184,7 @@ async def get_task_list(
|
||||
return response
|
||||
|
||||
except HttpError as error:
|
||||
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
||||
message = _format_reauth_message(error, user_google_email)
|
||||
logger.error(message, exc_info=True)
|
||||
raise Exception(message)
|
||||
except Exception as e:
|
||||
@@ -208,7 +230,7 @@ async def create_task_list(
|
||||
return response
|
||||
|
||||
except HttpError as error:
|
||||
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
||||
message = _format_reauth_message(error, user_google_email)
|
||||
logger.error(message, exc_info=True)
|
||||
raise Exception(message)
|
||||
except Exception as e:
|
||||
@@ -256,7 +278,7 @@ async def update_task_list(
|
||||
return response
|
||||
|
||||
except HttpError as error:
|
||||
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
||||
message = _format_reauth_message(error, user_google_email)
|
||||
logger.error(message, exc_info=True)
|
||||
raise Exception(message)
|
||||
except Exception as e:
|
||||
@@ -296,7 +318,7 @@ async def delete_task_list(
|
||||
return response
|
||||
|
||||
except HttpError as error:
|
||||
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
||||
message = _format_reauth_message(error, user_google_email)
|
||||
logger.error(message, exc_info=True)
|
||||
raise Exception(message)
|
||||
except Exception as e:
|
||||
@@ -425,7 +447,7 @@ async def list_tasks(
|
||||
return response
|
||||
|
||||
except HttpError as error:
|
||||
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
||||
message = _format_reauth_message(error, user_google_email)
|
||||
logger.error(message, exc_info=True)
|
||||
raise Exception(message)
|
||||
except Exception as e:
|
||||
@@ -602,7 +624,7 @@ async def get_task(
|
||||
return response
|
||||
|
||||
except HttpError as error:
|
||||
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
||||
message = _format_reauth_message(error, user_google_email)
|
||||
logger.error(message, exc_info=True)
|
||||
raise Exception(message)
|
||||
except Exception as e:
|
||||
@@ -677,7 +699,7 @@ async def create_task(
|
||||
return response
|
||||
|
||||
except HttpError as error:
|
||||
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
||||
message = _format_reauth_message(error, user_google_email)
|
||||
logger.error(message, exc_info=True)
|
||||
raise Exception(message)
|
||||
except Exception as e:
|
||||
@@ -765,7 +787,7 @@ async def update_task(
|
||||
return response
|
||||
|
||||
except HttpError as error:
|
||||
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
||||
message = _format_reauth_message(error, user_google_email)
|
||||
logger.error(message, exc_info=True)
|
||||
raise Exception(message)
|
||||
except Exception as e:
|
||||
@@ -806,7 +828,7 @@ async def delete_task(
|
||||
return response
|
||||
|
||||
except HttpError as error:
|
||||
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
||||
message = _format_reauth_message(error, user_google_email)
|
||||
logger.error(message, exc_info=True)
|
||||
raise Exception(message)
|
||||
except Exception as e:
|
||||
@@ -882,7 +904,7 @@ async def move_task(
|
||||
return response
|
||||
|
||||
except HttpError as error:
|
||||
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
||||
message = _format_reauth_message(error, user_google_email)
|
||||
logger.error(message, exc_info=True)
|
||||
raise Exception(message)
|
||||
except Exception as e:
|
||||
@@ -922,7 +944,7 @@ async def clear_completed_tasks(
|
||||
return response
|
||||
|
||||
except HttpError as error:
|
||||
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
||||
message = _format_reauth_message(error, user_google_email)
|
||||
logger.error(message, exc_info=True)
|
||||
raise Exception(message)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user