Skip to main content
Glama
yfmeii

WeChat Mini Program Dev MCP

by yfmeii

mp_ensureConnection

Verifies and maintains the automation session connection for WeChat Mini Program development, allowing optional configuration overrides or forced reconnection when needed.

Instructions

检查小程序自动化会话是否就绪。可选择覆盖连接设置或强制重连。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionNo
reconnectNo

Implementation Reference

  • The main handler function (execute) that implements the tool logic: parses input parameters, uses manager.withMiniProgram to ensure connection (with optional override and reconnect), fetches current page and system info, formats and returns the connection details as text result.
    execute: async (rawArgs, context: ToolContext) => {
      const args = ensureConnectionParameters.parse(rawArgs ?? {});
      const result = await manager.withMiniProgram<ContentResult>(
        context.log,
        {
          overrides: args.connection,
          reconnect: args.reconnect ?? false,
        },
        async (miniProgram, config) => {
          const page = await miniProgram.currentPage();
          let systemInfo: unknown;
          try {
            systemInfo = await miniProgram.systemInfo();
          } catch {
            systemInfo = null;
          }
    
          return toTextResult(
            formatJson({
              mode: config.mode,
              projectPath: config.projectPath,
              wsEndpoint: config.wsEndpoint,
              port: config.port,
              autoClose: config.autoClose ?? false,
              currentPage: page
                ? { path: page.path, query: page.query }
                : null,
              systemInfo,
            })
          );
        }
      );
    
      return result;
    },
  • Zod schema for the tool's input parameters, extending connectionContainerSchema with an optional 'reconnect' boolean flag.
    export const ensureConnectionParameters = connectionContainerSchema
      .extend({
        reconnect: z.coerce.boolean().optional().default(false),
      });
  • Factory function that defines and returns the tool object, including name, description, parameters schema, and execute handler. This tool is included in createApplicationTools.
    function createEnsureConnectionTool(manager: WeappAutomatorManager): AnyTool {
      return {
        name: "mp_ensureConnection",
        description:
          "检查小程序自动化会话是否就绪。可选择覆盖连接设置或强制重连。",
        parameters: ensureConnectionParameters,
        execute: async (rawArgs, context: ToolContext) => {
          const args = ensureConnectionParameters.parse(rawArgs ?? {});
          const result = await manager.withMiniProgram<ContentResult>(
            context.log,
            {
              overrides: args.connection,
              reconnect: args.reconnect ?? false,
            },
            async (miniProgram, config) => {
              const page = await miniProgram.currentPage();
              let systemInfo: unknown;
              try {
                systemInfo = await miniProgram.systemInfo();
              } catch {
                systemInfo = null;
              }
    
              return toTextResult(
                formatJson({
                  mode: config.mode,
                  projectPath: config.projectPath,
                  wsEndpoint: config.wsEndpoint,
                  port: config.port,
                  autoClose: config.autoClose ?? false,
                  currentPage: page
                    ? { path: page.path, query: page.query }
                    : null,
                  systemInfo,
                })
              );
            }
          );
    
          return result;
        },
      };
    }
  • Function that creates the array of application tools, including mp_ensureConnection via createEnsureConnectionTool.
    export function createApplicationTools(
      manager: WeappAutomatorManager
    ): AnyTool[] {
      return [
        createEnsureConnectionTool(manager),
        createNavigateTool(manager),
        createScreenshotTool(manager),
        createCallWxMethodTool(manager),
        createGetConsoleLogsTool(manager),
      ];
    }
  • src/tools.ts:7-13 (registration)
    Top-level function that aggregates all tools, including application tools containing mp_ensureConnection.
    export function createTools(manager: WeappAutomatorManager): AnyTool[] {
      return [
        ...createApplicationTools(manager),
        ...createPageTools(manager),
        ...createElementTools(manager),
      ];
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions the tool can '检查...是否就绪' (check if ready) and optionally '覆盖连接设置或强制重连' (override connection settings or force reconnection), which gives some behavioral context about connection management. However, it doesn't describe what '就绪' (ready) means operationally, what happens during reconnection, error conditions, or performance characteristics. For a connection management tool with complex parameters, this is insufficient.

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 appropriately concise with two clear Chinese sentences. The first sentence states the core purpose, and the second adds optional capabilities. There's no wasted language, though it could be slightly more specific about what '就绪' (ready) entails.

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

Completeness2/5

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

Given the tool's complexity (2 parameters with 13 nested properties, 0% schema coverage, no annotations, no output schema), the description is inadequate. It doesn't explain what constitutes a 'ready' session, what the tool returns, error handling, or how the numerous connection options interact. For a session management tool with rich configuration possibilities, this leaves too much undefined.

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

Parameters2/5

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

Schema description coverage is 0%, so the schema provides no parameter documentation. The description only vaguely references '连接设置' (connection settings) and '强制重连' (force reconnection), which partially maps to the 'connection' and 'reconnect' parameters. However, it doesn't explain the 13 nested properties within 'connection' (like mode, cliPath, projectPath, etc.) or their relationships. The description adds minimal value beyond what's implied by parameter names.

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

Purpose4/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: '检查小程序自动化会话是否就绪' (check if mini-program automation session is ready). It specifies a verb ('检查' - check) and resource ('小程序自动化会话' - mini-program automation session). However, it doesn't explicitly distinguish this from sibling tools like 'mp_navigate' or 'mp_getLogs' that also operate on mini-program sessions.

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

Usage Guidelines3/5

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

The description provides some usage context: '可选择覆盖连接设置或强制重连' (optionally override connection settings or force reconnection), which implies this tool is used when connection state needs verification or modification. However, it doesn't explicitly state when to use this versus alternatives or what prerequisites exist. The guidance is implied rather than explicit.

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/yfmeii/weapp-dev-mcp'

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