Skip to main content
Glama

write_email_draft

Create draft emails in Gmail by providing recipient address, subject line, and body content through API integration.

Instructions

Create a draft email using the Gmail API.

Args:
    recipient_email (str): The email address of the recipient.
    subject (str): The subject line of the email.
    body (str): The main content/body of the email.

Returns:
    dict or None: A dictionary containing the draft information including 'id' and 'message' 
                 if successful, None if an error occurs.

Raises:
    HttpError: If there is an error communicating with the Gmail API.
    
Note:
    This function requires:
    - Gmail API credentials to be properly configured
    - USER_EMAIL environment variable to be set with the sender's email address
    - Appropriate Gmail API permissions for creating drafts

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
recipient_emailYes
subjectYes
bodyYes

Implementation Reference

  • The handler function for the 'write_email_draft' tool, decorated with @mcp.tool() for registration. It creates a draft email in Gmail using the Gmail API, taking recipient_email, subject, and body as inputs.
    @mcp.tool()
    def write_email_draft(recipient_email: str, subject: str, body: str) -> dict:
        """Create a draft email using the Gmail API.
        
        Args:
            recipient_email (str): The email address of the recipient.
            subject (str): The subject line of the email.
            body (str): The main content/body of the email.
        
        Returns:
            dict or None: A dictionary containing the draft information including 'id' and 'message' 
                         if successful, None if an error occurs.
        
        Raises:
            HttpError: If there is an error communicating with the Gmail API.
            
        Note:
            This function requires:
            - Gmail API credentials to be properly configured
            - USER_EMAIL environment variable to be set with the sender's email address
            - Appropriate Gmail API permissions for creating drafts
        """
        try:
            # create gmail api client
            service = get_gmail_service()
    
            message = EmailMessage()
    
            message.set_content(body)
    
            message["To"] = recipient_email
            message["From"] = os.getenv("USER_EMAIL")
            message["Subject"] = subject
    
            # encoded message
            encoded_message = base64.urlsafe_b64encode(message.as_bytes()).decode()
    
            create_message = {"message": {"raw": encoded_message}}
            # pylint: disable=E1101
            draft = (
                service.users()
                .drafts()
                .create(userId="me", body=create_message)
                .execute()
            )
    
            print(f'Draft id: {draft["id"]}\nDraft message: {draft["message"]}')
    
        except HttpError as error:
            print(f"An error occurred: {error}")
            draft = None
    
        return draft
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes the operation's purpose, return values (success dictionary with id/message or None), error conditions (HttpError), and prerequisites (credentials, environment variable, permissions). It doesn't mention rate limits, retry behavior, or concurrency considerations, but covers the essential behavioral aspects for a write operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (Args, Returns, Raises, Note) and efficiently conveys necessary information. While slightly longer than minimal, each section earns its place by providing valuable context. The information is front-loaded with the core purpose stated first.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (write operation with API dependencies), no annotations, and no output schema, the description does a good job of providing context. It explains the operation, parameters, return values, errors, and prerequisites. While it could mention more about the Gmail API context or provide examples, it covers the essential information needed to understand and use the tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description must compensate for the lack of parameter documentation in the schema. It provides clear parameter descriptions in the Args section, explaining what each parameter represents (recipient_email, subject, body). While it doesn't specify format constraints or examples, it adds substantial meaning beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Create a draft email') and resource ('using the Gmail API'), with no sibling tools to differentiate from. It provides a complete verb+resource+scope statement that leaves no ambiguity about what the tool does.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. While it mentions prerequisites (Gmail API credentials, environment variable, permissions), it doesn't indicate scenarios where this tool is appropriate or when other email-related tools might be preferred. No explicit when/when-not/alternatives information is provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ramaiyaKushal/mcp-learning'

If you have feedback or need assistance with the MCP directory API, please join our Discord server