Search K
Appearance
让 AI 智能体通过 Chrome WebMCP 协议,直接帮你把文章写入博客。写完后无需重启服务器,新文章立即可访问。
任何能连接 Chrome DevTools Protocol (CDP) 的 AI 都可以通过本页面为博客写文章。
AI 需要先让 Chrome 暴露调试接口。关闭所有 Chrome 窗口,然后用命令行重新启动:
Windows:
"C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222macOS:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222Linux:
google-chrome --remote-debugging-port=9222启动后,访问 http://localhost:9222/json 能看到所有打开的标签页列表,说明连接成功。
在 Chrome 中打开本页面:
https://www.zhangjy.top/03.随笔杂谈/03.AI写作助手等一下让页面加载完,F12 → Application → WebMCP 面板会显示两个已注册的工具。
连接到 localhost:9222 后,AI 通过 CDP 的 Runtime.evaluate 在页面中执行 JavaScript:
先获取工具列表:
// AI 通过 CDP Runtime.evaluate 执行:
navigator.modelContext.getTools()调用 list_blog_categories:
// 通过 CDP Runtime.evaluate 或者 WebMCP.invokeTool 执行:
const mc = navigator.modelContext
const tools = await mc.getTools()
const cat = tools.find(t => t.name === 'list_blog_categories')
JSON.parse(await mc.executeTool(cat, '{}'))调用 write_blog_post:
const mc = navigator.modelContext
const tools = await mc.getTools()
const tool = tools.find(t => t.name === 'write_blog_post')
await mc.executeTool(tool, JSON.stringify({
category: "随笔杂谈",
title: "文章标题",
content: `---
title: 文章标题
date: 2026-06-07
categories:
- 随笔杂谈
tags:
- 标签
---
# 文章正文`
}))1. 用户告诉 AI:"帮我写一篇关于 XXX 的文章"
2. AI 确认 Chrome 已用 --remote-debugging-port=9222 启动
3. AI 通过 CDP 连接到 localhost:9222
4. AI 打开或定位到本页面
5. AI 执行 getTools() 确认工具可用
6. AI 调用 list_blog_categories 获取分类
7. AI 撰写 Markdown 内容(含 frontmatter)
8. AI 调用 write_blog_post 写入
9. 等待约 6 秒,文章出现在博客首页executeTool 第二个参数必须传 JSON 字符串(JSON.stringify()),不能传 JS 对象content 必须包含 YAML frontmatter,否则不会出现在文章列表list_blog_categories 返回的完全一致--remote-debugging-port=9222 是 AI 连接的唯一入口list_blog_categories列出博客可用的文章分类文件夹
write_blog_post将 Markdown 文章写入指定分类,自动编号、补全 frontmatter