Skip to main content
Glama

cocos_add_button_with_label

Create a labeled button UI element in Cocos Creator by combining node creation, transforms, button components, and label components into a single function call.

Instructions

Create a button node with a child Label in one call.

The most common UI primitive — menus typically have 2-4 buttons, each requiring:

btn_node = cocos_create_node(scene, parent, name, ...)
cocos_add_uitransform(scene, btn_node, W, H)
cocos_add_sprite(scene, btn_node, sprite_frame_uuid, ...)  # optional
btn = cocos_add_button(scene, btn_node, ...)
lbl_node = cocos_create_node(scene, btn_node, "Label")
cocos_add_uitransform(scene, lbl_node, W, H)
lbl = cocos_add_label(scene, lbl_node, text, font_size, ...)

Folds all seven calls into one. Structure produced::

Btn (Node + UITransform + optional Sprite + Button)
 └── Label (Node + UITransform + Label)

Design-token presets (label_color_preset / label_size_preset / bg_color_preset) resolve through the project's UI theme. Forward click_events from cocos_make_click_event verbatim.

Returns {button_node_id, label_node_id, button_component_id, label_component_id, sprite_component_id}.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scene_pathYes
parent_idYes
label_textYes
widthNo
heightNo
nameNo
pos_xNo
pos_yNo
font_sizeNo
sprite_frame_uuidNo
label_color_presetNo
label_size_presetNo
bg_color_presetNo
transitionNo
zoom_scaleNo
click_eventsNo
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes the tool's behavior: it creates a composite UI element, handles design-token presets through the project's UI theme, forwards click events verbatim from 'cocos_make_click_event', and specifies the return structure. However, it lacks details on error handling, permissions, or rate limits, which are minor gaps given the context.

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

Conciseness5/5

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

The description is well-structured and front-loaded with the main purpose, followed by detailed context, examples, and return values. Every sentence adds value: the first states the core function, the second explains the common use case, the third lists the folded calls, the fourth shows the structure, the fifth covers design tokens, the sixth explains click events, and the seventh specifies returns. No waste, highly efficient.

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

Completeness5/5

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

Given the complexity (16 parameters, no annotations, no output schema), the description is remarkably complete. It covers purpose, usage, behavioral traits, parameter semantics, and return values in detail. The lack of output schema is mitigated by explicitly stating the return structure. For a tool with high parameter count and zero schema coverage, this description provides all necessary context for effective use.

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

Parameters5/5

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

The schema description coverage is 0%, so the description must compensate fully. It adds significant meaning beyond the schema: it explains that parameters like 'label_color_preset', 'label_size_preset', and 'bg_color_preset' resolve through the project's UI theme, clarifies that 'click_events' are forwarded from 'cocos_make_click_event', and implies default behaviors for optional parameters (e.g., sprite is optional). This provides essential context not in the schema.

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

Purpose5/5

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

The description clearly states the tool creates a button node with a child label in one call, specifying the exact structure produced (Btn with UITransform, optional Sprite, Button, and child Label with UITransform and Label). It distinguishes from siblings like 'cocos_add_button' and 'cocos_add_label' by emphasizing it folds seven separate calls into one, making the purpose specific and differentiated.

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

Usage Guidelines5/5

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

The description explicitly states when to use this tool: for the 'most common UI primitive' where menus typically have 2-4 buttons, and it folds seven separate calls into one. It implies alternatives by listing the individual sibling tools (e.g., cocos_create_node, cocos_add_uitransform, cocos_add_button, cocos_add_label) that would otherwise be needed, providing clear context for usage versus those alternatives.

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