Overview
What is This
A Cloudflare Worker that exposes an MCP (Model Context Protocol) server for plotting math functions, drawing STEM diagrams, and rendering the results as SVG or PNG. Source on GitHub: lingion/plot-mcp-worker.
Stack (verified against source)
| Layer | What it does | Source |
|---|---|---|
| Runtime | Cloudflare Workers (ES module), compatibility date 2026-04-22 | wrangler.toml |
| Routing | JSON-RPC 2.0 at POST /mcp; web URLs at /plot, /png, /s/{token}, /force.svg, /force-analysis.svg, /circuit.svg, /venn.svg, /c-memory.svg, /shape3d.html, /multi_plot, /multi_plot.png | src/index.ts (handler at L3290) |
| Math engine | expr-eval parser for inline expressions like sin(x), x^2+1 | src/plot.ts (import L1) |
| SVG renderer | Hand-written string concatenation. Card layout, grid, ticks (nice/pi-aware/log), annotations, bar/box/pie/hist/scatter/line series | src/render.ts (1123 lines) |
| PNG renderer | @resvg/resvg-wasm compiled to WebAssembly; loads CJK font from KV and pathifies text | src/render.ts L1-3, L1073-1112 |
| CJK font | opentype.js converts CJK glyphs and math unicode (π, ², ∫, √) to SVG paths so resvg can render them | src/render.ts L139-159 (pathifyCjkText) |
| Storage | Cloudflare KV namespace SHORT_LINKS; 30-day TTL on short link records; 8-char tokens | src/constants.ts L7-9; wrangler.toml L11-13 |
| Diagram generators | Force analysis (8 templates), circuits (10 templates), Venn, C memory layout, 3D shapes | src/extras.ts (1657 lines); templates in src/index.ts L902-1173 |
Source tree
plot-mcp-worker/
|-- src/
| |-- index.ts 3471 lines HTTP entry + canonical tool dispatcher + short-link store
| |-- render.ts 1123 lines SVG/PNG rendering (math plots)
| |-- plot.ts 1520 lines PlotSpec builder, transforms, error bars, statistics
| |-- extras.ts 1657 lines Force/circuit/Venn/C-memory/3D SVG renderers
| |-- types.ts 136 lines Frozen interface (RenderFormat, PlotSeries, etc.)
| |-- constants.ts 48 lines Limits, palette, defaults
| |-- router.ts 94 lines Compat layer (legacy -> canonical name)
| |-- compat.ts 80 lines Legacy name mapping table
| |-- utils.ts 91 lines Base64/gzip helpers, XML escape, clamp, parseInteger
| |-- mcp.ts 26 lines CORS headers + JSON-RPC 2.0 helpers
| |-- types.d.ts 9 lines Type declarations
|-- scripts/ 12 verification/deploy scripts (see Local Dev page)
|-- docs/ README assets (CN/EN showcase images, examples)
|-- capabilities.json Tool manifest (legacy format, 22 capabilities)
|-- wrangler.toml Worker config (route, KV binding, .ttf rule)
|-- tsconfig.json ES2022 strict, bundler resolution
|-- package.json 3 deps: expr-eval, opentype.js, @resvg/resvg-wasm
8,255 total source lines across 11 TypeScript files.
Two version numbers (intentional)
package.json:0.2.0— the npm/release versionsrc/constants.tsSERVER_VERSION:0.4.14— reported byhealthtool / initialize response
The mismatch exists because SERVER_VERSION tracks the deployed-worker iteration independently from the npm release. Don't try to align them — it's a deliberate separation between the deployment surface and the package surface.
Live MCP endpoint
POST JSON-RPC 2.0 to https://your-worker.your-domain.com/mcp. Initialize returns protocolVersion: "2025-03-26", server name plot-mcp-worker, version 0.4.14. Full tool list at /mcp tools/list returns 24 tools (see Tools Reference page).
See also: Technical post: Building plot-mcp-worker — deep dive into the expression parser, 5-transform data pipeline, smart axis intelligence, CJK text-to-path, and diagram generators.