cocos-creator-mcp-server

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Cocos Creator MCP Server Skill

Cocos Creator MCP Server 技能

Skill by ara.so — MCP Skills collection.
A comprehensive MCP (Model Context Protocol) server plugin for Cocos Creator 3.8+ that enables AI assistants to interact with the Cocos Creator editor through a standardized protocol. Provides 50 powerful tools covering 99% of editor operations including scenes, nodes, components, prefabs, assets, project management, debugging, and preferences.
ara.so开发的技能 — MCP技能合集。
一款面向Cocos Creator 3.8+的全面MCP(Model Context Protocol)服务器插件,可让AI助手通过标准化协议与Cocos Creator编辑器交互。提供50个强大工具,覆盖99%的编辑器操作,包括场景、节点、组件、预制件、资源、项目管理、调试和偏好设置。

Installation

安装

Prerequisites

前置条件

  • Cocos Creator 3.8.6 or higher
  • MCP-compatible client (Claude Desktop, Claude CLI, Cursor, etc.)
  • Cocos Creator 3.8.6 或更高版本
  • 兼容MCP的客户端(Claude Desktop、Claude CLI、Cursor等)

Plugin Installation

插件安装

  1. From Cocos Store (Recommended):
  2. Manual Installation:
    bash
    # Clone the repository
    git clone https://github.com/DaxianLee/cocos-mcp-server.git
    
    # Install in Cocos Creator extensions folder
    # Windows: %USERPROFILE%/.CocosCreator/extensions/
    # macOS: ~/.CocosCreator/extensions/
    # Copy the plugin folder to the extensions directory
  3. Enable in Cocos Creator:
    • Open Cocos Creator
    • Go to Extensions → Extension Manager
    • Find "Cocos Creator MCP Server" and enable it
    • Configure server port (default: 3000) in the MCP panel
  1. 从Cocos商店安装(推荐):
  2. 手动安装
    bash
    # 克隆仓库
    git clone https://github.com/DaxianLee/cocos-mcp-server.git
    
    # 安装到Cocos Creator扩展文件夹
    # Windows: %USERPROFILE%/.CocosCreator/extensions/
    # macOS: ~/.CocosCreator/extensions/
    # 将插件文件夹复制到扩展目录
  3. 在Cocos Creator中启用
    • 打开Cocos Creator
    • 进入 扩展 → 扩展管理器
    • 找到「Cocos Creator MCP Server」并启用
    • 在MCP面板中配置服务器端口(默认:3000)

Client Configuration

客户端配置

Claude Desktop (
claude_desktop_config.json
):
json
{
  "mcpServers": {
    "cocos-creator": {
      "type": "http",
      "url": "http://127.0.0.1:3000/mcp"
    }
  }
}
Claude CLI:
bash
claude mcp add --transport http cocos-creator http://127.0.0.1:3000/mcp
Cursor (
.cursor/mcp.json
or settings):
json
{
  "mcpServers": {
    "cocos-creator": {
      "url": "http://localhost:3000/mcp"
    }
  }
}
Claude Desktop
claude_desktop_config.json
):
json
{
  "mcpServers": {
    "cocos-creator": {
      "type": "http",
      "url": "http://127.0.0.1:3000/mcp"
    }
  }
}
Claude CLI
bash
claude mcp add --transport http cocos-creator http://127.0.0.1:3000/mcp
Cursor
.cursor/mcp.json
或设置界面):
json
{
  "mcpServers": {
    "cocos-creator": {
      "url": "http://localhost:3000/mcp"
    }
  }
}

Core Concepts

核心概念

Action-Based Tool System

基于动作的工具系统

All 50 tools follow a unified "action + parameters" pattern:
typescript
{
  "tool": "category_operation",
  "arguments": {
    "action": "specific_action",
    // ... action-specific parameters
  }
}
This design reduces token consumption by ~50% and increases AI call success rates.
所有50个工具遵循统一的「动作 + 参数」模式:
typescript
{
  "tool": "category_operation",
  "arguments": {
    "action": "specific_action",
    // ... 动作专属参数
  }
}
该设计可减少约50%的token消耗,并提升AI调用成功率。

Tool Categories

