Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
9ad0884
feat(cloudrun): ✨ add cloudrun plugin specification and implementatio…
binggg Aug 21, 2025
b187a97
feat(cloudrun): add CloudRun MCP plugin, docs, and tests ✨
binggg Aug 22, 2025
61b421b
feat(functions,database): unify trigger ops and extend db actions ✨
binggg Aug 22, 2025
bf01555
chore(tools): regenerate tools.json via MCP server 🧰
binggg Aug 22, 2025
2bcbd8f
docs(mcp-tools): auto-generate from tools.json with script 📝
binggg Aug 22, 2025
960117b
docs(mcp-tools): source from GitHub tools.json and sanitize table text 🧹
binggg Aug 22, 2025
6934efc
docs(mcp-tools): header links to GitHub tools.json; use local JSON on…
binggg Aug 22, 2025
85306ab
docs(mcp-tools): switch param details to nested bullets for complex t…
binggg Aug 22, 2025
4928952
docs(mcp-tools): improve readability with 4-space nested bullets and …
binggg Aug 22, 2025
d48bc3c
docs(mcp-tools): cap indent to two levels for child params for better…
binggg Aug 22, 2025
27ae8e6
docs(mcp-tools): flat table params with nested keys, add 参数 section a…
binggg Aug 22, 2025
2ea20dd
docs(mcp-tools): use HTML tables; merge desc/enum/default into 说明; ph…
binggg Aug 22, 2025
f745d41
docs(mcp-tools): HTML tables with merged 说明; move long examples to <d…
binggg Aug 22, 2025
8ca9469
chore: regenerate tools.json and docs; include server updates 🔁
binggg Aug 22, 2025
942dca5
feat(cloudrun): add CloudRun local run, rules, and workflow ✨
binggg Aug 25, 2025
6bb7938
docs(cloudrun): rewrite plugin guide in natural Chinese language ✨
binggg Aug 25, 2025
4272f7f
feat(cloudrun): integrate AI agent functionality into CloudRun plugin 🤖
binggg Aug 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README-ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

| 🚀 **核心能力** | 🛠️ **支持平台** |
|---|---|
| 🤖 **AI智能开发**: AI自动生成代码和架构设计<br>☁️ **云开发集成**: 一键接入数据库、云函数、静态托管<br>⚡ **快速部署**: 几分钟内完成全栈应用上线 | **Web应用**: 现代化前端 + 静态托管<br>**微信小程序**: 云开发小程序解决方案<br>**后端服务**: 云数据库 + 无服务器函数+云托管 |
| 🤖 **AI智能开发**: AI自动生成代码和架构设计<br>☁️ **云开发集成**: 一键接入数据库、云函数、静态托管<br>⚡ **快速部署**: 几分钟内完成全栈应用上线<br>🤖 **AI智能体开发**: 创建和部署个性化AI应用 | **Web应用**: 现代化前端 + 静态托管<br>**微信小程序**: 云开发小程序解决方案<br>**后端服务**: 云数据库 + 无服务器函数+云托管<br>**AI智能体**: 基于函数型云托管的AI应用 |

📚 [快速开始](https://docs.cloudbase.net/ai/cloudbase-ai-toolkit/getting-started) | 🛠️ [IDE配置](https://docs.cloudbase.net/ai/cloudbase-ai-toolkit/ide-setup/) | 🎨 [项目模板](https://docs.cloudbase.net/ai/cloudbase-ai-toolkit/templates) | 📖 [开发指南](https://docs.cloudbase.net/ai/cloudbase-ai-toolkit/development) | 🎮 [使用案例](https://docs.cloudbase.net/ai/cloudbase-ai-toolkit/examples) | 🎓 [教程](https://docs.cloudbase.net/ai/cloudbase-ai-toolkit/tutorials) | 🔌 [插件系统](https://docs.cloudbase.net/ai/cloudbase-ai-toolkit/plugins) | 🔧 [MCP工具](https://docs.cloudbase.net/ai/cloudbase-ai-toolkit/mcp-tools) | ❓ [常见问题](https://docs.cloudbase.net/ai/cloudbase-ai-toolkit/faq)

Expand All @@ -47,6 +47,7 @@
- **🤖 AI 原生** - 专为 AI 编程工具设计的规则库,生成代码符合云开发最佳实践
- **🚀 一键部署** - MCP 自动化部署到腾讯云开发 CloudBase 平台,Serverless 架构无需购买服务器
- **📱 全栈应用** - Web + 小程序 + 数据库 + 后端一体化,支持多种应用形式和后端托管
- **🤖 AI智能体** - 基于函数型云托管开发个性化AI应用,支持SSE流式响应
- **🔧 智能修复** - AI 自动查看日志并修复问题,降低运维成本
- **⚡ 极速体验** - 国内 CDN 加速,比海外平台访问速度更快
- **📚 知识检索** - 内置云开发、微信小程序等专业知识库的智能向量检索
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ When coding in **Cursor/VSCode GitHub Copilot/WinSurf/CodeBuddy/Augment Code/Cla

| 🚀 **Core Capabilities** | 🛠️ **Supported Platforms** |
|---|---|
| 🤖 **AI-Powered Development**: AI auto-generates code and architecture<br>☁️ **Cloud Integration**: One-click access to database, cloud functions, static hosting<br>⚡ **Rapid Deployment**: Full-stack apps online in minutes | **Web Apps**: Modern frontend + static hosting<br>**WeChat Mini-Programs**: Cloud-native mini-program solutions<br>**Backend Services**: Cloud database + serverless functions + cloud hosting |
| 🤖 **AI-Powered Development**: AI auto-generates code and architecture<br>☁️ **Cloud Integration**: One-click access to database, cloud functions, static hosting<br>⚡ **Rapid Deployment**: Full-stack apps online in minutes<br>🤖 **AI Agent Development**: Create and deploy personalized AI applications | **Web Apps**: Modern frontend + static hosting<br>**WeChat Mini-Programs**: Cloud-native mini-program solutions<br>**Backend Services**: Cloud database + serverless functions + cloud hosting<br>**AI Agents**: Function-based cloud hosting for AI applications |

📚 [Quick Start](https://docs.cloudbase.net/ai/cloudbase-ai-toolkit/getting-started) | 🛠️ [IDE Setup](https://docs.cloudbase.net/ai/cloudbase-ai-toolkit/ide-setup/) | 🎨 [Project Templates](https://docs.cloudbase.net/ai/cloudbase-ai-toolkit/templates) | 📖 [Development Guide](https://docs.cloudbase.net/ai/cloudbase-ai-toolkit/development) | 🎮 [Use Cases](https://docs.cloudbase.net/ai/cloudbase-ai-toolkit/examples) | 🎓 [Tutorials](https://docs.cloudbase.net/ai/cloudbase-ai-toolkit/tutorials) | 🔌 [Plugin System](https://docs.cloudbase.net/ai/cloudbase-ai-toolkit/plugins) | 🔧 [MCP Tools](https://docs.cloudbase.net/ai/cloudbase-ai-toolkit/mcp-tools) | ❓ [FAQ](https://docs.cloudbase.net/ai/cloudbase-ai-toolkit/faq)

Expand All @@ -42,6 +42,7 @@ When coding in **Cursor/VSCode GitHub Copilot/WinSurf/CodeBuddy/Augment Code/Cla
- **🤖 AI-Native** - Rule library designed for AI programming tools, generates code following CloudBase best practices
- **🚀 One-Click Deploy** - MCP automated deployment to Tencent CloudBase platform, Serverless architecture without server management
- **📱 Full-Stack Apps** - Web + Mini-programs + Database + Backend integration, supports multiple app types and backend hosting
- **🤖 AI Agent Development** - Create personalized AI applications based on function-based cloud hosting, supports SSE streaming responses
- **🔧 Smart Debugging** - AI automatically reviews logs and fixes issues, reducing operational costs
- **⚡ Lightning Fast** - Domestic CDN acceleration, faster access than overseas platforms
- **📚 Knowledge Retrieval** - Built-in intelligent vector search for CloudBase and WeChat Mini-Program professional knowledge bases
Expand Down
7 changes: 7 additions & 0 deletions config/.cursor/rules/cloudbase-rules.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ alwaysApply: true
首先需要识别当前的开发场景类型:
- **Web 项目**:React/Vue/原生 JS 等前端项目
- **微信小程序**:小程序云开发项目
- **云托管项目**:CloudBase Run 后端服务项目(支持 Java/Go/Python/Node.js/PHP/.NET 等任意语言,适合 WebSocket 长连接、长耗时任务、需要连接数据库/消息队列等场景)
- **数据库相关**:涉及数据操作的项目
- **UI 设计**:需要界面设计的项目

Expand All @@ -23,6 +24,7 @@ alwaysApply: true
**📋 场景规则映射表(必须遵守):**
- **Web 项目** → 必读:`rules/web-development.mdc` + `rules/cloudbase-platform.mdc`
- **微信小程序** → 必读:`rules/miniprogram-development.mdc` + `rules/cloudbase-platform.mdc`
- **云托管项目** → 必读:`rules/cloudrun-development.mdc` + `rules/cloudbase-platform.mdc`
- **数据库操作** → 额外读:`rules/database.mdc`
- **UI 设计** → 额外读:`rules/ui-design.mdc`

Expand Down Expand Up @@ -213,6 +215,11 @@ alwaysApply: true
- 避免忽略专业规则文件的指导
- 重要技术方案建议与用户确认

### 🔄 质量保障
如发现开发不符合规范,可以:
- 指出具体问题点
- 要求重新执行规则检查流程
- 明确指定需要遵循的规则文件
### 🔄 质量保障
如发现开发不符合规范,可以:
- 指出具体问题点
Expand Down
213 changes: 213 additions & 0 deletions config/rules/cloudrun-development.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
---
description: 云托管(CloudBase Run)后端开发规则(函数型/容器型)
globs: ["**/*.js", "**/*.ts", "**/*.py", "**/*.go", "**/*.java", "**/*.php", "**/Dockerfile"]
alwaysApply: false
---

# 云托管(CloudBase Run)AI 开发规则

面向 AI 助理与工程协作,提供「何时用、怎么用」的最简规则与工具工作流。

## 1. 何时使用云托管(适用场景)

- 需要长连接能力:WebSocket / SSE / 服务器推送。
- 需要长时间执行或常驻进程:不适合云函数的长任务、后台任务。
- 需要指定运行环境/系统依赖:自定义镜像、特定系统库。
- 使用多语言/任意框架:如 Java、Go、PHP、.NET、Python、Node.js 等。
- 需要稳定对外服务与弹性伸缩:按量计费、可缩容到 0。
- 需要私网/内网访问:VPC/PRIVATE 访问、小程序 `callContainer` 内网直连。
- 需要开发 AI 智能体:基于函数型云托管开发个性化 AI 应用。

## 2. 模式选择(快速对比)

- 函数型:上手最快,内置 HTTP/WebSocket/SSE,端口固定 3000;本地运行受工具支持。
- 容器型:任意语言与运行时,需 Dockerfile;本地运行不在本工具支持范围。

### 模式对比清单

| 维度 | 函数型 | 容器型 |
| --- | --- | --- |
| 语言/框架 | Node.js(通过 `@cloudbase/functions-framework` 承载) | 任意语言/运行时(Java/Go/PHP/.NET/Python/Node.js 等) |
| 运行方式 | 函数框架加载函数(Runtime) | Docker 镜像启动进程 |
| 端口 | 固定 3000 | 应用自行监听 `PORT`(部署时由平台注入) |
| Dockerfile | 不需要 | 必须(且可本地构建通过) |
| 本地运行 | 支持(工具内置) | 不支持(建议用 Docker 自行调试) |
| 典型场景 | WebSocket/SSE/流式响应、表单/文件、低时延、单实例多函数、共享内存 | 任意系统依赖/语言、已有容器化应用迁移 |

## 3. 开发硬性要求(务必满足)

- 必须监听 `PORT` 环境变量(容器内真实端口)。
- 无状态服务:数据写入外部(DB/存储/缓存)。
- 请求外禁止后台常驻线程/进程。
- 依赖最小化、镜像瘦身;缩短冷启动和部署时长。
- 资源约束:`Mem = 2 × CPU`(如 0.25 vCPU → 0.5 GB)。
- 访问控制:仅 Web 场景开启公网;小程序优先内网直连,建议关闭公网。

## 4. 工具(白话说明 & 读写分离)

- 用来“看信息”的:`queryCloudRun`
- `list`:我有哪些服务?可按名称/类型过滤
- `detail`:某个服务现在的配置、版本、访问地址
- `templates`:可直接用的起步模板
- 用来“做事情”的:`manageCloudRun`
- `init`:创建本地项目(可选模板)
- `download`:把已有服务的代码拉到本地
- `run`:本地跑起来(仅函数型,支持普通函数和Agent模式)
- `deploy`:把本地代码部署到云托管
- `delete`:删除服务(需要显式确认)
- `createAgent`:创建 AI 智能体(基于函数型云托管)
- 重要参数(只记这几个)
- `targetPath`:本地目录(必须是绝对路径)
- `serverConfig`:CPU/Mem/实例数/访问类型/环境变量等部署参数
- `runOptions`:本地运行端口与临时环境变量(函数型),支持 `runMode: 'normal' | 'agent'`
- `agentConfig`:Agent 配置(agentName、botTag、description、template)
- 删除一定要带 `force: true`,否则不会执行

## 5. 核心工作流(先懂步骤,再看示例)

1) 选模式
- 需要多语言/已有容器/Docker:选“容器型”
- 需要长连接/流式/低时延/多函数共存:优先“函数型”
2) 初始化本地项目
- 通用:用模板 `init`(函数型/容器型都可从模板起步)
- 容器型务必“检查或生成 Dockerfile”:
- Node.js 最小示例:
```dockerfile
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
ENV NODE_ENV=production
EXPOSE 3000
CMD ["node","server.js"]
```
- Python 最小示例:
```dockerfile
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt ./
RUN pip install -r requirements.txt --no-cache-dir
COPY . .
ENV PORT=3000
EXPOSE 3000
CMD ["python","app.py"]
```
3) 本地运行(仅函数型)
- 通过 `run` 自动使用 `npm run dev/start` 或入口文件
4) 配置访问
- 根据需要设置 `OpenAccessTypes`(WEB/VPC/PRIVATE);Web 场景配好安全域名与认证
5) 部署
- `deploy` 时指定 CPU/Mem/实例数/环境变量等
6) 验证
- 用 `detail` 确认访问地址与配置是否符合预期

1) 选模板/看服务
```json
{ "name": "queryCloudRun", "arguments": { "action": "templates" } }
```
```json
{ "name": "queryCloudRun", "arguments": { "action": "detail", "detailServerName": "my-svc" } }
```

2) 初始化项目
```json
{ "name": "manageCloudRun", "arguments": { "action": "init", "serverName": "my-svc", "targetPath": "/abs/ws/my-svc", "template": "helloworld" } }
```

3) 下载代码(可选)
```json
{ "name": "manageCloudRun", "arguments": { "action": "download", "serverName": "my-svc", "targetPath": "/abs/ws/my-svc" } }
```

4) 本地运行(仅函数型)
```json
{ "name": "manageCloudRun", "arguments": { "action": "run", "serverName": "my-svc", "targetPath": "/abs/ws/my-svc", "runOptions": { "port": 3000 } } }
```

5) 部署上线
```json
{ "name": "manageCloudRun", "arguments": { "action": "deploy", "serverName": "my-svc", "targetPath": "/abs/ws/my-svc", "serverConfig": { "OpenAccessTypes": ["WEB"], "Cpu": 0.5, "Mem": 1, "MinNum": 0, "MaxNum": 5 } } }
```

6) 创建 AI 智能体(可选)
```json
{ "name": "manageCloudRun", "arguments": { "action": "createAgent", "serverName": "my-agent", "targetPath": "/abs/ws/agents", "agentConfig": { "agentName": "MyAgent", "botTag": "demo", "description": "我的智能体", "template": "blank" } } }
```

7) 运行智能体(可选)
```json
{ "name": "manageCloudRun", "arguments": { "action": "run", "serverName": "my-agent", "targetPath": "/abs/ws/agents/my-agent", "runOptions": { "port": 3000, "runMode": "agent" } } }
```

## 6. 最佳实践(强烈建议)

- 优先 PRIVATE/VPC 或小程序内网 `callContainer`,减少公网暴露。
- Web 必须用 CloudBase Web SDK 认证;小程序由平台鉴权。
- 机密通过环境变量下发;多环境(dev/stg/prod)分离配置。
- 部署前后用 `queryCloudRun.detail` 校验配置与可达性。
- 镜像分层可复用、体积小;监测启动时延与内存占用。
- Agent 开发:使用 `@cloudbase/aiagent-framework`,支持 SSE 流式响应,BotId 格式为 `ibot-{name}-{tag}`。

## 7. 快速排查

- 访问失败:检查 OpenAccessTypes/域名/端口、实例是否缩容为 0。
- 部署失败:校验 Dockerfile/构建日志/镜像体积与 CPU/Mem 配比。
- 本地运行失败:仅支持函数型;需 `package.json` 的 `dev`/`start` 或入口 `index.js|app.js|server.js`。
- 性能抖动:减小依赖与初始化;适当提高 MinNum;优化冷启动。
- Agent 运行失败:检查 `@cloudbase/aiagent-framework` 依赖、BotId 格式、SSE 响应格式。

