Skip to main content

Mini Program Plugin

The Mini Program plugin provides a complete toolchain for WeChat Mini Program development and release workflows, including code upload, preview, and npm build.

Configuration

Environment variables

# Set the Mini Program code upload key (choose one)
export MINIPROGRAM_PRIVATE_KEY="<your private key content>"
# or
export MINIPROGRAM_PRIVATE_KEY_PATH="/path/to/private.key"

# Enable the Mini Program plugin
export CLOUDBASE_MCP_PLUGINS_ENABLED="env,database,functions,hosting,storage,setup,rag,gateway,download,miniprogram"

MCP config

{
"mcpServers": {
"cloudbase": {
"command": "npx",
"args": ["npm-global-exec@latest", "@cloudbase/cloudbase-mcp@latest"],
"env": {
"MINIPROGRAM_PRIVATE_KEY": "<your mini program private key>",
"CLOUDBASE_MCP_PLUGINS_ENABLED": "env,database,functions,hosting,storage,setup,rag,gateway,download,miniprogram"
}
}
}
}

Tools

uploadMiniprogramCode

Upload Mini Program code to WeChat.

Params:

  • appId: Mini Program appId
  • projectPath: project path
  • version: version
  • desc: version description (optional)
  • setting: compilation settings (optional)
  • robot: robot index 1-30 (optional)
  • type: project type miniProgram / miniGame (optional)

previewMiniprogramCode

Preview Mini Program code and generate a QR code.

Params:

  • appId: Mini Program appId
  • projectPath: project path
  • desc: preview description (optional)
  • setting: compilation settings (optional)
  • robot: robot index 1-30 (optional)
  • type: project type miniProgram / miniGame (optional)
  • qrcodeFormat: image / base64 / terminal (optional)
  • qrcodeOutputDest: output path for QR code (optional)
  • pagePath: page path to open in preview (optional)
  • searchQuery: query params for the preview page (optional)

buildMiniprogramNpm

Build Mini Program npm packages.

Params:

  • appId: Mini Program appId
  • projectPath: project path
  • type: project type miniProgram / miniGame (optional)
  • robot: robot index 1-30 (optional)

getMiniprogramProjectConfig

Get Mini Program project config.

Params:

  • appId: Mini Program appId
  • projectPath: project path
  • type: project type miniProgram / miniGame (optional)

getMiniprogramSourceMap

Get SourceMap of the latest uploaded version (useful for production error debugging).

Params:

  • appId: Mini Program appId
  • projectPath: project path
  • robot: which CI robot to use (1-30)
  • sourceMapSavePath: SourceMap output path
  • type: project type miniProgram / miniGame (optional)

checkMiniprogramCodeQuality

Check Mini Program code quality and generate a report (requires miniprogram-ci 1.9.11+).

Params:

  • appId: Mini Program appId
  • projectPath: project path
  • saveReportPath: report output path
  • type: project type miniProgram / miniGame (optional)

packMiniprogramNpmManually

Build Mini Program npm for complex project structures where node_modules is in a custom location.

Params:

  • packageJsonPath: path of the package.json associated with the node_modules you want to build
  • miniprogramNpmDistDir: target directory for generated miniprogram_npm
  • ignores: ignore rules (optional)

Usage Scenarios

Typical workflow

  1. Build dependencies

    Call buildMiniprogramNpm to build npm packages
    Call packMiniprogramNpmManually for complex project structures
  2. Preview & test

    Call previewMiniprogramCode to generate a preview QR code
  3. Release

    Call uploadMiniprogramCode to upload code to WeChat
  4. Debug & improve

    Call getMiniprogramSourceMap to download SourceMap for debugging
    Call checkMiniprogramCodeQuality to run code quality checks and generate a report

Key setup

Before using this plugin, configure the code upload key in WeChat Official Accounts Platform:

  1. Visit WeChat Official Accounts Platform
  2. Go to "Management → Development Management → Development Settings → Mini Program code upload"
  3. Generate the "code upload key"
  4. Configure IP allowlist (recommended)

Notes

  • The code upload key grants permissions to preview and upload code
  • The key is not stored in plaintext on the WeChat platform
  • If the key is lost, you must reset it—store it securely
  • Enable IP allowlist to reduce security risk

FAQ

Q: How do I get the Mini Program appId?

A: You can find the appId in the Mini Program management page on the WeChat platform.

Q: What is the robot index used for?

A: Robot index is used to separate different upload tasks. You can set a value between 1 and 30.

Q: What compilation settings are supported?

A: Common compile options like ES6/ES7 transforms, code minification, and WXSS minification.

Q: What is SourceMap used for?

A: SourceMap helps debug production errors by mapping minified stack traces back to original source.

Q: What does code quality checking include?

A: Code style checks, performance issues, potential bugs, and optimization suggestions with a detailed report.

Q: When should I use manual npm packing?

A: Use it when your project has a special directory structure, custom node_modules location, or special build needs.