Skip to main content
Glama

cocos_add_button

Add interactive button components to Cocos Creator scenes with configurable visual transitions and click event bindings for user interface functionality.

Instructions

Attach cc.Button. transition: 0=NONE, 1=COLOR, 2=SCALE, 3=SPRITE.

color_preset (e.g. "primary", "secondary", "danger") sets normal_color from the project's UI theme AND auto-derives matching hover / pressed / disabled shades — pass explicit RGBA args only when you want to override those derived values.

click_events: list of dicts from cocos_make_click_event(). Each binds a button press to a script method. Example: evt = cocos_make_click_event(scene, gm_node, 'GameManager', 'onRestart') cocos_add_button(scene, btn_node, click_events=[evt])

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scene_pathYes
node_idYes
transitionNo
zoom_scaleNo
click_eventsNo
normal_color_rNo
normal_color_gNo
normal_color_bNo
normal_color_aNo
hover_color_rNo
hover_color_gNo
hover_color_bNo
hover_color_aNo
pressed_color_rNo
pressed_color_gNo
pressed_color_bNo
pressed_color_aNo
disabled_color_rNo
disabled_color_gNo
disabled_color_bNo
disabled_color_aNo
color_presetNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden. It discloses that the tool attaches a button component (implying mutation/creation), explains color preset behavior and auto-derivation logic, and shows click event binding. However, it doesn't mention permissions, error conditions, rate limits, or what happens if the node already has a button component.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured with key information front-loaded: purpose, transition types, color_preset behavior, and click_events usage. The example is helpful and well-placed. Some sentences could be slightly more concise, but overall it's appropriately sized for the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complex 22-parameter schema with 0% description coverage and no annotations, the description does a good job covering the most important aspects: transition types, color system, and click events. The presence of an output schema reduces the need to explain return values. However, for such a complex tool, more complete parameter coverage would be ideal.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage and 22 parameters, the description adds significant value beyond the schema. It explains the meaning of 'transition' values (0-3), clarifies color_preset behavior and its relationship to RGBA parameters, and provides usage context for click_events. However, it doesn't cover all 22 parameters - notably missing scene_path and node_id semantics.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Attach cc.Button' with specific details about transition types. It distinguishes from sibling 'cocos_add_button_with_label' by focusing on button attachment without label functionality. However, it doesn't explicitly contrast with other UI component tools like 'cocos_add_toggle' or 'cocos_add_slider'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context about when to use color_preset versus explicit RGBA values, and includes a concrete example showing how to use click_events with cocos_make_click_event. However, it doesn't explicitly state when NOT to use this tool versus alternatives like 'cocos_add_button_with_label' or other UI components.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/chenShengBiao/cocos-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server