AI 接入指南
拾墨 (ShiMo) 的三种 AI 接入方式 —— MCP Server、REST API 与 Agent Skill 完整配置参考
AI 接入指南
拾墨为 AI Agent 提供三种原生接入路径,按推荐顺序排列:
方式一:MCP Server(推荐)
MCP (Model Context Protocol) 是最推荐的接入方式,无需手动启动任何服务,AI 客户端通过 stdio 直接调用。
注册到 Claude Code
在项目根目录创建 .mcp.json(与 package.json 同级):
{
"mcpServers": {
"shimo": {
"type": "stdio",
"command": "bun",
"args": ["run", "<shimo项目根目录>/server/mcp.ts"]
}
}
}注册到 Claude Desktop
编辑 ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"shimo": {
"command": "bun",
"args": ["run", "<shimo项目根目录>/server/mcp.ts"]
}
}
}重启 Claude Desktop 后,即可在对话中直接调用 format_wechat_article 工具。
工具说明
| 工具名 | 说明 |
|---|---|
format_wechat_article | 将 Markdown 转换为微信公众号兼容的内联样式 HTML |
format_wechat_article 参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
markdown | string | 是 | 原始 Markdown 文本(最大 200KB) |
theme | string | 否 | 主题 ID,默认 elegant |
方式二:REST API
启动 bun run dev 后,渲染接口随主应用一同启动于 localhost:3000,无需单独运行后端进程。
端点
POST http://localhost:3000/api/render
请求体
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
markdown | string | 是 | 原始 Markdown 文本(最大 200KB) |
theme | string | 否 | 主题 ID,默认 elegant |
示例
curl -X POST http://localhost:3000/api/render \
-H "Content-Type: application/json" \
-d '{"markdown": "# 壹· 标题\n\n正文内容。", "theme": "spec"}'成功响应 (200):
{
"html": "<section id=\"we-article\" style=\"...\">...</section>"
}主题列表
| Theme ID | 中文名 | 适用场景 |
|---|---|---|
spec | 规格 | 技术/教程/开发者文章(推荐) |
elegant | 典雅 | 人文/随笔/文化 |
vibrant | 活力 | 年轻化/营销/生活方式 |
minimalist | 极简 | 商务/简报 |
tech | 科技 | 科技资讯/产品 |
comic | 漫画 | 趣味/娱乐 |
hand-drawn | 手绘 | 创意/手工 |
方式三:Agent Skill 文件
对于支持 Skill 系统的 AI Agent 框架(如 Antigravity),可直接安装以下 Skill 文件。
安装方式
将以下内容保存为 skills/shimo-formatter/SKILL.md:
---
name: shimo-formatter
description: 使用拾墨 (ShiMo) 将 Markdown 转换为微信公众号 HTML。当用户提到"微信格式化"、"公众号排版"、"转换为微信 HTML"、"format for WeChat"、"微信文章"时触发。即使用户没有明确说"拾墨",只要目标是微信公众号发布,也应使用本技能。
---
# ShiMo Formatter
将 Markdown 转换为可直接粘贴到微信公众号编辑器的内联样式 HTML。
## 调用方式
**优先**:检查 MCP 工具列表中是否有 `format_wechat_article`,有则直接调用。
**备选**:通过 REST API 调用(需要在项目根目录先运行 `bun run dev`):
```bash
curl -X POST http://localhost:3000/api/render \
-H "Content-Type: application/json" \
-d '{"markdown": "<内容>", "theme": "spec"}'
```
## 主题选择
| 场景 | 推荐主题 |
| :--- | :--- |
| 技术/教程/开发者文章 | `spec`(默认)|
| 人文/随笔/文化 | `elegant` |
| 年轻化/营销/生活 | `vibrant` |
| 未指定 | `spec` |
其余可选:`minimalist` `tech` `comic` `hand-drawn`
## 执行步骤
1. 读取 Markdown 文件或接收用户提供的内容
2. 选择合适主题(未指定时用 `spec`)
3. 调用 MCP 工具或 REST API 获取 HTML
4. 将 `html` 字段完整写入 `<原文件名>-wechat.html`,不要修改内容
5. 告知用户:浏览器打开该文件 → 全选(⌘A)→ 复制 → 粘贴至微信编辑器渲染流程说明
了解数据如何被处理:
- Markdown AST —
remark-parse+remark-gfm解析为 AST - WeChat 增强 — 8 个自定义 rehype 插件处理警示框、代码块、列表、分割线等
- HTML 转换 —
rehype-stringify输出 HTML 字符串 - CSS 内联 —
juice将主题 CSS 全部注入style=""属性 - 输出 —
<section id="we-article">包裹的自包含 HTML,可直接粘贴微信编辑器
源码位置
app/api/render/route.ts ← Next.js Route Handler
lib/render.ts ← unified 管道 + juice 内联逻辑
lib/themes.ts ← CSS 主题加载器
lib/plugins/ ← 8 个自定义 rehype 插件
server/mcp.ts ← MCP Server 入口
skills/shimo-formatter/SKILL.md ← AI Agent Skill