Skip to content

feat(google-mail): Add threading support (thread_id, In-Reply-To, References, get-email) #3

@frankhli843

Description

@frankhli843

Problem

Emails sent via the Gmail MCP tool (send-email) cannot be threaded correctly for recipients. The threadId parameter only groups messages on the sender's Gmail — recipients see each reply as a separate conversation.

This is because:

  1. send-email has no parameters for thread_id, in_reply_to, or references headers
  2. There is no get-email action to retrieve the Message-ID header from a sent/received message
  3. Without knowing the Gmail-assigned Message-ID, it's impossible to set proper In-Reply-To and References headers on replies

Background

Per RFC 2822 and Gmail's threading logic, recipient-side threading requires:

  • In-Reply-To: <Message-ID of parent email>
  • References: <space-separated Message-IDs of conversation chain>
  • Subject: Re: <original subject>

The threadId in the Gmail API request body only affects the sender's mailbox. Recipients rely entirely on these RFC headers.

Proposed Changes

1. Add threading parameters to send-email and create-draft

  • thread_id (string, optional) — Gmail thread ID for sender-side threading
  • in_reply_to (string, optional) — RFC 2822 Message-ID of the email being replied to
  • references (string[], optional) — List of Message-IDs from the conversation chain

2. Add new get-email action

  • message_id (string, required) — The ID of the message to retrieve
  • format (enum, optional) — full, metadata, minimal, raw
  • metadata_headers (string[], optional) — Specific headers to return (e.g., ["Message-ID", "In-Reply-To", "References"])

3. Backend: pass threading headers through to Gmail API

The invoke-action backend needs to:

  • Include threadId in the Gmail API send request body
  • Set In-Reply-To and References in the raw MIME when provided
  • Return Message-ID header in get-email responses

Intended Workflow

  1. Receive/find an email → note its Gmail id
  2. Call get-email with format=metadata, metadata_headers=["Message-ID"] → get the RFC Message-ID
  3. Call send-email with thread_id, in_reply_to=<that Message-ID>, references=[<that Message-ID>], subject="Re: ..."
  4. Email threads correctly for both sender AND recipient ✅

Reference Implementation

I have a working fork with the client-side changes (parameters, prompts, tools, configuration):
https://github.com/frankhli843/agent-toolkit/tree/fix/gmail-threading-support

Happy to open a PR if helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions