Skip to content

Instantly share code, notes, and snippets.

@lingoota
Created March 31, 2026 09:07
Show Gist options
  • Select an option

  • Save lingoota/05ac35e726aa0299b8a33be3a70497ff to your computer and use it in GitHub Desktop.

Select an option

Save lingoota/05ac35e726aa0299b8a33be3a70497ff to your computer and use it in GitHub Desktop.
Claude Code Skill — Notion Workspace 操作指南(MCP + Writer Token 雙軌策略、資料庫對照表、屬性格式參考)
name notion-workspace
description 使用者提到 Notion、資料庫修改、建頁面、建資料庫、查資料庫架構、修改屬性、 Notion 搜尋、新增頁面、支出、待辦、閱讀清單、物品清單、訂閱支出 等相關操作時觸發此 Skill。 注意:「卡片盒」有兩套系統 — Notion 端由使用者手動維護,本地端(knowledge/notes/)由 Claude 協作。 此 Skill 處理的是 Notion 端的操作。本地端卡片請用 knowledge-distill Skill。

Notion Workspace 操作指南

安全規則(每次操作前必讀)

  1. 先查再改:任何修改前,先用 notion-fetchnotion-search 確認目標的當前狀態
  2. 修改前報告:告知使用者即將變更的內容,等確認後再執行
  3. 不刪除只新增:除非使用者明確要求刪除,否則只做新增/修改
  4. 屬性類型轉換要警告:改 select → multi_select 等類型轉換可能丟失資料,必須先警告
  5. 一次只改一件事:不要在一次操作中同時改多個不相關的屬性
  6. 模板資料庫不要動:標記為「模板/分享」的資料庫是給部落格讀者看的,不要修改

卡片盒系統區分

系統 位置 維護者 操作方式
Notion 卡片盒 Notion 資料庫 使用者手動 此 Skill(但原則上不主動修改)
本地卡片盒 knowledge/notes/K*.md Claude 協作 knowledge-distill Skill

使用者說「建卡片」→ 預設是本地端(knowledge-distill)。 使用者說「看我 Notion 卡片盒」→ 用此 Skill 查詢。

兩種 Notion API 的區分與應用時機

MCP(OAuth,user scope) Writer Token(Integration)
連線方式 claude mcp add 安裝,瀏覽器 OAuth 授權 .envNOTION_WRITER_TOKEN,Python requests 直打
存取範圍 使用者帳號所有內容 只有手動加入 Integration 連線的頁面/資料庫
適用場景 即時互動:查架構、建單筆、改屬性、搜尋 批量腳本:幾十~幾千筆一次跑完
Token 消耗 每筆 MCP 呼叫都吃 Claude token 零 Claude token(Python 背景執行)
速度 每筆約 2-3 秒(含 MCP 來回) 每秒 2 筆(Notion rate limit 安全線)

選擇原則

  • ≤ 5 筆操作 → 用 MCP,直接在對話中完成
  • > 5 筆批量操作 → 寫 Python 腳本用 Writer Token,背景執行
  • 查詢/搜尋/讀取架構 → 一律用 MCP(不需寫入權限)
  • 新增支出等日常單筆 → 用 MCP

Writer Token 使用方式

import os, requests
from dotenv import load_dotenv
load_dotenv()
token = os.getenv("NOTION_WRITER_TOKEN")
headers = {
    "Authorization": f"Bearer {token}",
    "Notion-Version": "2022-06-28",
    "Content-Type": "application/json",
}
# 範例:更新頁面屬性
requests.patch(f"https://api.notion.com/v1/pages/{page_id}", headers=headers, json={
    "properties": {"欄位名": {"relation": [{"id": "ref_page_id"}]}}
})

注意:Writer Token 的 Notion API 屬性格式與 MCP 不同。MCP 用 SQLite 值格式(見下方屬性格式參考),Writer Token 用 Notion API 原生 JSON 格式

MCP 工具速查

工具 用途 常用場景
notion-search 搜尋頁面/資料庫 找目標、確認存在
notion-fetch 取得頁面/資料庫完整內容 查架構、讀內容
notion-create-pages 建立新頁面 在資料庫中新增一筆
notion-create-database 建立新資料庫 在頁面下建 inline DB
notion-update-page 修改頁面屬性或內容 改欄位值、寫入內容
notion-update-data-source 修改資料庫結構 新增/改名/刪除屬性
notion-update-view 修改檢視設定 排序、篩選、顯示欄位
notion-create-view 建立新檢視 新增 Table/Board view
notion-duplicate-page 複製頁面 複製模板
notion-move-pages 移動頁面 搬移到其他位置
notion-create-comment 新增評論 在頁面留言
notion-get-comments 取得評論 查看留言
notion-get-users 取得使用者 查 workspace 成員
notion-get-teams 取得團隊 查 teamspace

