# 拾音做本地 MCP，卡在 Gatekeeper 和 SQLite

> 拾音下一版可以讓 Claude Code、Codex、Claude Desktop 直接讀這台電腦上的會議。MCP 協定一百多行就寫完，時間都花在協定以外：macOS 的 Gatekeeper 讓 AI 工具執行拾音時卡住，SQLite 的唯讀連線有時打不開，Windows 版 Claude Desktop 讀的設定檔也不在一般的位置。

- 網址：https://www.weibuilds.com/blog/shiyin-local-mcp/
- 作者：weiwei
- 日期：2026-11-10
- 主題：AI 與自動化
- 標籤：shiyin、mcp、claude-code、sqlite、macos

拾音下一版可以讓 Claude Code、Codex、Claude Desktop 讀這台電腦上的會議紀錄和逐字稿。在設定裡按一下就加好，只能讀不能改，拾音也不用開著。程式已經在[公開 repo](https://github.com/juinwei7/Shiyin) 的 main，還沒發版。

MCP 協定本身沒什麼，我只做了 `initialize`、`tools/list`、`tools/call` 這幾個方法，Swift 和 C# 各一百多行。沒用官方 SDK，Swift 版要多帶 swift-log、swift-system，划不來。時間都花在協定以外的地方。

## 架構

<figure>
<svg class="diagram" viewBox="0 0 760 266" role="img" aria-label="Claude Code、Codex、Claude Desktop 用 stdio、一行一個 JSON-RPC 執行啟動檔 shiyin-mcp。啟動檔 exec 拾音的執行檔並帶 --mcp，這個模式不建 NSApplication、不進 Dock。它用唯讀連線讀 SQLite，每次呼叫才打開；拾音 app 開著時照樣寫同一個資料庫（WAL）。" xmlns="http://www.w3.org/2000/svg">
  <defs>
    <marker id="mcp-ar" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto"><path d="M0 0L10 5L0 10z" fill="var(--ink-2)"/></marker>
  </defs>
  <g font-size="13" font-family="inherit" fill="var(--ink)">
    <text x="214" y="22" font-size="12" fill="var(--ink-2)">stdio，一行一個 JSON-RPC</text>
    <rect x="20" y="34" width="170" height="38" rx="19" fill="var(--paper-2)" stroke="var(--rule)"/>
    <text x="105" y="58" text-anchor="middle">Claude Code</text>
    <rect x="20" y="84" width="170" height="38" rx="19" fill="var(--paper-2)" stroke="var(--rule)"/>
    <text x="105" y="108" text-anchor="middle">Codex</text>
    <rect x="20" y="134" width="170" height="38" rx="19" fill="var(--paper-2)" stroke="var(--rule)"/>
    <text x="105" y="158" text-anchor="middle">Claude Desktop</text>
    <g stroke="var(--ink-2)" stroke-width="1.5" fill="none">
      <path d="M190 53L248 98" marker-end="url(#mcp-ar)"/>
      <line x1="190" y1="103" x2="248" y2="103" marker-end="url(#mcp-ar)"/>
      <path d="M190 153L248 108" marker-end="url(#mcp-ar)"/>
      <line x1="460" y1="103" x2="498" y2="103" marker-end="url(#mcp-ar)"/>
      <line x1="620" y1="133" x2="620" y2="188" marker-end="url(#mcp-ar)"/>
      <line x1="460" y1="220" x2="498" y2="220" marker-end="url(#mcp-ar)"/>
    </g>
    <rect x="250" y="73" width="210" height="60" rx="6" fill="var(--paper-2)" stroke="var(--rule)"/>
    <text x="355" y="98" text-anchor="middle" font-weight="600">啟動檔 bin/shiyin-mcp</text>
    <text x="355" y="118" text-anchor="middle" font-size="12" fill="var(--ink-2)">拾音每次啟動時改寫路徑</text>
    <rect x="500" y="73" width="240" height="60" rx="6" fill="var(--topic-ai)"/>
    <text x="620" y="98" text-anchor="middle" font-weight="600" fill="var(--paper)">拾音的執行檔 --mcp</text>
    <text x="620" y="118" text-anchor="middle" font-size="12" fill="var(--paper)">不建 NSApplication、不進 Dock</text>
    <text x="630" y="166" font-size="12" fill="var(--ink-2)">唯讀</text>
    <rect x="500" y="190" width="240" height="60" rx="6" fill="var(--paper-2)" stroke="var(--rule)"/>
    <text x="620" y="215" text-anchor="middle" font-weight="600">SQLite（WAL）</text>
    <text x="620" y="235" text-anchor="middle" font-size="12" fill="var(--ink-2)">每次呼叫才打開、回完就關</text>
    <rect x="250" y="190" width="210" height="60" rx="6" fill="var(--paper-2)" stroke="var(--rule)"/>
    <text x="355" y="215" text-anchor="middle" font-weight="600">拾音 app</text>
    <text x="355" y="235" text-anchor="middle" font-size="12" fill="var(--ink-2)">開著也沒關係，照樣寫入</text>
    <text x="479" y="212" text-anchor="middle" font-size="12" fill="var(--ink-2)">寫</text>
  </g>
</svg>
<figcaption>Windows 沒有啟動檔，是另一個小的 shiyin-mcp.exe，跟 Shiyin.exe 放在同一個資料夾。</figcaption>
</figure>

工具有五個：`list_meetings`、`search_meetings`、`get_meeting_notes`、`get_transcript`、`list_action_items`。

## Mac 和 Windows 的進入點不一樣

Mac 沒有另外做執行檔，用的就是拾音本身。`main.swift` 在 SwiftUI 啟動前先看參數，帶 `--mcp` 就進 MCP 模式，跑完 `exit`。不建 `NSApplication`，Dock 上也不會冒出圖示。拆成獨立的小程式比較乾淨，但資料庫和匯出的型別都在 app 的執行檔裡，要先改成 library，還得另外簽章。

Windows 沒辦法這樣做。WinUI 的 exe 是視窗程式，啟動時會把參數轉給已經開著的拾音，還有 Velopack 的 hook，跟 stdio 合不來，只好另外做一個 `shiyin-mcp.exe` 放在旁邊。

## 唯讀連線打不開

拾音開著的時候可能正在寫資料庫，MCP 這邊只開唯讀連線，靠 WAL 讓兩邊同時用。測試時卻遇到唯讀連線直接打不開，SQLite 回錯誤碼 14。拾音上次是正常關閉的，旁邊的 `-wal`、`-shm` 檔已經清掉，唯讀連線沒辦法自己建。現在遇到這種情況改開一般連線，一樣不跑 migration、不改資料。

連線也不常駐，每次 `tools/call` 才開、回完就關。拾音剛更新、要升級資料庫時，才不會被 MCP 的連線擋住。版本對不上就直接告訴 AI：「先打開拾音一次」或「更新拾音」。

## Gatekeeper 讓程序卡住

<figure>
<svg class="diagram" viewBox="0 0 760 216" role="img" aria-label="寫啟動檔之前的檢查。第一步看拾音有沒有被 App Translocation 搬到暫時路徑，路徑裡有 /AppTranslocation/ 就不寫啟動檔。第二步看主執行檔有沒有 com.apple.quarantine 隔離屬性，有就拿掉整個 bundle 的隔離屬性，不然 Gatekeeper 會跳提示、程序卡住。最後寫 bin/shiyin-mcp，內容是 exec 拾音的執行檔加 --mcp。" xmlns="http://www.w3.org/2000/svg">
  <defs>
    <marker id="gk-ar" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto"><path d="M0 0L10 5L0 10z" fill="var(--ink-2)"/></marker>
  </defs>
  <g font-size="13" font-family="inherit" fill="var(--ink)">
    <rect x="20" y="20" width="225" height="60" rx="6" fill="var(--paper-2)" stroke="var(--rule)"/>
    <text x="132" y="45" text-anchor="middle" font-weight="600">被 App Translocation 搬走？</text>
    <text x="132" y="65" text-anchor="middle" font-size="12" fill="var(--ink-2)">路徑裡有 /AppTranslocation/</text>
    <rect x="267" y="20" width="225" height="60" rx="6" fill="var(--paper-2)" stroke="var(--rule)"/>
    <text x="379" y="45" text-anchor="middle" font-weight="600">從網路下載、帶隔離屬性？</text>
    <text x="379" y="65" text-anchor="middle" font-size="12" fill="var(--ink-2)">com.apple.quarantine</text>
    <rect x="514" y="20" width="226" height="60" rx="6" fill="var(--topic-ai)"/>
    <text x="627" y="45" text-anchor="middle" font-weight="600" fill="var(--paper)">寫 bin/shiyin-mcp</text>
    <text x="627" y="65" text-anchor="middle" font-size="12" fill="var(--paper)">exec '…/Shiyin' --mcp</text>
    <rect x="20" y="140" width="225" height="60" rx="6" fill="none" stroke="var(--accent)"/>
    <text x="132" y="165" text-anchor="middle" font-weight="600">不寫啟動檔</text>
    <text x="132" y="185" text-anchor="middle" font-size="12" fill="var(--ink-2)">請使用者先拖進「應用程式」</text>
    <rect x="267" y="140" width="225" height="60" rx="6" fill="var(--paper-2)" stroke="var(--rule)"/>
    <text x="379" y="165" text-anchor="middle" font-weight="600">拿掉整個 bundle 的隔離屬性</text>
    <text x="379" y="185" text-anchor="middle" font-size="12" fill="var(--ink-2)">不然 Gatekeeper 跳提示、程序卡住</text>
    <g stroke="var(--ink-2)" stroke-width="1.6" fill="none">
      <line x1="245" y1="50" x2="265" y2="50" marker-end="url(#gk-ar)"/>
      <line x1="492" y1="50" x2="512" y2="50" marker-end="url(#gk-ar)"/>
      <line x1="132" y1="80" x2="132" y2="138" marker-end="url(#gk-ar)"/>
      <line x1="379" y1="80" x2="379" y2="138" marker-end="url(#gk-ar)"/>
      <path d="M492 170H627V82" marker-end="url(#gk-ar)"/>
    </g>
    <g font-size="12" fill="var(--ink-2)">
      <text x="255" y="42" text-anchor="middle">否</text>
      <text x="502" y="42" text-anchor="middle">否</text>
      <text x="142" y="114">是</text>
      <text x="389" y="114">是</text>
    </g>
  </g>
</svg>
<figcaption>AI 工具的設定只登記啟動檔，拾音搬家、更新後，下次啟動就改寫成新路徑。</figcaption>
</figure>

AI 工具的設定要寫一個執行檔路徑，可是使用者會把拾音拖到別的資料夾，也會更新。我讓 AI 工具登記 `SHIYIN_HOME/bin/shiyin-mcp` 這個 shell 啟動檔，拾音每次啟動時把裡面的路徑改成自己現在的位置。符號連結比較省事，但 `Bundle.main` 會變成連結所在的資料夾，讀不到 app 的設定。

最意外的是 Gatekeeper，驗證時才撞到。從網路下載的 DMG 裝的 app，每個檔案都帶 `com.apple.quarantine`。AI 工具直接執行 bundle 裡的執行檔，macOS 跳出提示等人按，程序就停在那裡，AI 工具只看到逾時，看不出原因。拾音自己都跑得起來，代表使用者早就放行過，寫啟動檔時就把整個 bundle 的隔離屬性一起拿掉。也試過改用 `open -a` 開，stdio 會接不起來。

## Claude Desktop 讀錯設定檔

<figure>
<svg class="diagram" viewBox="0 0 760 212" role="img" aria-label="拾音按「加到 Claude Desktop」時有兩個可能的設定檔位置。一般的 %APPDATA%\Claude\claude_desktop_config.json，只在沒有 MSIX 套件時才寫；MSIX 版的 Claude Desktop 讀不到這裡。偵測到 MSIX 套件時寫 %LOCALAPPDATA%\Packages\Claude_pzs8sxrjxfjjc\LocalCache\Roaming\Claude\claude_desktop_config.json，Claude Desktop 讀的是這裡。" xmlns="http://www.w3.org/2000/svg">
  <defs>
    <marker id="ms-ar" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto"><path d="M0 0L10 5L0 10z" fill="var(--ink-2)"/></marker>
  </defs>
  <g font-size="13" font-family="inherit" fill="var(--ink)">
    <rect x="20" y="78" width="150" height="56" rx="6" fill="var(--paper-2)" stroke="var(--rule)"/>
    <text x="95" y="102" text-anchor="middle" font-weight="600">拾音</text>
    <text x="95" y="121" text-anchor="middle" font-size="12" fill="var(--ink-2)">加到 Claude Desktop</text>
    <rect x="215" y="16" width="360" height="54" rx="6" fill="var(--paper-2)" stroke="var(--rule)"/>
    <text x="231" y="38" font-size="12">%APPDATA%\Claude\claude_desktop_config.json</text>
    <text x="231" y="58" font-size="12" fill="var(--ink-2)">沒有 MSIX 套件時才寫這裡</text>
    <rect x="215" y="128" width="360" height="72" rx="6" fill="var(--topic-ai)"/>
    <g font-size="12" fill="var(--paper)">
      <text x="231" y="150">%LOCALAPPDATA%\Packages\Claude_pzs8sxrjxfjjc\</text>
      <text x="231" y="168">LocalCache\Roaming\Claude\claude_desktop_config.json</text>
      <text x="231" y="188">偵測到 MSIX 套件就寫這裡</text>
    </g>
    <rect x="634" y="78" width="116" height="56" rx="6" fill="var(--paper-2)" stroke="var(--rule)"/>
    <text x="692" y="102" text-anchor="middle" font-weight="600">Claude Desktop</text>
    <text x="692" y="121" text-anchor="middle" font-size="12" fill="var(--ink-2)">MSIX 套件</text>
    <g stroke="var(--ink-2)" stroke-width="1.5" fill="none">
      <path d="M170 96L213 46" stroke-dasharray="5 4" marker-end="url(#ms-ar)"/>
      <path d="M170 116L213 160" marker-end="url(#ms-ar)"/>
      <path d="M632 118L579 160" marker-end="url(#ms-ar)"/>
      <path d="M632 94L579 50" stroke-dasharray="5 4"/>
    </g>
    <text x="605" y="79" text-anchor="middle" font-size="20" font-weight="600" fill="var(--accent)">✕</text>
    <text x="612" y="156" font-size="12" fill="var(--ink-2)">讀</text>
  </g>
</svg>
<figcaption>寫錯地方不會報錯，Claude Desktop 只是看不到拾音。</figcaption>
</figure>

Windows 上的 Claude Desktop 是 MSIX 套件，AppData 被虛擬化。設定寫進一般的 `%APPDATA%\Claude\`，它根本不讀，連它自己的「Edit Config」都會打開錯的檔案（[anthropics/claude-code#26073](https://github.com/anthropics/claude-code/issues/26073)）。現在偵測到 MSIX 套件就寫進套件自己的 `LocalCache`，就算還沒開過、資料夾不在也先建好。

## 回傳給 AI 的格式

工具回的是 Markdown，不是 JSON。中文內容包上欄位名稱和跳脫字元，JSON 會長三成。逐字稿一次最多兩萬字，截斷時最後一行直接寫好下一次怎麼叫，例如 `get_transcript(meeting_id: 42, start: "12:34")`。會議裡也可能有人唸出一段 prompt，所以 `instructions` 寫明會議內容是資料，不是給 AI 的指令。
