This commit is contained in:
2025-12-31 13:42:30 -08:00
parent afe35c51bf
commit 3b687c1a4c
2 changed files with 273 additions and 2 deletions

View File

@@ -32,6 +32,25 @@ def register_email_tools(mcp: FastMCP, service: EmailService):
result = service.list_emails(mailbox, limit, offset, include_body)
return result.model_dump()
@mcp.tool(description="List draft emails in the Drafts mailbox with pagination.")
def list_drafts(
mailbox: Optional[str] = None,
limit: int = 50,
offset: int = 0,
include_body: bool = False,
) -> dict:
"""
List draft emails.
Args:
mailbox: Drafts mailbox/folder override (default: auto-detect)
limit: Maximum number of drafts to return (default: 50)
offset: Number of drafts to skip for pagination (default: 0)
include_body: Whether to include body snippets (default: False)
"""
result = service.list_drafts(mailbox, limit, offset, include_body)
return result.model_dump()
@mcp.tool(description="Read a specific email by ID with full body content and attachment information.")
def read_email(
mailbox: str,
@@ -108,6 +127,89 @@ def register_email_tools(mcp: FastMCP, service: EmailService):
result = service.delete_email(email_id, mailbox, permanent)
return result.model_dump()
@mcp.tool(description="Delete a drafted email by ID, optionally permanently.")
def delete_draft(
email_id: str,
mailbox: Optional[str] = None,
permanent: bool = False,
) -> dict:
"""
Delete a draft email.
Args:
email_id: The unique ID of the draft
mailbox: Drafts mailbox/folder override (default: auto-detect)
permanent: If True, permanently delete; if False, move to Trash (default: False)
"""
result = service.delete_draft(email_id, mailbox, permanent)
return result.model_dump()
@mcp.tool(description="Save a new draft email to the Drafts mailbox.")
def save_draft(
to: list[str],
subject: str,
body: str,
cc: Optional[list[str]] = None,
bcc: Optional[list[str]] = None,
reply_to: Optional[str] = None,
html_body: Optional[str] = None,
mailbox: Optional[str] = None,
) -> dict:
"""
Save a new email draft.
Args:
to: List of recipient email addresses
subject: Email subject line
body: Plain text email body
cc: List of CC recipients (optional)
bcc: List of BCC recipients (optional)
reply_to: Reply-to address (optional)
html_body: HTML version of the email body (optional)
mailbox: Drafts mailbox/folder override (default: auto-detect)
"""
result = service.save_draft(to, subject, body, cc, bcc, reply_to, html_body, mailbox)
return result.model_dump()
@mcp.tool(description="Edit an existing draft email. Only provided fields will be modified.")
def edit_draft(
email_id: str,
mailbox: Optional[str] = None,
to: Optional[list[str]] = None,
subject: Optional[str] = None,
body: Optional[str] = None,
cc: Optional[list[str]] = None,
bcc: Optional[list[str]] = None,
reply_to: Optional[str] = None,
html_body: Optional[str] = None,
) -> dict:
"""
Update an existing draft email.
Args:
email_id: The unique ID of the draft
mailbox: Drafts mailbox/folder override (default: auto-detect)
to: List of recipient email addresses
subject: Email subject line
body: Plain text email body
cc: List of CC recipients (optional)
bcc: List of BCC recipients (optional)
reply_to: Reply-to address (optional)
html_body: HTML version of the email body (optional)
"""
result = service.update_draft(
email_id,
mailbox,
to,
subject,
body,
cc,
bcc,
reply_to,
html_body,
)
return result.model_dump()
@mcp.tool(description="Send a new email via SMTP. Supports plain text and HTML content, CC, BCC, and reply-to.")
async def send_email(
to: list[str],