Skip to main content
Glama

cocos_read_preview_state

Retrieve runtime game state values from Cocos Creator preview by evaluating JavaScript expressions against exposed window objects.

Instructions

Evaluate a JavaScript expression against the running preview and return the value.

The preview page must expose state on window for this to be useful — the pattern is window.game = this inside a GameManager's onLoad. Then you can read window.game.score, cc.director.getScene().name, etc.

Returns {ok, value, error}. On a JS exception, ok=False and error carries the message — a bad expression can't crash the tool.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes
expressionNowindow.game
wait_msNo
viewport_widthNo
viewport_heightNo
timeout_msNo
Behavior4/5

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

With no annotations provided, the description carries full burden and does well. It discloses that expressions are evaluated against a running preview, that the tool handles JS exceptions gracefully ('a bad expression can't crash the tool'), and describes the return format structure. It could mention performance implications of the wait/timeout parameters or whether this affects the preview state, but covers key behavioral aspects.

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 efficiently structured with four focused sentences: purpose statement, prerequisite condition, concrete examples, and return format with error handling. Every sentence adds essential information with zero waste, making it easy to parse while being comprehensive.

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?

For a tool with 6 parameters, no annotations, and no output schema, the description does well by explaining the core functionality, prerequisites, examples, and return format. It could more explicitly connect parameters like 'wait_ms' and 'timeout_ms' to the preview interaction behavior, but covers the essential context needed to understand and use the tool effectively.

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 for 6 parameters, the description compensates well by explaining the core 'expression' parameter through examples and context. It doesn't explicitly document all parameters (url, wait_ms, viewport dimensions, timeout), but the examples and context provide meaningful guidance for the primary use case. The description adds significant 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 specific action ('Evaluate a JavaScript expression against the running preview and return the value'), identifies the resource ('the running preview'), and distinguishes from siblings by focusing on reading state rather than adding/modifying components like most other tools. It provides concrete examples of what can be read, making the purpose unambiguous.

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 for when to use this tool ('The preview page must expose state on `window` for this to be useful') and gives a specific pattern example. However, it doesn't explicitly state when NOT to use it or name alternative tools for different scenarios, though the sibling list suggests many alternatives for different operations.

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