MCPInstall

feishu-doc-writer

飞书文档写入。Markdown 转 Block、创建文档块、处理并发,支持 Mermaid 绘图块。

Installs
112
Last 24h
—
Trending rank
—
Security
Not audited

Install

Works with every agent the skills CLI supports.

npx skills add https://github.com/alextangson/feishu_skills --skill feishu-doc-writer
  1. 01

    Install

    Run the command in your project. The CLI asks which agents to install for.

  2. 02

    Describe the task

    Ask your agent for something this skill covers. It loads feishu-doc-writer automatically when relevant.

  3. 03

    Review the result

    The agent follows the SKILL.md steps, scripts and references bundled with the skill.

SKILL.md

The instructions your agent reads when the skill is triggered.

飞书文档写入

通过 Docx API 写入内容到飞书云文档。飞书文档使用 Block 树模型,不接受原始 Markdown。

Base URL: https://open.feishu.cn/open-apis/docx/v1

认证与 Token 获取

从 feishu_skills 根目录执行共享脚本:

TOKEN="$(./scripts/get_feishu_token.sh)"

请求头统一使用 Authorization: Bearer ${TOKEN}。

如果业务接口返回 token 无效、过期或 401,强制刷新后仅重试一次原请求:

TOKEN="$(./scripts/get_feishu_token.sh --force-refresh)"

环境变量:

  • FEISHU_APP_ID
  • FEISHU_APP_SECRET

本地缓存: ./.feishu_token_cache.json(未过期直接复用,默认提前 5 分钟刷新)


推荐方式:转换 API

飞书提供官方 Markdown → Blocks 转换端点:

POST /documents/{document_id}/convert
{
  "content": "# 标题\n\n正文\n\n- 列表项",
  "content_type": "markdown"
}

✅ 无需手动构建 Block JSON,支持标准 Markdown ⚠️ 不支持飞书特有块(Callout 等)— 需手动创建


Block 类型

block_type名称JSON Key说明
1页面page文档根节点
2文本text段落
3-11标题1-9heading1-heading9-
12无序列表bullet每项单独一个 block
13有序列表ordered-
14代码块code需指定 style.language
15引用quote-
17待办todo带 style.done
19高亮块callout飞书特有,容器块
22分割线divider-
27图片image两步:创建占位 + 上传
31表格table-

创建 Blocks

POST /documents/{document_id}/blocks/{block_id}/children?document_revision_id=-1
{
  "children": [...],
  "index": 0
}
  • block_id: 父块 ID(根节点用 document_id)
  • index: 插入位置(0=开头,-1=末尾)

删除 Blocks

删除父块下指定范围的子块:

DELETE /documents/{document_id}/blocks/{block_id}/children/batch_delete?document_revision_id=-1
{
  "start_index": 3,
  "end_index": 4
}
  • block_id: 要操作的父块 ID
  • start_index: 起始子块下标(包含)
  • end_index: 结束子块下标(不包含)
  • ⚠️ 该接口是 DELETE,不是 POST

Block 示例

文本:

{"block_type": 2, "text": {"elements": [{"text_run": {"content": "段落"}}]}}

标题:

{"block_type": 3, "heading1": {"elements": [{"text_run": {"content": "标题"}}]}}

代码块:

{
  "block_type": 14,
  "code": {
    "style": {"language": 1},
    "elements": [{"text_run": {"content": "console.log('hello')"}}]
  }
}

Mermaid 绘图块(插件块):

{
  "block_type": 40,
  "add_ons": {
    "component_type_id": "blk_631fefbbae02400430b8f9f4",
    "record": "{\"data\":\"flowchart TD\\nA-->B\",\"theme\":\"default\",\"view\":\"codeChart\"}"
  }
}
  • block_type = 40 表示插件块
  • component_type_id = blk_631fefbbae02400430b8f9f4 可用于 Mermaid 绘图
  • record 是字符串化 JSON,目前验证过的字段:
    • data: Mermaid 源码
    • theme: 通常用 default
    • view: 通常用 codeChart
  • 如果文档里已经有人手动插入过“本文绘图”格式的 Mermaid,优先先读取该块,再复用它的 component_type_id/theme/view

高亮块(Callout):

{
  "block_type": 19,
  "callout": {
    "background_color": 1,
    "border_color": 1,
    "emoji_id": "bulb"
  },
  "children": [
    {"block_type": 2, "text": {"elements": [{"text_run": {"content": "提示内容"}}]}}
  ]
}

图片(两步):

  1. 创建占位:{"block_type": 27, "image": {}}
  2. 上传:PUT /documents/{document_id}/blocks/{block_id}/image

