Skip to content

feat(all-mcp): 新增 dump 對話為 Markdown 的 tool #2

@kiki830621

Description

@kiki830621

Problem

Original request:
「還要有能夠 dump 對話成 .md 的功能」

目前 get_chat_history 只回 JSON 陣列,欄位是 TDLib 原始 schema(id, date, is_outgoing, sender.user_id, text, type)。要轉成可讀的 Markdown 逐字稿需要 AI 在 context 內手工處理:

  • Unix timestamp → 可讀日期
  • sender.user_id → 人名(需另外 get_user 查)
  • is_outgoing → 「我 / 對方」
  • photo / other type → placeholder

每抓一段對話就要手工重做一次,token 浪費且容易出錯。

Type

feature

Expected

一個 tool 就能 dump:

dump_chat_to_markdown(
  chat_id: 489601378,
  output_path: "/tmp/pei-chun-chat.md",
  since_date: "2026-03-01",      // 可選
  until_date: "2026-04-15",      // 可選
  include_media_placeholders: true // [photo], [voice], [sticker] 等
)

輸出 Markdown 格式建議:

# 對話:培鈞 徐 (chat_id=489601378)
匯出時間:2026-04-15 23:40:00
訊息數:327 (since 2026-03-01)

---

## 2026-04-14

**14:32 我**:
到了嗎

**14:33 培鈞**:
我隨時出發

**14:35 培鈞**[photo]

**14:40 我**> 如果只是外殼小凹,不是邊角嚴重撞擊...(超過 300 字省略;完整內容見原訊息)

Actual

目前只能 get_chat_history → JSON → AI 在 context 內逐筆解析格式化。3-4 輪 tool call + 大量 token。

Impact

  • 使用者要備份 / 歸檔對話時要 AI 花半小時處理
  • 對話引用到學術/合作專案文件(例:communication/ 資料夾)需要一致的可讀格式
  • 語意搜尋、後續分析(grep、embedding)要有純文字版

Depends on

Design considerations(給 diagnose 階段參考)

  • 人名查詢:每個 sender.user_id 要 resolve 成 first_name + last_name
    • 快取 user info 避免重複 API call
    • is_outgoing=true 用「我」或顯示自己名字?(建議:可選參數 self_label
  • Media 處理:photo / voice / video / sticker
    • MVP:只放 [photo] 等 placeholder
    • v2:可選是否下載附件到同目錄 attachments/
  • Long text:超長訊息要不要截斷?(建議:預設不截斷,提供 max_message_length 參數)
  • 排序:TDLib 回的是 newest-first,Markdown 應該 oldest-first
  • Timezone:用本機還是 UTC?(建議:預設本機,可選 timezone 參數)
  • Output:寫檔還是回傳 string?(建議:兩者都支援——output_path 選填,沒給就回傳內容)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions