Skip to main content
Glama

cocos_add_and_attach_script

Create a TypeScript script file and attach it as a component to a scene node in one operation, eliminating UUID handling errors and simplifying Cocos Creator workflow.

Instructions

Write a TS script file + attach it as a component in ONE call.

Replaces the 3-call sequence agents ran dozens of times per session::

r = cocos_add_script(project, "Bird", source)       # file + meta
short = cocos_compress_uuid(r["uuid"])               # UUID form
cid = cocos_add_script(scene, node_id, short, props) # attach

The two same-named cocos_add_script tools (the project- level writer vs. the scene-level attacher) were the main friction — agents accidentally passed the standard UUID to the attacher, or skipped the compress step entirely and got a silently-broken component.

Arguments:

  • project_path / rel_path / source — where the .ts lives. rel_path follows cocos_add_script's prefix rules (bare name → assets/scripts/<name>.ts).

  • scene_path / node_id — target scene (or .prefab) and the node's array index.

  • props — component @property values, forwarded verbatim. Use {"__id__": N} for node/component refs, {"__uuid__": "..."} for asset refs.

  • uuid — optional override for the .ts.meta UUID. Omit to let the underlying add_script preserve an existing UUID on overwrite (idempotent mode) or mint a fresh one on first write.

Returns::

{
  "script_path":    "/abs/path/Foo.ts",
  "rel_path":       "assets/scripts/Foo.ts",
  "uuid_standard":  "5372d6f5-...",       # 36-char form
  "uuid_compressed":"5372db1cH...",       # what scenes use
  "component_id":   <int>,                # attached comp's id
  "created":        <bool>,               # False if meta preserved
}

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_pathYes
rel_pathYes
sourceYes
scene_pathYes
node_idYes
propsNo
uuidNo
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 key behaviors: it's a write operation (creates/updates files and attaches components), explains idempotent mode ('preserve an existing UUID on overwrite'), mentions potential errors ('silently-broken component'), and details the return structure. However, it doesn't cover permissions, rate limits, or error handling beyond the UUID issue.

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 well-structured and appropriately sized. It front-loads the core purpose, provides context about the problem it solves, details parameters in a clear section, and shows the return format. While comprehensive, every sentence earns its place by adding necessary information. The only minor improvement would be slightly tighter formatting of the parameter explanations.

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 (7 parameters, no annotations, no output schema), the description provides complete context. It explains the tool's purpose, when to use it, detailed parameter semantics, behavioral characteristics, and the exact return structure. For a mutation tool with rich functionality and no structured metadata, this description adequately compensates with thorough textual documentation.

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?

With 0% schema description coverage for 7 parameters, the description fully compensates by providing detailed semantic explanations for all parameters. It explains what each parameter does (e.g., 'rel_path follows cocos_add_script's prefix rules'), provides usage examples ('Use {"__id__": N} for node/component refs'), and clarifies optional behavior ('Omit to let the underlying add_script preserve an existing UUID'). This adds substantial value beyond the bare 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's purpose: 'Write a TS script file + attach it as a component in ONE call.' It specifies the exact action (write and attach), the resource (TS script file), and distinguishes it from sibling tools by explaining it replaces the problematic 3-call sequence involving 'cocos_add_script' and 'cocos_compress_uuid'.

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 provides explicit usage guidelines by explaining when to use this tool ('Replaces the 3-call sequence agents ran dozens of times per session') and when not to use alternatives (avoiding the 'two same-named cocos_add_script tools' that cause friction). It names specific sibling tools ('cocos_add_script', 'cocos_compress_uuid') and describes the problems they cause, giving clear context for tool selection.

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