文本样式

{
  "text_run": {
    "content": "样式文本",
    "text_element_style": {
      "bold": true,
      "italic": true,
      "strikethrough": true,
      "underline": true,
      "inline_code": true,
      "background_color": 1,
      "text_color": 1
    }
  }
}

并发处理

飞书文档支持多人协作,需处理并发:

  1. 获取最新 revision: GET /documents/{document_id}
  2. 带 revision 写入: ?document_revision_id={revision}
  3. 冲突时重试(HTTP 409)

Mermaid 推荐流程

当用户要求“按本文绘图格式统一 Mermaid”时,不要直接写普通文本块或代码块里的 ```mermaid。

推荐顺序:

  1. 先读取目标文档所有块,确认是否已存在人工调整好的 Mermaid 绘图块
  2. 如果存在,读取该块的:
    • block_type
    • add_ons.component_type_id
    • add_ons.record
  3. 复用同样的绘图块结构创建新图,而不是继续写 code 块
  4. 新图创建成功后,再删除旧的 Mermaid 代码块,避免文档里同时保留两套内容

适用场景:

  • 用户已经把某一张 Mermaid 图手动改成了理想样式,要求“其他图也改成这种格式”
  • 需要让多张流程图在同一篇 Docx 中保持一致视觉效果

实战建议

  1. 普通结构优先用文本块/标题块
  2. 代码展示用 block_type = 14
  3. 流程图展示优先用 Mermaid 插件块,不要把 ```mermaid 当最终呈现形式
  4. 替换旧图时,先插入新块,再删除旧块,避免内容丢失
  5. 涉及批量替换时,先读取父块 children 顺序,再按 index 精确删除

最佳实践

  1. 优先用转换 API(简化开发)
  2. 批量创建 blocks(减少 API 调用)
  3. 处理并发冲突(带 revision 参数)
  4. 图片分两步(占位 + 上传)
  5. Mermaid 图优先复用现有插件块格式

FAQ

What does the feishu-doc-writer skill do?

飞书文档写入。Markdown 转 Block、创建文档块、处理并发,支持 Mermaid 绘图块。

How do I install feishu-doc-writer?

Run npx skills add https://github.com/alextangson/feishu_skills --skill feishu-doc-writer in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/feishu-doc-writer/ (personal) or .claude/skills/feishu-doc-writer/ (project).

Which AI agents can use feishu-doc-writer?

Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.

Is feishu-doc-writer safe to install?

No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.

Who maintains feishu-doc-writer?

It is published by alextangson in alextangson/feishu_skills. It has 112 recorded installs.

More from alextangson/feishu_skills

View all →

feishu-calendar

alextangson/feishu_skills

飞书日历。创建日程、查询日程、更新日程。

feishu-bitable

alextangson/feishu_skills

飞书多维表格操作。记录 CRUD、字段管理、视图、权限、公式、关联。

feishu-card

alextangson/feishu_skills

Open the skill to read its SKILL.md instructions.

feishu-im

alextangson/feishu_skills

飞书消息与群管理。发送消息、建群、置顶、加急、撤回、群菜单/Tab/公告。

feishu-task

alextangson/feishu_skills

Open the skill to read its SKILL.md instructions.

feishu-approval

alextangson/feishu_skills

飞书审批。创建审批实例、查询审批状态。

Popular docs & writing skills

View category →

grill-with-docs

mattpocock/skills

A relentless interview to sharpen a plan or design, which also creates docs (ADR's and glossary) as we go.

Docs & Writing1.2M installs

lark-markdown

open.feishu.cn

飞书 Markdown:查看、创建、上传、编辑和比较飞书中的原生 Markdown 文件。当用户要操作飞书 Markdown 文件,或比较其远端版本及本地草稿时使用。纯本地 Markdown 文件操作不触发本 skill。不负责将 Markdown 导入为飞书在线文档,也不负责文件搜索、权限、评论、移动、删除等云空间管理操作。

Docs & Writing778.7K installs

writing-beats

mattpocock/skills

Writing, exploit; assemble raw material into a journey of beats, grounding each term before a beat leans on it.

Docs & Writing490.7K installs

writing-shape

mattpocock/skills

Writing, exploit: shape raw material into an article, paragraph by paragraph.

Docs & Writing490.2K installs

writing-fragments

mattpocock/skills

Writing, explore: mine raw fragments, no structure yet.

Docs & Writing489.6K installs

writing-for-agents

mattpocock/skills

Writing documents for agents. Use when creating or editing skills, or modifying AGENTS.md or CLAUDE.md.

Docs & Writing479.3K installs