# CLI 与 MCP 自动化教程 (CLI & Local MCP Automation Guide)

> Canonical HTML: https://downman.sbs/guides/cli-mcp.html
> English: https://downman.sbs/en/guides/cli-mcp.html | 繁體中文: https://downman.sbs/zh-tw/guides/cli-mcp.html

DownMan 内置极简命令行参数与零外部依赖的本地 stdio MCP 服务（默认关闭），方便在终端脚本或 Claude Code、Cursor 等 AI 客户端中安全调度下载任务。

DownMan includes minimal CLI flags and a zero-dependency local stdio MCP server (disabled by default) so scripts, Claude Code and Cursor can safely manage downloads.

## 按需启用本地自动化 API 与安全边界 / Opt-in local automation API and security boundaries

本地自动化与 MCP 服务默认处于关闭状态。需要使用时，请在桌面端打开“设置 → 高级 → 本地自动化与 MCP 服务”，开启开关即可生效。

Local automation and MCP are off by default. Enable them under Settings → Advanced → Local automation & MCP service whenever you need them.

开启后应用仅监听 127.0.0.1 动态回环端口，并生成 32 字节随机令牌写入仅当前用户可读的本地文件（0600 权限）。服务会拒绝浏览器跨域 Origin 请求、仅允许 http/https/ftp/magnet/thunder 协议，严禁修改应用设置或导出凭据，且同样遵循桌面授权状态。

When enabled, DownMan binds a dynamic 127.0.0.1 loopback port with a 32-byte CSPRNG token stored in a user-only (0600) file. Browser Origin headers are rejected, only http/https/ftp/magnet/thunder URLs are allowed, app settings and credentials are never exposed, and license rules still apply.

## 接入 Claude Code / Cursor 与 7 个聚焦工具 / Connect Claude Code / Cursor and use 7 focused tools

在“设置 → 高级”点击“复制 MCP 客户端配置”，将生成的 mcpServers JSON 粘贴到 Claude Code 或 Cursor 的 MCP 配置文件即可完成接入，无需安装额外依赖。

Click Copy MCP client config in Settings → Advanced and paste the generated mcpServers JSON into Claude Code or Cursor—no extra packages required.

MCP 服务提供 7 个职责清晰的工具：list_downloads（查询列表）、add_download（新建下载并支持校验值）、probe_repository（探测 HF 仓库/GH Release/多链接）、pause_downloads、resume_downloads、remove_downloads（默认保留本地文件）与 get_download_details（查看进度与校验结果）。

The MCP server exposes 7 focused tools: list_downloads, add_download (with optional checksum), probe_repository (Hugging Face / GitHub Release / batch URLs), pause_downloads, resume_downloads, remove_downloads (keeps local files by default) and get_download_details.

## 极简 CLI 命令行调用 / Minimal CLI invocation

桌面版也支持直接通过命令行参数投递任务，例如传入 --add URL、--dir 保存目录、--name 文件名、--checksum 校验值、--later 稍后下载，以及 --status --json 查看当前任务快照。

You can also pass flags directly to the desktop executable, such as --add URL, --dir folder, --name filename, --checksum digest, --later to queue paused, and --status --json for a JSON snapshot.

若客户端返回无法连接本地自动化服务的提示，请确认 DownMan 正在运行，且“设置 → 高级”中的自动化开关处于开启状态。

If an MCP client reports that the local service is unavailable, make sure DownMan is running and that Local automation & MCP service is turned on in Settings → Advanced.
