工具:get_thread
從已驗證使用者的 Gmail 帳戶擷取特定電子郵件討論串,包括郵件清單。
選用的 messageFormat 參數可控制傳回的訊息格式。根據預設 (或使用 FULL_CONTENT),這項函式會傳回郵件的完整內容。使用 MINIMAL 僅納入主旨和摘要 (不含內文)。使用 METADATA_ONLY 僅納入基本中繼資料 (訊息 ID、討論串 ID、標籤、時間戳記和大小估計值)。
下列範例示範如何使用 curl 叫用 get_thread MCP 工具。
| Curl 要求 |
|---|
curl --location 'https://gmailmcp.googleapis.com/mcp/v1' \ --header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \ --header 'content-type: application/json' \ --header 'accept: application/json, text/event-stream' \ --data '{ "method": "tools/call", "params": { "name": "get_thread", "arguments": { // provide these details according to the tool's MCP specification } }, "jsonrpc": "2.0", "id": 1 }' |
輸入內容的結構定義
GetThread RPC 的要求訊息。
GetThreadRequest
| JSON 表示法 |
|---|
{
"threadId": string,
"messageFormat": enum ( |
| 欄位 | |
|---|---|
threadId |
必填。要擷取的執行緒專屬 ID。 |
messageFormat |
(選用步驟) 指定要在執行緒中傳回的訊息格式。預設值為 FULL_CONTENT。注意:MINIMAL 格式會傳回 ID、摘要、主旨、寄件者、收件者、副本、日期和標籤 ID。METADATA_ONLY 格式會傳回 id、from、to、cc、date、labelIds。FULL_CONTENT 會傳回 ID、摘要、主旨、寄件者、收件者、副本、日期、標籤 ID、附件 ID、純文字內文、HTML 內文和附件。 |
MessageFormat
列舉,用於控制討論串中訊息的詳細程度。
| 列舉 | |
|---|---|
MESSAGE_FORMAT_UNSPECIFIED |
預設為 FULL_CONTENT。 |
MINIMAL |
傳回郵件摘要和重要標頭 (主旨、寄件者、收件者、副本、日期)。 |
FULL_CONTENT |
傳回「MINIMAL」中的所有資訊,以及每則訊息的完整內文內容。 |
METADATA_ONLY |
僅限中繼資料:不包括主旨、摘要、內文、附件檔名。 |
輸出內容的結構定義
包含訊息清單的討論串。
討論串
| JSON 表示法 |
|---|
{
"id": string,
"messages": [
{
object ( |
| 欄位 | |
|---|---|
id |
執行緒的專屬 ID。 |
messages[] |
對話串中的訊息清單,依時間順序排列。 |
訊息
| JSON 表示法 |
|---|
{
"id": string,
"snippet": string,
"subject": string,
"sender": string,
"toRecipients": [
string
],
"ccRecipients": [
string
],
"date": string,
"plaintextBody": string,
"attachmentIds": [
string
],
"htmlBody": string,
"attachments": [
{
object ( |
| 欄位 | |
|---|---|
id |
訊息的專屬 ID。 |
snippet |
郵件內文的程式碼片段。 |
subject |
從標頭擷取的郵件主旨: |
sender |
寄件者的電子郵件地址。 |
toRecipients[] |
收件者電子郵件地址。 |
ccRecipients[] |
副本收件者的電子郵件地址。 |
date |
訊息日期,採用 ISO 8601 格式 (YYYY-MM-DD)。 |
plaintextBody |
完整內文內容,只有在 MessageFormat 為 FULL_CONTENT 時才會填入。 |
attachmentIds[] |
僅供輸出。附件 ID,只有在 MessageFormat 為 FULL_CONTENT 時才會填入。 |
htmlBody |
電子郵件的 HTML 內容,只有在 MessageFormat 為 FULL_CONTENT 時才會填入。 |
attachments[] |
僅供輸出。附件,只有在 MessageFormat 為 FULL_CONTENT 時才會填入。 |
labelIds[] |
附加至郵件的標籤 ID。包括使用者標籤和標準系統標籤的 ID,但僅限於 |
AttachmentMetadata
| JSON 表示法 |
|---|
{ "id": string, "mimeType": string, "filename": string } |
| 欄位 | |
|---|---|
id |
僅供輸出。附件的 ID。 |
mimeType |
附件的 MIME 類型。 |
filename |
附件的檔案名稱。 |
工具註解
破壞性提示:❌ | 等冪提示:✅ | 唯讀提示:✅ | 開放世界提示:❌
授權範圍
需要下列其中一種 OAuth 範圍:
https://mail.google.com/https://www.googleapis.com/auth/gmail.modifyhttps://www.googleapis.com/auth/gmail.readonlyhttps://www.googleapis.com/auth/gmail.metadata