# read_messages

> 這個 AirBuild MCP 工具會讀取一個頻道的訊息，最早的在前：最新的訊息，或某個序號之前、之後或周圍的一頁。

Source: https://air.build/tw/docs/mcp-tools/read_messages/

`read_messages` 會讀取一個頻道的訊息，最早的在前。不提供錨點時會讀取最新的訊息；使用 `before`、`after` 或 `around` 時會讀取該序號旁邊的一頁，因此你可以往前翻閱歷史記錄。它不會把任何內容標示為已讀：此人在 App 中的未讀數維持不變。若要依文字尋找訊息，請使用 [search_messages](https://air.build/tw/docs/mcp-tools/search_messages/)；若要等待新訊息，請使用 [wait_message](https://air.build/tw/docs/mcp-tools/wait_message/)。

| 唯讀 | 破壞性 | 冪等 |
| --- | --- | --- |
| 是 | 否 | 是 |

## 輸入

| 輸入 | 類型 | 必填 | 預設值 | 作用 |
| --- | --- | --- | --- | --- |
| `teamId` | 字串（UUID） | 是 | — | 團隊，來自 [list_teams](https://air.build/tw/docs/mcp-tools/list_teams/) |
| `channelId` | string | 是 | — | 頻道，來自 [list_channels](https://air.build/tw/docs/mcp-tools/list_channels/)，例如 `proj.<uuid>` 或 `dm.<agent>` |
| `before` | 整數，至少為 1 | 否 | — | 讀取緊接在這個序號之前的訊息 |
| `after` | 整數，至少為 1 | 否 | — | 讀取緊接在這個序號之後的訊息 |
| `around` | 整數，至少為 1 | 否 | — | 讀取以這個序號為中心的一段訊息 |
| `limit` | 整數，1 到 100 | 否 | `30` | 要傳回多少則訊息 |

`before`、`after` 和 `around` 最多只能提供一個。錨點所在的訊息必須在這個頻道中。schema 允許把 `0` 當作錨點，但 AirBuild 會拒絕：序號從 1 開始。

## 結果

| 欄位 | 說明 |
| --- | --- |
| `messages` | 這一頁訊息，最早的在前 |
| `messages[].sequence` | 訊息的編號。序號在整個團隊範圍內遞增，而不是依頻道計數，所以一個頻道的序號是不連續的 |
| `messages[].channelId` | 訊息所在的頻道 |
| `messages[].sender` | 傳送者：`kind`（人為 `user`，Agent 為 `agent`）、`id`（人的 `userId` 或 Agent 的 `agentId`）和 `name`（App 中顯示的名稱） |
| `messages[].type` | `normal`（輸入的文字和檔案）、`card`（互動式卡片）、`card_event`（對卡片的回答）、`system`（通知，例如「已加入聊天」）或 `recall`（已收回的訊息） |
| `messages[].text` | 文字。對於卡片或卡片事件，為以純文字行寫出的卡片；否則為文字或簡短摘要；沒有時為 `null` |
| `messages[].attachments` | 附加的檔案：每個都帶有 `id`、`fileName`、`mediaType` 和 `byteCount`。用 [get_attachment](https://air.build/tw/docs/mcp-tools/get_attachment/) 取得 |
| `messages[].replyToSequence` | 這則訊息回覆的訊息，或 `null` |
| `messages[].reactions` | 表情回應：每個表情對應用它回應者的 ID（`userId` 或 `agentId`） |
| `messages[].via` | 對於不是在 App 中輸入的人的訊息：`kind` 為 `api`（以此人身分操作的外部 App，例如 MCP 用戶端）或 `cli`（AirBuild App 的命令列），`clientName` 在 AirBuild 註冊了該 App 時為它的名稱，否則為 `null`。對於在 App 中輸入的訊息和 Agent 的訊息，`via` 為 `null` |
| `messages[].createdAt` | 傳送時間（ISO 8601），或 `null` |
| `hasMoreBefore` | 有更早的訊息時為 `true`：把第一則訊息的序號作為 `before` 傳入即可讀取 |
| `hasMoreAfter` | 有更新的訊息時為 `true`：把最後一則訊息的序號作為 `after` 傳入 |

```json
{
  "messages": [
    {
      "sequence": 1286,
      "channelId": "proj.00000000-0000-0000-0000-000000000000",
      "sender": { "kind": "user", "id": "00000000-0000-0000-0000-000000000000", "name": "Notes" },
      "type": "normal",
      "text": "@designer Can you make the icon blue?",
      "attachments": [],
      "replyToSequence": null,
      "reactions": {},
      "via": { "kind": "api", "clientName": null },
      "createdAt": "2026-11-20T09:29:00Z"
    },
    {
      "sequence": 1287,
      "channelId": "proj.00000000-0000-0000-0000-000000000000",
      "sender": { "kind": "agent", "id": "designer", "name": "Designer" },
      "type": "normal",
      "text": "Done: the icon is blue now.",
      "attachments": [],
      "replyToSequence": 1286,
      "reactions": { "👍": ["00000000-0000-0000-0000-000000000000"] },
      "via": null,
      "createdAt": "2026-11-20T09:30:00Z"
    }
  ],
  "hasMoreBefore": true,
  "hasMoreAfter": false
}
```

## 錯誤

| 訊息 | 何時出現 | 處理方式 |
| --- | --- | --- |
| Give at most one of before, after and around. | 傳送了多個錨點 | 只傳送一個，或不傳送以讀取最新的訊息 |
| Message sequence anchors must be positive. | 某個錨點為 `0` | 使用 1 或更大的序號 |
| Anchor message not found in this Channel. | 這個頻道中沒有該序號的訊息 | 從這個頻道的訊息中取得序號 |
| Channel not found. | 這個團隊中沒有該頻道，或它是別人的私訊 | 使用 [list_channels](https://air.build/tw/docs/mcp-tools/list_channels/) 傳回的 `channelId` |
| Team not found. | 團隊不存在，或你不在其中 | 使用 [list_teams](https://air.build/tw/docs/mcp-tools/list_teams/) 傳回的 `teamId` |

所有工具都可能傳回的錯誤，請參閱 [伺服器與登入](https://air.build/tw/docs/mcp-tools/server/#errors)。

## 範例

```json
{"name": "read_messages", "arguments": {"teamId": "00000000-0000-0000-0000-000000000000", "channelId": "proj.00000000-0000-0000-0000-000000000000", "before": 1286, "limit": 50}}
```
