Skip to main content
Glama

mp_evaluate

Execute a JavaScript function within a WeChat Mini Program's AppService context and return its JSON-serialized result. Use for reading dynamic page data or performing state assertions.

Instructions

向小程序 AppService 注入并执行一个函数,返回其结果。functionSource 必须是完整的 function 表达式字符串(如 function(){ return getCurrentPages().pop().data.ready }() => wx.getStorageSync('token')),不能是裸语句。函数体跑在 AppService 上下文,可用 getCurrentPages()、getApp()、wx 等全局;args 数组会按顺序作为函数入参展开。返回值经 JSON 序列化,别返回 DOM/句柄类不可序列化对象。

适合在 page.data 不稳定时显式读取 / 状态机断言 / 内联绕过 modal。可选 timeoutMs 覆盖默认 15s(上限 600s),用于长耗时异步。⚠️ 等任意条件请用 mp_pollUntil(内置 predicate 轮询,比 evaluate+waitTimeout+evaluate 手写循环稳);要调 wx.* API 用 mp_callWx。注意:函数体别遍历完整 prototype 链或做复杂反射,可能命中 SDK wrapper 抛 'Cannot read property is of undefined',保持函数体最小。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
argsNo
maxBytesNo
timeoutMsNo
connectionNo可选连接覆盖(不传则用默认会话)。可用字段:mode(launch|connect)、cliPath、projectPath、wsEndpoint、timeout、port(【自动化端口】→ cli auto --auto-port,默认 9420;不是 IDE HTTP 服务端口,别把 IDE 服务端口传进来)、account、ticket、trustProject、args、cwd、autoClose、autoLaunch、launchTimeout、connectTimeout。
functionSourceYes
Behavior5/5

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

No annotations provided, but description fully discloses execution context, global objects, JSON serialization of return, timeout defaults and limits, and potential errors (prototype chain issues).

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?

Well-structured: starts with core purpose, then usage guidelines, then warnings. Every sentence adds value despite length.

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 5 parameters, no output schema, and nested objects, description covers input constraints, behavior, return, timeout, and edge cases. Minor gap: maxBytes not mentioned.

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?

Schema coverage is 20% (only connection described). Description adds meaning for functionSource (full function expression), args (passed as arguments), timeoutMs (default and max), and connection (optional override). However, maxBytes parameter is not explained.

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?

Clear verb+resource: inject and execute a function in AppService, return result. Distinguished from siblings mp_callWx and mp_pollUntil by specifying alternate use cases.

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?

Explicitly states when to use (unstable page.data, state machine assertions) and when not (use mp_pollUntil for waiting, mp_callWx for wx.* APIs). Also warns against complex prototype traversal.

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/Chaixueyuan/weapp-agent-mcp'

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