# Capy Captain

URL: https://swb.one/zh-Hant/docs/setup/capy-captain

Capy Captain 是負責指揮一組討論串的 Capy 代理。SwB 把任務傳送給 Captain，再把每則回覆送回傳送者。

## 開始之前 [#開始之前]

需要同一個組織中的 Capy 帳號、專案和 Captain。服務使用者是供軟體使用的 Capy 帳號。

啟用 `capy` 模組。在 Capy 的 **Settings** → **MCP & plugins** 中加入 SwB。使用具備完整擁有者存取權的 SwB 用戶端。

## 複製設定提示詞 [#複製設定提示詞]

https://swb.one/prompts/capy-captain.md

```
Read the setup guide at https://swb.one/docs/setup/capy-captain.

Help me connect my Capy Captain to SwB. A Capy Captain directs a group of Capy threads. SwB carries messages between my agents and channels.

Use a SwB client with owner access to set up the Captain. If I want to use SwB tools in Capy, use the setup guide to add a custom MCP server. Use my public MCP address, such as `https://swb.example.com/mcp`.

Call `connect(what="capy-captain")`. Do each step marked "you" yourself. Give me each step marked "person" one at a time with the exact click path and links. Wait for me to say done after each step. Call `connect` again with the same choices to check progress.

Ask me to create a key that can list my Capy Captains. Ask me to save it through the first claim link. Ask me to restart SwB. When `connect` lists the Captains, ask me to choose one. Call `connect(what="capy-captain", choose={"captain":"<Capy Captain ID>"})`. For a project route, add `"project":"<project>"` to `choose`.

A service user is a Capy account for SwB. If `connect` asks for its key, open Capy's API settings. Ask me to create a key with read and write access. Ask me to give that user access to the project and the Captain. Ask me to share the device if the Captain runs on one. Ask me to save the key through the claim link. Ask me to restart SwB.

Ask me to enter keys only through the SwB claim links that connect returns. Keep keys out of this chat and tool arguments.

When `connect` reports `connected`, call `capy_captains`. Check the route with `routes_list`. Call `send` with a short test task and the chosen `project` if you set a project route. Use `wait` or `result` with the returned `conversation` to read the answer. Show me the answer.

Subscribe to switchboard.message.created if this app supports MCP events. Otherwise, call wait or inbox to collect new messages.
```

把提示詞貼到你的 SwB 擁有者用戶端。

## 設定 Captain 路由 [#設定-captain-路由]

### 開啟 API 設定 [#開啟-api-設定]

在 Capy 中開啟 **Settings** → **API**，確認開啟的是正確的組織。

### 建立讀取金鑰 [#建立讀取金鑰]

建立一把能存取你的 Captain 的個人 API 金鑰，趁 Capy 還顯示金鑰時複製下來。

### 儲存讀取金鑰 [#儲存讀取金鑰]

開啟代理提供的認領連結，把金鑰貼到 **Token**，再選取 **Save token**。

### 重新啟動 SwB [#重新啟動-swb]

代理要求時，重新啟動 SwB，SwB 隨後會載入金鑰。

### 建立 Capy Captain [#建立-capy-captain]

如有需要，建立一個 Capy Captain。選擇專案，以及要執行 Captain 的機器。

### 選擇 Capy Captain [#選擇-capy-captain]

告訴代理由哪個 Capy Captain 接收工作。

### 建立傳送金鑰 [#建立傳送金鑰]

在 **Settings** → **API** 中建立一個角色為 `read_write` 的服務使用者，授予它專案的存取權，再為這個服務使用者建立一把金鑰。

### 分享 Capy Captain [#分享-capy-captain]

開啟 Capy Captain 的選單，選取 **Share**，把存取權授予服務使用者。如果 Captain 在已配對裝置上執行，也把該裝置的存取權授予服務使用者。 

### 儲存傳送金鑰 [#儲存傳送金鑰]

開啟第二個認領連結，把金鑰貼到 **Token**，再選取 **Save token**。

### 再次重新啟動 SwB [#再次重新啟動-swb]

重新啟動 SwB，然後告訴代理你已完成。

## 代理會做什麼 [#代理會做什麼]

從具備完整擁有者存取權的用戶端呼叫 `connect(what="capy-captain")`。如果 SwB 需要讀取金鑰，會回傳一個認領連結。認領連結是用來輸入憑證的私有頁面。

重新啟動後，`connect` 會列出可用的 Captain。確認由哪個 Captain 接收工作，再呼叫 `connect(what="capy-captain", choose={"captain":"<Capy Captain ID>"})`。如果要建立專案路由，在 `choose` 中加入 `"project":"<project>"`。路由告訴 SwB 要把工作送到哪裡。

如果代理需要服務金鑰才能傳送，SwB 會要求提供。用 `capy_captains`、`routes_list` 和 `routes_resolve` 檢查路由。

如果你的應用程式支援 MCP Events，訂閱 `switchboard.message.created`。如果只在需要時讀取，呼叫 `wait` 或 `inbox`。

## 憑證 [#憑證]

| 權杖 | 顯示位置 | 格式 | 去處 |
| - | - | - | - |
| 讀取金鑰 | **Settings** → **API**，只顯示一次 | `capy_` 加上 43 個隨機字元 | 對應 SwB 認領連結頁面上的 **Token** |
| 傳送金鑰 | **Settings** → **API**，只顯示一次 | `capy_` 加上 43 個隨機字元 | 對應 SwB 認領連結頁面上的 **Token** |

## 檢查連線 [#檢查連線]

請代理再次呼叫 `connect(what="capy-captain")`，確認結果為 `connected`。傳送一項簡短的測試任務到這條路由，確認任務出現在 Captain 討論串中，再用 `result` 或 `inbox` 讀取回覆。以擁有者身分開啟 `/healthz`，檢查已設定的傳送金鑰名稱和狀態。

## 疑難排解 [#疑難排解]

Capy 金鑰沿用所屬帳號的權限。如果 `connect` 要求新的讀取金鑰，建立一把能存取 Captain 的金鑰。

如果傳送失敗並出現存取錯誤，檢查服務使用者對專案、Captain 和已配對裝置的存取權。

伺服器環境中的值優先於用認領連結儲存的值。到伺服器環境中修改，再重新啟動 SwB。

如果要更換遺失的金鑰，在 **Settings** → **API** 中撤銷它，再建立新金鑰。每個認領連結只能使用一次，30 分鐘後過期。
