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 appIdprojectPath: project pathversion: versiondesc: version description (optional)setting: compilation settings (optional)robot: robot index 1-30 (optional)type: project typeminiProgram/miniGame(optional)
previewMiniprogramCode
Preview Mini Program code and generate a QR code.
Params:
appId: Mini Program appIdprojectPath: project pathdesc: preview description (optional)setting: compilation settings (optional)robot: robot index 1-30 (optional)type: project typeminiProgram/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 appIdprojectPath: project pathtype: project typeminiProgram/miniGame(optional)robot: robot index 1-30 (optional)
getMiniprogramProjectConfig
Get Mini Program project config.
Params:
appId: Mini Program appIdprojectPath: project pathtype: project typeminiProgram/miniGame(optional)
getMiniprogramSourceMap
Get SourceMap of the latest uploaded version (useful for production error debugging).
Params:
appId: Mini Program appIdprojectPath: project pathrobot: which CI robot to use (1-30)sourceMapSavePath: SourceMap output pathtype: project typeminiProgram/miniGame(optional)
checkMiniprogramCodeQuality
Check Mini Program code quality and generate a report (requires miniprogram-ci 1.9.11+).
Params:
appId: Mini Program appIdprojectPath: project pathsaveReportPath: report output pathtype: project typeminiProgram/miniGame(optional)
packMiniprogramNpmManually
Build Mini Program npm for complex project structures where node_modules is in a custom location.
Params:
packageJsonPath: path of thepackage.jsonassociated with thenode_modulesyou want to buildminiprogramNpmDistDir: target directory for generatedminiprogram_npmignores: ignore rules (optional)
Usage Scenarios
Typical workflow
-
Build dependencies
Call buildMiniprogramNpm to build npm packagesCall packMiniprogramNpmManually for complex project structures -
Preview & test
Call previewMiniprogramCode to generate a preview QR code -
Release
Call uploadMiniprogramCode to upload code to WeChat -
Debug & improve
Call getMiniprogramSourceMap to download SourceMap for debuggingCall 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:
- Visit WeChat Official Accounts Platform
- Go to "Management → Development Management → Development Settings → Mini Program code upload"
- Generate the "code upload key"
- 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.