Cocos AI Automation Development
Purpose
Use this skill to drive Cocos Creator as an AI-assisted development target: install and connect MCP, operate the editor through MCP and UI automation, create scenes/assets/scripts, tune behavior, and validate results with small runnable gates.
This skill complements ai-mini-game-development: use that skill for game-phase discipline, and use this skill for Cocos-specific tooling and editor-operation details.
Core Workflow
Establish the project and editor state.
- Identify the Cocos project root and Cocos Creator version.
- Check whether the editor is open, whether the target scene is loaded, and whether a preview server is running.
- Preserve user changes. Do not reset or overwrite scenes unless explicitly requested.
Connect MCP before modifying the scene.
- Prefer the maintained Tuya fork when available:
https://github.com/hzq510473048/cocos_mcp.
- Use the original upstream only when the Tuya fork is unavailable or when comparing upstream changes:
https://github.com/RomaRogov/cocos-mcp.
- Install it under the project extension folder when the user wants project-local automation.
- Ask the user to start the MCP service from Cocos when needed; Codex can then call tools against
http://localhost:3000/mcp.
- Confirm available tools with
client.listTools() before assuming a capability exists.
Make a minimal testable change first.
- Create a visible object, material, light, camera, and simple behavior before adding polish.
- For physics, verify the basic loop before adding realistic textures, rails, controls, or camera work.
- Save the scene and read properties back through MCP.
Use the right operation channel.
- Use MCP for nodes, components, assets, scene save/load, and property queries.
- Use filesystem edits for TypeScript scripts and generated assets.
- Use Computer Use for Cocos UI actions that MCP cannot do reliably, such as opening panels, clicking refresh, or visually inspecting the editor.
- Use browser/preview only after the editor has compiled scripts and the scene has been saved.
- Validate after every meaningful step.
- Query components and node hierarchy through MCP.
- Inspect Cocos logs with
operate_current_scene/get-last-logs.
- Use the editor view or preview to verify visual behavior.
- Stop and ask for user feedback when the next judgment is about feel, visual quality, or gameplay intent.
MCP Client Pattern
Run MCP calls from the installed extension directory so the SDK dependency resolves:
cd /path/to/CocosProject/extensions/cocos-mcp
node --input-type=module - <<'NODE'
import { Client } from './node_modules/@modelcontextprotocol/sdk/dist/esm/client/index.js';
import { StreamableHTTPClientTransport } from './node_modules/@modelcontextprotocol/sdk/dist/esm/client/streamableHttp.js';
const client = new Client({ name: 'codex', version: '0.1.0' });
await client.connect(new StreamableHTTPClientTransport(new URL('http://localhost:3000/mcp')));
const tools = await client.listTools();
console.log(tools.tools.map((tool) => tool.name).join('\n'));
await client.close();
NODE
Prefer short scripts that:
- connect once,
- call several MCP tools,
- print compact JSON/text,
- save the scene,
- close the client.
MCP Installation Sources
Use one of these installation paths for new Cocos projects.
Preferred: Install From The Tuya Fork
Use this when network and GitHub access are available.
mkdir -p <CocosProject>/extensions
cd <CocosProject>/extensions
git clone https://github.com/hzq510473048/cocos_mcp.git cocos-mcp
cd cocos-mcp
npm install
npm run build
Then restart Cocos Creator, open the cocos-mcp panel, start the server, and verify script_hot_reload appears in client.listTools().
Offline Or Transfer Install: Use The Standard Archive
Use this when moving between computers or when GitHub access is unavailable. The expected archive name is:
cocos-mcp-tuya-1.0.2-script-hot-reload.zip
Install it like this:
mkdir -p <CocosProject>/extensions
cd <CocosProject>/extensions
unzip /path/to/cocos-mcp-tuya-1.0.2-script-hot-reload.zip
cd cocos-mcp
npm install
npm run build
If the archive already includes dist, it may load immediately, but still run npm install && npm run build after transfer to normalize dependencies for the local machine.
Updating The Fork From Upstream
When the original author changes RomaRogov/cocos-mcp, keep local custom work in a branch and rebase or merge upstream:
cd <CocosProject>/extensions/cocos-mcp
git remote add upstream https://github.com/RomaRogov/cocos-mcp.git 2>/dev/null || true
git fetch upstream
git checkout main
git rebase upstream/main
npm install
npm run build
After resolving conflicts, restart Cocos Creator/MCP and confirm script_hot_reload still appears.
Practical Rules
- Read
references/quick-workflow.md before starting a new Cocos automation task.
- Read
references/pitfalls.md when working with physics, script hot reload, editor UI refresh, scene preview, or visual polish.
- Use generated bitmap assets for quick material validation, then import them into
assets/ and refresh Cocos so .meta files are created.
- When adding TypeScript components, edit the
.ts file first, wait for Cocos to compile it, confirm it appears in get_available_component_types, then add it with modify_nodes.
- When a component schema changes, use the fixed hot-reload recovery flow instead of ad hoc debugging:
- if the local
cocos-mcp exposes script_hot_reload, call it first with the script path, expected component type, and one or more code snippets that must appear in generated editor/preview chunks;
- trigger Cocos import/compile by focusing the editor, clicking asset refresh, or reloading the editor window if needed;
- verify the generated script chunk or editor status reflects the new source, not only that the
.ts file changed;
- query
get_available_component_types and query_components;
- if new
@property fields are still absent, remove and re-add the component, then serialize properties again;
- save the scene and verify the scene file/MCP query agree.
Do not trust stale component data or ask the user to diagnose this pattern unless the recovery flow fails.
- For this project-local
cocos-mcp fork, script_hot_reload is available after restarting Cocos Creator/MCP. Example:
{
"scriptAssetPath": "assets/JuggleGameController.ts",
"componentType": "JuggleGameController",
"expectedRuntimeSnippets": [
"Math.min(this._lastDownwardSpeed * this.naturalBounceRestitution"
],
"targets": ["editor", "preview"],
"touchBeforeRefresh": true,
"waitMs": 1200,
"retryCount": 2
}
Treat a failed script_hot_reload result as a real stale-runtime warning. Do not proceed to gameplay tuning until either generated chunks match the source or the editor/MCP service has been restarted and checked again.
- For physics demos, favor stable observable behavior over pure engine restitution when the backend is inconsistent. Document any scripted correction as a validation aid.
- When tuning rigid-body scenes, treat visual symptoms such as "sticking", "micro bouncing", "sliding instead of rolling", or "teleport-like state jumps" as coupling problems first. Inspect material restitution/friction, rigid-body sleep/damping, kinematic transform sync, scripted surface correction, scripted bounce assist, and visual roll helpers together before changing one parameter repeatedly.
- Keep tuning values serialized as component properties so later agents can adjust them through MCP.
Gameplay-Specific Skills
Keep this skill focused on Cocos Creator automation. For specific game genres or mechanics, layer a narrower gameplay skill underneath it.
- For Cocos ball, rebound, rolling, flipper, seesaw, paddle, launch-arc, sticking, or micro-bounce gameplay, also use
cocos-ball-physics-gameplay.
- For genre-specific tuning, keep detailed physics, input, and gameplay rules in the gameplay skill, not here.
- This skill should still own Cocos-specific execution concerns: opening the correct scene, MCP tool availability, component serialization, asset import, script hot reload, generated chunk verification, and editor/preview validation.
Done Criteria
A Cocos automation task is not done until:
- the scene is saved,
- modified nodes/components/assets are queried back successfully,
- Cocos logs show no relevant script or import errors,
- the user can run or preview the scene,
- any remaining subjective tuning points are clearly named.
1---2name: cocos-ai-automation-development3description: Automate Cocos Creator projects with AI agents, MCP tools, and local editor control. Use when Codex needs to install or connect cocos-mcp, inspect or modify a Cocos Creator project, create or tune 3D/2D scenes, add nodes/components/materials/scripts/assets, interact with Cocos Creator UI, preview behavior, debug physics/rendering issues, or document repeatable Cocos AI automation workflows.4---56# Cocos AI Automation Development78## Purpose910Use this skill to drive Cocos Creator as an AI-assisted development target: install and connect MCP, operate the editor through MCP and UI automation, create scenes/assets/scripts, tune behavior, and validate results with small runnable gates.1112This skill complements `ai-mini-game-development`: use that skill for game-phase discipline, and use this skill for Cocos-specific tooling and editor-operation details.1314## Core Workflow15161. Establish the project and editor state.17 - Identify the Cocos project root and Cocos Creator version.18 - Check whether the editor is open, whether the target scene is loaded, and whether a preview server is running.19 - Preserve user changes. Do not reset or overwrite scenes unless explicitly requested.20212. Connect MCP before modifying the scene.22 - Prefer the maintained Tuya fork when available: `https://github.com/hzq510473048/cocos_mcp`.23 - Use the original upstream only when the Tuya fork is unavailable or when comparing upstream changes: `https://github.com/RomaRogov/cocos-mcp`.24 - Install it under the project extension folder when the user wants project-local automation.25 - Ask the user to start the MCP service from Cocos when needed; Codex can then call tools against `http://localhost:3000/mcp`.26 - Confirm available tools with `client.listTools()` before assuming a capability exists.27283. Make a minimal testable change first.29 - Create a visible object, material, light, camera, and simple behavior before adding polish.30 - For physics, verify the basic loop before adding realistic textures, rails, controls, or camera work.31 - Save the scene and read properties back through MCP.32334. Use the right operation channel.34 - Use MCP for nodes, components, assets, scene save/load, and property queries.35 - Use filesystem edits for TypeScript scripts and generated assets.36- Use Computer Use for Cocos UI actions that MCP cannot do reliably, such as opening panels, clicking refresh, or visually inspecting the editor.37- Use browser/preview only after the editor has compiled scripts and the scene has been saved.38395. Validate after every meaningful step.40 - Query components and node hierarchy through MCP.41 - Inspect Cocos logs with `operate_current_scene/get-last-logs`.42 - Use the editor view or preview to verify visual behavior.43 - Stop and ask for user feedback when the next judgment is about feel, visual quality, or gameplay intent.4445## MCP Client Pattern4647Run MCP calls from the installed extension directory so the SDK dependency resolves:4849```bash50cd /path/to/CocosProject/extensions/cocos-mcp51node --input-type=module - <<'NODE'52import { Client } from './node_modules/@modelcontextprotocol/sdk/dist/esm/client/index.js';53import { StreamableHTTPClientTransport } from './node_modules/@modelcontextprotocol/sdk/dist/esm/client/streamableHttp.js';5455const client = new Client({ name: 'codex', version: '0.1.0' });56await client.connect(new StreamableHTTPClientTransport(new URL('http://localhost:3000/mcp')));5758const tools = await client.listTools();59console.log(tools.tools.map((tool) => tool.name).join('\n'));6061await client.close();62NODE63```6465Prefer short scripts that:6667- connect once,68- call several MCP tools,69- print compact JSON/text,70- save the scene,71- close the client.7273## MCP Installation Sources7475Use one of these installation paths for new Cocos projects.7677### Preferred: Install From The Tuya Fork7879Use this when network and GitHub access are available.8081```bash82mkdir -p <CocosProject>/extensions83cd <CocosProject>/extensions84git clone https://github.com/hzq510473048/cocos_mcp.git cocos-mcp85cd cocos-mcp86npm install87npm run build88```8990Then restart Cocos Creator, open the `cocos-mcp` panel, start the server, and verify `script_hot_reload` appears in `client.listTools()`.9192### Offline Or Transfer Install: Use The Standard Archive9394Use this when moving between computers or when GitHub access is unavailable. The expected archive name is:9596```text97cocos-mcp-tuya-1.0.2-script-hot-reload.zip98```99100Install it like this:101102```bash103mkdir -p <CocosProject>/extensions104cd <CocosProject>/extensions105unzip /path/to/cocos-mcp-tuya-1.0.2-script-hot-reload.zip106cd cocos-mcp107npm install108npm run build109```110111If the archive already includes `dist`, it may load immediately, but still run `npm install && npm run build` after transfer to normalize dependencies for the local machine.112113### Updating The Fork From Upstream114115When the original author changes `RomaRogov/cocos-mcp`, keep local custom work in a branch and rebase or merge upstream:116117```bash118cd <CocosProject>/extensions/cocos-mcp119git remote add upstream https://github.com/RomaRogov/cocos-mcp.git 2>/dev/null || true120git fetch upstream121git checkout main122git rebase upstream/main123npm install124npm run build125```126127After resolving conflicts, restart Cocos Creator/MCP and confirm `script_hot_reload` still appears.128129## Practical Rules130131- Read `references/quick-workflow.md` before starting a new Cocos automation task.132- Read `references/pitfalls.md` when working with physics, script hot reload, editor UI refresh, scene preview, or visual polish.133- Use generated bitmap assets for quick material validation, then import them into `assets/` and refresh Cocos so `.meta` files are created.134- When adding TypeScript components, edit the `.ts` file first, wait for Cocos to compile it, confirm it appears in `get_available_component_types`, then add it with `modify_nodes`.135- When a component schema changes, use the fixed hot-reload recovery flow instead of ad hoc debugging:136 0. if the local `cocos-mcp` exposes `script_hot_reload`, call it first with the script path, expected component type, and one or more code snippets that must appear in generated editor/preview chunks;137 1. trigger Cocos import/compile by focusing the editor, clicking asset refresh, or reloading the editor window if needed;138 2. verify the generated script chunk or editor status reflects the new source, not only that the `.ts` file changed;139 3. query `get_available_component_types` and `query_components`;140 4. if new `@property` fields are still absent, remove and re-add the component, then serialize properties again;141 5. save the scene and verify the scene file/MCP query agree.142 Do not trust stale component data or ask the user to diagnose this pattern unless the recovery flow fails.143- For this project-local `cocos-mcp` fork, `script_hot_reload` is available after restarting Cocos Creator/MCP. Example:144145```json146{147 "scriptAssetPath": "assets/JuggleGameController.ts",148 "componentType": "JuggleGameController",149 "expectedRuntimeSnippets": [150 "Math.min(this._lastDownwardSpeed * this.naturalBounceRestitution"151 ],152 "targets": ["editor", "preview"],153 "touchBeforeRefresh": true,154 "waitMs": 1200,155 "retryCount": 2156}157```158159Treat a failed `script_hot_reload` result as a real stale-runtime warning. Do not proceed to gameplay tuning until either generated chunks match the source or the editor/MCP service has been restarted and checked again.160- For physics demos, favor stable observable behavior over pure engine restitution when the backend is inconsistent. Document any scripted correction as a validation aid.161- When tuning rigid-body scenes, treat visual symptoms such as "sticking", "micro bouncing", "sliding instead of rolling", or "teleport-like state jumps" as coupling problems first. Inspect material restitution/friction, rigid-body sleep/damping, kinematic transform sync, scripted surface correction, scripted bounce assist, and visual roll helpers together before changing one parameter repeatedly.162- Keep tuning values serialized as component properties so later agents can adjust them through MCP.163164## Gameplay-Specific Skills165166Keep this skill focused on Cocos Creator automation. For specific game genres or mechanics, layer a narrower gameplay skill underneath it.167168- For Cocos ball, rebound, rolling, flipper, seesaw, paddle, launch-arc, sticking, or micro-bounce gameplay, also use `cocos-ball-physics-gameplay`.169- For genre-specific tuning, keep detailed physics, input, and gameplay rules in the gameplay skill, not here.170- This skill should still own Cocos-specific execution concerns: opening the correct scene, MCP tool availability, component serialization, asset import, script hot reload, generated chunk verification, and editor/preview validation.171172## Done Criteria173174A Cocos automation task is not done until:175176- the scene is saved,177- modified nodes/components/assets are queried back successfully,178- Cocos logs show no relevant script or import errors,179- the user can run or preview the scene,180- any remaining subjective tuning points are clearly named.