工具分类

  • scene_* - Scene management and hierarchy
  • node_* - Node lifecycle, transforms, and hierarchy
  • component_* - Component management and scripting
  • prefab_* - Prefab browsing, creation, and instantiation
  • asset_* - Asset management and analysis
  • project_* - Project control and build system
  • debug_* - Console, logs, and system debugging
  • preferences_* - Editor preferences
  • server_* - Server information
  • broadcast_* - Message broadcasting
  • scene_* - 场景管理与层级操作
  • node_* - 节点生命周期、变换与层级操作
  • component_* - 组件管理与脚本操作
  • prefab_* - 预制件浏览、创建与实例化
  • asset_* - 资源管理与分析
  • project_* - 项目控制与构建系统
  • debug_* - 控制台、日志与系统调试
  • preferences_* - 编辑器偏好设置
  • server_* - 服务器信息
  • broadcast_* - 消息广播

Key Tools & Usage

核心工具与用法

Scene Management

场景管理

Get Current Scene

获取当前场景

typescript
// Tool: scene_management
{
  "action": "get_current_scene"
}
// Returns: { uuid: string, name: string, path: string }
typescript
// 工具: scene_management
{
  "action": "get_current_scene"
}
// 返回: { uuid: string, name: string, path: string }

Open Scene

打开场景

typescript
{
  "action": "open_scene",
  "sceneUuid": "scene-uuid-here"
}
typescript
{
  "action": "open_scene",
  "sceneUuid": "scene-uuid-here"
}

Create New Scene

创建新场景

typescript
{
  "action": "create_scene",
  "name": "MyNewScene",
  "savePath": "db://assets/scenes/"
}
typescript
{
  "action": "create_scene",
  "name": "MyNewScene",
  "savePath": "db://assets/scenes/"
}

Save Current Scene

保存当前场景

typescript
{
  "action": "save_scene"
}
typescript
{
  "action": "save_scene"
}

Node Operations

节点操作

Create Node

创建节点

typescript
// Tool: node_lifecycle
{
  "action": "create",
  "name": "PlayerNode",
  "parentUuid": "parent-node-uuid",  // Optional, defaults to scene root
  "nodeType": "2DNode",  // or "3DNode"
  "components": [  // Optional pre-installed components
    {
      "type": "cc.Sprite",
      "properties": {
        "spriteFrame": "texture-uuid"
      }
    }
  ]
}
typescript
// 工具: node_lifecycle
{
  "action": "create",
  "name": "PlayerNode",
  "parentUuid": "parent-node-uuid",  // 可选,默认场景根节点
  "nodeType": "2DNode",  // 或 "3DNode"
  "components": [  // 可选预安装组件
    {
      "type": "cc.Sprite",
      "properties": {
        "spriteFrame": "texture-uuid"
      }
    }
  ]
}

Query Nodes

查询节点

typescript
// Tool: node_query
{
  "action": "find_by_name",
  "name": "Player",
  "exactMatch": false  // Use pattern matching
}

// Or find all nodes
{
  "action": "find_all",
  "includeComponents": true
}
typescript
// 工具: node_query
{
  "action": "find_by_name",
  "name": "Player",
  "exactMatch": false  // 使用模式匹配
}

// 或查询所有节点
{
  "action": "find_all",
  "includeComponents": true
}

Delete Node

删除节点

typescript
// Tool: node_lifecycle
{
  "action": "delete",
  "uuid": "node-uuid-to-delete"
}
typescript
// 工具: node_lifecycle
{
  "action": "delete",
  "uuid": "node-uuid-to-delete"
}

Transform Node

变换节点

typescript
// Tool: node_transform
{
  "action": "set_property",
  "uuid": "node-uuid",
  "property": "position",
  "value": { "x": 100, "y": 200, "z": 0 }
}

// Set rotation
{
  "action": "set_property",
  "uuid": "node-uuid",
  "property": "rotation",
  "value": { "x": 0, "y": 0, "z": 45 }  // Euler angles
}

// Set scale
{
  "action": "set_property",
  "uuid": "node-uuid",
  "property": "scale",
  "value": { "x": 2, "y": 2, "z": 1 }
}
typescript
// 工具: node_transform
{
  "action": "set_property",
  "uuid": "node-uuid",
  "property": "position",
  "value": { "x": 100, "y": 200, "z": 0 }
}

// 设置旋转
{
  "action": "set_property",
  "uuid": "node-uuid",
  "property": "rotation",
  "value": { "x": 0, "y": 0, "z": 45 }  // 欧拉角
}

// 设置缩放
{
  "action": "set_property",
  "uuid": "node-uuid",
  "property": "scale",
  "value": { "x": 2, "y": 2, "z": 1 }
}