常用資料庫對照表(範例)

將你自己的 Notion 資料庫 ID 填入,方便 Claude 快速定位操作目標。

範例格式

資料庫 data_source_id 標題欄位 核心屬性
單筆支出清單 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 支出描述 金額(number)、分類(select)、購買日期(date)、備註(rich_text)
閱讀清單 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Name Type(multi_select)、作者(multi_select)、閱讀狀態(select)、Score(select)
待辦清單 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Name 狀態(select)、截止日(date)
卡片盒 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (title) 使用者手動維護,不主動修改

💡 data_source_id 怎麼取得:用 notion-fetch 取得資料庫頁面,回傳內容中會包含 data_source_id。或在 Notion 網頁版打開資料庫,URL 中的長 UUID 即為 database_id。

模板 / 分享用(標記不要動)

如果你有分享給讀者的模板資料庫,在這裡標記「禁止修改」,避免 Claude 誤改:

資料庫 data_source_id 用途
物品清單模板 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 分享模板,禁止修改

支出分類系統(範例:relation + rollup 取代 select)

架構

單筆支出清單使用 relation + rollup 取代舊的 select 分類:

欄位 類型 用途
分類對照 relation → 分類對照表 選擇子分類(如「電腦商品」)
大分類(新) rollup 自動帶出大分類(如「3C數位」)
分類(舊) select 舊大分類,遷移完成後可隱藏
子分類(舊) select 舊子分類,遷移完成後可隱藏

批量遷移 SOP(Python 腳本方式,推薦)

1. 從 SQLite 取得所有支出的 page_id 和舊子分類
2. 建立舊子分類 → 分類對照表 page_id 對應表,存為 migration_plan.json
3. 用 Python 腳本 + NOTION_WRITER_TOKEN 批量更新
4. 腳本自動處理:429 重試、進度儲存(每 10 筆)、斷點續傳
5. 處理需要人工判斷的項目(如舊分類拆分成多個新分類)
6. 處理無子分類的支出(需人工標記)

注意:MCP 批量方式 token 成本太高,超過 5 筆一律用 Python 腳本。

常用操作 SOP

查詢資料庫架構

1. notion-search 找到目標資料庫
2. notion-fetch 取得完整架構(屬性名稱、類型、select 選項等)
3. 整理成表格呈現給使用者

修改資料庫屬性

1. notion-fetch 確認當前狀態
2. 告知使用者變更內容,等確認
3. notion-update-data-source 執行修改
4. notion-fetch 驗證結果

在資料庫新增一筆

1. 確認目標資料庫和必填欄位
2. notion-create-pages 建立頁面(注意屬性格式)
3. 回報結果

建立新的 inline 資料庫

1. 確認父頁面位置
2. notion-create-database(設定 title、properties、is_inline)
3. 回報結果和新資料庫 ID

批量更新頁面屬性(通用)

超過 5 筆的批量操作,一律用 Python 腳本 + Writer Token。

屬性格式參考(MCP update-page 使用 SQLite 值格式)

建立/修改頁面時,各屬性類型的值格式:

  • title: "文字"(純字串)
  • rich_text: "文字"(純字串)
  • number: 12345.67
  • select: "選項名稱"(純字串)
  • multi_select: "[\"選項1\", \"選項2\"]"(JSON 陣列字串)
  • date: 拆分為 date:欄位:startdate:欄位:enddate:欄位:is_datetime
  • checkbox: "__YES__""__NO__"
  • url: "https://example.com"
  • relation: "[\"https://www.notion.so/UUID無破折號\"]"(完整 Notion URL,UUID 不加破折號)

注意事項

  • 本地 RAG 優先:如果使用者只是要「搜尋知識庫內容」,優先用本地 RAG(knowledge-search Skill),Notion MCP 用於「操作 Notion 資料庫結構和內容」
  • 重複名稱資料庫:操作前務必用 data_source_id 確認是正確的那個,不要只靠名稱
  • Relation 連動:修改有 relation 的資料庫時,注意對面資料庫也會同步變動
  • MCP update-page 屬性格式是 SQLite 值格式:和 Notion API 的 JSON 格式不同,relation 用 JSON 陣列字串、select 用純字串
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment