douyin-dm-mcp
douyin-dm-mcp
一个用于抖音网页版私信的 Model Context Protocol 服务器和本地 HTTP API,基于 Playwright 构建。两个接口复用同一个持久化本地浏览器配置文件,读取当前渲染的会话和消息,并且仅在明确启用时发送单条消息。
该项目使用抖音当前的独立聊天页面:
https://www.douyin.com/chat?isPopup=1登录和账户状态检查仍使用抖音首页。/messages 当前返回 404 页面,不用于自动化。
安全边界
DOUYIN_ALLOW_SEND默认为false,因此默认禁用真实发送。send_message默认为dryRun: true。干运行会验证当前快照,而不会打开会话或更改页面状态。真实发送需要同时禁用干运行并设置
DOUYIN_ALLOW_SEND=true。在读取或真实发送之前,服务器会验证昵称唯一、会话位置和确切昵称仍然匹配,以及打开的聊天标题匹配。
重复昵称被标记为
targetable: false,MCP 工具和基于昵称的 CLI 都会拒绝。如果点击发送后无法确认结果,服务器返回
SEND_STATUS_UNKNOWN,并且不会自动重试。每个浏览器配置文件都有独占的文件系统锁,以防止并发 Chromium 实例损坏它。MCP、HTTP API 和操作员 CLI 不能同时针对同一个
DOUYIN_PROFILE运行。所有页面操作都串行化,以防止跨会话读取或发送。
该项目不修改浏览器指纹、不绕过验证挑战,也不调用抖音的私有 WebSocket/Protobuf 接口。
日志写入 stderr,并编辑消息正文、cookie 和密码字段。
Related MCP server: dy-mcp
当前限制
抖音渲染的会话 DOM 不暴露受支持的稳定会话 ID、用户 ID、sec_uid 或稳定的个人资料链接。因此:
conversationKey是不透明的,仅对最新的list_conversations快照有效。调用
list_conversations会创建新键,并立即使上一个快照中的所有键过期。每个会话都返回
stableKey: false;重复昵称还会返回targetable: false。在调用
read_messages或send_message之前先调用list_conversations,然后使用该确切结果中的键。会话列表仅包含浏览器当前渲染的项目;
complete始终为false。模糊昵称匹配、批量发送、陌生人搜索和搜索到发送的回退均有意不支持。
详细的实时页面证据记录在 RESEARCH.md 中。
要求
Node.js 20 或更高版本
npm
能够显示 Chromium 的桌面环境,用于初始二维码登录
安装
npm install
npx playwright install chromium
npm run build配置
环境变量 | 默认值 | 描述 |
|
| 配置文件名称;仅限字母、数字、下划线和连字符 |
|
| 无头运行 Chromium;初始登录时请保持为 |
|
| 允许真实消息发送 |
|
| 启用调试日志 |
|
| 导航超时(毫秒) |
|
| 页面操作超时(毫秒) |
|
| 发送尝试之间的最小间隔 |
|
| HTTP API 绑定地址 |
|
| HTTP API 端口 |
| 未设置 | Bearer 密钥,至少 16 个字符;非回环绑定必需 |
这些变量从进程环境中读取。项目不加载 .env。请以 .env.example 为参考,然后在 shell 中导出这些值,或在 MCP 客户端的 env 块中设置它们。
浏览器数据存储在:
.data/profiles/<DOUYIN_PROFILE>此目录包含身份验证数据。请勿提交或共享。
登录
首次使用或会话过期时,运行:
npm run login使用抖音扫描显示的二维码。登录后,脚本会打印结构化状态,安全关闭 Chromium,并将经过身份验证的会话保留在持久化配置文件中。
检查当前会话:
npm run status成功结果示例:
{
"ok": true,
"browserRunning": true,
"loggedIn": true,
"currentUrl": "https://www.douyin.com/jingxuan"
}启动 MCP 服务器
编译后的入口点是:
node dist/index.jsCodex CLI 示例:
codex mcp add douyin-dm -- node /absolute/path/to/douyin-dm-mcp/dist/index.js通用 MCP 客户端配置:
{
"mcpServers": {
"douyin-dm": {
"command": "node",
"args": ["/absolute/path/to/douyin-dm-mcp/dist/index.js"],
"env": {
"DOUYIN_PROFILE": "default",
"DOUYIN_ALLOW_SEND": "false"
}
}
}
}对于授权的真实发送,请将该 MCP 进程的 DOUYIN_ALLOW_SEND 设置为 true 并重启它。不要全局启用发送。
当 HTTP API 或 CLI 已持有同一配置文件锁时,请勿启动此进程。
启动 HTTP API
从源码运行:
npm run api或运行编译后的入口点:
node dist/api.js当 MCP 或 CLI 已持有同一配置文件锁时,请勿启动此进程。
默认基础 URL 是 http://127.0.0.1:3000。未经身份验证的健康检查是:
curl http://127.0.0.1:3000/healthAPI 路由:
方法 | 路径 | 输入 | 目的 |
|
| 无 | 进程存活检查;无需身份验证,无需浏览器 |
|
| 无 | 登录 / 浏览器会话 |
|
| 查询参数 | 当前渲染快照 + 新键 |
|
| JSON | 快照键的可见消息 |
|
| JSON | 默认干运行;真实发送需要两个门控 |
POST 请求需要 Content-Type: application/json。发送默认仍为干运行。真实发送仍需要同时满足 "dryRun": false 和 DOUYIN_ALLOW_SEND=true。
示例:
curl "http://127.0.0.1:3000/api/v1/conversations?limit=20"
curl -X POST http://127.0.0.1:3000/api/v1/messages/read \
-H "Content-Type: application/json" \
-d '{"conversationKey":"fallback:...:0","limit":20}'回环访问不需要 API 密钥。除非 DOUYIN_API_KEY 设置为至少 16 个字符,否则拒绝绑定到任何其他主机。配置后,在每个 /api/v1/* 请求中发送它:
curl http://127.0.0.1:3000/api/v1/status \
-H "Authorization: Bearer YOUR_API_KEY"API 返回与 MCP 相同的结构化成功和抖音错误对象。请求解析错误使用 INVALID_REQUEST、INVALID_JSON、UNSUPPORTED_MEDIA_TYPE 或 PAYLOAD_TOO_LARGE;身份验证失败使用 UNAUTHORIZED。
MCP 工具
browser_status
检查持久化抖音浏览器配置文件是否已通过身份验证。
输入:无。
list_conversations
打开独立聊天页面,并返回当前渲染的会话,以及新快照的不透明 conversationKey 值。
{
"limit": 20
}会话字段:
conversationKeystableKey,当前始终为falsepositionnicknamepreviewtimestamptargetable,当重复昵称导致无法安全选择时为false
read_messages
从 list_conversations 返回的会话中读取当前可见的消息。
{
"conversationKey": "fallback:550e8400-e29b-41d4-a716-446655440000:0",
"limit": 20
}消息字段:
direction:incoming或outgoing,来自已验证的发送方 DOM 证据type:text,或unsupported表示无法识别的消息类型content:可见文本,为空时为null
拒绝 targetable: false 的会话。
send_message
向已验证的会话发送一条消息。
{
"conversationKey": "fallback:550e8400-e29b-41d4-a716-446655440000:0",
"text": "Test message",
"dryRun": true
}真实发送需要满足以下所有条件:
DOUYIN_ALLOW_SEND=true。dryRun=false。目标昵称在当前快照中是唯一的。
会话位置和确切昵称仍与快照匹配。
打开的聊天标题与目标昵称完全匹配。
消息没有前导或尾随空白。
逻辑 Slate 编辑器文本与请求的文本完全匹配。
点击发送后,服务器会等待一条具有确切规范文本的新外发消息。如果确认失败,则返回 SEND_STATUS_UNKNOWN;调用方必须手动检查会话,而不是自动重试。最小发送间隔在会话列表刷新之间保持不变。
操作员 CLI
列出当前渲染的会话:
npm run chat -- list按确切且唯一的昵称读取消息:
npm run chat -- read "Exact nickname"真实发送还需要 DOUYIN_ALLOW_SEND。PowerShell 示例:
$env:DOUYIN_ALLOW_SEND="true"
npm run chat -- send "Exact nickname" "Test message"
Remove-Item Env:DOUYIN_ALLOW_SENDCLI 仅接受确切昵称,当找不到匹配或多个匹配时拒绝继续。
当 MCP 或 HTTP API 已持有同一配置文件锁时,请勿运行 CLI。
开发
npm run lint
npm test
npm run build
npm run smoke:mcp测试涵盖配置解析、结构化错误、配置文件锁定、页面操作串行化、快照过期、重复拒绝、目标验证、消息方向、干运行隔离、编辑器回滚、成功发送确认、未知发送状态、持久化速率限制和包安全默认值。
项目结构
src/
browser/ Browser lifecycle, profile locking, and operation serialization
douyin/ DouyinService, centralized selectors, and page objects
index.ts MCP stdio server
api.ts HTTP API process entry point
api/ Versioned HTTP routes, validation, and authentication
scripts/
login.ts QR-code login
status.ts Authentication status check
chat.ts Operator CLI
mcp-smoke.ts MCP transport smoke check
tests/unit/ Repeatable behavioral tests
RESEARCH.md Live-page evidence and engineering research许可证
根据宽松的 MIT 许可证 许可。
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
No tool schema history has been recorded yet.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Let AI tools securely access your LinkedIn network and DMs
Browser MCP for logged-in tasks. Uses your Chrome — credentials stay local. Zero-token replay.
Messaging tools for AI agents: send messages, manage chats, groups and channels.
Managed LinkedIn MCP server for AI agents: search, connect, message and enrich on accounts you own.
Related MCP Servers
- FlicenseBqualityDmaintenanceEnables automated interaction with Xiaohongshu (Little Red Book) social media platform through browser automation. Supports login management, status checking, and publishing text content with images to Xiaohongshu accounts.33-
- FlicenseNot gradedqualityDmaintenanceEnables automation of Douyin (TikTok China) tasks including parsing share links to get watermark-free download URLs and uploading videos from specified local paths.14-
- AlicenseNot gradedqualityDmaintenanceEnables automated Douyin video uploads and account management using Playwright for browser simulation. It supports QR code login, cookie persistence, and automated metadata handling for publishing videos through natural language or API commands.916MIT
- FlicenseNot gradedqualityDmaintenanceAutomates the Douyin Creator Platform to manage login states and publish image-text content via the MCP protocol. It enables users to check authentication status, manage cookies, and automate article publishing with titles, text, and images.-
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/3xian/douyin-dm-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server