Move Node in Hierarchy

调整节点层级

typescript
// Tool: node_hierarchy
{
  "action": "move",
  "uuid": "node-uuid",
  "newParentUuid": "new-parent-uuid",
  "siblingIndex": 0  // Optional position among siblings
}
typescript
// 工具: node_hierarchy
{
  "action": "move",
  "uuid": "node-uuid",
  "newParentUuid": "new-parent-uuid",
  "siblingIndex": 0  // 可选,在兄弟节点中的位置
}

Component Management

组件管理

Add Engine Component

添加引擎组件

typescript
// Tool: component_manage
{
  "action": "add",
  "nodeUuid": "node-uuid",
  "componentType": "cc.Sprite",
  "properties": {
    "spriteFrame": "texture-uuid",
    "sizeMode": 0
  }
}

// Common component types:
// cc.Sprite, cc.Label, cc.Button, cc.RichText,
// cc.UITransform, cc.Canvas, cc.Widget,
// cc.BoxCollider2D, cc.RigidBody2D, etc.
typescript
// 工具: component_manage
{
  "action": "add",
  "nodeUuid": "node-uuid",
  "componentType": "cc.Sprite",
  "properties": {
    "spriteFrame": "texture-uuid",
    "sizeMode": 0
  }
}

// 常见组件类型:
// cc.Sprite, cc.Label, cc.Button, cc.RichText,
// cc.UITransform, cc.Canvas, cc.Widget,
// cc.BoxCollider2D, cc.RigidBody2D 等

Attach Custom Script

附加自定义脚本

typescript
// Tool: component_script
{
  "action": "add_script",
  "nodeUuid": "node-uuid",
  "scriptName": "PlayerController",  // Script file name without .ts
  "properties": {
    "speed": 100,
    "jumpForce": 500
  }
}
typescript
// 工具: component_script
{
  "action": "add_script",
  "nodeUuid": "node-uuid",
  "scriptName": "PlayerController",  // 不带.ts的脚本文件名
  "properties": {
    "speed": 100,
    "jumpForce": 500
  }
}

Get Component Information

获取组件信息

typescript
// Tool: component_query
{
  "action": "get_components",
  "nodeUuid": "node-uuid"
}
// Returns array with type (cid) and properties for each component
typescript
// 工具: component_query
{
  "action": "get_components",
  "nodeUuid": "node-uuid"
}
// 返回包含每个组件类型(cid)和属性的数组

Remove Component (IMPORTANT)

删除组件(重要)

typescript
// Tool: component_manage
// MUST use component's cid (type field), NOT script name!
// First, get component info:
{
  "action": "get_components",
  "nodeUuid": "node-uuid"
}
// Returns: [{ type: "comp.PlayerController!1234abcd", ... }]

// Then remove using exact type (cid):
{
  "action": "remove",
  "nodeUuid": "node-uuid",
  "componentType": "comp.PlayerController!1234abcd"  // Use exact cid
}
typescript
// 工具: component_manage
// 必须使用组件的cid(type字段),而非脚本名称!
// 首先获取组件信息:
{
  "action": "get_components",
  "nodeUuid": "node-uuid"
}
// 返回: [{ type: "comp.PlayerController!1234abcd", ... }]

// 然后使用精确的type(cid)删除:
{
  "action": "remove",
  "nodeUuid": "node-uuid",
  "componentType": "comp.PlayerController!1234abcd"  // 使用精确的cid
}

Set Component Properties

设置组件属性

typescript
// Tool: set_component_property
{
  "nodeUuid": "node-uuid",
  "componentType": "cc.Sprite",
  "properties": {
    "color": { "r": 255, "g": 0, "b": 0, "a": 255 }
  }
}

// For custom scripts, use full cid from get_components
{
  "nodeUuid": "node-uuid",
  "componentType": "comp.PlayerController!1234abcd",
  "properties": {
    "health": 100,
    "maxSpeed": 200
  }
}
typescript
// 工具: set_component_property
{
  "nodeUuid": "node-uuid",
  "componentType": "cc.Sprite",
  "properties": {
    "color": { "r": 255, "g": 0, "b": 0, "a": 255 }
  }
}

// 对于自定义脚本,使用get_components返回的完整cid
{
  "nodeUuid": "node-uuid",
  "componentType": "comp.PlayerController!1234abcd",
  "properties": {
    "health": 100,
    "maxSpeed": 200
  }
}

