When to use this skill
Use this skill for CloudBase platform knowledge when you need to:
- Understand CloudBase storage and hosting concepts
- Configure authentication for different platforms (Web vs Mini Program)
- Deploy and manage cloud functions
- Understand database permissions and access control
- Work with data models (MySQL and NoSQL)
- Access CloudBase console management pages
This skill provides foundational knowledge that applies to all CloudBase projects, regardless of whether they are Web, Mini Program, or backend services.
How to use this skill (for a coding agent)
Understand platform differences
- Web and Mini Program have completely different authentication approaches
- Must strictly distinguish between platforms
- Never mix authentication methods across platforms
Follow best practices
- Use SDK built-in authentication features (Web)
- Understand natural login-free feature (Mini Program)
- Configure appropriate database permissions
- Use cloud functions for cross-collection operations
Use correct SDKs and APIs
- Different platforms require different SDKs for data models
- MySQL data models must use models SDK, not collection API
- Use
envQuery tool to get environment ID
CloudBase Platform Knowledge
Storage and Hosting
Static Hosting vs Cloud Storage:
- CloudBase static hosting and cloud storage are two different buckets
- Generally, publicly accessible files can be stored in static hosting, which provides a public web address
- Static hosting supports custom domain configuration (requires console operation)
- Cloud storage is suitable for files with privacy requirements, can get temporary access addresses via temporary file URLs
Static Hosting Domain:
- CloudBase static hosting domain can be obtained via
getWebsiteConfig tool
- Combine with static hosting file paths to construct final access addresses
- Important: If access address is a directory, it must end with
/
Environment and Authentication
- SDK Initialization:
- CloudBase SDK initialization requires environment ID
- Can query environment ID via
envQuery tool
- For Web, always initialize synchronously:
import cloudbase from "@cloudbase/js-sdk"; const app = cloudbase.init({ env: "xxxx-yyy" });
- Do not use dynamic imports like
import("@cloudbase/js-sdk") or async wrappers such as initCloudBase() with internal initPromise
- Then proceed with login, for example using anonymous login
Authentication Best Practices
Important: Authentication methods for different platforms are completely different, must strictly distinguish!
Web Authentication
- Must use SDK built-in authentication: CloudBase Web SDK provides complete authentication features
- Recommended method:
auth.toDefaultLoginPage() redirect to default login page
- Forbidden behavior: Do not use cloud functions to implement login authentication logic
- User management: After login, get user information via
auth.getCurrentUser()
Mini Program Authentication
- Login-free feature: Mini program CloudBase is naturally login-free, no login flow needed
- User identifier: In cloud functions, get
wxContext.OPENID via wx-server-sdk
- User management: Manage user data in cloud functions based on openid
- Forbidden behavior: Do not generate login pages or login flow code
Cloud Functions
- Node.js Cloud Functions:
- Node.js cloud functions need to include
package.json, declaring required dependencies
- Can use
createFunction to create functions
- Use
updateFunctionCode to deploy cloud functions
- Prioritize cloud dependency installation, do not upload node_modules
functionRootPath refers to the parent directory of function directories, e.g., cloudfunctions directory
Database Permissions
⚠️ CRITICAL: Always configure permissions BEFORE writing database operation code!
Permission Model:
- CloudBase database access has permissions
- Default basic permissions include:
- READONLY: Everyone can read, only creator/admin can write
- PRIVATE: Only creator/admin can read/write
- ADMINWRITE: Everyone can read, only admin can write (⚠️ NOT for Web SDK write!)
- ADMINONLY: Only admin can read/write
- CUSTOM: Fine-grained control with custom rules
Platform Compatibility (CRITICAL):
- ⚠️ Web SDK cannot use
ADMINWRITE or ADMINONLY for write operations
- ✅ For user-generated content in Web apps, use CUSTOM rules
- ✅ For admin-managed data (products, settings), use READONLY
- ✅ Cloud functions have full access regardless of permission type
Configuration Workflow:
Create collection → Configure security rules → Write code → Test
- Use
writeSecurityRule MCP tool to configure permissions
- Wait 2-5 minutes for cache to clear before testing
- See
no-sql-web-sdk/security-rules.md for detailed examples
Common Scenarios:
- E-commerce products:
READONLY (admin manages via cloud functions)
- Shopping carts:
CUSTOM with auth.uid check (users manage their own)
- Orders:
CUSTOM with ownership validation
- System logs:
PRIVATE or ADMINONLY
Cross-Collection Operations:
- If user has no special requirements, operations involving cross-database collections must be implemented via cloud functions
Cloud Function Optimization:
- If involving cloud functions, while ensuring security, can minimize the number of cloud functions as much as possible
- For example: implement one cloud function for client-side requests, implement one cloud function for data initialization
Data Models
Get Data Model Operation Object:
- Mini Program: Need
@cloudbase/wx-cloud-client-sdk, initialize const client = initHTTPOverCallFunction(wx.cloud), use client.models
- Cloud Function: Need
@cloudbase/node-sdk@3.10+, initialize const app = cloudbase.init({env}), use app.models
- Web: Need
@cloudbase/js-sdk, initialize const app = cloudbase.init({env}), after login use app.models
Data Model Query:
- Can call MCP
manageDataModel tool to:
- Query model list
- Get model detailed information (including Schema fields)
- Get specific models SDK usage documentation
MySQL Data Model Invocation Rules:
- MySQL data models cannot use collection method invocation, must use data model SDK
- Wrong:
db.collection('model_name').get()
- Correct:
app.models.model_name.list({ filter: { where: {} } })
- Use
manageDataModel tool's docs method to get specific SDK usage
Console Management
After creating/deploying resources, provide corresponding console management page links:
Static Hosting: https://console.cloud.tencent.com/tcb/hosting
Cloud Function: https://tcb.cloud.tencent.com/dev?envId=${envId}#/scf/detail?id=${functionName}&NameSpace=${envId}
Database Collection: https://tcb.cloud.tencent.com/dev?envId=${envId}#/db/doc/collection/${collectionName}
Data Model: https://tcb.cloud.tencent.com/dev?envId=${envId}#/db/doc/model/${modelName}
Usage: After creating corresponding resources, replace variables with actual values, provide to user for management operations.
1---2name: cloudbase-platform-33description: CloudBase platform knowledge and best practices. Use this skill for general CloudBase platform understanding, including storage, hosting, authentication, cloud functions, database permissions, and data models.4---56## When to use this skill78Use this skill for **CloudBase platform knowledge** when you need to:910- Understand CloudBase storage and hosting concepts11- Configure authentication for different platforms (Web vs Mini Program)12- Deploy and manage cloud functions13- Understand database permissions and access control14- Work with data models (MySQL and NoSQL)15- Access CloudBase console management pages1617**This skill provides foundational knowledge** that applies to all CloudBase projects, regardless of whether they are Web, Mini Program, or backend services.1819---2021## How to use this skill (for a coding agent)22231. **Understand platform differences**24 - Web and Mini Program have completely different authentication approaches25 - Must strictly distinguish between platforms26 - Never mix authentication methods across platforms27282. **Follow best practices**29 - Use SDK built-in authentication features (Web)30 - Understand natural login-free feature (Mini Program)31 - Configure appropriate database permissions32 - Use cloud functions for cross-collection operations33343. **Use correct SDKs and APIs**35 - Different platforms require different SDKs for data models36 - MySQL data models must use models SDK, not collection API37 - Use `envQuery` tool to get environment ID3839---4041# CloudBase Platform Knowledge4243## Storage and Hosting44451. **Static Hosting vs Cloud Storage**:46 - CloudBase static hosting and cloud storage are two different buckets47 - Generally, publicly accessible files can be stored in static hosting, which provides a public web address48 - Static hosting supports custom domain configuration (requires console operation)49 - Cloud storage is suitable for files with privacy requirements, can get temporary access addresses via temporary file URLs50512. **Static Hosting Domain**:52 - CloudBase static hosting domain can be obtained via `getWebsiteConfig` tool53 - Combine with static hosting file paths to construct final access addresses54 - **Important**: If access address is a directory, it must end with `/`5556## Environment and Authentication57581. **SDK Initialization**:59 - CloudBase SDK initialization requires environment ID60 - Can query environment ID via `envQuery` tool61 - For Web, always initialize synchronously:62 - `import cloudbase from "@cloudbase/js-sdk"; const app = cloudbase.init({ env: "xxxx-yyy" });`63 - Do **not** use dynamic imports like `import("@cloudbase/js-sdk")` or async wrappers such as `initCloudBase()` with internal `initPromise`64 - Then proceed with login, for example using anonymous login6566## Authentication Best Practices6768**Important: Authentication methods for different platforms are completely different, must strictly distinguish!**6970### Web Authentication71- **Must use SDK built-in authentication**: CloudBase Web SDK provides complete authentication features72- **Recommended method**: `auth.toDefaultLoginPage()` redirect to default login page73- **Forbidden behavior**: Do not use cloud functions to implement login authentication logic74- **User management**: After login, get user information via `auth.getCurrentUser()`7576### Mini Program Authentication77- **Login-free feature**: Mini program CloudBase is naturally login-free, no login flow needed78- **User identifier**: In cloud functions, get `wxContext.OPENID` via wx-server-sdk79- **User management**: Manage user data in cloud functions based on openid80- **Forbidden behavior**: Do not generate login pages or login flow code8182## Cloud Functions83841. **Node.js Cloud Functions**:85 - Node.js cloud functions need to include `package.json`, declaring required dependencies86 - Can use `createFunction` to create functions87 - Use `updateFunctionCode` to deploy cloud functions88 - Prioritize cloud dependency installation, do not upload node_modules89 - `functionRootPath` refers to the parent directory of function directories, e.g., `cloudfunctions` directory9091## Database Permissions9293**⚠️ CRITICAL: Always configure permissions BEFORE writing database operation code!**94951. **Permission Model**:96 - CloudBase database access has permissions97 - Default basic permissions include:98 - **READONLY**: Everyone can read, only creator/admin can write99 - **PRIVATE**: Only creator/admin can read/write100 - **ADMINWRITE**: Everyone can read, **only admin can write** (⚠️ NOT for Web SDK write!)101 - **ADMINONLY**: Only admin can read/write102 - **CUSTOM**: Fine-grained control with custom rules1031042. **Platform Compatibility** (CRITICAL):105 - ⚠️ **Web SDK cannot use `ADMINWRITE` or `ADMINONLY` for write operations**106 - ✅ For user-generated content in Web apps, use **CUSTOM** rules107 - ✅ For admin-managed data (products, settings), use **READONLY**108 - ✅ Cloud functions have full access regardless of permission type1091103. **Configuration Workflow**:111 ```112 Create collection → Configure security rules → Write code → Test113 ```114 - Use `writeSecurityRule` MCP tool to configure permissions115 - Wait 2-5 minutes for cache to clear before testing116 - See `no-sql-web-sdk/security-rules.md` for detailed examples1171184. **Common Scenarios**:119 - **E-commerce products**: `READONLY` (admin manages via cloud functions)120 - **Shopping carts**: `CUSTOM` with `auth.uid` check (users manage their own)121 - **Orders**: `CUSTOM` with ownership validation122 - **System logs**: `PRIVATE` or `ADMINONLY`1231245. **Cross-Collection Operations**:125 - If user has no special requirements, operations involving cross-database collections must be implemented via cloud functions1261273. **Cloud Function Optimization**:128 - If involving cloud functions, while ensuring security, can minimize the number of cloud functions as much as possible129 - For example: implement one cloud function for client-side requests, implement one cloud function for data initialization130131## Data Models1321331. **Get Data Model Operation Object**:134 - **Mini Program**: Need `@cloudbase/wx-cloud-client-sdk`, initialize `const client = initHTTPOverCallFunction(wx.cloud)`, use `client.models`135 - **Cloud Function**: Need `@cloudbase/node-sdk@3.10+`, initialize `const app = cloudbase.init({env})`, use `app.models`136 - **Web**: Need `@cloudbase/js-sdk`, initialize `const app = cloudbase.init({env})`, after login use `app.models`1371382. **Data Model Query**:139 - Can call MCP `manageDataModel` tool to:140 - Query model list141 - Get model detailed information (including Schema fields)142 - Get specific models SDK usage documentation1431443. **MySQL Data Model Invocation Rules**:145 - MySQL data models cannot use collection method invocation, must use data model SDK146 - **Wrong**: `db.collection('model_name').get()`147 - **Correct**: `app.models.model_name.list({ filter: { where: {} } })`148 - Use `manageDataModel` tool's `docs` method to get specific SDK usage149150## Console Management151152After creating/deploying resources, provide corresponding console management page links:1531541. **Static Hosting**: https://console.cloud.tencent.com/tcb/hosting1551562. **Cloud Function**: https://tcb.cloud.tencent.com/dev?envId=${envId}#/scf/detail?id=${functionName}&NameSpace=${envId}1571583. **Database Collection**: https://tcb.cloud.tencent.com/dev?envId=${envId}#/db/doc/collection/${collectionName}1591604. **Data Model**: https://tcb.cloud.tencent.com/dev?envId=${envId}#/db/doc/model/${modelName}161162**Usage**: After creating corresponding resources, replace variables with actual values, provide to user for management operations.163