Skip to content

實際範例 ​

四個日常工作,每個都附上一次性的設定、代理送出的請求,以及你會看到的核准內容。開頭都一樣:從服務商的網頁複製 token,用 --from-clipboard 存進 keymitt。token 不會經過對話,也不會留在 shell 歷程裡。

新增密碼之後

MCP 伺服器只在啟動時讀取政策。執行 keymitt add 或 keymitt allow 之後,請在 AI 用戶端重新啟動 keymitt 伺服器。 Claude Code 的做法是 /mcp → keymitt → Reconnect。

整理 GitHub issue ​

「列出 my-org/my-app 還沒關的 bug,從最舊的開始,並建議哪些可以關掉。」

**設定。**建立一個能讀取 issue 的 fine-grained token,複製之後執行:

sh
keymitt add github --description "GitHub token, issues read-only" --host api.github.com --from-clipboard

代理呼叫 http_request:

json
{
  "url": "https://api.github.com/repos/my-org/my-app/issues?labels=bug&state=open&direction=asc",
  "headers": {
    "Authorization": "Bearer {{secret:github}}",
    "Accept": "application/vnd.github+json"
  }
}

你核准的內容:

text
send github → https://api.github.com | GET https://api.github.com/repos/my-org/my-app/issues?labels=bug&state=open&direction=asc | Accept: application/vnd.github+json | Authorization: Bearer {{secret:github}}

代理拿到 issue 清單。它從頭到尾看不到 token,也沒辦法把 token 送到 api.github.com 以外的地方。

部署網站到 Cloudflare Pages ​

「建置文件,部署到 Cloudflare Pages 的 docs 專案。」

**設定。**建立一個有 Cloudflare Pages: Edit 權限的 API token,複製之後執行:

sh
keymitt add cloudflare --description "Cloudflare API token, Pages edit" --command wrangler --env CLOUDFLARE_API_TOKEN --from-clipboard

keymitt 會印出找到的程式,符號連結會追到真正的檔案,例如 wrangler → /opt/homebrew/lib/node_modules/wrangler/bin/wrangler.js。只有這支程式拿得到 token, 而且只能放在 CLOUDFLARE_API_TOKEN。

代理先自己建置網站(不需要密碼),再呼叫 run_with_secrets:

json
{
  "command": ["wrangler", "pages", "deploy", "dist", "--project-name", "docs"],
  "env": { "CLOUDFLARE_API_TOKEN": "{{secret:cloudflare}}" }
}

你核准的內容:

text
use cloudflare → /opt/homebrew/lib/node_modules/wrangler/bin/wrangler.js (as wrangler) | args: pages deploy dist --project-name docs | env: CLOUDFLARE_API_TOKEN={{secret:cloudflare}} | dir: /Users/you/site

代理讀得到 wrangler 的輸出,包括部署網址。就算 token 被印出來,代理看到的也只是 [REDACTED:cloudflare]。

查詢 staging 資料庫 ​

「staging 這一週每天各有多少人註冊?」

**設定。**從密碼管理工具複製一個唯讀資料庫帳號的密碼,然後執行:

sh
keymitt add pg-staging --description "staging DB, read-only user" --command psql --env PGPASSWORD --from-clipboard

代理呼叫 run_with_secrets:

json
{
  "command": ["psql", "-h", "staging-db.example.internal", "-U", "readonly", "-d", "app", "-c",
              "select date(created_at), count(*) from users where created_at > now() - interval '7 days' group by 1 order by 1"],
  "env": { "PGPASSWORD": "{{secret:pg-staging}}" }
}

你核准的內容會包含完整的 SQL,所以你清楚知道會執行什麼:

text
use pg-staging → /opt/homebrew/Cellar/postgresql@18/18.6_1/bin/psql | args: -h staging-db.example.internal -U readonly -d app -c 'select date(created_at), count(*) from users …' | env: PGPASSWORD={{secret:pg-staging}} | dir: /Users/you/app

還是建議用唯讀帳號:keymitt 保護的是密碼,不是密碼背後的資料。

Debian 與 Ubuntu

在這兩個系統上,psql 連結到 pg_wrapper,這支腳本一定要用 psql 這個名稱啟動才能運作。請改成允許真正的程式, 例如 --command /usr/lib/postgresql/16/bin/psql(版本號會不同)。代理會在 list_secrets 看到這個路徑,直接呼叫它。

升級之後

keymitt 存的是真正檔案的路徑,而 Homebrew 的路徑裡含有版本號。升級後程式換了位置時,執行 keymitt allow pg-staging --command psql,讓政策指向新的檔案。

代理需要一組你還沒存的密碼 ​

「把 release notes 貼到 Slack 的 #releases。」

代理呼叫 list_secrets,找不到 Slack 的密碼,於是呼叫 request_secret。你會收到這樣的訊息,而不是被要求把 token 貼進對話:

text
Please store this secret yourself by running in a terminal:
  keymitt add slack-bot --description 'Slack bot token for release notes' --command <program> --host <api-host>
Replace <program>/<api-host> with what it may be used for (intended use: slack.com chat.postMessage), or
drop the flags you don't need. keymitt will prompt for the value without echoing it; if you have copied
the value, add --from-clipboard to read it from the clipboard instead. …

**設定。**到 Slack app 的 OAuth & Permissions 頁面複製 bot token,把指令裡的佔位參數填好再執行:

sh
keymitt add slack-bot --description "Slack bot token for release notes" --host slack.com --from-clipboard

重新連線 keymitt 伺服器之後,代理呼叫 http_request:

json
{
  "method": "POST",
  "url": "https://slack.com/api/chat.postMessage",
  "headers": {
    "Authorization": "Bearer {{secret:slack-bot}}",
    "Content-Type": "application/json; charset=utf-8"
  },
  "body": "{\"channel\": \"#releases\", \"text\": \"keymitt 0.1.0 is out: …\"}"
}

核准視窗也會顯示訊息內容的開頭,貼出去之前你可以先確認文字。

小技巧 ​

  • **名稱與說明要寫清楚。**代理是依照 list_secrets 列出的名稱與說明來挑密碼的。
  • **token 權限越小越好。**keymitt 管的是 token 能送去哪裡,管不到它在那裡能做什麼。
  • 事後回顧。keymitt audit 會列出每一次使用、核准結果與執行結果,絕不包含值。

以 MIT 或 Apache-2.0 授權釋出。