拾墨 ShiMo

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 参数

参数类型必填说明
markdownstring原始 Markdown 文本(最大 200KB)
themestring主题 ID,默认 elegant

方式二:REST API

启动 bun run dev 后,渲染接口随主应用一同启动于 localhost:3000,无需单独运行后端进程。

端点

POST http://localhost:3000/api/render

请求体

字段类型必填说明
markdownstring原始 Markdown 文本(最大 200KB)
themestring主题 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)→ 复制 → 粘贴至微信编辑器

渲染流程说明

了解数据如何被处理:

  1. Markdown ASTremark-parse + remark-gfm 解析为 AST
  2. WeChat 增强 — 8 个自定义 rehype 插件处理警示框、代码块、列表、分割线等
  3. HTML 转换rehype-stringify 输出 HTML 字符串
  4. CSS 内联juice 将主题 CSS 全部注入 style="" 属性
  5. 输出<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