Prefab Operations

预制件操作

List Prefabs

列出预制件

typescript
// Tool: prefab_browse
{
  "action": "list",
  "folderPath": "db://assets/prefabs/"  // Optional
}
typescript
// 工具: prefab_browse
{
  "action": "list",
  "folderPath": "db://assets/prefabs/"  // 可选
}

Create Prefab from Node

从节点创建预制件

typescript
// Tool: prefab_lifecycle
{
  "action": "create",
  "nodeUuid": "source-node-uuid",
  "savePath": "db://assets/prefabs/MyPrefab.prefab"
}
typescript
// 工具: prefab_lifecycle
{
  "action": "create",
  "nodeUuid": "source-node-uuid",
  "savePath": "db://assets/prefabs/MyPrefab.prefab"
}

Instantiate Prefab

实例化预制件

typescript
// Tool: prefab_instance
{
  "action": "instantiate",
  "prefabUuid": "prefab-uuid",
  "parentUuid": "parent-node-uuid",  // Optional
  "position": { "x": 0, "y": 0, "z": 0 }  // Optional
}
typescript
// 工具: prefab_instance
{
  "action": "instantiate",
  "prefabUuid": "prefab-uuid",
  "parentUuid": "parent-node-uuid",  // 可选
  "position": { "x": 0, "y": 0, "z": 0 }  // 可选
}

Apply Instance Changes to Prefab

将实例变更应用到预制件

typescript
// Tool: prefab_instance
{
  "action": "apply",
  "nodeUuid": "prefab-instance-uuid"
}
typescript
// 工具: prefab_instance
{
  "action": "apply",
  "nodeUuid": "prefab-instance-uuid"
}

Revert Instance to Original

将实例还原为原始预制件

typescript
// Tool: prefab_instance
{
  "action": "revert",
  "nodeUuid": "prefab-instance-uuid"
}
typescript
// 工具: prefab_instance
{
  "action": "revert",
  "nodeUuid": "prefab-instance-uuid"
}

Asset Management

资源管理

Import Assets

导入资源

typescript
// Tool: asset_manage
{
  "action": "import",
  "paths": [
    "/path/to/texture.png",
    "/path/to/audio.mp3"
  ]
}
typescript
// 工具: asset_manage
{
  "action": "import",
  "paths": [
    "/path/to/texture.png",
    "/path/to/audio.mp3"
  ]
}

Query Assets by Type

按类型查询资源

typescript
// Tool: asset_query
{
  "action": "query_by_type",
  "type": "cc.Texture2D",  // cc.Texture2D, cc.SpriteFrame, cc.Prefab, cc.AudioClip, etc.
  "folder": "db://assets/textures/"  // Optional
}
typescript
// 工具: asset_query
{
  "action": "query_by_type",
  "type": "cc.Texture2D",  // cc.Texture2D, cc.SpriteFrame, cc.Prefab, cc.AudioClip等
  "folder": "db://assets/textures/"  // 可选
}

Get Asset Dependencies

获取资源依赖

typescript
// Tool: asset_analyze
{
  "action": "get_dependencies",
  "uuid": "asset-uuid"
}
typescript
// 工具: asset_analyze
{
  "action": "get_dependencies",
  "uuid": "asset-uuid"
}

Delete Asset

删除资源

typescript
// Tool: asset_operations
{
  "action": "delete",
  "uuid": "asset-uuid"
}
typescript
// 工具: asset_operations
{
  "action": "delete",
  "uuid": "asset-uuid"
}

Project Control

项目控制

Run Project

运行项目

typescript
// Tool: project_manage
{
  "action": "run",
  "preview": true  // false for simulator
}
typescript
// 工具: project_manage
{
  "action": "run",
  "preview": true  // false表示使用模拟器
}

Build Project

构建项目

typescript
// Tool: project_build_system
{
  "action": "build",
  "platform": "web-mobile",  // web-mobile, android, ios, windows, mac
  "buildPath": "/path/to/build/output"
}
typescript
// 工具: project_build_system
{
  "action": "build",
  "platform": "web-mobile",  // web-mobile, android, ios, windows, mac
  "buildPath": "/path/to/build/output"
}

Get Project Info

获取项目信息

typescript
// Tool: project_manage
{
  "action": "get_info"
}
// Returns project name, version, path, settings
typescript
// 工具: project_manage
{
  "action": "get_info"
}
// 返回项目名称、版本、路径、设置

