modify_email
Manage email labels by archiving, trashing, or marking emails as read/unread. Add or remove labels to organize and streamline email workflows efficiently.
Instructions
Modify email labels (archive, trash, mark read/unread, etc.)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| add_labels | No | ||
| id | Yes | ||
| remove_labels | No |
Implementation Reference
- server.py:364-404 (handler)The core handler function for the 'modify_email' tool, decorated with @mcp.tool for automatic registration and schema inference. It authenticates with Google, calls the Gmail API to modify email labels by adding or removing them as specified.@mcp.tool( name="modify_email", description="Modify email labels (archive, trash, mark read/unread, etc.)", ) async def modify_email(id: str, add_labels: Optional[List[str]] = None, remove_labels: Optional[List[str]] = None) -> str: """ Modify email labels (archive, trash, mark read/unread, etc.) Args: id (str): Email message ID add_labels (array, optional): Labels to add (e.g., ['INBOX', 'UNREAD']) remove_labels (array, optional): Labels to remove (e.g., ['INBOX', 'SPAM']) Returns: str: Success message """ creds = get_google_credentials() if not creds: return "Google authentication failed." if not add_labels and not remove_labels: return "add_labels 또는 remove_labels 중 하나는 제공되어야 합니다." try: service = build('gmail', 'v1', credentials=creds) body = {} if add_labels: body['addLabelIds'] = add_labels if remove_labels: body['removeLabelIds'] = remove_labels message = service.users().messages().modify(userId='me', id=id, body=body).execute() logger.info(f"메시지 ID: {message['id']} 수정 완료.") return f"이메일 수정 성공. 메시지 ID {message['id']}의 라벨 업데이트 완료." except HttpError as error: logger.error(f"API 오류 발생: {error}") return f"Gmail API 오류: {error.resp.status} - {error.content.decode()}" except Exception as e: logger.exception("이메일 수정 중 오류:") return f"예상치 못한 오류 발생: {str(e)}"
- server.py:200-206 (registration)A resource function that lists available tools including 'modify_email', indicating its registration in the system.available_google_tools = [ "list_emails", "search_emails", "send_email", "modify_email", "list_events", "create_event", "update_event", "delete_event", "search_google", "read_gdrive_file", "search_gdrive" ] logger.info(f"Resource 'get_available_google_tools' 호출됨. 반환: {available_google_tools}") return available_google_tools
- server.py:368-379 (schema)Function signature and docstring defining the input schema (parameters: id:str, add_labels:Optional[List[str]], remove_labels:Optional[List[str]] ) and output (str success/error message).async def modify_email(id: str, add_labels: Optional[List[str]] = None, remove_labels: Optional[List[str]] = None) -> str: """ Modify email labels (archive, trash, mark read/unread, etc.) Args: id (str): Email message ID add_labels (array, optional): Labels to add (e.g., ['INBOX', 'UNREAD']) remove_labels (array, optional): Labels to remove (e.g., ['INBOX', 'SPAM']) Returns: str: Success message """