## 8. 函数型云托管(Function 模式)要点(精简)

- 定义:云托管 + 函数框架(`@cloudbase/functions-framework`)+ 函数代码,让容器服务开发像写云函数一样简单。
- 何时选择:需要 WebSocket/SSE/文件上传/流式响应;需要长任务或连接 DB/消息队列;需要单实例多函数与共享内存、低时延与更好日志/调试。
- Agent 模式:基于函数型云托管开发 AI 智能体,使用 `@cloudbase/aiagent-framework`,支持 SSE 流式响应和个性化 AI 应用。
- 工具支持:本地运行仅支持函数型(`manageCloudRun` → `run`);部署用 `manageCloudRun` → `deploy`;查询用 `queryCloudRun`。
- 迁移提示:与云函数调用链/运行时不同,迁移需少量改造(含客户端调用方式)。
- 可移植性:基于函数框架,可在本地/主机/Docker 运行,非云托管需自管构建与部署。


## 9. 服务调用方式(精简示例)

- HTTP 直接访问(WEB 公网开启时)
```bash
curl -L "https://<your-service-domain>"
```

- 微信小程序(内网直连,建议关闭公网)
```js
// app.js(确保已 wx.cloud.init())
const res = await wx.cloud.callContainer({
config: { env: "<envId>" },
path: "/",
method: "GET",
header: { "X-WX-SERVICE": "<serviceName>" }
});
```

- Web(JS SDK,需配置安全域名与认证)
```js
import cloudbase from "@cloudbase/js-sdk";
const app = cloudbase.init({ env: "<envId>" });
await app.auth().toDefaultLoginPage();
const res = await app.callContainer({
name: "<serviceName>", method: "POST", path: "/api",
header: { "Content-Type": "application/json" },
data: { key: "value" }
});
```

- Node.js(服务端/云函数内调用)
```js
import tcb from "@cloudbase/node-sdk";
const app = tcb.init({});
const res = await app.callContainer({
name: "<serviceName>", method: "GET", path: "/health",
timeout: 5000
});
```

- 建议
- Mini Program/Server 侧优先内网(VPC/PRIVATE)调用,减少暴露面。
- Web 场景需开启 WEB、公网域名与安全域名,并使用 SDK 认证。

Loading
Loading