Skip to main content
Glama

mp_ensureConnection

Ensures the WeChat mini-program automation session is ready, automatically launching or reconnecting the developer tools if needed. Use this before any UI operation to guarantee a stable connection.

Instructions

确保小程序自动化会话就绪——这是连接链路的默认入口:在 mp_screenshot / page_* / element_* 之前先调它。它会自愈:会话未就绪时自动拉起微信开发者工具 / 重启 cli auto 并建立 automator 连接,不只是被动检查。

何时用:任何“先连上再操作”的场景,直接调本工具,不需要先 mp_diagnoseConnection(那是只读探测,可跳过)。 失败时:先读错误信息里的 Next step 引导,通常是 ① 带 reconnect=true 重试,或 ② 先 mp_listProjects 再带 projectSelection 重试——不要原样重试同一调用,也不要直接停下来找用户。

defaultProject 不在 recents 时,server 会用 defaultProject 重启 cli auto,第一次仍可能失败——此时按错误信息 retry 即可。

返回 JSON 含 mode / projectPath / defaultProjectPath / wsEndpoint / port / 内嵌 diagnosis / currentPage(已就绪可信,无需再调 mp_currentPage 校验)/ systemInfo。connect 模式无法确认 IDE 当前打开项目时 projectPath 会是 null,defaultProjectPath 仅表示持久化默认值,不会冒充当前项目。

参数:reconnect=true 强制丢弃现有会话重连(用于会话疑似失效/卡死);projectSelection 传 mp_listProjects 返回的 index / name / path 之一,用于在“需要选择项目”的提示后定向选中;所选路径会用于当前 ensure 并保存为默认项目,同名项目请用 index 或完整 path 消歧。connection 可选,覆盖默认连接参数。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
reconnectNo
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。
projectSelectionNo
Behavior5/5

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

With no annotations, the description fully carries the burden. It discloses self-healing behavior, session management, retry logic, and details about the return JSON (e.g., projectPath being null in connect mode). No contradictions.

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 front-loaded with the core purpose, then usage, failure recovery, and parameter details. Each section adds value without unnecessary repetition despite the length.

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 tool's complexity, no annotations, and no output schema, the description covers purpose, usage, failure recovery, parameter semantics, and key return fields. It is sufficient for an agent to use correctly.

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?

Schema coverage is only 33%, but the description compensates by explaining each parameter in context: reconnect forces discard and reconnection, projectSelection accepts index/name/path for disambiguation, and connection details fields with a caution about the port.

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 ensures a mini-program automation session is ready and identifies itself as the default entry point before screenshot/page/element tools. It distinguishes itself from mp_diagnoseConnection by noting that it is read-only and can be skipped.

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 says to call this tool before other actions and not to call mp_diagnoseConnection first. Provides failure handling guidance: retry with reconnect=true or list projects first, and warns against retrying the same call or stopping.

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