scratch-mcp

scratch-mcp

Enables AI agents to create, compile, and run Scratch projects by editing plain text and using a live editor loop.

Category
访问服务器

README

scratch-mcp

An MCP server that lets an AI agent build and run real Scratch projects. The agent writes a project as readable text, the server compiles it to a runnable Scratch 3 .sb3, loads it into a live self-hosted Scratch editor, runs it, and reads the result back — an Xcode-style edit → reload → run → snapshot loop over a real project, not a one-shot generation.

An AI-authored Scratch project compiled and running in the live editor — the assembled blocks on the left were produced from text by the compiler; the stage shows the pen drawing it just ran.

Above: the repeat (36) [ move (60) steps · turn ↻ (170) degrees ] pen program below was written as plain text, compiled to .sb3, and run in the live editor by tool calls — those are real, correctly-assembled Scratch blocks.

The tools

The MCP server is deliberately thin: the agent edits the project's source text with its own file tools, and the server handles build + live editor + inspection. Ten stdio tools:

Tool What it does
new_project Scaffold a project folder that compiles clean
open_project Set the active project for subsequent calls
list_projects List projects under the projects root
compile Compile source → .sb3; returns fail-loud diagnostics (no editor needed)
reload Compile and load into the live editor — loads nothing if compilation fails
run Green-flag the project and await a real run-completion signal (with a timeout)
stop Stop all running scripts
snapshot Screenshot the stage as a PNG image
read_state Variables, lists, and per-sprite state — namespaced (no global/local collisions)
import_sb3 Load an existing .sb3 to run / inspect (load-only)

The loop

The agent edits plain text — a project.yaml manifest plus one *.sprite.scratch file per sprite, in scratchblocks syntax — then calls reloadrunsnapshot and sees what happened:

# cat.sprite.scratch
when green flag clicked
set [r v] to ((3) + (4))
if <(1) > (2)> then
  change [b v] by (1)
else
  set [b v] to (9)
end
repeat until <(c) = (5)>
  change [c v] by (1)
end

The text is the single source of truth — readable, diffable, and reviewable — exactly like Swift files are canonical and the compiled app is derived. The user watches it all land live in the editor tab.

Use it

Point an MCP client (Claude Desktop, Claude Code, …) at the built server:

{
  "mcpServers": {
    "scratch": { "command": "node", "args": ["/abs/path/to/scratch-mcp/dist/src/index.js"] }
  }
}

The editor browser tab launches lazily on the first reload/import_sb3 and stays open for the session, so changes appear live. Set SCRATCH_MCP_HEADLESS=1 to run it without a visible window.

How it works

Three subsystems, one coherent server:

  • Source*.sprite.scratch (scratchblocks text) + a project.yaml manifest.

    name: Grammar
    sprites:
      - name: Cat
        source: cat.sprite.scratch
    variables:
      global: { r: 0, b: 0, c: 0 }
    
  • Compiler (src/compiler/) — a manifest parser + a hand-rolled scratchblocks parser + a per-category block dictionary (blocks/categories/*.ts, guarded by a signature-uniqueness check) + a hand-rolled JSZip packager that emits Scratch-3 .sb3. Headless verification runs against scratch-vm@5.0.300. It's fail-loud: any unsupported block, unresolved name, or malformed script becomes a precise file:line diagnostic rather than a silently-broken project.

    import { compileProject } from "./src/compiler/index.js";
    const { ok, sb3, diagnostics } = await compileProject("path/to/project-dir");
    // ok === false + diagnostics (and no sb3) if anything is malformed — collect-all.
    
  • Live-editor bridge (src/editor/) — a self-hosted scratch-gui Vite app whose live VM is driven through Playwright (launch / loadProject / run / stop / snapshot / readState / close), never by faking UI drags. That keeps it robust — the fragile drag-and-drop path is explicitly avoided.

  • MCP layer (src/mcp/) — a Session (active project + a lazily-launched editor singleton) and ten thin tool handlers that wrap the compiler and bridge, surfacing diagnostics and namespaced state to the calling agent.

Block palette

The compiler covers the entire Scratch 3 default palette — 135 block definitions across all 11 categories (Motion · Looks · Sound · Events · Control · Sensing · Operators · Variables · Lists · Pen · Music), plus broadcasts and the extensions[] (Pen/Music) machinery. Every block is verified under a dual standard: a runtime assertion in a headless VM where the effect is observable, or a structural assertion on the emitted project.json plus a load-and-run check otherwise — and a coverage test proves every block's signature round-trips to its own opcode.

Out of scope for now: custom blocks/procedures, a real asset resolver (costumes/sounds resolve to a placeholder), on-stage monitors, and a decompiler (import_sb3 is load-only — turning a .sb3 back into editable source is a separate forward-vs-reverse problem).

Develop

Requires Node ≥ 25. The compiler/test stack has no native build step.

npm install
npm run build      # tsc -p tsconfig.json  → dist/
npm test           # vitest run  (compiler + headless-VM + editor + MCP tests)

The self-hosted editor (only needed for the live bridge) is built separately under editor/.

Roadmap

  • [x] Live-editor bridge (self-hosted scratch-gui, VM-driven via Playwright)
  • [x] Compiler pipeline (text → .sb3, headless-VM proven, fail-loud)
  • [x] Infrastructure extensions (broadcasts, lists, Pen/Music extensions[])
  • [x] Full core block-palette dictionary (135 blocks, dual-standard tested)
  • [x] MCP server — 10 stdio tools wrapping the compiler + bridge; real run-completion signal + per-sprite namespaced state
  • [ ] Custom blocks / procedures
  • [ ] Asset resolver (real costumes/sounds/backdrops)
  • [ ] Decompiler + editable import_sb3

Tech

TypeScript (strict, ESM) · Node ≥ 25 · @modelcontextprotocol/sdk · Zod · Vitest · JSZip · js-yaml · Playwright · headless scratch-vm@5.0.300.

Design specs and implementation plans live under docs/superpowers/.


Bundles and drives the MIT/BSD-licensed Scratch runtime and editor (scratch-vm, scratch-gui) by the Scratch Foundation. Not affiliated with or endorsed by the Scratch Foundation.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选