Debugging

调试

Get Console Logs

获取控制台日志

typescript
// Tool: debug_console
{
  "action": "get_logs",
  "filter": "error",  // Optional: log, warn, error
  "limit": 50  // Optional
}
typescript
// 工具: debug_console
{
  "action": "get_logs",
  "filter": "error",  // 可选: log, warn, error
  "limit": 50  // 可选
}

Clear Console

清空控制台

typescript
// Tool: debug_console
{
  "action": "clear"
}
typescript
// 工具: debug_console
{
  "action": "clear"
}

Search Log Files

搜索日志文件

typescript
// Tool: debug_logs
{
  "action": "search",
  "pattern": "Error:",
  "maxLines": 100
}
typescript
// 工具: debug_logs
{
  "action": "search",
  "pattern": "Error:",
  "maxLines": 100
}

Common Patterns

常见模式

Creating a Complete Game Object

创建完整游戏对象

typescript
// 1. Create node
const createNode = {
  tool: "node_lifecycle",
  arguments: {
    action: "create",
    name: "Player",
    nodeType: "2DNode"
  }
};
// Response includes: { uuid: "player-node-uuid" }

// 2. Add sprite component
const addSprite = {
  tool: "component_manage",
  arguments: {
    action: "add",
    nodeUuid: "player-node-uuid",
    componentType: "cc.Sprite",
    properties: {
      spriteFrame: "player-texture-uuid"
    }
  }
};

// 3. Attach script
const addScript = {
  tool: "component_script",
  arguments: {
    action: "add_script",
    nodeUuid: "player-node-uuid",
    scriptName: "PlayerController",
    properties: {
      speed: 300,
      health: 100
    }
  }
};

// 4. Position node
const setPosition = {
  tool: "node_transform",
  arguments: {
    action: "set_property",
    uuid: "player-node-uuid",
    property: "position",
    value: { x: 0, y: 0, z: 0 }
  }
};
typescript
// 1. 创建节点
const createNode = {
  tool: "node_lifecycle",
  arguments: {
    action: "create",
    name: "Player",
    nodeType: "2DNode"
  }
};
// 响应包含: { uuid: "player-node-uuid" }

// 2. 添加精灵组件
const addSprite = {
  tool: "component_manage",
  arguments: {
    action: "add",
    nodeUuid: "player-node-uuid",
    componentType: "cc.Sprite",
    properties: {
      spriteFrame: "player-texture-uuid"
    }
  }
};

// 3. 附加脚本
const addScript = {
  tool: "component_script",
  arguments: {
    action: "add_script",
    nodeUuid: "player-node-uuid",
    scriptName: "PlayerController",
    properties: {
      speed: 300,
      health: 100
    }
  }
};

// 4. 设置节点位置
const setPosition = {
  tool: "node_transform",
  arguments: {
    action: "set_property",
    uuid: "player-node-uuid",
    property: "position",
    value: { x: 0, y: 0, z: 0 }
  }
};

Working with Prefabs

预制件操作流程

typescript
// 1. Find a node to convert
const findNode = {
  tool: "node_query",
  arguments: {
    action: "find_by_name",
    name: "Enemy"
  }
};

// 2. Create prefab from node
const createPrefab = {
  tool: "prefab_lifecycle",
  arguments: {
    action: "create",
    nodeUuid: "enemy-node-uuid",
    savePath: "db://assets/prefabs/Enemy.prefab"
  }
};

// 3. Instantiate multiple times
const spawn1 = {
  tool: "prefab_instance",
  arguments: {
    action: "instantiate",
    prefabUuid: "enemy-prefab-uuid",
    position: { x: 100, y: 0, z: 0 }
  }
};

const spawn2 = {
  tool: "prefab_instance",
  arguments: {
    action: "instantiate",
    prefabUuid: "enemy-prefab-uuid",
    position: { x: -100, y: 0, z: 0 }
  }
};
typescript
// 1. 查找要转换的节点
const findNode = {
  tool: "node_query",
  arguments: {
    action: "find_by_name",
    name: "Enemy"
  }
};

// 2. 从节点创建预制件
const createPrefab = {
  tool: "prefab_lifecycle",
  arguments: {
    action: "create",
    nodeUuid: "enemy-node-uuid",
    savePath: "db://assets/prefabs/Enemy.prefab"
  }
};

