mcpField
D
drawspec

drawspec

本地服务
github.com/nuncaeslupus媒体与设计03 天前更新

关于 drawspec

drawspec 将语义化 JSON 描述转换为无需坐标的图表,面向语言模型和需要稳定图表输出的作者。它支持多种图表类型,并可验证描述,再生成 SVG、PNG 或纯文本。

主要功能

  1. 01无需坐标的 JSON 图表描述
  2. 02支持 30 多种图表类型
  3. 03验证错误定位到 JSON 字段
  4. 04生成 SVG、PNG 和纯文本
  5. 05通过 TOML 或 CSS 设置主题

适用场景

  1. 01根据 JSON 规格渲染流程图
  2. 02验证模型生成的图表描述
  3. 03无需手动定位元素即可创建时序图
  4. 04为终端或代码块输出文本图表

MCP 相关

可选的 drawspec-mcp 包提供列出图表类型、获取示例和 Schema、验证文档及渲染图表的工具。验证错误以结构化数据返回,供客户端处理。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"nuncaeslupus-drawspec": {
"command": "uvx",
"args": [
"drawspec"
]
}
}
}
启动命令uvx drawspec

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
pypidrawspec0.4.3

工具

5

收录的工具列表 · 更新于 1 周前

此工具无需参数。

详细介绍

README 配图 drawspec

PyPI License: MIT drawspec MCP server – quality and maintenance score on Glama drawspec on mcprush

Built with claude-arsenal

drawspec:一张蓝图,包含品牌字标、JSON 流程规范以及 drawspec 根据它绘制的流程图;字标后方有淡淡的大型维恩图和饼图,旁边还有 drawspec 绘制的思维导图和项目文件树,以及 drawspec 的文本输出——一张小型序列图,分别以框线字符和 ASCII 绘制

根据 JSON 描述绘制图表——无需坐标,不会放错位置。 你只需描述图表的含义:方框、箭头、标签,以及它们各自的角色。drawspec 会决定每个元素的位置、大小、路径和颜色,并绘制出简洁的 SVG、PNG 或纯文本图表。

它首先是为大模型打造的。手写 SVG 的 LLM 能写对内容,却常常放错位置——箭头没指到方框、文本溢出、线条未能接上。drawspec 文档没有容易写错的 x、y 或字体大小字段:这些字段会被拒绝,任何错误都会返回并准确指出问题字段,让模型修正后重试。

pip install drawspec
drawspec render diagram.json -o diagram.svg

浏览图集:绘制 30 多种图表 →

示例

你编写:

{
  "$schema": "https://nuncaeslupus.github.io/drawspec/schema/drawspec-v1.schema.json",
  "version": 1,
  "kind": "flow",
  "title": "The nightly import",
  "description": "The vendor's export is fetched, checked and loaded into staging before it replaces the live table; a timeout and a deadlock are each retried in place.",
  "nodes": [
    {"id": "fetch", "text": "Fetch the vendor's export", "role": "start"},
    {"id": "check", "text": "Do the row counts match?", "role": "decision"},
    {"id": "load", "text": "Load into staging"},
    {"id": "page", "text": "Page the data owner", "role": "terminal"},
    {"id": "swap", "text": "Swap staging into live", "role": "terminal"}
  ],
  "edges": [
    {"from": "fetch", "to": "fetch", "label": "timed out: retry"},
    {"from": "fetch", "to": "check"},
    {"from": "check", "to": "load", "label": "yes"},
    {"from": "check", "to": "page", "label": "no"},
    {"from": "load", "to": "load", "label": "deadlock: retry"},
    {"from": "load", "to": "swap"}
  ]
}

drawspec 绘制:

流程图:获取供应商导出文件,遇到超时则重试;检查行数;若匹配,则加载到暂存区,遇到死锁则重试,然后切换到线上;否则通知数据负责人

