csdn-blog-mcp
Automates authoring and publishing of CSDN blog posts. Generates SEO-optimized markdown scaffolds in six style presets, packages content with front-matter into local drafts, scores drafts for SEO (0-100 with suggestions), and publishes to CSDN via browser automation — filling the title, pasting the body, selecting tags/category/visibility, and returning the article URL (defaults to saving in the CSDN draft box). Also handles CSDN login/session management (login, check, clear), editor selector diagnostics, rate limiting for direct publishes, and retrieval of published article stats (views, likes, comments, favorites) through CSDN's public API.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@csdn-blog-mcp write a blog post about Python decorators and check its SEO"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
📝 csdn-blog-mcp — CSDN 博文自动写作与发布 MCP
语言 / Languages: 简体中文 | English
一个 MCP(Model Context Protocol)服务器,让 AI Agent(Cursor、Claude 等)成为 CSDN 博客的写作 + 发布助手——生成 SEO 优化的博文骨架、打包保存草稿、SEO 自检、再通过浏览器自动化一键推送到 CSDN 草稿箱。它还能从你已发布的博文里提炼写作风格,让 AI 按你的语气写。
基于 FastMCP 构建,发布走 Playwright 浏览器自动化路线,跨平台支持 Windows / macOS / Linux。
⭐ 如果这个项目帮到你,欢迎去仓库点个 Star 支持一下~ 👉 https://gitee.com/gdouage/csdn-mcp 你的一颗星,是个人开发者继续更新的最大动力 ❤️
仓库 | |
协议 | |
作者 | abbuibuibui |
联系 |
⚠️ 重要风险提示 CSDN 没有公开的博文发布 API,本工具通过浏览器自动化模拟人工操作发布。
CSDN 用户协议禁止「使用未经授权的自动化程序发布内容」,请知悉风险。
内置频率限制(默认每天 2 篇、间隔 ≥ 30 分钟)以降低封号风险。
登录/发布可能触发验证码,需人工介入。
CSDN 编辑器改版会导致选择器失效,失败时会自动截图存证。
📌 项目介绍
能力 | 说明 |
写博文 | 生成 SEO 优化的 markdown 骨架(6 种风格预设),打包正文 + front-matter 保存为草稿 |
风格对齐 | 从你已发布的博文提炼写作风格,AI 按你的语气写(不套个人化称呼) |
SEO 自检 | 标题长度/关键词前置、摘要、关键词密度、H2/H3 层级、代码块语言、图片 alt、标签数,0-100 评分 |
草稿管理 | 列出 / 读取 / 删除本地草稿,统一存放在 drafts/ |
发布 CSDN | Playwright 自动化打开编辑器、填标题、粘正文、选标签/分类/可见性、点发布、读回文章 URL |
登录管理 | 首次可见浏览器登录保存 session,之后 headless 发布;可检查/清除登录态 |
文章统计 | 通过 CSDN 公开接口读取阅读/点赞/评论/收藏数(无需登录) |
频率限制 | 内置每天发文上限 + 最小间隔,可查询当前状态 |
核心流程:
get_style_guide → generate_blog_scaffold → 填充正文 → write_blog → seo_check → csdn_login(首次) → publish_csdn → csdn_statsRelated MCP server: Hexo Blog MCP Server
🏗️ 项目架构
┌──────────────────────────────────────────────┐
│ AI Agent (Cursor / Claude) │
│ 通过 MCP 协议调用 │
└──────────────────────┬───────────────────────┘
│
▼
┌──────────────────────────────────────────────┐
│ csdn-blog-mcp Server │
│ (FastMCP, 14 个工具) │
├──────────┬──────────┬──────────┬──────────────┤
│ 写博文 │ 草稿库 │ 发布登录 │ 统计/限流 │
│ (4 tools)│ (3 tools)│ (5 tools)│ (2 tools) │
├──────────┴──────────┴──────────┴──────────────┤
│ 底层能力 │
│ Markdown 解析 │ YAML front-matter │ Playwright │
└──────────────────────────────────────────────┘
│
▼
┌──────────────────────────────────────────────┐
│ CSDN 网页编辑器 / 公开统计 API │
└──────────────────────────────────────────────┘目录结构:
csdn-blog-mcp/
├── src/csdn_blog_mcp/
│ ├── server.py # MCP 服务入口 + 工具注册
│ ├── writer.py # 写博文:generate_blog_scaffold / write_blog
│ ├── seo.py # SEO 自检:seo_check
│ ├── library.py # 草稿库:list / read / delete
│ ├── auth.py # 登录态:check_login / login / clear_session
│ ├── publisher.py # 发布:publish_csdn(Playwright 方案 A)
│ ├── stats.py # 统计:csdn_stats(公开 API)
│ ├── style.py # 风格指南加载:get_style_guide
│ ├── util.py # run_in_thread:让浏览器工具绕开 MCP 的 asyncio 循环
│ └── config.py # 路径 / cookie 存储 / 频率限制
├── STYLE_GUIDE.md # 从作者博文提炼的写作风格提示词(MCP 自用)
├── drafts/ # 本地草稿存放处(git 忽略)
├── pyproject.toml
├── .gitignore
├── README.md # 中文(默认,Gitee 首页展示)
└── README.en.md # English🛠️ 技术栈与依赖
层级 | 技术 |
协议 | MCP (Model Context Protocol) |
框架 | FastMCP |
语言 | Python 3.12+ |
浏览器自动化 | Playwright (Chromium) |
HTTP 请求 | httpx(统计接口) |
构建系统 | setuptools |
🚀 快速开始
1. 环境要求
Python 3.12+
支持 MCP 的 AI 客户端(Cursor、Claude Desktop 等)
发布功能需安装 Playwright 浏览器内核(见下)
2. 获取代码
git clone https://gitee.com/gdouage/csdn-mcp.git
cd csdn-mcp3. 安装
# 创建虚拟环境
python -m venv .venv
# Windows
.venv\Scripts\pip install -e .
.venv\Scripts\playwright install chromium
# macOS / Linux
.venv/bin/pip install -e .
.venv/bin/playwright install chromium
playwright install chromium会把浏览器内核下到本机缓存目录(Windows 是%LOCALAPPDATA%\ms-playwright,macOS/Linux 是~/.cache/ms-playwright),不在项目里,跨平台自动适配。
4. 配置 MCP 客户端
Cursor
添加到 ~/.cursor/mcp.json(把 <项目路径> 换成你本机的实际路径):
{
"mcpServers": {
"csdn-blog-mcp": {
"command": "<项目路径>/.venv/Scripts/python.exe",
"args": ["-m", "csdn_blog_mcp.server"],
"env": {
"PYTHONPATH": "<项目路径>/src"
}
}
}
}macOS / Linux 把
Scripts/python.exe换成bin/python。 可选环境变量CSDN_BLOG_HOME:自定义草稿/cookie 存放目录(默认项目根目录)。
5. 首次登录 CSDN 🎬
让 AI 调用 csdn_login,会弹出一个浏览器,手动登录 CSDN(首次必须可见,可能遇验证码)。登录成功后 session 自动保存,之后发布就能 headless 跑。重启 Cursor,MCP 服务自动启动。
📡 14 个工具一览
写博文(4 个)
工具 | 功能 |
| 返回从作者已发布博文提炼的写作风格提示词(语气、两种文章类型、标题/开头/结构/必备元素/SEO),写文前先调它对齐风格 |
| 生成 SEO 优化的 markdown 骨架(6 种风格:开源项目介绍/保姆级教程/技术教程/原理分析/踩坑笔记/通用) |
| 打包正文 + YAML front-matter,保存为本地草稿 |
| 分析草稿 SEO,返回 0-100 评分 + 改进建议 |
草稿库(3 个)
工具 | 功能 |
| 列出本地草稿(按时间倒序) |
| 读取草稿内容 + 元数据 |
| 删除草稿 |
发布与登录(5 个)
工具 | 功能 |
| 用已保存 session 检查是否仍登录 |
| 打开可见浏览器手动登录,保存 session |
| 清除已保存 session |
| 浏览器自动化把草稿发到 CSDN:默认存草稿箱(不公开), |
| 探测 CSDN 编辑器各关键元素,报告每个选择器是否命中—— |
统计与限流(2 个)
工具 | 功能 |
| 读取已发布文章的阅读/点赞/评论/收藏数(公开 API) |
| 查询当前发文频率限制状态 |
📝 典型工作流
场景 1:从零写一篇并发布
get_style_guide() # 先读风格提示词,对齐作者语气/结构
generate_blog_scaffold("Playwright 自动化", ["playwright","python","爬虫"], "tutorial")
→ 拿到骨架,AI 按风格指南填充正文
write_blog(topic="Playwright 自动化完全指南", content=<填充后的正文>, tags=[...])
→ 保存草稿,拿到 file_path
seo_check(file_path)
→ 看评分,按建议修改
csdn_login() # 首次登录(会弹浏览器,手动登录)
publish_csdn(file_path) # 默认存入 CSDN 草稿箱(不公开)
# 审阅满意后,在 CSDN 后台手动点发布;或 publish_csdn(file_path, as_draft=False) 直接发
csdn_stats(article_url) # 直接发布后看数据场景 2:只写不发(零风险)
get_style_guide → generate_blog_scaffold → 填充 → write_blog → seo_check
# 草稿留在 drafts/,手动复制到 CSDN 编辑器发布(5 秒的事)场景 3:发布前检查登录与限流
rate_limit_status() # 今天还能发吗?
check_csdn_login() # session 还有效吗?
publish_csdn(file_path) # 都 OK 再发💡 设计说明
写作零风险:
get_style_guide/generate_blog_scaffold/write_blog/seo_check纯本地文本处理,不碰网络风格对齐:从作者已发布博文提炼写作风格,但不套个人化称呼(如"小b"),保持中性语气
发布走方案 A:Playwright 模拟人工操作 CSDN 网页编辑器,不碰内部 API,封号风险最低
默认存草稿箱:
publish_csdn默认as_draft=True,只存到 CSDN 在线草稿箱不公开,你审阅后再手动发布session 持久化:登录态存为 Playwright 标准 storageState JSON,git 忽略,过期提示重登
频率限制:仅对直接发布生效(默认每天 2 篇、间隔 ≥ 30 分钟);存草稿箱不限频
失败存证:发布失败自动截图到
.cookies/screenshots/,方便排查选择器失效选择器集中:
publisher.py顶部SELECTORS字典统一管理,关键元素配多组回退选择器,CSDN 改版只需改这里抗 UI 漂移:固定视口 + 网络层广告拦截 + 弹层自动关闭 + 多选择器回退 + 鲁棒点击重试,缓解分辨率变化/广告/小改版导致的失效
自诊断:
diagnose_editor探测编辑器各元素命中情况,publish_csdn失败时跑它定位是哪个选择器被改版了绕开 asyncio 循环:MCP 服务在 asyncio 事件循环里跑工具函数,而 Playwright 的 sync API 拒绝在运行中的循环里启动;
util.run_in_thread装饰器检测到循环时把浏览器工具丢到独立线程执行,无循环时(独立脚本)直接跑,零开销正文用剪贴板粘贴:往 CSDN 编辑器逐字符
keyboard.type会触发自动缩进/自动列表,把 markdown 弄乱(列表-变- -、代码块缩进失控);改为写剪贴板后Ctrl+V一次性粘贴,保留原始 markdown 结构拟人节奏:每步操作间随机延迟 0.8-2.2 秒,降低风控触发概率
⚠️ 风险与合规
风险 | 说明 | 应对 |
封号 | CSDN 对批量发文有风控 | 默认每天 2 篇、间隔 30 分钟、内容差异化 |
验证码 | 登录/发布可能弹滑块验证码 | 自动化过不了,需人工介入(csdn_login 弹浏览器) |
ToS | 协议禁止未授权自动化发布 | 方案 A 风险最低;默认只存草稿箱 |
UI 漂移 | CSDN 编辑器改版 | 多选择器回退 + 失败截图存证 + |
最务实路径:先只用「写博文」部分(零风险),发布那一下保留人工点击。稳定运行后再开自动发布。
💬 反馈与贡献
如果这个项目对你有帮助,拜托:
⭐ 去仓库点个 Star:csdn-mcp
🐛 遇到问题提 Issue
✉️ 想交流可发邮件:3244940576@qq.com(作者:abbuibuibui)
也欢迎提交 Pull Request(请先说明改动目的与测试方式)~
📄 许可证
本项目基于 MIT License 开源。
Copyright (c) 2026 abbuibuibuiAvailable Tools
14 toolstool_check_csdn_loginA
Check whether the saved CSDN session is still logged in.
Opens a browser (headless by default), loads www.csdn.net with the saved storage state, and reports login status. Call this before publish_csdn to avoid a failed publish due to an expired session.
Args: headless: Run headless (default True for a quick check).
Returns: dict with {ok, logged_in, needs_login, saved_session, message}
Inputs: headless.
tool_clear_csdn_sessionA
Delete the saved CSDN session (forces a fresh login next time).
Returns: dict with {ok, message}
Inputs: no named parameters.
tool_csdn_loginA
Open a visible browser to log into CSDN and save the session.
First-time login MUST be visible (headless=False) so you can solve any captcha. After login is detected, the cookies + localStorage are saved so publish_csdn can run headless later. Complete the login in the browser window that opens.
Args: headless: Must be False for first login (kept for flexibility). timeout_ms: How long to wait for login (default 3 minutes).
Returns: dict with {ok, message, saved, path?}
Inputs: headless, timeout_ms.
tool_csdn_statsA
Fetch view/like/comment/collect counts for a published CSDN article.
Uses CSDN's public article-detail JSON endpoint (no login required). Call this after publish_csdn to track how a post is doing.
Args: article_url: Full CSDN article URL (e.g. https://blog.csdn.net//article/details/).
Returns: dict with {ok, article_url, article_id, title, views, likes, comments, collects, publish_time}
Inputs: article_url (required).
tool_delete_draftB
Delete a draft markdown file from the local drafts folder.
Args: file_path: Absolute path or filename of the draft to delete.
Returns: dict with {ok, message, file_path}
Inputs: file_path (required).
tool_diagnose_editorA
Diagnose the CSDN markdown editor to detect UI drift / broken selectors.
Opens the CSDN editor with your saved session and probes every key element (title display/input, content editor, save-draft button/item, publish button, tag/category inputs, dialog publish button). For each selector it reports which fallback matched (or none), so when publish_csdn starts failing you can run this to see exactly which selectors CSDN changed and update SELECTORS in publisher.py accordingly.
Requires a saved session — call csdn_login first.
Args: headless: Run headless (default True). Set False to watch. timeout_ms: Per-action timeout in milliseconds.
Returns: dict with {ok, url, results: {element: matched_selector | null}, needs_login?, message?}
Inputs: headless, timeout_ms.
tool_generate_blog_scaffoldA
Generate an SEO-optimized markdown scaffold for a CSDN blog post.
Returns a markdown skeleton tuned for CSDN ranking: keyword-front-loaded title ideas, H2/H3 hierarchy, intro hook, code-block placeholders, and suggested tags. Use this BEFORE writing to get a good structure, then fill it in and pass the result to write_blog.
Tip: call get_style_guide first so the filled-in content matches the author's voice.
Args: topic: The blog topic / subject. keywords: SEO keywords (the first one is front-loaded into title ideas). style: Writing style preset — "intro" (开源项目/MCP 介绍文), "tutorial" (保姆级部署教程), "technical", "analysis", "notes", or "general". tags: Optional pre-chosen tags; otherwise suggested from keywords.
Returns: dict with {ok, topic, style, title_suggestions, tags_suggested, scaffold}
Inputs: topic (required), tags, style, keywords.
tool_get_style_guideA
Return the CSDN writing style guide (the MCP's own prompt).
The guide was distilled from the author's published CSDN posts and documents the tone (address reader '你', casual but neutral, no personal persona), the two article types (intro vs. step-by-step tutorial), title patterns, opening hooks, required elements (tables, code blocks, emoji headers, '注意!' callouts, Star solicitation), SEO rules, and what to avoid. Call this BEFORE generate_blog_scaffold / write_blog so content matches the author's style.
Returns: dict with {ok, path, guide} on success, or {ok, message} if missing.
Inputs: no named parameters.
tool_list_draftsA
List all draft blog posts in the local drafts folder (newest first).
Returns each draft's filename, title, summary, tags, created timestamp, and size. Use this to see what's ready to publish.
Returns: dict with {ok, drafts: [...], count}
Inputs: no named parameters.
tool_publish_csdnA
Send a local draft to CSDN via browser automation (Plan A).
By default (as_draft=True) saves the article to CSDN's online 草稿箱 (draft box) WITHOUT publishing — you then review it in the browser and publish manually. Set as_draft=False to publish directly (public immediately, returns the article URL).
Fills the CSDN markdown editor: title, body, tags, category, visibility, then clicks 存草稿 or 发布文章. Direct publish enforces a rate limit (default 2/day, min 30 min apart) to avoid anti-automation flags; saving drafts is not rate-limited.
Requires a saved session — call csdn_login first. If the session expired, returns needs_login=True so you can re-run csdn_login.
WARNING: This drives CSDN's web UI. Selectors may break when CSDN changes its editor; a screenshot is saved on failure to help diagnose. Respect CSDN's terms — keep frequency low and content genuine.
Args: file_path: Absolute path to the draft .md file (from write_blog). tags: Override tags from the draft's front-matter (3-5 recommended). category: Override CSDN category (e.g. "后端"). visibility: Override visibility — "public", "private", or "fans" (only meaningful when as_draft=False). as_draft: True (default) = save to CSDN draft box, not public. False = publish directly and return the article URL. headless: Run headless (default True). Set False to watch the action. timeout_ms: Per-action timeout in milliseconds. skip_rate_limit: Bypass the rate limit (use with care — risks a ban). Only applies when as_draft=False.
Returns: dict with {ok, as_draft, message, title, draft_manage_url?, article_url?, screenshot?, needs_login?}
Inputs: file_path (required), tags, as_draft, category, +4 more.
tool_rate_limit_statusA
Check the current publish rate-limit status without publishing.
Returns whether a new publish is allowed, today's count, the last publish timestamp, and minutes since the last publish.
Returns: dict with {allowed, reason, today_count, last_publish_ts, minutes_since_last}
Inputs: no named parameters.
tool_read_draftA
Read a draft markdown file and return its content + parsed metadata.
Args: file_path: Absolute path, or just a filename resolved against the drafts folder.
Returns: dict with {ok, file_path, title, summary, tags, category, keywords, visibility, status, created, content}
Inputs: file_path (required).
tool_seo_checkA
Analyze a draft markdown file for CSDN SEO issues before publishing.
Checks title length & keyword placement, summary, keyword density, H2/H3 hierarchy, word count, code-block language hints, image alt text, and tag count. Returns a 0-100 score with actionable warnings.
Args: file_path: Absolute path to the draft .md file.
Returns: dict with {ok, score, checks, fail_count, warn_count, suggestions, summary}
Inputs: file_path (required).
tool_write_blogA
Package blog content into a CSDN-ready markdown file and save it.
Adds YAML front-matter (title, summary, tags, category, keywords, style,
visibility, timestamps) and writes the file to the local drafts folder.
The publish_csdn tool reads this same file later. If content already has
front-matter, the arguments override individual fields. If summary is
empty, it is auto-extracted from the first paragraph.
Args: topic: Blog title (used as H1 and filename slug if filename is empty). content: Markdown body. May include leading front-matter (--- ... ---). keywords: SEO keywords for the front-matter. tags: CSDN tags (3-5 recommended). category: CSDN category, e.g. "后端", "前端", "运维", "AI". summary: Article summary; auto-extracted if empty. style: Writing style (informational; stored in front-matter). visibility: "public", "private", or "fans". filename: Override filename (without .md). Auto-generated if empty. overwrite: If True, overwrite an existing draft with the same name.
Returns: dict with {ok, file_path, filename, title, summary, tags, category, visibility, bytes}
Inputs: topic (required), content (required), tags, style, +6 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 14 tools
Each tool has a distinct purpose: session tools (login/check/clear), draft CRUD (list/read/write/delete), pre-writing helpers (style guide vs scaffold), publishing, diagnostics, stats, and rate limiting are all cleanly separated. The only near-pair (get_style_guide vs generate_blog_scaffold) is clearly differentiated as voice guidance vs structural skeleton. No two tools appear interchangeable.
Most names follow a verb_noun pattern (get_style_guide, write_blog, list_drafts, read_draft, delete_draft, publish_csdn, diagnose_editor). A few deviate with noun-first or noun_verb forms (csdn_login, csdn_stats, seo_check, rate_limit_status), and the uniform 'tool_' prefix is a wrapper artifact. Still readable and mostly predictable.
14 tools is well-scoped for a full draft-to-publish workflow: prep (style/scaffold/SEO), local draft management, session handling, publishing, and post-publish tracking. Each tool earns its place with no obvious redundancy.
The write → SEO check → publish → track lifecycle is well covered, plus session and rate-limit management. Minor gaps exist: no dedicated draft-edit/update tool (relying on write_blog's overwrite flag) and no tool to list or manage already-published articles beyond per-URL stats.
Maintenance
Related MCP Connectors
Draft SEO blog articles from topic to ready-to-review post.
Live SEO workflow tools for Claude Code, Codex, and AI agents.
Google rank and AI Overview checks with no key. With an API key, write and publish SEO articles.
SEO & marketing toolkit for AI agents: GA4, Search Console, AdSense, GTM, PageSpeed, Trends.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to publish content to XiaoHongShu (Little Red Book) social platform, including checking login status and posting with titles, content, images, and hashtags through browser automation.4ISC
- AlicenseAqualityDmaintenanceEnables AI clients to manage Hexo blogs by providing tools for article CRUD operations, local previewing, and GitHub Pages deployment. It also supports site configuration access and automated Git backups to streamline the entire blogging workflow.121MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to automatically publish photo notes to Xiaohongshu (RedNote) using Playwright browser automation. It supports title, body, and image uploads while maintaining persistent login sessions for seamless automated posting.1MIT
- FlicenseNot gradedqualityBmaintenanceEnables AI clients to automate Xiaohongshu through Playwright, including login, searching and retrieving notes/comments/feeds, analyzing images, interacting via comments/likes/favorites, and publishing or deleting notes with anti-detection measures.17-