Back to search
douyin-upload-mcp-skill
SkillGitHub
基于浏览器自动化的抖音视频/图文上传 MCP & Skill,适用于openclaw或任何支持skill,mcp的agent. o( ̄▽ ̄)ブ
Safety scan
A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.
Checked today
Badge for your README
Markdown
[](/listings/wjz-p--douyin-upload-mcp-skill)HTML
<a href="/listings/wjz-p--douyin-upload-mcp-skill"><img src="/api/listings/wjz-p--douyin-upload-mcp-skill/badge.svg" alt="findsafeskills safety rating" /></a>Install
i
What was scanned
The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.
SKILL.md · Manifest · 115 lines
View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)
- ---
- name: douyin-upload-mcp-skill
- description: 通过抖音创作者平台(creator.douyin.com)发布视频和图文内容。首选调用 MCP 工具完成操作,MCP 无法满足时可运行 Skill 脚本兜底。禁止自行启动外部浏览器访问抖音。
- ---
- # 抖音 MCP Skill
- ## ⚠️ 操作优先级(必须遵守)
- 1. **🥇 首选:调用 MCP 工具** — 直接调用本 Skill 暴露的 MCP 工具完成操作。绝大多数场景都应该走这条路径。
- 2. **🥈 兜底:运行 Skill 脚本** — 当 MCP 工具无法满足需求时,运行本 Skill 项目中的脚本(如 `demo.js`、`demo-imagetext.js`)
- 3. **🥉 最次:连接 Skill 管理的浏览器** — 仅前两种方式都无法解决时,通过 `douyin_browser_info` 获取 CDP 连接信息接管浏览器。**需先征得用户同意**
- **绝对禁止**:自行启动新的浏览器实例访问抖音页面。
- ## 支持范围
- | 类型 | 支持 | 说明 |
- |------|------|------|
- | 发布视频 | ✅ | 上传视频 + 选封面 + 填标题简介 + 发布 |
- | 发布图文 | ✅ | 上传图片 + 填标题简介 + 选音乐 + 发布 |
- | 发布全景视频 | ❌ | 不支持(场景极少) |
- | 发布纯文字 | ❌ | 不支持(场景极少) |
- ## 可用 MCP 工具
- ### 核心发布工具
- | 工具名 | 说明 | 入参 |
- |--------|------|------|
- | `douyin_publish_video` | 发布视频(全自动,内部自动检查登录) | `filePath`(必填), `title`, `description`, `timeout` |
- | `douyin_publish_imagetext` | 发布图文(全自动,内部自动检查登录) | `filePaths`(必填,字符串数组), `title`, `description` |
- ### 登录与状态
- | 工具名 | 说明 | 入参 |
- |--------|------|------|
- | `douyin_check_login` | 检查登录状态并推进登录流程 | `smsCode`(可选,短信验证码) |
- | `douyin_probe` | 探测页面各元素状态 | 无 |
- | `douyin_screenshot` | 对当前页面截图保存 | 无 |
- ### 页面操作
- | 工具名 | 说明 | 入参 |
- |--------|------|------|
- | `douyin_navigate_to` | 打开指定抖音页面 URL(仅 douyin.com 域名) | `url`, `timeout` |
- | `douyin_reload_page` | 刷新页面 | `timeout` |
- | `douyin_browser_info` | 获取浏览器连接信息(兜底接管用) | 无 |
- ## 典型使用流程
- ### 1. 登录(多次调用 `douyin_check_login` 推进)
- ```
- 第1次调用 → phase: qrcode → 用户扫码
- 第2次调用 → phase: sms_verification → 自动点击接收短信
- 第3次调用 → phase: sms_code_input → 用户告知验证码
- 第4次调用(smsCode="123456") → phase: logged_in → 登录完成
- ```
- ### 2. 发布视频
- ```
- 调用 douyin_publish_video:
- filePath: "C:/videos/test.mp4"
- title: "我的视频"
- description: "视频简介 #标签"
- ```
- ### 3. 发布图文
- ```
- 调用 douyin_publish_imagetext:
- filePaths: ["C:/images/1.png", "C:/images/2.png"]
- title: "我的图文"
- description: "图文简介 #标签"
- ```
- ## MCP 客户端配置
- ```json
- {
- "mcpServers": {
- "douyin": {
- "command": "node",
- "args": ["<项目绝对路径>/src/mcp-server.js"]
- }
- }
- }
- ```
- 也可通过 `npm run mcp` 手动启动。
- ## 架构
- ```
- MCP Client → mcp-server.js → index.js → browser.js → Daemon
- ↓
- douyin-ops.js → operator.js → CDP → Chrome → douyin.com
- ```
- - **Daemon**(独立进程):管理浏览器生命周期,闲置 30 分钟自动销毁
- - **browser.js**:Skill 侧连接器,按需自启 Daemon
- - **operator.js**:纯 CDP 底层原子操作
- - **douyin-ops.js**:抖音业务编排层
- - **mcp-server.js**:MCP 工具协议层
- ### 端口配置(与 gemini-skill 共享同一浏览器实例)
- | 配置项 | 默认值 | 说明 |
- |--------|--------|------|
- | CDP 端口 | 40821 | 与 gemini-skill 共享 |
- | Daemon 端口 | 40225 | 与 gemini-skill 共享 |
- 多个 skill 共用同一个浏览器实例 + 同一个 Daemon,各 skill 各用各的 tab。
README.md · README · 192 lines
View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)
- ## 基于 CDP 操控抖音创作者平台,实现视频、图文的全自动发布。
- <p align="center">
- <a href="https://github.com/WJZ-P/douyin-upload-mcp-skill/">
- <img src="markdown/douyin.png" alt="Logo" width="150" height="150" style="margin: 0; border-radius: 24px;">
- </a>
- </p>
- <h1 align="center">Douyin Upload MCP Skill</h1>
- <p align="center">
- <a href="#快速开始">快速开始</a>
- ·
- <a href="https://github.com/WJZ-P/douyin-upload-mcp-skill/issues">报告 Bug</a>
- ·
- <a href="https://github.com/WJZ-P/douyin-upload-mcp-skill/issues">提出新特性</a>
- </p>
- <p align="center">
- <a href="./README.en.md">English</a> | 中文
- </p>
- <br>
- <p align="center">
- <img src="./markdown/example.png" alt="抖音自动发布示例" width="100%">
- </p>
- <p align="center"><em>▲ 通过 MCP 工具全自动发布视频和图文</em></p>
- <br>
- # douyin-upload-mcp-skill
- 基于 CDP(Chrome DevTools Protocol)的抖音创作者平台自动化上传服务,通过 MCP 协议对外暴露工具,支持视频和图文的全自动发布。
- ## 功能
- - **视频发布**:上传视频 → 等待转码 → AI 封面推荐 → 填写标题/简介 → 一键发布
- - **图文发布**:上传多张图片 → 填写标题/简介 → 自动选择音乐 → 一键发布
- - **登录管理**:扫码 → 短信验证 → 验证码输入,全流程自动推进
- - **浏览器托管**:独立 Daemon 进程管理 Chrome 生命周期,闲置 30 分钟自动销毁
- ## 快速开始
- ### 1. 安装依赖
- ```bash
- npm install
- ```
- ### 2. 作为 MCP 服务使用(推荐)
- 在 MCP 客户端配置中添加:
- ```json
- {
- "mcpServers": {
- "douyin": {
- "command": "node",
- "args": ["<项目绝对路径>/src/mcp-server.js"]
- }
- }
- }
- ```
- 或手动启动:
- ```bash
- npm run mcp
- ```
- ### 3. 运行 Demo 测试
- ```bash
- # 视频发布
- node src/demo.js
- # 图文发布
- node src/demo-imagetext.js
- ```
- ## MCP 工具列表
- ### 核心发布
- | 工具 | 说明 | 必填参数 | 可选参数 |
- |------|------|----------|----------|
- | `douyin_publish_video` | 发布视频 | `filePath` | `title`, `description`, `timeout` |
- | `douyin_publish_imagetext` | 发布图文 | `filePaths` | `title`, `description` |
- ### 登录与状态
- | 工具 | 说明 | 可选参数 |
- |------|------|----------|
- | `douyin_check_login` | 检查登录状态并推进登录流程 | `smsCode` |
- | `douyin_probe` | 探测页面元素状态 | — |
- | `douyin_screenshot` | 页面截图 | — |
- ### 页面操作
- | 工具 | 说明 | 参数 |
- |------|------|------|
- | `douyin_navigate_to` | 导航到指定抖音 URL | `url`, `timeout` |
- | `douyin_reload_page` | 刷新页面 | `timeout` |
- | `douyin_browser_info` | 获取浏览器连接信息 | — |
- ## 登录流程
- MCP 不支持中途交互,登录需要多次调用 `douyin_check_login` 推进:
- ```
- 第 1 次调用 → phase: qrcode → 截图保存二维码,用户扫码
- 第 2 次调用 → phase: sms_verification → 自动点击「接收短信验证码」
- 第 3 次调用 → phase: sms_code_input → 提示输入验证码
- 第 4 次调用 → phase: logged_in → 传入 smsCode 完成登录
- ```
- ## 架构
- ```
- MCP Client → mcp-server.js → index.js → browser.js → Daemon
- ↓
- douyin-ops.js → operator.js → CDP → Chrome → douyin.com
- ```
- | 层 | 文件 | 职责 |
- |----|------|------|
- | 协议层 | `mcp-server.js` | MCP 工具注册,stdio 传输 |
- | 入口层 | `index.js` | 对外暴露 `createDouyinSession()` |
- | 业务层 | `douyin-ops.js` | 抖音业务编排(上传、填写、发布) |
- | 原子层 | `operator.js` | CDP 底层操作(locate/click/type),带人类行为模拟 |
- | 连接层 | `browser.js` | 连接 Daemon 获取浏览器实例 |
- | Daemon | `daemon/` | 独立进程管理浏览器生命周期 |
- ## 配置
- 所有配置通过环境变量或 `.env` 文件设置。项目根目录已提供 `.env` 模板,可直接修改。
- **配置优先级:** `process.env` > `.env.development` > `.env` > 代码默认值
- > `.env.development` 不会被 git 追踪,适合存放本地私有配置(如浏览器路径)。
- ### 浏览器配置
- | 变量 | 默认值 | 说明 |
- |------|--------|------|
- | `BROWSER_PATH` | 自动检测 | 浏览器可执行文件路径,支持 Chrome / Edge / Chromium。不设则自动按优先级检测系统已安装的浏览器 |
- | `BROWSER_DEBUG_PORT` | `40821` | CDP 远程调试端口。多个 skill(如 gemini-skill)共享同一端口即共享同一浏览器实例 |
- | `BROWSER_HEADLESS` | `false` | 是否无头模式。首次使用建议关闭(`false`),方便扫码登录 |
- | `BROWSER_USER_DATA_DIR` | `~/.wjz_browser_data` | 浏览器用户数据目录,保存登录态、cookies 等。首次运行会自动从系统默认浏览器目录克隆 |
- | `BROWSER_PROTOCOL_TIMEOUT` | `60000` | CDP 协议超时时间(毫秒)。视频上传等长操作可适当增大 |
- ### Daemon 配置
- | 变量 | 默认值 | 说明 |
- |------|--------|------|
- | `DAEMON_PORT` | `40225` | Daemon HTTP 服务端口。与 gemini-skill 共享同一 Daemon |
- | `DAEMON_TTL_MS` | `1800000` | 闲置超时时间(毫秒),默认 30 分钟。超时后自动关闭浏览器并退出 Daemon,下次调用时自动重新拉起 |
- ### 其他配置
- | 变量 | 默认值 | 说明 |
- |------|--------|------|
- | `OUTPUT_DIR` | `./douyin-output` | 截图、二维码等输出文件目录 |
- | `DOUYIN_URL` | `https://creator.douyin.com/` | 抖音创作者平台首页 URL |
- ### 关于 OpenClaw 浏览器复用
- [OpenClaw](https://github.com/) 的默认 CDP 端口是 **18800**。如果你希望复用 OpenClaw 已启动的浏览器会话,可以将 `BROWSER_DEBUG_PORT` 改为 `18800`:
- ```env
- BROWSER_DEBUG_PORT=18800
- ```
- **但请注意**:OpenClaw 自带的浏览器会话**没有集成 Stealth 反爬插件**,在反检测能力上不如本项目自行维护的浏览器实例。本项目使用 `puppeteer-extra-plugin-stealth` 提供了完整的反爬保护(隐藏 webdriver 标记、模拟真实浏览器指纹等),能更好地规避抖音平台的自动化检测。
- **建议**:除非有特殊需求,推荐使用默认端口 `40821`,让项目自行管理浏览器实例以获得最佳的反爬效果。
- ## 技术栈
- - **puppeteer-core** + **puppeteer-extra-plugin-stealth**:CDP 连接 + 反检测
- - **@modelcontextprotocol/sdk**:MCP 协议实现
- - **原生 Node.js HTTP**:Daemon 微服务
- ## License
- [AGPL-3.0](LICENSE)
- ## LINUX DO
- 本项目支持 [LINUX DO](https://linux.do) 社区
src/daemon/engine.js · Bundled script · 271 lines · 2 findings marked
- /**
- * engine.js — 浏览器引擎
- *
- * 职责:
- * 维护 _browser 单例,封装 launch / connect / terminate。
- * 复用 stealth 插件、反检测参数、路径检测逻辑。
- */
- import puppeteerCore from 'puppeteer-core';
- import { addExtra } from 'puppeteer-extra';
- import StealthPlugin from 'puppeteer-extra-plugin-stealth';
- import { createConnection } from 'node:net';
- import { existsSync, mkdirSync, cpSync } from 'node:fs';
- import { platform, homedir } from 'node:os';
- import { join, basename } from 'node:path';
- import config from '../config.js';
- // ── Stealth 包装 ──
- const puppeteer = addExtra(puppeteerCore);
- puppeteer.use(StealthPlugin());
- // ── 单例 ──
- let _browser = null;
- let _shuttingDown = false;
- let _shutdownCallback = null;
- export function onBrowserExit(cb) {
- _shutdownCallback = cb;
- }
- function registerDisconnectHandler(browser) {
- browser.on('disconnected', () => {
- if (_shuttingDown) return;
- console.log('[engine] 🔌 浏览器连接断开(用户关闭了浏览器窗口?)');
- _browser = null;
- if (_shutdownCallback) {
- _shutdownCallback();
- }
- });
- }
- // ── 浏览器候选路径 ──
- const BROWSER_CANDIDATES = {
- win32: [
- 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
- 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
- 'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe',
- 'C:\\Program Files\\Microsoft\\Edge\\Application\\msedge.exe',
- 'C:\\Program Files\\Chromium\\Application\\chrome.exe',
- ],
- darwin: [
- '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
- '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',
- '/Applications/Chromium.app/Contents/MacOS/Chromium',
- ],
- linux: [
- '/usr/bin/google-chrome',
- '/usr/bin/google-chrome-stable',
- '/usr/bin/microsoft-edge',
- '/usr/bin/microsoft-edge-stable',
- '/usr/bin/chromium',
- '/usr/bin/chromium-browser',
- '/snap/bin/chromium',
- ],
- };
- function detectBrowser() {
- const envPaths = [
- process.env.PROGRAMFILES,
- process.env['PROGRAMFILES(X86)'],
- process.env.LOCALAPPDATA,
- ];
- const os = platform();
- const candidates = [...(BROWSER_CANDIDATES[os] || [])];
- if (os === 'win32') {
- for (const base of envPaths) {
- if (!base) continue;
- candidates.push(
- `${base}\\Google\\Chrome\\Application\\chrome.exe`,
- `${base}\\Microsoft\\Edge\\Application\\msedge.exe`,
- );
- }
- }
- for (const p of candidates) {
- if (existsSync(p)) return p;
- }
- return undefined;
- }
- // ── userDataDir 相关 ──
- const GLOBAL_WJZ_DATA_DIR = join(homedir(), '.wjz_browser_data');
- function getDefaultBrowserDataDir() {
- const os = platform();
- const home = homedir();
- const candidates = [];
- if (os === 'win32') {
- const localAppData = process.env.LOCALAPPDATA || join(home, 'AppData', 'Local');
- candidates.push(
- join(localAppData, 'Google', 'Chrome', 'User Data'),
- join(localAppData, 'Microsoft', 'Edge', 'User Data'),
- join(localAppData, 'Chromium', 'User Data'),
- );
- } else if (os === 'darwin') {
- const lib = join(home, 'Library', 'Application Support');
- candidates.push(
- join(lib, 'Google', 'Chrome'),
- join(lib, 'Microsoft Edge'),
- join(lib, 'Chromium'),
- );
- } else {
- candidates.push(
- join(home, '.config', 'google-chrome'),
- join(home, '.config', 'microsoft-edge'),
- join(home, '.config', 'chromium'),
- );
- }
- for (const dir of candidates) {
- if (existsSync(dir)) return dir;
- }
- return undefined;
- }
- function cloneProfileFromDefault(sourceDir, targetDir) {
- console.log(`[engine] 首次运行,从浏览器默认数据克隆资产: ${sourceDir} → ${targetDir}`);
- const SKIP_NAMES = new Set([
- 'singletonlock', 'singletonsocket', 'singletoncookie', 'lockfile',
- 'cache', 'code cache', 'gpucache', 'dawncache', 'grshadercache',
- 'crashpadmetrics-active.pma', 'browsermetrics', 'browsermetrics-spare.pma',
- ]);
- const filterFunc = (src) => !SKIP_NAMES.has(basename(src).toLowerCase());
- try {
- cpSync(sourceDir, targetDir, { recursive: true, filter: filterFunc });
- Warning: On first run, copies your whole Chrome/Edge profile (cookies, saved logins, session data) into ~/.wjz_browser_data. This is far more than a Douyin uploader needs. The copy is local, and no upload of it is shown.
- Line 142 on GitHub
- console.log('[engine] 克隆完成');
- } catch (err) {
- console.warn(`[engine] ⚠ 克隆出错(浏览器仍可启动,但需重新登录): ${err.message}`);
- }
- }
- function resolveUserDataDir() {
- if (config.browserUserDataDir) return config.browserUserDataDir;
- if (existsSync(GLOBAL_WJZ_DATA_DIR)) return GLOBAL_WJZ_DATA_DIR;
- mkdirSync(GLOBAL_WJZ_DATA_DIR, { recursive: true });
- const defaultDir = getDefaultBrowserDataDir();
- if (defaultDir) {
- cloneProfileFromDefault(defaultDir, GLOBAL_WJZ_DATA_DIR);
- }
- return GLOBAL_WJZ_DATA_DIR;
- }
- // ── 启动参数 ──
- const BROWSER_ARGS = [
- '--no-first-run',
- '--disable-default-apps',
- '--disable-popup-blocking',
- '--disable-gpu',
- '--disable-software-rasterizer',
- '--disable-dev-shm-usage',
- ...(platform() === 'linux'
- ? ['--no-sandbox', '--disable-setuid-sandbox']
- : []),
- '--disable-background-networking',
- '--disable-background-timer-throttling',
- '--disable-backgrounding-occluded-windows',
- '--disable-renderer-backgrounding',
- '--disable-features=Translate',
- '--no-default-browser-check',
- '--disable-crash-reporter',
- '--hide-crash-restore-bubble',
- '--test-type',
- '--safebrowsing-disable-download-protection',
- '--safebrowsing-disable-extension-blacklist',
- ];
- function isPortAlive(port, host = '127.0.0.1', timeout = 1500) {
- return new Promise((resolve) => {
- const socket = createConnection({ host, port });
- const timer = setTimeout(() => { socket.destroy(); resolve(false); }, timeout);
- socket.on('connect', () => { clearTimeout(timer); socket.destroy(); resolve(true); });
- socket.on('error', () => { clearTimeout(timer); resolve(false); });
- });
- }
- // ── 公开 API ──
- export function getBrowser() {
- return _browser;
- }
- export async function ensureBrowserForDaemon() {
- const port = config.browserDebugPort;
- if (_browser && _browser.isConnected()) {
- return _browser;
- }
- const alive = await isPortAlive(port);
- if (alive) {
- try {
- _browser = await puppeteer.connect({
- browserURL: `http://127.0.0.1:${port}`,
- defaultViewport: null,
- protocolTimeout: config.browserProtocolTimeout,
- });
- registerDisconnectHandler(_browser);
- console.log(`[engine] 已连接到端口 ${port} 的浏览器`);
- return _browser;
- } catch (err) {
- console.warn(`[engine] 连接失败: ${err.message},将尝试启动`);
- }
- }
- const executablePath = config.browserPath || detectBrowser();
- if (!executablePath) {
- throw new Error(
- `[engine] 未找到可用浏览器。请设置 BROWSER_PATH 或安装 Chrome/Edge。`
- );
- }
- const userDataDir = resolveUserDataDir();
- _browser = await puppeteer.launch({
- executablePath,
- headless: config.browserHeadless,
- userDataDir,
- defaultViewport: null,
- args: [...BROWSER_ARGS, `--remote-debugging-port=${port}`],
- Warning: Launches the browser holding the copied profile with a remote-debugging port open on this machine, so any local program can drive a browser signed in to the user's sites. It also turns off Safe Browsing's download protection.
- Line 238 on GitHub
- ignoreDefaultArgs: ['--enable-automation'],
- protocolTimeout: config.browserProtocolTimeout,
- handleSIGINT: false,
- handleSIGTERM: false,
- handleSIGHUP: false,
- });
- const pid = _browser.process()?.pid;
- registerDisconnectHandler(_browser);
- console.log(`[engine] 浏览器已启动 pid=${pid} port=${port} path=${executablePath}`);
- return _browser;
- }
- export async function terminateBrowser() {
- if (!_browser) return;
- _shuttingDown = true;
- try {
- const pid = _browser.process()?.pid;
- await _browser.close();
- console.log(`[engine] 浏览器已终止 pid=${pid || 'N/A'}`);
- } catch (err) {
- console.warn(`[engine] 终止浏览器时出错: ${err.message}`);
- try {
- _browser.process()?.kill('SIGKILL');
- } catch { /* ignore */ }
- } finally {
- _browser = null;
- _shuttingDown = false;
- }
- }
Ratings and comments
Sign in to rate this skill.
Sign inFree to use. If it’s helped, pass it on.