// 3. 多次实例化
const spawn1 = {
  tool: "prefab_instance",
  arguments: {
    action: "instantiate",
    prefabUuid: "enemy-prefab-uuid",
    position: { x: 100, y: 0, z: 0 }
  }
};

const spawn2 = {
  tool: "prefab_instance",
  arguments: {
    action: "instantiate",
    prefabUuid: "enemy-prefab-uuid",
    position: { x: -100, y: 0, z: 0 }
  }
};

Batch Node Operations

批量节点操作

typescript
// 1. Find all enemy nodes
const findEnemies = {
  tool: "node_query",
  arguments: {
    action: "find_by_name",
    name: "Enemy",
    exactMatch: false  // Pattern match
  }
};
// Returns: [{ uuid: "enemy1-uuid" }, { uuid: "enemy2-uuid" }, ...]

// 2. Delete all enemies
// For each enemy uuid:
const deleteEnemy = {
  tool: "node_lifecycle",
  arguments: {
    action: "delete",
    uuid: "enemy-uuid"
  }
};
typescript
// 1. 查找所有敌人节点
const findEnemies = {
  tool: "node_query",
  arguments: {
    action: "find_by_name",
    name: "Enemy",
    exactMatch: false  // 模式匹配
  }
};
// 返回: [{ uuid: "enemy1-uuid" }, { uuid: "enemy2-uuid" }, ...]

// 2. 删除所有敌人
// 对每个敌人uuid执行:
const deleteEnemy = {
  tool: "node_lifecycle",
  arguments: {
    action: "delete",
    uuid: "enemy-uuid"
  }
};

Scene Setup Workflow

场景搭建流程

typescript
// 1. Create new scene
const newScene = {
  tool: "scene_management",
  arguments: {
    action: "create_scene",
    name: "Level1",
    savePath: "db://assets/scenes/"
  }
};

// 2. Create background node
const background = {
  tool: "node_lifecycle",
  arguments: {
    action: "create",
    name: "Background",
    nodeType: "2DNode",
    components: [{
      type: "cc.Sprite",
      properties: {
        spriteFrame: "bg-texture-uuid"
      }
    }]
  }
};

// 3. Create UI canvas
const canvas = {
  tool: "node_lifecycle",
  arguments: {
    action: "create",
    name: "Canvas",
    nodeType: "2DNode",
    components: [{
      type: "cc.Canvas"
    }]
  }
};

// 4. Save scene
const saveScene = {
  tool: "scene_management",
  arguments: {
    action: "save_scene"
  }
};
typescript
// 1. 创建新场景
const newScene = {
  tool: "scene_management",
  arguments: {
    action: "create_scene",
    name: "Level1",
    savePath: "db://assets/scenes/"
  }
};

// 2. 创建背景节点
const background = {
  tool: "node_lifecycle",
  arguments: {
    action: "create",
    name: "Background",
    nodeType: "2DNode",
    components: [{
      type: "cc.Sprite",
      properties: {
        spriteFrame: "bg-texture-uuid"
      }
    }]
  }
};

// 3. 创建UI画布
const canvas = {
  tool: "node_lifecycle",
  arguments: {
    action: "create",
    name: "Canvas",
    nodeType: "2DNode",
    components: [{
      type: "cc.Canvas"
    }]
  }
};

// 4. 保存场景
const saveScene = {
  tool: "scene_management",
  arguments: {
    action: "save_scene"
  }
};

Configuration

配置

Server Settings

服务器设置

Access via MCP panel in Cocos Creator:
  • Port: Default 3000, customizable
  • Auto-start: Enable to launch server with editor
  • Tool Management: Selectively enable/disable specific tools
通过Cocos Creator中的MCP面板访问:
  • 端口:默认3000,可自定义
  • 自动启动:启用后编辑器启动时自动启动服务器
  • 工具管理:选择性启用/禁用特定工具

Tool Configuration

工具配置

The plugin saves tool configurations in editor preferences. Enable/disable tools through the MCP panel's tool management tab.
插件将工具配置保存到编辑器偏好设置中,可通过MCP面板的工具管理标签启用/禁用工具。

Environment Variables

环境变量

For external integrations, you can configure:
bash
undefined
对于外部集成,可配置:
bash
undefined

MCP server endpoint

MCP服务器端点

Project path (if automating multiple projects)

项目路径(如果要自动化多个项目)

