前言¶
在 DSH 裏寫代碼、跑命令,通常由 DSH 自己的模型通過 ctx.tools 完成。若你同時在用 Codex CLI,希望由 Codex 發起任務、讀回結構化結果,再自行跑驗收命令,普通 DSH 工具對 Codex 不可見——能力必須離開 DSH 進程,以 MCP 等形式暴露給外部調用方。
GEB-lab/dsh-codex-mcp 是運行在 DSH 宿主進程內的 DSH host plugin:在本地拉起僅監聽迴環地址的 Streamable HTTP MCP 服務,Codex 經 Bearer 鑑權調用 MCP 工具,插件再拉起本機已安裝的 DSH CLI(--profile headless --json),由 DSH 讀寫代碼、執行命令並流式輸出 NDJSON。寫代碼的仍是 DSH;Codex 只負責派發任務、解析返回、自己重跑驗收。
社區目錄頁:skillhub.cn 插件條目。目錄爲獨立站點,與 DeepSeek / 幻方無官方從屬關係。
這是什麼¶
一句話:DSH 進程內的 MCP 橋——Codex 經 http://127.0.0.1:39391/mcp(默認)把開發任務交給 DSH headless,無需每次手寫 shell 包裝腳本。
維護者:GEB-lab。許可證:MIT(README 標明 zero runtime dependencies)。package.json 當前版本爲 0.1.1。
調用鏈(摘自 README):
Codex CLI
└─ MCP (Streamable HTTP + Bearer token) http://127.0.0.1:39391/mcp
└─ DSH host plugin dsh-codex-mcp (lives inside the DSH process)
└─ node <dsh install>/lib/bin.js --profile headless --json
└─ DSH reads/writes code, runs commands, streams NDJSON events
爲何做成插件而不是 DSH 內置工具¶
README 說明:常規 DSH agent 工具只對 DSH 自己的模型可見,Codex 無法調用。該插件在宿主加載時通過 ctx.effect 啓動 HTTP MCP 端點,卸載時關閉;自行實現 Streamable HTTP 與 legacy JSON-RPC,不依賴 MCP SDK 或 @deepseek-ai/* 包,避免在 profile 內解析額外依賴;子進程 DSH 路徑優先從宿主安裝旁的 @deepseek-ai/dsh 的 lib/bin.js 定位,或由 DSH_APP_ROOT / dshCli 指定。
核心功能¶
MCP 工具(三個)¶
| 工具 | 作用 |
|---|---|
dsh_env() |
無副作用、不消耗模型 token;返回插件、MCP URL/token、DSH CLI 與 profile、默認 cwd/超時、併發狀態,以及可粘貼的 Codex config.toml 片段 |
dsh_run(task, cwd?, timeout_sec?, include_events?) |
新建 headless 會話;task 經 stdin 傳入,避免引號與 argv 長度問題;成功時返回 final answer、session id、cwd、exit、turn_end、token 用量、步數與耗時 |
dsh_resume(session_id, task, cwd?, timeout_sec?) |
在同一會話上續聊;cwd 須與首次 dsh_run 一致,否則 DSH 拒絕啓動 |
結果與失敗語義¶
- 結構化字段包含最終回答、
session、cwd、exit、turn_end、每輪 token、步數、時長;失敗時附帶 stderr 尾部與分類原因。 - 以下情況插件按 MCP 錯誤返回:超時、子進程非零退出、
turn_end非completed、未收到final事件、最終回答爲空——不輕信 DSH 自述的「已完成」。 - 超時會對進程樹做 kill(Windows 爲
taskkill /T /F,其他平臺爲進程組),避免殘留 agent。 maxConcurrentRuns默認 4,超額調用快速失敗,不靜默排隊。- 默認僅綁定
127.0.0.1;Bearer token 首次啓動生成(32 隨機字節,文件權限0600),默認路徑$DSH_HOME/codex-mcp.token,校驗使用 sha256 +timingSafeEqual。 - 工具描述支持中英(
locale/en.json、locale/zh.json),配置項locale默認zh。
環境要求¶
| 項 | 要求 |
|---|---|
| DSH | 桌面或 CLI 安裝,且 @deepseek-ai/dsh 支持 --profile headless --json |
| Node | ^22.19.0 \|\| >=24.0.0(使用宿主自帶 Node) |
| 憑證 | ~/.dsh profile 中已配置模型 API Key(GUI Models 或憑證服務) |
| Profile | 需有 headless profile;桌面 profile 不接受 --json |
安裝與啓用¶
在 DSH 側添加插件(命令來自 README,注意 --profile desktop):
# from GitHub (recommended)
dsh plugin --profile desktop add github:GEB-lab/dsh-codex-mcp
# from a release tarball
dsh plugin --profile desktop add https://github.com/GEB-lab/dsh-codex-mcp/releases/latest/download/dsh-codex-mcp.tgz
# local checkout, for development (changes apply after a host restart)
dsh plugin --profile desktop add link:/absolute/path/to/dsh-codex-mcp
dsh plugin 會轉發到對應 profile 的包管理器,並在 dsh.profile.bundles 中選中新 bundle。若 HMR 開啓則立即加載,否則需重啓 DSH。
驗證 MCP 是否就緒:
curl -i http://127.0.0.1:39391/mcp -X POST \
-H "authorization: Bearer $(cat ~/.dsh/codex-mcp.token)" \
-H "content-type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{}}}'
無 curl 時可用倉庫內冒煙腳本(node scripts/smoke.mjs 僅測協議與 dsh_env;加 --task 會消耗 token),腳本會打印本機適用的 config.toml 片段。
Codex 側配置¶
編輯 ~/.codex/config.toml:
[mcp_servers.dsh_codex]
url = "http://127.0.0.1:39391/mcp"
http_headers = { Authorization = "Bearer <contents of $DSH_HOME/codex-mcp.token>" }
startup_timeout_sec = 30
tool_timeout_sec = 3600
enabled = true
執行 codex mcp list 應看到 dsh_codex … enabled Bearer token。
可選:插件配置¶
在 bundle 默認或 ~/.dsh/profiles/<profile>/cordis.patch.yml 中覆蓋 dsh-codex-mcp 的 config,例如:
- id: dsh-codex-mcp
name: dsh-codex-mcp
config:
port: 39400
defaultCwd: 'D:\code'
常用鍵:host(默認 127.0.0.1,非迴環需 allowNonLoopback: true)、port(默認 39391,0 爲自動選端口)、path(默認 /mcp)、defaultTimeoutSec(默認 3600)、permissionMode(默認 danger-full-access)、maxConcurrentRuns(默認 4)等;完整表格見 GitHub README「Configuration」一節。
典型用法¶
在 Codex 中可向模型說明:用 dsh_run 在指定目錄完成改動,返回後由 Codex 自己跑測試。README 示例(路徑按你的環境替換):
Use
dsh_runto have DSH, inC:\work\proj, add typed input support tosrc/sum.mjsplus threenode:testcases; only touchsrc/andtest/. After it returns, runnode --test test\*.test.mjsyourself and report the result.
dsh_run 成功時文本結果中會包含 session: 與續聊提示,例如:
--- continue this session ---
dsh_resume({ "session_id": "session-1a2b3c4d-...", "task": "<next task>" })
適用場景與注意¶
適合誰:已同時使用 DSH(headless + 已配 API Key)與 Codex CLI,希望用 Codex 編排多步開發、把具體改碼交給 DSH,並由 Codex 保留驗收與彙報鏈路的工作流場景。
安全與權限:插件以當前 DSH 宿主進程的權限運行子 headless agent;默認 permissionMode 爲 danger-full-access。安裝前請閱讀倉庫源碼與 MIT 許可證,確認 token 文件與僅迴環綁定策略符合你的環境。非迴環綁定需顯式配置且仍有對端地址校驗(詳見 README「Security model」)。
分類:社區目錄將該插件歸爲 工作流。
結尾¶
dsh-codex-mcp 把「Codex 派發、DSH 執行」固定在本地 MCP 迴環上,用三個工具和環境探測降低接線成本,並對超時、退出碼與空結果做統一失敗分類。需要細節、配置表與安全說明時,以倉庫 README 爲準。
- 目錄頁:https://www.skillhub.cn/plugins/GEB-lab/dsh-codex-mcp
- GitHub:https://github.com/GEB-lab/dsh-codex-mcp