同一文档也可以输出为文本,适用于终端、提交消息或代码块 (--format text --charset ascii):

             *---------------------------*
             | Fetch the vendor's export +-+ timed out: retry
             |                           |<+
             *-------------+-------------*
                           |
                           v
                       +--------------------------+
                       < Do the row counts match? >
                       ++-------------------+-----+
                        | yes               | no
                   +----+                   |
                   v                        v
+-------------------+                      .---------------------.
| Load into staging +-+ deadlock: retry    ( Page the data owner )
|                   |<+                    '---------------------'
+---------+---------+
          |
          v
       .------------------------.
       ( Swap staging into live )
       '------------------------'

序列图也同样简单——只需按顺序列出参与者和消息; 激活条、箭头和间距都会自动处理:

{
  "version": 1,
  "kind": "sequence",
  "title": "Resolving a name the first time",
  "caption": "Nothing is cached yet, so the resolver walks the hierarchy from the top.",
  "participants": [
    {"id": "laptop", "text": "Laptop"},
    {"id": "resolver", "text": "Recursive resolver", "role": "emphasis"},
    {"id": "root", "text": "Root server"},
    {"id": "tld", "text": "`.org` server"},
    {"id": "auth", "text": "Authoritative server"}
  ],
  "messages": [
    {"from": "laptop", "to": "resolver", "text": "where is `wiki.example.org`?"},
    {"from": "resolver", "to": "root", "text": "where is `wiki.example.org`?"},
    {"from": "root", "to": "resolver", "text": "ask the `.org` servers", "role": "weak"},
    {"from": "resolver", "to": "tld", "text": "where is `wiki.example.org`?"},
    {"from": "tld", "to": "resolver", "text": "ask `ns1.example.org`", "role": "weak"},
    {"from": "resolver", "to": "auth", "text": "where is `wiki.example.org`?"},
    {"from": "auth", "to": "resolver", "text": "`203.0.113.7`", "role": "weak"},
    {"from": "resolver", "to": "resolver", "text": "cache it for the TTL", "note": "the next lookup stops here"},
    {"from": "resolver", "to": "laptop", "text": "`203.0.113.7`", "role": "weak"}
  ]
}

序列图:一台笔记本电脑向递归解析器发出请求;递归解析器依次向根服务器、.org 服务器和权威服务器发出请求,缓存答案后再作出回复

30 多种图表类型

流程图、序列图、状态机、ER 图和类图、甘特图、泳道图、思维导图、时间线、维恩图、桑基图、矩形树图、饼图和条形图、看板、鱼骨图、家谱、文件树等——一种格式即可绘制所有图表。点击图表可查看大图,点击类型名称可查看其源代码——代码全部公开。

sequenceentitiesstates
A checkout sequence diagram with alt and par fragments A database schema of customers, orders and order lines with crow's-foot ends A support ticket state machine
ganttmindmapsankey
A migration plan as a Gantt chart with phases and milestones A mind map planning a team offsite A Sankey diagram of where a budget goes
vennchartfishbone
A three-set Venn diagram of logs, metrics and traces A bar and line chart of incidents per quarter A fishbone diagram of causes of a flaky CI
sunbursttreemappie
The feelings wheel as a sunburst: core feelings in the middle, finer ones read outward A treemap of disk usage by folder A pie chart of monthly spending

完整列表:flow · tree · cycle · stack · timeline · columns · matrix · pyramid · rings · funnel · chart · quadrant · scatter · curve · files · states · sequence · lanes · entities · gantt · board · fishbone · venn · journey · treemap · sankey · numberline · barmodel · waterfall · pie · mindmap · argument · familytree · meter · rag · clock · sunburst。每种都有一个示例,见 docs/reference, 图集 (docs/gallery/index.html)会绘制所有图表。

