straightedge

straightedge

Enables AI agents to deterministically control Mermaid diagram layout through semantic operations like alignment, distribution, resizing, and history management via MCP.

Category
访问服务器

README

Straightedge

Tell your agent how the diagram should look. Straightedge gives an AI agent deterministic, editable layout controls for Mermaid while keeping the Mermaid source ordinary and portable.

Prompt → picture → persistent intent

Start with ordinary Mermaid. There is no Straightedge metadata yet, so Mermaid chooses the default left-to-right layout.

Default Mermaid pipeline with four nodes in one left-to-right line

Tell the agent:

“Give the three processing stages equal-width boxes. Keep them in a row with 64 pixels between them, then put Database 72 pixels below Model.”

The source stays unchanged; the layout changes:

Pipeline after equal sizing, an ordered row, and relative database placement

The new sidecar records semantic intent rather than generated coordinates:

- no pipeline.layout.json
+ {
+   "version": 3,
+   "ops": [
+     { "op": "equalize_size", "nodes": ["ingest", "enrich", "model"],
+       "dimension": "width", "value": 116 },
+     { "op": "resize_node", "node": "db", "width": 104, "height": 76 },
+     { "op": "row_nodes", "nodes": ["ingest", "enrich", "model"],
+       "gap": 64, "align": "center" },
+     { "op": "place_relative", "node": "db", "reference": "model",
+       "side": "below", "gap": 72 }
+   ]
+ }

Then tell the agent:

“Apply the executive-light theme and fit it to a wide README frame.”

The same pipeline after applying the executive-light theme and README-wide presentation frame

That prompt appends two operations; it does not flatten the earlier intent:

  "ops": [
    ... layout operations above,
+   { "op": "apply_theme", "theme": "executive-light" },
+   { "op": "set_presentation",
+     "presentation": { "preset": "readme-wide", "minFontSize": 12 } }
  ]

Shape-aware instructions use the same loop. For example:

“Make Review Gate about 10% smaller.”

Before resize After shape-aware resize
Draft, circular Review Gate, and Publish before resizing Draft, a ten-percent smaller circular Review Gate, and Publish after resizing

The agent resolves “10% smaller” from inspected geometry and persists one deterministic operation. Both dimensions are equal, so the circle stays circular:

  "ops": [
    { "op": "set_presentation",
      "presentation": { "width": 720, "height": 240, "padding": 24 } },
+   { "op": "resize_node", "node": "review_gate",
+     "width": 94.0921875, "height": 94.0921875 }
  ]

The smaller circle is valid but intentionally demonstrates honest diagnostics: the active checks flag its tighter label padding for review instead of claiming the result is aesthetically perfect. The pipeline presentation has no blocking problems. Regenerate every image and copied sidecar with npm run docs:assets; the exact inputs live in examples.

Straightedge records visual instructions next to each source:

pipeline.mmd            Mermaid source; Straightedge reads it
pipeline.layout.json    ordered visual intent; safe to remove or reset
pipeline.png            generated render; ignored by Git in examples

Coordinates are deliberately not stored. On every render, Straightedge obtains a fresh ELK baseline, replays semantic operations such as row_nodes, align_nodes, and resize_node, paints the result in Chromium, and checks the resulting DOM geometry. Stable Mermaid node IDs preserve intent as labels and structure evolve.

Project status

0.2.0-alpha.1 is the initial OSS preview. Its supported scope is Mermaid flowcharts without subgraphs. Other Mermaid diagram families, org-chart routing, semantic tree layout, multi-user editing, and remote editor hosting are not supported yet. See SPEC.md, ADR-0001, and the implemented initial-release plan in ADR-0007. A future, complete Conda/Pixi distribution is designed in ADR-0008; no Conda package or channel exists yet.

Requirements:

  • Node.js 22.12 or newer;
  • a Chromium browser usable by Puppeteer (straightedge doctor --json reports the resolved one);
  • macOS or Linux for the current local/CI evidence. CI runs Ubuntu with Node 22.

Chromium's sandbox stays enabled by default. The repository's disposable GitHub-hosted jobs opt out with STRAIGHTEDGE_CHROMIUM_NO_SANDBOX=1; do not use that escape hatch for untrusted diagrams or on a shared host. See SECURITY.md.

The npm package name is reserved in metadata but this preview has not been published. Do not use an npm install --global straightedge command until a release exists.

Run from source

This is the initial-release golden path:

git clone https://github.com/gmjen/straightedge.git
cd straightedge
npm ci
npm run build
node dist/cli.js doctor
node dist/cli.js render examples/pipeline.mmd
node dist/cli.js edit examples/pipeline.mmd

render writes PNG beside the source by default. --svg writes SVG and --output <path> chooses a different destination. Structured commands accept --json. Exit code 0 means no warning or error was found, 1 means reviewable warnings, and 2 means a blocking diagnostic or runtime/input failure.