COCOS_PROJECT_PATH=/path/to/project
undefined
COCOS_PROJECT_PATH=/path/to/project
undefined

Troubleshooting

故障排除

Server Won't Start

服务器无法启动

Issue: MCP server fails to start in Cocos Creator
Solutions:
  1. Check port is not in use:
    netstat -an | grep 3000
  2. Try different port in MCP panel settings
  3. Restart Cocos Creator
  4. Check extension is enabled in Extension Manager
问题:MCP服务器在Cocos Creator中启动失败
解决方案
  1. 检查端口是否被占用:
    netstat -an | grep 3000
  2. 在MCP面板设置中尝试其他端口
  3. 重启Cocos Creator
  4. 检查扩展管理器中插件是否已启用

Tool Calls Failing

工具调用失败

Issue: AI can't execute tools or gets errors
Solutions:
  1. Verify server is running (check MCP panel status)
  2. Ensure scene is open (many tools require active scene)
  3. Check UUIDs are valid (use query tools first)
  4. Enable debug logging in console to see detailed errors
问题:AI无法执行工具或返回错误
解决方案
  1. 验证服务器是否运行(检查MCP面板状态)
  2. 确保场景已打开(许多工具需要激活场景)
  3. 检查UUID是否有效(先使用查询工具获取)
  4. 在控制台启用调试日志查看详细错误

Component Removal Fails

组件删除失败

Issue: Cannot remove component or script
Solution: Always use the exact
cid
(type field) from
component_query
:
typescript
// ✅ CORRECT
// First get component info
{ action: "get_components", nodeUuid: "node-uuid" }
// Returns: [{ type: "comp.MyScript!abc123", ... }]

// Then remove with exact cid
{
  action: "remove",
  nodeUuid: "node-uuid",
  componentType: "comp.MyScript!abc123"
}

// ❌ WRONG - Don't use script name
{
  action: "remove",
  nodeUuid: "node-uuid",
  componentType: "MyScript"  // Will fail!
}
问题:无法删除组件或脚本
解决方案: 始终使用
component_query
返回的精确
cid
(type字段):
typescript
// ✅ 正确方式
// 先获取组件信息
{ action: "get_components", nodeUuid: "node-uuid" }
// 返回: [{ type: "comp.MyScript!abc123", ... }]

// 然后使用精确的cid删除
{
  action: "remove",
  nodeUuid: "node-uuid",
  componentType: "comp.MyScript!abc123"
}

// ❌ 错误方式 - 不要使用脚本名称
{
  action: "remove",
  nodeUuid: "node-uuid",
  componentType: "MyScript"  // 会失败!
}

Prefab References Lost

预制件引用丢失

Issue: Prefab loses component or asset references
Solutions:
  • This was fixed in v1.4.0+
  • Ensure using latest plugin version
  • Internal references use
    {"__id__": x}
    format
  • External references set to
    null
    (as expected)
  • Asset references preserve UUID format
问题:预制件丢失组件或资源引用
解决方案
  • 该问题已在v1.4.0+版本中修复
  • 确保使用最新插件版本
  • 内部引用使用
    {"__id__": x}
    格式
  • 外部引用设置为
    null
    (符合预期)
  • 资源引用保留UUID格式

Connection Issues

连接问题

Issue: MCP client can't connect to server
Solutions:
  1. Verify URL in client config matches server port
  2. Check firewall isn't blocking localhost connections
  3. Restart both Cocos Creator and MCP client
  4. Test with:
    curl http://127.0.0.1:3000/mcp
问题:MCP客户端无法连接到服务器
解决方案
  1. 验证客户端配置中的URL与服务器端口匹配
  2. 检查防火墙是否阻止本地连接
  3. 重启Cocos Creator和MCP客户端
  4. 使用以下命令测试:
    curl http://127.0.0.1:3000/mcp

Performance Degradation

性能下降

Issue: Editor becomes slow with MCP server
Solutions:
  1. Disable unused tools in tool management
  2. Reduce log levels in debug tools
  3. Limit query result counts
  4. Close unnecessary editor panels
问题:启用MCP服务器后编辑器变慢
解决方案
  1. 在工具管理中禁用未使用的工具
  2. 降低调试工具的日志级别
  3. 限制查询结果数量
  4. 关闭不必要的编辑器面板

Cross-Platform Path Issues

跨平台路径问题

