cocos-mcp-v2-ui

cocos-mcp-v2-ui

Enables MCP clients to control Cocos Creator 2.x for UI design, such as translating Figma designs into Cocos scenes by creating nodes, components, and prefabs.

Category
访问服务器

README

cocos-mcp-v2-ui

MCP server (UI-design tools) for Cocos Creator 2.x (verified on 2.4.11), built as an editor package. It lets an MCP client (Claude Code) drive the editor to build UI — ideal for translating a Figma design into a Cocos scene: read the design with the Figma MCP, then create nodes/components/sprites/prefabs here.

Ported (not mechanically) from the 3.8.x cocos-mcp-server. 2.x differs fundamentally: the scene bridge is the callback-based Editor.Scene.callSceneScript, node size/anchor live on the node (no UITransform), and the package is plain CommonJS.

Architecture

Claude Code ──stdio(MCP)──▶ bridge/  ──HTTP /rpc──▶ editor package (main proc)
                          (system Node,            core/server + registry + tools
                           @modelcontextprotocol)        │
                                                          ▼  Editor.Scene.callSceneScript
                                                   scene.js (scene proc, cc.* live)
  • Editor package (main.js, core/, tools/, scene.js, scene/) runs inside Cocos Creator. main.js starts an HTTP server (core/server.js) exposing GET /health, POST /rpc {tool,args}, GET /tools, and a stateless POST /mcp.
  • Bridge (bridge/) is a separate Node process Claude spawns. It speaks the MCP protocol over stdio (via the official SDK) and proxies tools/list+tools/call to the editor's HTTP /tools+/rpc. Keeping MCP-spec compliance out of the editor's old Node.
  • Single-responsibility / DRY: tool modules are thin (schema + delegate). Everything crossing into the scene goes through one core/scene-bridge.js#callScene; one core/response.js shape; scene-side has one resolveNode, one serialize, one applyTransform.

Install

  1. Symlink (or copy) this folder into the project's packages/:
    ln -s /Users/nguyennt/Documents/MCP/cocos-mcp-v2-ui \
          /Users/nguyennt/Documents/Cocos/testMCP/packages/cocos-mcp-v2-ui
    
  2. Install the bridge deps once: cd bridge && npm install.
  3. Open the project in Cocos Creator 2.4.x. The package auto-starts the server on port 8585 (autoStart: true). Panel: menu Extension → Cocos MCP v2 UI.

Connect to Claude Code

claude mcp add cocos-ui --transport stdio -- \
  node /Users/nguyennt/Documents/MCP/cocos-mcp-v2-ui/bridge/bin/cocos-ui-bridge.js --port 8585

Verify: /mcp in Claude lists cocos-ui connected and the 32 tools. The editor must be running with a scene open for scene tools to work (otherwise they return No active scene).

Tools (32)

Category Tools
ping ping
scene get_current_scene, get_scene_hierarchy, open_scene, save_scene, capture_node
node create_node, create_node_tree, get_node_info, find_nodes, set_node_transform, set_node_property, set_node_properties_batch, set_sibling_index, delete_node, duplicate_node
component add_component, set_component_property, get_components, set_component_reference, add_click_event, set_label_style, apply_widget, draw_rounded_rect, apply_gradient
asset import_asset, query_asset_uuid
prefab create_prefab, instantiate_prefab
referenceImage add_reference_image, set_reference_image_data, remove_reference_image

Highlights (added per build-experience feedback)

  • color is forgiving: set_component_property/set_node_property/tree specs accept {r,g,b,a}, [r,g,b,a], or a hex string ("#161718").
  • create_node_tree: build an entire node + component + property subtree in ONE call (returns uuids).
  • capture_node: render a node/Canvas to a PNG on disk so the agent can see and self-correct.
  • draw_rounded_rect: native rounded backgrounds/borders via cc.Graphics — no texture hacks.
  • apply_gradient: bakes a rounded gradient PNG and binds it as a spriteFrame — real gradient buttons/badges (cc.Graphics fill is solid-only).
  • set_component_reference + add_click_event: wire ScrollView.content, Widget.target, button handlers, etc.
  • Enum names: enum props accept names (type:"VERTICAL", sizeMode:"CUSTOM") as well as numbers.
  • import_asset auto-creates the destination folder, auto-rasterizes SVG-content files, and fails loudly instead of silently importing nothing. spriteFrame assignment now preserves node size.

MCP tool name = <category>_<method> (e.g. node_create_node, referenceImage_add_reference_image).

Figma → Cocos workflow

  1. Read the design with the Figma MCP (positions, sizes, colors, text).
  2. scene_get_scene_hierarchy → find the Canvas uuid.
  3. (optional) export a screenshot from Figma → asset_import_asset → referenceImage_add_reference_image { spriteFrameUuid } to trace it.
  4. node_create_node per element → component_add_component (cc.Sprite/cc.Label/ cc.Button/cc.Widget/cc.Layout) → component_set_component_property (string, fontSize, color, spriteFrame) → node_set_node_transform to place/size.
  5. For images: asset_import_asset returns spriteFrameUuid — pass that to set_component_property property:"spriteFrame" (it persists; the texture uuid does not).
  6. Reusable bits: prefab_create_prefab → prefab_instantiate_prefab.
  7. scene_save_scene.

Notes & limitations (2.x specifics)

  • capture_node framing (edit-mode) — in the editor (not Play), only a screen-aligned camera renders to an off-screen texture; a custom orthographic projection comes back blank. So capture_node renders through the scene's game camera at the scene's design resolution. It captures correctly when the UI is authored at that design resolution; a node much larger than the design resolution is framed to the design-res region (not the whole node). Tip: set the scene's design resolution to your screen size (e.g. 1080×2400) for full-screen captures.
  • One render component per node (2.x) — cc.Sprite, cc.Graphics, cc.Label, cc.RichText all derive from cc.RenderComponent and are mutually exclusive on a node. So a node can't have both draw_rounded_rect (Graphics) and apply_gradient/spriteFrame (Sprite). This is an engine rule, not a tool bug — add_component reports the exact conflict, and apply_gradient auto-applies to a child node when the target already has a render component.
  • Reference image is simulated — Cocos 2.x has no native reference-image gizmo. We add a low-opacity Sprite node __ReferenceImage__ behind the UI. Remove it before shipping (remove_reference_image); it is a real scene node.
  • Editor Hierarchy/Inspector may not refresh instantly after mutations made through the cc runtime — the live scene/canvas does update; reselect a node or reload the scene to refresh the panels. Not a tool failure.
  • No main-process hot-reload in 2.4.x: editing main.js/core//tools//scene/ during development requires a full editor restart (Developer → Reload Editor). At runtime this is irrelevant — the server starts on project open.
  • spriteFrame: importing a PNG yields a texture and a sprite-frame sub-asset. Bind the sub-asset uuid (returned as spriteFrameUuid). Passing a texture uuid is handled as a best-effort wrap but does not persist on save.
  • Verified editor IPC (2.4.11): save scene:stash-and-save, open scene:open-by-uuid, asset query/import asset-db:query-uuid-by-url / asset-db:import-assets, prefab create scene:create-prefab (url, serialized-content) via the _Scene.PrefabUtils recipe.

Tests

  • Unit (pure logic — colors, enums, PNG encoder, gradient, SVG sniff; no editor needed):
    node test/unit.test.js
    
  • Integration (error/edge paths for the scene & component tools; needs the editor running with a scene open — creates a temp container node and deletes it afterwards):
    node test/integration.test.js --port 8585
    
  • See test/manual-checklist.md for the per-tool manual verification steps.

推荐服务器

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

官方
精选