在大模型中使用

  • MCP 服务 — pip install 'drawspec[mcp]' 会安装 drawspec-mcp,其中包含工具 list_kinds、get_example、get_schema、validate_document 和 render_document。出错时会返回模型可据此采取操作的数据: {"pointer": "/edges/0/to", "message": …}。 请参阅指南。
  • AGENTS.md — 一页涵盖完整格式,专为模型一次读完而编写:适用的图表类型、大小限制、角色、示例,以及 各种错误的含义。llms.txt 为其编制索引。
  • Agent Skill — 将 skills/drawspec/ 复制到你的 skills 目录。
  • JSON Schema — 在文档中加入 "$schema": "https://nuncaeslupus.github.io/drawspec/schema/drawspec-v1.schema.json" 即可在编辑器中输入时获得补全和错误提示,也可在结构化输出调用中使用。

典型工作流程:模型选择一种图表类型,编写 JSON,调用 validate_document,修复报告的问题,然后进行渲染。

你将获得

你编写drawspec 决定
节点、边、标签坐标、框大小、画布大小
每个节点的语义角色(start、decision、emphasis 等)形状、字体、颜色、描边粗细
图表类型布局、边的路由、箭头、标签位置
  • SVG 可直接嵌入 Markdown 或 HTML:它会采用页面的文本颜色,不包含全局样式或可能冲突的 ID,也绝不单靠颜色传达信息,因此在深色模式和灰度打印中均可使用。--variant dark=<theme> 会添加适配 prefers-color-scheme 的深色版本。
  • PNG 支持浅色、深色或透明背景(pip install 'drawspec[png]')。
  • 纯文本(框线字符或 ASCII),适用于许多类型,包括流程、状态机、时序图、甘特图和文件树。
  • 主题:修改一个 TOML 文件,项目中的所有图表都会随之更新。 drawspec theme from site.css 可根据你的 CSS 或设计令牌创建主题。
  • 设计上易于阅读:每种类型都有大小限制;超过限制时,drawspec 会建议你拆分图表,而不是绘制过于密集的图表。

命令行

drawspec render diagram.json -o diagram.svg          # or to stdout
drawspec render diagram.json -o diagram.png          # needs drawspec[png]; --background dark, --scale 3
drawspec render diagram.json --theme blueprint -o sheet.png
drawspec render diagram.json --format text           # 80 columns; --charset ascii
drawspec validate diagram.json                       # every error, by JSON pointer
drawspec theme from site.css -o house.toml           # a theme from your CSS
drawspec schema --out drawspec-v1.schema.json        # for editor completion

它不是什么

  • 不是图布局引擎。 对于包含数百个节点的图,请使用 Graphviz。
  • 不是绘图库。 chart 用于展示你已知的少量数值;它不支持统计、日期、对数刻度或交互。
  • 不是绘图程序。 对于重点在于事物位置的内容——例如平面图、地图——不适合使用这种不含坐标的格式。

文档

页面涵盖内容
指南安装、绘制第一个图表、选择类型、嵌入、在 CI 中验证、主题
文档格式每种类型的所有字段,以及每个被拒绝的字段及其原因
命令行每条命令、每个选项和每种退出代码
主题每个主题键及其默认值
AGENTS.md一页了解格式,供语言模型使用

参考文档由代码生成(make docs),如果内容发生偏差,测试就会失败。

开发

make sync     # install with dev extras
make lint     # ruff + strict mypy
make test     # pytest
make gallery  # render every reference document into docs/gallery
make readme   # redraw the README's example images in docs/readme
make docs     # regenerate the format, CLI and theme references
make schema   # regenerate the published JSON Schema

库位于 src/drawspec/,示例位于 docs/reference/,测试位于 tests/。docs/brief.md 和 corpus/ 保存了原始设计简报及其依据的证据。.claude/ 和 claude-arsenal/ 是开发工具,不会影响软件包。

相关项目

使用 claude-arsenal 构建,这是一个由规范驱动的 Claude Code 工作流,其技能使用 drawspec 绘制图表。同一作者的项目:

  • integral-job-search — 在 Claude Code 中以对话形式开展、以候选人为中心的求职。
  • literary-critic — 让 LLM 像专业编辑一样为整部小说手稿建立索引、分析并提供建议。
  • doc-control — 供 AI Agent 以修订模式编辑 Word 文档的确定性工具(开发中)。

许可证

MIT — 详见 LICENSE。

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。