@beings-labs/dsh-cloudflare-connector:在 DSH 裏用瀏覽器 OAuth 接入 Cloudflare 官方 MCP

前言

在 DeepSeek Harness(DSH)裏讓智能體操作 Cloudflare,常見做法是自管 API Token,或在對話裏拼裝授權流程。Cloudflare 已提供面向智能體的官方 MCP 服務;難點往往落在本地 OAuth、會話持久化,以及把上游工具穩定暴露給 DSH 裏的 agent 與其他插件。

下面介紹社區插件 @beings-labs/dsh-cloudflare-connector(維護者 beings-labs,分類 admin-security)。它連接 Cloudflare 官方 API MCP server,保留上游 MCP 協議與工具契約;同時提供本地共享服務與 TypeScript 類型,供插件開發者直接發 API 請求,而無需自行創建或輪換 Cloudflare API Token。

這是什麼

一句話定位:面向 DSH 智能體與插件開發者的 Cloudflare 接入層——瀏覽器登錄、官方 MCP 工具、可選的共享連接 API。

該連接器使用獨立的 tool、service、callback 與 credential 命名空間,不是圍繞其他 connector 工具構建的集成的即插即用替代品。

核心功能

以下爲 README 中已寫明的能力,安裝前可按需對照源碼覈對。

  1. 瀏覽器登錄:Cloudflare OAuth + PKCE,複用 DSH 已有本地 Web 服務;默認授予 user:read、account:read,用於身份與賬號發現,而非默認訪問全部 Cloudflare 資源。
  2. Agent 可用工具:上游工具以 mcp__cloudflare_connector__* 暴露,輸入 schema 與上游一致;輔助工具包括 cloudflare_connector_authorize、cloudflare_connector_status、cloudflare_connector_test 等(完整列表見 README「Agent helper tools」表)。
  3. 插件開發者向:單一共享連接、公開 TypeScript 類型;可在自有插件裏直接請求 API,減少嵌套的面向模型工具調用。
  4. 權限邊界清晰:資源類操作可能需要額外瀏覽器授權;authorized 表示本地已存憑證,不表示所有 scope 均已授予。
  5. 會話持久化:私有憑證存儲、自動刷新 token、重啓後重連;憑證默認路徑爲 $DSH_HOME/dsh-cloudflare-connector/auth.json(未設置 DSH_HOME 時爲 ~/.dsh/dsh-cloudflare-connector/auth.json),文件權限 0600。

Browser OAuth 需要 loopback 源站;不支持遠程託管的 DSH Web 服務器。通過對話調用工具還需要 DSH 內可用的模型連接,與 Cloudflare 授權相互獨立。

安裝與啓用

1. 安裝到指定 profile

在你要實際運行的 DSH profile 中安裝已發佈包:

dsh plugin --profile <profile> add @beings-labs/dsh-cloudflare-connector

將 <profile> 替換爲你的 profile 名稱,然後重啓 DSH。

若使用本地開發目錄(需先在該倉庫執行 npm ci),可用 link 安裝:

dsh plugin --profile <profile> add link:/absolute/path/to/dsh-cloudflare-connector

2. 可選配置

默認無需改配置。若要自定義,編輯 profile 的 cordis.patch.yml:

- id: beings-labs-cloudflare-connector
  config:
    enabled: true
    announceToAgent: true
    scopes:
      - user:read
      - account:read
    # tokenFile: /absolute/path/to/private/auth.json

常用項:enabled(默認 true)、announceToAgent(是否在 agent prompt 中包含授權說明)、scopes(初始 scope 列表)、endpoint(默認 https://mcp.cloudflare.com/mcp)、tokenFile(憑證絕對路徑)。併發使用多個 profile 時,應爲各 profile 使用不同的 tokenFile。

典型用法

登錄 Cloudflare

讓 agent 調用:

Call cloudflare_connector_status and cloudflare_connector_authorize.

在返回的 authorizationUrl 中用瀏覽器打開並完成授權;回調由 DSH 本地處理。不要在對話中粘貼 API Token、access token 或 refresh token。

若瀏覽器回調無法到達 DSH,可通過本地工具調用 cloudflare_connector_finish,傳入完整回調 URL({"code":"<full callback URL>"});回調 URL 含敏感短期參數,勿寫入 issue、日誌或其他聊天。

驗證只讀連接

授權後,可讓 agent 執行類似指令:

Test the Cloudflare connection, then list the accounts I can access. Do not modify any resources.

預期:cloudflare_connector_status 報告 authorized: true、connected: true;cloudflare_connector_test 列出可用工具。上游在服務端廣告時,可出現 mcp__cloudflare_connector__execute、mcp__cloudflare_connector__whoami、mcp__cloudflare_connector__search 等。

追加 scope

當 Cloudflare 要求額外 scope 時,連接器會準備同意 URL,或出現 authorization_required / HTTP 403 insufficient_scope。步驟一般爲:

  1. 調用 cloudflare_connector_authorize 獲取待處理 URL;
  2. 瀏覽器批准;
  3. 授權與重連完成後重試原操作。

若要主動申請已知 scope(且無待處理流程),可向 cloudflare_connector_authorize 傳入例如 {"scopes":["zone.read"]}。scope 名稱須與授權服務器 scopes_supported 一致;錯誤 scope 會得到 invalid_scope,而非新同意流程。放棄流程或收縮權限可調用 cloudflare_connector_clear 後重新授權(僅刪除本地憑證;必要時還需在 Cloudflare 側撤銷上游授權)。

適用場景與注意

適合誰

  • 在 DSH 對話中通過官方 MCP 工具查詢或操作 Cloudflare 的開發者與運維;
  • 編寫 DSH 插件、需要共享 Cloudflare 連接與類型定義的插件作者。

安全與信任

  • 插件在當前 DSH 進程權限下運行;安裝前應閱讀源碼與 MIT 許可證,僅安裝你信任的插件。
  • 同一 profile 內授權或 cloudflare_connector_clear 會影響所有消費該連接的插件與消費者。
  • 連接器不強制只讀,也不替你制定 agent 的審批策略;消費者共享已授權的 Cloudflare 訪問能力。

排障提示(節選)

README「Troubleshooting」表中列出:輔助工具缺失多與 profile 配置或重啓有關;其餘症狀請直接對照官方 README 表格操作。

結尾

@beings-labs/dsh-cloudflare-connector 把 Cloudflare 官方 MCP 與 DSH 本地 OAuth、憑證存儲和工具命名銜接起來,降低「自管 Token + 自接 MCP」的重複勞動。若你正在 DSH 生態裏做 admin-security 類集成,可從目錄頁瞭解收錄信息,並以 GitHub README 的 Quick start 爲準完成安裝與首次授權。

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

小夜