miniprogram-development

Project rules for WeChat mini programs, small apps that run inside WeChat, using Tencent CloudBase services.

In plain words
What is it for?
Building mini-program pages, configuring the project, connecting to CloudBase, opening projects in the WeChat developer tools, and handling user identities without a login screen.
Why use it?
They help create the required file structure and use mini-program authentication and cloud functions correctly.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/tencentcloudcommunity/mcp-server/miniprogram-development
Clone the repo
git clone --depth 1 https://github.com/TencentCloudCommunity/mcp-server
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,272 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01272
Opus 5 $0.00000 $0.00636
Sonnet 5 $0.00000 $0.00254
Haiku 4.5 $0.00000 $0.00127

Measured 2d ago against content hash 4517faae32af, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

miniprogram-development scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

src/CloudBase-AI-ToolKit/config/rules/miniprogram-development.mdc · 91 lines

How it starts

The opening of the file, as written. The whole thing — 91 lines — stays where its author put it; the contents beside it link to each section on GitHub.

微信小程序开发规则

项目结构

  1. 如果用户需要开发小程序,你会使用微信云开发的各种能力来开发项目,小程序的基础库直接用 latest 即可
  2. 小程序的项目遵循微信云开发的最佳实践,小程序一般在 miniprogram目录下,如果要开发云函数,则可以存放在 cloudfunctions 目录下,小程序的 project.config.json 需要指定miniprogramRoot这些
  3. 生成小程序页面的时候,必须包含页面的配置文件例如index.json等,要符合规范,避免编译出错

开发工具

微信开发者工具 CLI 打开项目

  • 当检测到当前项目为小程序项目时,建议用户使用微信开发者工具进行预览调试和发布
  • 使用 CLI 命令打开项目(指向 project.config.json 所在目录):
    • Windows: "C:\Program Files (x86)\Tencent\微信web开发者工具\cli.bat" open --project "项目根目录路径"
    • macOS: /Applications/wechatwebdevtools.app/Contents/MacOS/cli open --project "/path/to/project/root"
  • 项目根目录路径为包含 project.config.json 文件的目录

云开发集成

  1. 小程序 wx.cloud 的时候,需要指定环境 Id,环境 id 可以通过 envQuery 工具来查询
  2. 生成小程序代码的时候,如果需要用到素材图片,比如 tabbar 的 iconPath 等地方,可以从 unsplash 通过 url 来下载,可以参考工作流程中的下载远程资源流程,在生成小程序代码的时候,如果用到了iconPath 这些,必须同时帮用户下载图标,避免构建报错

小程序认证特性

重要:小程序云开发天然免登录,严禁生成登录页面或登录流程!

  1. 免登录特性:小程序云开发不需要用户登录,可以在云函数中通过 wx-server-sdk 获取用户身份
  2. 用户身份获取:在云函数中通过 cloud.getWXContext().OPENID 获取用户的唯一标识
  3. 用户数据管理:基于 openid 在云函数中进行用户数据管理,无需登录流程
// 云函数中获取用户身份示例
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext();
  const openid = wxContext.OPENID;
  
  return { openid: openid };
};

AI 大模型调用

小程序中基础库 3.7.1版本以上已经支持直接调用大模型

// 创建模型实例,这里我们使用 DeepSeek 大模型
const model = wx.cloud.extend.AI.createModel("deepseek");

// 我们先设定好 AI 的系统提示词,这里以七言绝句生成为例
const systemPrompt =
  "请严格按照七言绝句或七言律诗的格律要求创作,平仄需符合规则,押韵要和谐自然,韵脚字需在同一韵部。创作内容围绕用户给定的主题,七言绝句共四句,每句七个字;七言律诗共八句,每句七个字,颔联和颈联需对仗工整。同时,要融入生动的意象、丰富的情感与优美的意境,展现出古诗词的韵味与美感。";

// 用户的自然语言输入,如'帮我写一首赞美玉龙雪山的诗'
const userInput = "帮我写一首赞美玉龙雪山的诗";

// 将系统提示词和用户输入,传入大模型
const res = await model.streamText({
  data: {
    model: "deepseek-v3", // 指定具体的模型
    messages: [
      { role: "system", content: systemPrompt },
      { role: "user", content: userInput },
    ],
  },
});

// 接收大模型的响应
// 由于大模型的返回结果是流式的,所以我们这里需要循环接收完整的响应文本。
for await (let str of res.textStream) {
  console.log(str);
}

微信步数获取

微信步数获取必须使用CloudID方式(基础库2.7.0+)

  • 前端:wx.getWeRunData() 获取cloudID,使用 wx.cloud.CloudID(cloudID) 传递给云函数
  • 云函数:直接使用 weRunData.data 获取解密后的步数数据,检查 weRunData.errCode 处理错误
  • 禁止使用session_key手动解密方式,CloudID更安全简单
  • 必须实现降级机制(模拟数据)处理cloudID获取失败的情况

Read the full file on GitHub · 91 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 91 lines · 0 tokens per session scan A 4517faae32af

Subscribe to this mod's changes

miniprogram-development is a cursor rule published in the GitHub repository TencentCloudCommunity/mcp-server (28 stars, last pushed 1mo ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 1,272 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.