Conversational edit loop

Inspect first, submit a coherent operation or transaction, then read the returned image and scoped checks:

node dist/cli.js inspect chart.mmd
node dist/cli.js align chart.mmd box_a box_b --edge top
node dist/cli.js distribute chart.mmd ingest enrich model database \
  --axis horizontal --order given --gap 24
node dist/cli.js row chart.mmd ingest enrich model database --gap 24
node dist/cli.js stack chart.mmd ceo chief lead --gap 32
node dist/cli.js resize chart.mmd circle_y --scale 0.9
node dist/cli.js history chart.mmd
node dist/cli.js explain chart.mmd

Given-order distribution, row, and stack use the listed node order and persist it in sidecar v3. Old v1/v2 distribute operations with no order retain legacy current-position ordering. Preview a v3 migration with migrate; add --yes to write it.

Circle resizing is shape-aware: a scale changes both axes, and specifying only width or height resolves a single diameter. Rectangle dimensions remain independently editable. All resizing is center-preserving and labels are not scaled.

Use apply for one atomic batch:

node dist/cli.js apply chart.mmd '[
  {"op":"row_nodes","nodes":["a","b","c"],"gap":32},
  {"op":"resize_node","node":"c","width":120}
]' --json

The candidate is rendered and checked before one compare-and-swap sidecar write. A skipped ID, blocking geometry problem, parse failure, or runtime failure leaves the prior bytes unchanged.

Checks and honest claims

Every JSON and MCP result contains check.profile, check.completed, named check stages, and a bounded check.claim. A successful result says:

No blocking problems were detected by the active checks.

geometry checks replay, labels/shapes, overlap/gaps, edges, arrowheads, stale operations, and the required browser runtime. presentation includes those checks plus target-frame readability and advisories for unusually long connectors, doglegs, edited-direction contradictions, and excessive frame whitespace. A persisted frame activates presentation automatically:

node dist/cli.js check chart.mmd --profile presentation --json
node dist/cli.js check chart.mmd --profile presentation --suppress <stable-problem-id>

Suppression is request-scoped and never hides errors. A clean status means the active checks reported nothing, review means warnings require judgment, and failed means a blocking issue or required-stage failure.

Safe history, undo, and reset

history reports whether every operation is effective, overridden, partially overridden, or skipped. explain summarizes source direction, effective ordering, presentation policy, redundant intent, and edits that oppose or later adjust earlier intent.

Undo replays and renders the candidate before atomically removing the final operation. Reset is preview-only unless explicitly confirmed:

node dist/cli.js undo chart.mmd
node dist/cli.js reset chart.mmd                 # preview; no write
node dist/cli.js reset chart.mmd --yes           # move sidecar into .straightedge/backups/
node dist/cli.js restore chart.mmd <backup-path> # preview
node dist/cli.js restore chart.mmd <backup-path> --yes

reset --yes --no-backup is intentionally explicit and unrecoverable. Local backup state is ignored by Git.

Local editor

node dist/cli.js edit chart.mmd starts a token-protected server bound only to 127.0.0.1. The editor and agent surfaces share the same transaction engine. It supports drag, partial and shape-aware resize, numbered selection order, align/distribute/row/stack, safe repair, transactional undo, session redo, recoverable reset, viewport-only zoom/fit, and inline errors.

Unsaved Mermaid source is visibly marked. Any layout action or refresh offers Save and apply, Discard and apply, or Cancel; render responses cannot overwrite a dirty draft. Textarea undo remains native, while Cmd/Ctrl+Z and Cmd/Ctrl+Shift+Z operate on layout history when focus is outside text entry.

Connect an AI agent with MCP

Build from source, then configure an MCP client with the absolute CLI path:

{
  "mcpServers": {
    "straightedge": {
      "command": "node",
      "args": ["/absolute/path/to/straightedge/dist/cli.js", "mcp"]
    }
  }
}

The intended journey is inspect → describe visual intent → submit one semantic transaction → examine the rendered image and structured result → refine or undo. The MCP server exposes the same row, stack, distribute, resize, history, explain, undo, reset-preview, and restore behavior as the CLI.

Development and security

npm test              # fast domain tests
npm run test:coverage # baseline Node coverage report
npm run test:e2e      # real Chromium, CLI, transaction, and editor flows
npm run test:docs     # links, policy files, and visual dimensions
npm run test:package  # pack, clean install, CLI/API/types consumer smoke
npm run test:all      # complete local release gate

Straightedge has no telemetry and sends no diagram or other data to a any service. The editor is not safe to expose remotely. Mermaid uses strict security mode with HTML labels disabled; callers should still avoid untrusted source. See SECURITY.md for the private reporting channel and CONTRIBUTING.md for fixture and pull-request guidance.

License

Licensed under the BSD 3-Clause License.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选