Issue: Asset paths don't work on different OS
Solution: Always use Cocos
db://
protocol for asset paths:
typescript
// ✅ CORRECT - Cross-platform
"savePath": "db://assets/prefabs/MyPrefab.prefab"

// ❌ WRONG - Platform-specific
"savePath": "/Users/me/project/assets/prefabs/MyPrefab.prefab"
问题:资源路径在不同操作系统下无法正常工作
解决方案: 始终使用Cocos的
db://
协议作为资源路径:
typescript
// ✅ 正确方式 - 跨平台兼容
"savePath": "db://assets/prefabs/MyPrefab.prefab"

// ❌ 错误方式 - 平台专属
"savePath": "/Users/me/project/assets/prefabs/MyPrefab.prefab"

Advanced Usage

高级用法

Custom Message Broadcasting

自定义消息广播

typescript
// Listen for custom events
const listen = {
  tool: "broadcast_message",
  arguments: {
    action: "listen",
    channel: "game-events"
  }
};

// Send custom messages
const broadcast = {
  tool: "broadcast_message",
  arguments: {
    action: "broadcast",
    channel: "game-events",
    message: { event: "player_died", score: 100 }
  }
};
typescript
// 监听自定义事件
const listen = {
  tool: "broadcast_message",
  arguments: {
    action: "listen",
    channel: "game-events"
  }
};

// 发送自定义消息
const broadcast = {
  tool: "broadcast_message",
  arguments: {
    action: "broadcast",
    channel: "game-events",
    message: { event: "player_died", score: 100 }
  }
};

Preferences Management

偏好设置管理

typescript
// Get editor preferences
const getPrefs = {
  tool: "preferences_manage",
  arguments: {
    action: "get",
    key: "editor.grid.snap"
  }
};

// Set preferences
const setPrefs = {
  tool: "preferences_manage",
  arguments: {
    action: "set",
    key: "editor.grid.snap",
    value: true
  }
};
typescript
// 获取编辑器偏好设置
const getPrefs = {
  tool: "preferences_manage",
  arguments: {
    action: "get",
    key: "editor.grid.snap"
  }
};

// 设置偏好设置
const setPrefs = {
  tool: "preferences_manage",
  arguments: {
    action: "set",
    key: "editor.grid.snap",
    value: true
  }
};

System Information

系统信息

typescript
// Get detailed system info
const systemInfo = {
  tool: "debug_system",
  arguments: {
    action: "get_info"
  }
};
// Returns: editor version, OS, memory, performance stats
typescript
// 获取详细系统信息
const systemInfo = {
  tool: "debug_system",
  arguments: {
    action: "get_info"
  }
};
// 返回: 编辑器版本、操作系统、内存、性能统计

Best Practices

最佳实践

  1. Always Query Before Modify: Use query tools to get UUIDs before operations
  2. Use Exact CIDs for Components: Never use script names for removal
  3. Save After Major Changes: Call
    save_scene
    after structural changes
  4. Validate UUIDs: Check UUIDs exist before referencing
  5. Use db:// Paths: Always use Cocos protocol for cross-platform compatibility
  6. Enable Only Needed Tools: Disable unused tools for better performance
  7. Test Prefabs After Creation: Instantiate and verify before distributing
  8. Handle Errors Gracefully: Check tool responses for success/failure
  1. 修改前先查询:操作前使用查询工具获取UUID
  2. 使用精确CID操作组件:删除组件时绝不使用脚本名称
  3. 重大变更后保存:结构变更后调用
    save_scene
  4. 验证UUID有效性:引用前检查UUID是否存在
  5. 使用db://路径:始终使用Cocos协议保证跨平台兼容
  6. 仅启用必要工具:禁用未使用的工具提升性能
  7. 创建预制件后测试:实例化并验证后再分发
  8. 优雅处理错误:检查工具响应的成功/失败状态

Resources

资源

Version Compatibility

版本兼容性

  • Plugin Version: 1.5.0+ recommended (1.4.0+ on GitHub)
  • Cocos Creator: 3.8.6 or higher
  • MCP Clients: Claude Desktop, Claude CLI, Cursor, VS Code (with MCP extensions)
  • Node.js: Not required (plugin runs in editor runtime)
  • 插件版本:推荐v1.5.0+(GitHub上v1.4.0+)
  • Cocos Creator:3.8.6或更高版本
  • MCP客户端:Claude Desktop、Claude CLI、Cursor、VS Code(带MCP扩展)
  • Node.js:不需要(插件运行在编辑器运行时)