Sibling skills (local only)
Sibling CloudBase skills ship beside this skill. Use local relative paths such as ../auth-tool-cloudbase/SKILL.md.
If a referenced sibling skill file is missing from this environment, ask the user to install the full CloudBase plugin (or the missing skill). Do not HTTP-fetch remote skill or protocol markdown into the agent context.
Cross-cutting protocols (required before code changes or deployments):
- Change Safety Protocol:
references/protocols/change-safety-protocol.md
- Deployment Gate:
references/protocols/deployment-gate.md
- Sensitive Runtime Data Protection:
references/protocols/sensitive-runtime-data-protection.md
Activation Contract
Use this first when
- The user asks which CloudBase capability, service, or tool to use, or needs a high-level understanding of hosting, storage, authentication, cloud functions, or database options.
- The task is about console navigation, cross-platform differences, permission models, or platform-level best practices before implementation.
Read before writing code if
- It is still unclear whether the task belongs to Web, mini program, cloud functions, storage, MySQL / NoSQL, or auth.
- The response needs platform selection, conceptual explanation, or control-plane navigation more than direct implementation steps.
Then also read
- Minimal Web + database demo (BaaS-first, no cloud functions by default) ->
../minimal-web-baas-demo/SKILL.md
- Stack order for 最小前后端 / Lovable-like demos: Web SDK CRUD > MCP schema > template warmup during credential wait > cloud functions (default count = 0). Capability sniff: connector ready →
envQuery → lock one DB plane → MCP schema → @cloudbase/js-sdk CRUD → preview.
- Web app implementation ->
../web-development/SKILL.md
- Web auth and provider setup ->
../auth-tool-cloudbase/SKILL.md, ../auth-web-cloudbase/SKILL.md
- Mini program development ->
../miniprogram-development/SKILL.md
- WeChat Pay, Official Account OAuth, JSAPI Pay, or Native QR-code Pay through CloudBase Integration Center ->
../cloudbase-wechat-integration/SKILL.md (official docs: https://docs.cloudbase.net/integration/introduce/index.md)
- Cloud functions ->
../cloud-functions/SKILL.md
- Official HTTP API clients ->
../http-api-cloudbase/SKILL.md
- Document database ->
../cloudbase-document-database-web-sdk/SKILL.md or ../cloudbase-document-database-in-wechat-miniprogram/SKILL.md
- CloudBase PostgreSQL / PG ->
../postgresql-development-cloudbase/SKILL.md
- MySQL relational database / data modeling ->
../relational-database-mcp-cloudbase/SKILL.md or ../data-model-creation/SKILL.md
- Cloud storage ->
../cloud-storage-web/SKILL.md
Do NOT use for
- Direct implementation of web pages, auth flows, functions, or database operations when a more specific skill already fits.
- Low-level API parameter references or SDK recipes that belong in specialized skills.
Common mistakes / gotchas
- Treating this general skill as the default entry point for all CloudBase development.
- Staying here after the correct implementation skill is already clear.
- Mixing platform overview with platform-specific API shapes or SDK details.
- Using this overview skill as a detour in an existing application where the active auth, storage, and data files are already obvious.
- Making code or configuration changes without first following the Change Safety Protocol (
cloudbase-platform/references/protocols/change-safety-protocol.md).
- Starting any deployment, publish, custom domain, or CloudRun work without first completing the checks in
cloudbase-platform/references/protocols/deployment-gate.md.
- Echoing
x-cloudbase-context, full req.headers, or process.env from Cloud Functions / CloudRun (including httpbin-style debug images) — follow references/protocols/sensitive-runtime-data-protection.md.
- Confusing security domains with custom domains: these are two different tools for different purposes. See the "Domain Management Tools" table below for the authoritative split.
When to use this skill
Use this skill for CloudBase platform knowledge when you need to:
- Understand CloudBase storage and hosting concepts
- Compare platform capabilities before implementation
- Understand cross-platform auth differences (Web vs Mini Program)
- Understand database permissions and access control
- 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
- If the workspace is already an application with TODOs or prebuilt handlers, do not stay in platform overview mode. Move quickly to the concrete implementation skill and the existing files that own the flow.
Follow best practices
- Use SDK built-in authentication features (Web)
- Understand natural login-free feature (Mini Program)
- Configure appropriate database permissions
- Prefer
@cloudbase/js-sdk direct DB access for browser CRUD; use cloud functions only for secrets, scheduled/background jobs, or elevated cross-collection logic that security rules / RLS cannot express (see ../minimal-web-baas-demo/SKILL.md for the demo default)
Use correct SDKs and APIs
- Different platforms require different SDKs for data models
- MySQL data models must use models SDK, not collection API
- PostgreSQL / CloudBase PG work must route to
postgresql-development-cloudbase; do not reuse NoSQL app.database() / db.collection(...) snippets or MySQL queryMysqlDatabase / manageMysqlDatabase for PG data paths
- Use
envQuery tool to get environment ID
- In an existing Web application with fixed structure, inspect the existing
src/lib/backend.*, src/lib/auth.*, src/lib/*service.*, and bound page handlers before broad concept reading.
Use the canonical CloudBase MCP setup from the main cloudbase guideline
- This platform overview intentionally does not duplicate the full MCP / mcporter config block
- For the canonical config snippet, CLI commands, and auth examples, read the main
cloudbase guideline first
- Keep the same core rules here: prefer MCP when tools are available in this session; if not, configure MCP for next session and use
tcb CLI now (../cloudbase-cli/SKILL.md, ../cloudbase/references/tooling-fallback.md). Inspect tool schemas before MCP execution. Do not hard-code Secret ID / Secret Key / Env ID in config
- Keep the auth split explicit: management-side login uses
auth, while application-side auth configuration uses queryAppAuth / manageAppAuth
CloudBase Platform Knowledge
Domain Management Tools: Clear Distinction
When working with domain-related tasks, use the correct tool based on the requirement:
| Requirement |
Tool |
Parameters |
Purpose |
| Security Domain (安全域名) |
manageEnv(action="addSecurityDomain" | "removeSecurityDomain") |
domains (array of host:port strings) |
CORS/request source validation for browser uploads. No certificate involved. (Deprecated alias: envDomainManagement.) |
| Reuse existing Custom Domain |
queryGateway(listCustomDomains) → manageGateway(createRoute) |
domain = existing custom domain; route fields |
Expose a service/path on an already-bound custom domain. No certificateId. Prefer this when a custom domain already exists. |
| Bind new Custom Domain (自定义域名) |
manageGateway(action="bindCustomDomain") |
domain (string), certificateId (string) |
First-time bind of a new public HTTPS domain. Requires certId from SSL console. |
| Delete Custom Domain |
manageGateway(action="deleteCustomDomain") |
domain (string) |
Remove custom domain binding (only after routes on that domain are deleted). |
| Disable / enable gateway route |
manageGateway(action="disableRoute" | "enableRoute") |
path (required), prefer explicit domain |
Toggle Routes[].Enable via ModifyHTTPServiceRoute (not ModifyGatewayRoute). |
| Disable static hosting default domain |
queryGateway(listRoutes) → manageGateway(disableRoute) |
domain = *.tcloudbaseapp.com (DomainType=STATIC_STORE, IsDefault=true), usually path="/" |
Turns off public access on the shared hosting CDN default host. Do not use manageHosting. |
Key indicators for choosing the right tool:
- Task mentions "自定义域名访问" but env already has a custom domain →
listCustomDomains then createRoute(domain=...) (no certificateId)
- Task mentions "certificate ID" or "SSL" and needs to bind a new domain →
manageGateway(action="bindCustomDomain")
- Task mentions "浏览器上传" or "CORS" or "安全域名" → Use
manageEnv(action="addSecurityDomain" / "removeSecurityDomain")
- Task mentions "public access" or "HTTPS" with domain → Prefer reuse via
createRoute when possible; only bindCustomDomain for first-time domain bind
- Task mentions "关闭/禁用静态托管默认域名" /
*.tcloudbaseapp.com → queryGateway(listRoutes) then manageGateway(disableRoute) with that STATIC_STORE domain; never invent ModifyGatewayRoute
Error Code Troubleshooting: Route Through Official Docs
When a CloudBase tool call fails and the error message contains a specific error code (pattern Category.Code, e.g. OperationDenied.FreePackageDenied, ResourceNotFound.*), always route through the official docs before acting — do not guess the meaning, do not hardcode fix recipes here:
- Extract the error code from the error message.
- Look it up:
searchKnowledgeBase(mode="docs", action="searchDocs", query="<错误码>") — official docs search covers error-code pages. Act on the documented meaning and the fix steps the doc prescribes (plan limits → upgrade guidance, misconfiguration → config fix, etc.).
- If docs search returns nothing, fall back to the canonical error-code pages:
- Error code basics & self-service troubleshooting:
https://docs.cloudbase.net/error-code/basic
- Control-plane cloud API error codes:
https://cloud.tencent.com/document/product/876/34823
- Never assert capability-per-plan or error-code semantics from memory — official docs and the console plan comparison are the only authoritative sources. Example: for Web 安全域名 plan requirements, cite
https://cloud.tencent.com/document/product/876/127357 rather than assuming which tier unlocks it.
Recording Operation Results
When a task explicitly requires recording operation steps or results to a file (e.g., RESULT.json): perform the tool calls first, then write a complete record containing every attempt (action, success/failure, message) plus a summary with total / succeeded / failed counts. Do not write the file from memory before the calls finish.
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
- If the task needs COS SDK polling, file metadata lookup, or temporary URLs for an uploaded object, use cloud storage tools (
manageStorage / queryStorage), not manageHosting(action="upload")
Static Hosting Domain:
- CloudBase static hosting domain and website document config can be obtained via
queryHosting(action="websiteConfig")
- Combine with static hosting file paths to construct final access addresses
- Default shared host looks like
<envId>-<appId>.tcloudbaseapp.com (DomainType=STATIC_STORE, often IsDefault=true in queryGateway(listRoutes))
- To disable that default public host:
manageGateway(action="disableRoute", domain="<that-host>", path="/") (or updateRoute with enable=false). Re-enable with enableRoute. Do not look for a manageHosting disable-default-domain action; do not call non-existent ModifyGatewayRoute — the API is ModifyHTTPServiceRoute
- Important: If access address is a directory, it must end with
/
Cloud Storage Public URL:
- CRITICAL:
manageStorage(action=upload) and queryStorage(action=url) return temporaryUrl which is a temporary signed URL that expires (default 1 hour). Do NOT use this as a permanent public URL.
- To get the permanent public access URL for a cloud storage object:
- Call
envQuery(action=info) to get environment details
- Extract the storage CDN domain from
EnvInfo.Storages[0].CdnDomain (e.g., your-env-id.tcb.qcloud.la)
- Construct the public URL:
https://{CdnDomain}/{cloudPath}
- Example: If
CdnDomain is env-xxx.tcb.qcloud.la and cloudPath is uploads/avatar.jpg, the public URL is https://env-xxx.tcb.qcloud.la/uploads/avatar.jpg
- Note: The public URL is accessible only if the storage bucket ACL allows public read (default is
PRIVATE which requires signed URLs)
Environment and Authentication
SDK Initialization:
- CloudBase SDK initialization requires environment ID
- Can query environment ID via
envQuery tool
- If the user only provides an environment alias, nickname, or other short form, resolve it with
envQuery(action="list", alias=..., aliasExact=true) first and use the returned full EnvId
- Do not pass alias-like short forms directly into SDK init,
auth.set_env, console URLs, or generated config files
- For Web, always initialize synchronously:
import cloudbase from "@cloudbase/js-sdk"; const app = cloudbase.init({ env: "your-full-env-id" });
- Do not use dynamic imports like
import("@cloudbase/js-sdk") or async wrappers such as initCloudBase() with internal initPromise
- Then proceed with login using a verified method (username/password, phone, email, or WeChat)
Environment Management (via manageEnv):
The manageEnv tool provides full lifecycle management for CloudBase environments.
| Action |
Description |
Key Parameters |
listPackages |
Query available plans |
(none) |
create |
Create new environment (needs confirm) |
alias, packageId, resources, duration |
modifyPlan |
Change plan (upgrade/downgrade, needs confirm) |
envId, packageId |
renew |
Renew environment (needs confirm) |
envId, duration |
Creating an environment with specific resources:
manageEnv(action="create", alias="my-env", packageId="baas_personal",
resources=["flexdb","storage","function","postgresql"], confirm="yes")
resources (optional, create only): controls which CloudBase capabilities to enable:
flexdb — Document database (NoSQL)
storage — Cloud Storage
function — Cloud Functions
postgresql — PostgreSQL relational database (PG mode)
- Defaults to all four when omitted. MCP always sends non-empty
Resources to CreateEnv.
- Do not pass
region: CreateEnv does not accept Region; environment region is determined by account/package.
- ⚠️ All paid operations (create / modifyPlan / renew) require
confirm="yes".
Querying available packages before creating:
manageEnv(action="listPackages")
Changing plan (e.g. personal → standard):
manageEnv(action="modifyPlan", envId="your-env-id", packageId="baas_pf_standard", confirm="yes")
Renewing an environment:
manageEnv(action="renew", envId="your-env-id", duration=1, confirm="yes")
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: SMS login with
auth.getVerification(), for detailed, refer to web auth related docs
- Forbidden behavior: Do not use cloud functions to implement login authentication logic
- Session management: For route guards and login proof, use
auth.getSession() and require data.session; do not use deprecated getLoginState() or auth.getUser() / auth.getCurrentUser() as proof of real login.
- Provider and login-method setup: Use
queryAppAuth / manageAppAuth, not the MCP auth tool
- Anonymous login is disabled by default. Publishable
accessKey alone does not create a gateway-authenticated anonymous session. With @cloudbase/js-sdk 3.x, call await auth.signInAnonymously() (or an equivalent authenticated session) before NoSQL app.database() CRUD, or the gateway returns 401. If the app uses AuthGuard or RLS for access control, ensure is_anonymous checks are in place when anonymous access is allowed.
- ⚠️ PG RLS: Use
auth.uid(), NOT current_user. When writing RLS policies for CloudBase PostgreSQL, the user identity must use auth.uid() (returns the JWT sub / actual user ID as text, not uuid — unlike Supabase). Prefer owner columns as varchar(64) / text; if the column is uuid, cast with auth.uid()::uuid or you get operator does not exist: uuid = text. Do NOT use current_user or current_setting(...) — these PostgreSQL built-in functions return the database role name (e.g. authenticated), not the CloudBase auth user ID. CloudBase PG provides four auth helper functions: auth.uid(), auth.role(), auth.email(), auth.jwt(). Verify availability with SELECT proname FROM pg_proc WHERE pronamespace = 'auth'::regnamespace.
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
manageFunctions(action="createFunction") to create functions
- Use
manageFunctions(action="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
managePermissions(action="updateResourcePermission") to configure resource permissions
- If permissions were just changed, retry after a few seconds (typically within ~30s). Do not blind-wait 2-5 minutes. If it still fails, re-check the actual rule shape and active client write pattern first — most failures are misconfigured rules, not cache.
- See
no-sql-web-sdk/security-rules.md for detailed resourceType="noSqlDatabase" examples only; do not treat doc._openid, auth.openid, query-subset validation, or create / update / delete JSON templates as generic rules for functions, storage, or SQL tables
- Official references:
- General security rules overview:
https://cloud.tencent.com/document/product/876/41802
- NoSQL database security rules:
https://docs.cloudbase.net/database/security-rules
- Cloud function security rules:
https://docs.cloudbase.net/cloud-function/security-rules
- Storage security rules:
https://docs.cloudbase.net/storage/security-rules
Compatibility note:
- Canonical plugin name:
permissions
- Legacy plugin aliases
security-rule, security-rules, secret-rule, secret-rules, and access-control still resolve to the permissions plugin
- Legacy tools
readSecurityRule / writeSecurityRule are removed; prefer queryPermissions / managePermissions
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:
- Prefer security rules / RLS and client SDK when the permission model allows it
- Use cloud functions when the operation needs elevated privileges, server secrets, or multi-collection logic that rules cannot express
- For minimal Web demos (Todo / Notes / Kanban / 最小前后端), do not introduce cloud functions for CRUD — follow
../minimal-web-baas-demo/SKILL.md
Role Management (MCP)
CloudBase MCP provides role management via queryPermissions and managePermissions (CLI equivalent: tcb role). See each tool's schema for the full action list.
⚠️ CRITICAL: Role policies and resource permissions are two independent systems with NO automatic synchronization.
- Resource permissions (security rules) control access to specific resources (tables, collections, functions, storage)
- Roles (identity dimension) control policy bundles and member assignments
Query (queryPermissions): listRoles, getRole (by roleId / roleIdentity / roleName).
Manage (managePermissions): createRole, updateRole, deleteRoles, addRoleMembers, removeRoleMembers, addRolePolicies, removeRolePolicies.
managePermissions(action="createRole", roleName="Developer", roleIdentity="developer",
policies=["FunctionsAccess"], memberUids=["user-uid-1"])
⚠️ Only custom roles can be deleted. System roles are read-only.
See also: CLI equivalent commands in cloudbase-cli/references/permission.md
- Cloud Function Optimization:
- Browser CRUD should not default to a cloud-function middleware layer; prefer
@cloudbase/js-sdk → database (see ../minimal-web-baas-demo/SKILL.md)
- When cloud functions are truly required, keep the count minimal and scope each function to secrets, elevated privilege, or background work
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 links. All console URLs follow the pattern: https://tcb.cloud.tencent.com/dev?envId=${envId}#/{path} — replace ${envId} with the real EnvId resolved via envQuery (resolve aliases first; see Environment and Authentication below), and resource names with actual values.
The CloudBase console is updated frequently. If a live, logged-in console shows a different hash path from this list, prefer the live console path over stale documentation and then update this skill to match.
Entry points (one line each)
- Overview:
#/overview
- Template Center:
#/cloud-template/market
- Document Database:
#/db/doc · Collections #/db/doc/collection/${collectionName} · Models #/db/doc/model/${modelName}
- MySQL Database:
#/db/mysql · Tables #/db/mysql/table/default/ (must be enabled in console first)
- Cloud Functions:
#/scf · Detail #/scf/detail?id=${functionName}&NameSpace=${envId}
- CloudRun:
#/platform-run
- Cloud Storage:
#/storage
- AI+:
#/ai
- Static Hosting:
#/static-hosting (alt: https://console.cloud.tencent.com/tcb/hosting)
- Identity Authentication:
#/identity · Login management #/identity/login-manage · Token management #/identity/token-management
- Weida Low-Code:
#/lowcode/apps
- Logs & Monitoring:
#/devops/log
- Environment Settings:
#/env/http-access (security domains, CORS, env vars, quotas)
For configuration pages (like login management), guide users through the setup process rather than only dropping a link.
Reference index
All packaged reference files (required for skill lint reachability):
- protocols/change-safety-protocol.md
- protocols/deployment-gate.md
- protocols/sensitive-runtime-data-protection.md
1---
2name: cloudbase-platform
3description: CloudBase platform overview and routing guide. This skill should be used when users need high-level capability selection, platform concepts, console navigation, or cross-platform best practices before choosing a more specific implementation skill.
4version: 2.33.2
5alwaysApply: false
6---
7
8## Sibling skills (local only)
9
10Sibling CloudBase skills ship beside this skill. Use local relative paths such as `../auth-tool-cloudbase/SKILL.md`.
11
12If a referenced sibling skill file is missing from this environment, ask the user to install the full CloudBase plugin (or the missing skill). Do **not** HTTP-fetch remote skill or protocol markdown into the agent context.
13
14**Cross-cutting protocols** (required before code changes or deployments):
15- Change Safety Protocol: `references/protocols/change-safety-protocol.md`
16- Deployment Gate: `references/protocols/deployment-gate.md`
17- Sensitive Runtime Data Protection: `references/protocols/sensitive-runtime-data-protection.md`
18
19## Activation Contract
20
21### Use this first when
22
23- The user asks which CloudBase capability, service, or tool to use, or needs a high-level understanding of hosting, storage, authentication, cloud functions, or database options.
24- The task is about console navigation, cross-platform differences, permission models, or platform-level best practices before implementation.
25
26### Read before writing code if
27
28- It is still unclear whether the task belongs to Web, mini program, cloud functions, storage, MySQL / NoSQL, or auth.
29- The response needs platform selection, conceptual explanation, or control-plane navigation more than direct implementation steps.
30
31### Then also read
32
33- Minimal Web + database demo (BaaS-first, no cloud functions by default) -> `../minimal-web-baas-demo/SKILL.md`
34 - **Stack order for 最小前后端 / Lovable-like demos:** Web SDK CRUD > MCP schema > template warmup during credential wait > cloud functions (default count = 0). Capability sniff: connector ready → `envQuery` → lock one DB plane → MCP schema → `@cloudbase/js-sdk` CRUD → preview.
35- Web app implementation -> `../web-development/SKILL.md`
36- Web auth and provider setup -> `../auth-tool-cloudbase/SKILL.md`, `../auth-web-cloudbase/SKILL.md`
37- Mini program development -> `../miniprogram-development/SKILL.md`
38- WeChat Pay, Official Account OAuth, JSAPI Pay, or Native QR-code Pay through CloudBase Integration Center -> `../cloudbase-wechat-integration/SKILL.md` (official docs: `https://docs.cloudbase.net/integration/introduce/index.md`)
39- Cloud functions -> `../cloud-functions/SKILL.md`
40- Official HTTP API clients -> `../http-api-cloudbase/SKILL.md`
41- Document database -> `../cloudbase-document-database-web-sdk/SKILL.md` or `../cloudbase-document-database-in-wechat-miniprogram/SKILL.md`
42- CloudBase PostgreSQL / PG -> `../postgresql-development-cloudbase/SKILL.md`
43- MySQL relational database / data modeling -> `../relational-database-mcp-cloudbase/SKILL.md` or `../data-model-creation/SKILL.md`
44- Cloud storage -> `../cloud-storage-web/SKILL.md`
45
46### Do NOT use for
47
48- Direct implementation of web pages, auth flows, functions, or database operations when a more specific skill already fits.
49- Low-level API parameter references or SDK recipes that belong in specialized skills.
50
51### Common mistakes / gotchas
52
53- Treating this general skill as the default entry point for all CloudBase development.
54- Staying here after the correct implementation skill is already clear.
55- Mixing platform overview with platform-specific API shapes or SDK details.
56- Using this overview skill as a detour in an existing application where the active auth, storage, and data files are already obvious.
57- Making code or configuration changes without first following the Change Safety Protocol (`cloudbase-platform/references/protocols/change-safety-protocol.md`).
58- Starting any deployment, publish, custom domain, or CloudRun work without first completing the checks in `cloudbase-platform/references/protocols/deployment-gate.md`.
59- Echoing `x-cloudbase-context`, full `req.headers`, or `process.env` from Cloud Functions / CloudRun (including httpbin-style debug images) — follow `references/protocols/sensitive-runtime-data-protection.md`.
60- **Confusing security domains with custom domains**: these are two different tools for different purposes. See the "Domain Management Tools" table below for the authoritative split.
61
62## When to use this skill
63
64Use this skill for **CloudBase platform knowledge** when you need to:
65
66- Understand CloudBase storage and hosting concepts
67- Compare platform capabilities before implementation
68- Understand cross-platform auth differences (Web vs Mini Program)
69- Understand database permissions and access control
70- Access CloudBase console management pages
71
72**This skill provides foundational knowledge** that applies to all CloudBase projects, regardless of whether they are Web, Mini Program, or backend services.
73
74---
75
76## How to use this skill (for a coding agent)
77
781. **Understand platform differences**
79 - Web and Mini Program have completely different authentication approaches
80 - Must strictly distinguish between platforms
81 - Never mix authentication methods across platforms
82 - If the workspace is already an application with TODOs or prebuilt handlers, do not stay in platform overview mode. Move quickly to the concrete implementation skill and the existing files that own the flow.
83
842. **Follow best practices**
85 - Use SDK built-in authentication features (Web)
86 - Understand natural login-free feature (Mini Program)
87 - Configure appropriate database permissions
88 - Prefer `@cloudbase/js-sdk` direct DB access for browser CRUD; use cloud functions only for secrets, scheduled/background jobs, or elevated cross-collection logic that security rules / RLS cannot express (see `../minimal-web-baas-demo/SKILL.md` for the demo default)
89
903. **Use correct SDKs and APIs**
91 - Different platforms require different SDKs for data models
92 - MySQL data models must use models SDK, not collection API
93 - PostgreSQL / CloudBase PG work must route to `postgresql-development-cloudbase`; do not reuse NoSQL `app.database()` / `db.collection(...)` snippets or MySQL `queryMysqlDatabase` / `manageMysqlDatabase` for PG data paths
94 - Use `envQuery` tool to get environment ID
95 - In an existing Web application with fixed structure, inspect the existing `src/lib/backend.*`, `src/lib/auth.*`, `src/lib/*service.*`, and bound page handlers before broad concept reading.
96
974. **Use the canonical CloudBase MCP setup from the main `cloudbase` guideline**
98 - This platform overview intentionally does **not** duplicate the full MCP / mcporter config block
99 - For the canonical config snippet, CLI commands, and auth examples, read the main `cloudbase` guideline first
100 - Keep the same core rules here: prefer MCP when tools are available in this session; if not, configure MCP for next session and use `tcb` CLI now (`../cloudbase-cli/SKILL.md`, `../cloudbase/references/tooling-fallback.md`). Inspect tool schemas before MCP execution. Do not hard-code Secret ID / Secret Key / Env ID in config
101 - Keep the auth split explicit: management-side login uses `auth`, while application-side auth configuration uses `queryAppAuth` / `manageAppAuth`
102
103---
104
105# CloudBase Platform Knowledge
106
107### Domain Management Tools: Clear Distinction
108
109When working with domain-related tasks, use the correct tool based on the requirement:
110
111| Requirement | Tool | Parameters | Purpose |
112|-------------|------|------------|---------|
113| **Security Domain (安全域名)** | `manageEnv(action="addSecurityDomain" \| "removeSecurityDomain")` | `domains` (array of host:port strings) | CORS/request source validation for browser uploads. No certificate involved. (Deprecated alias: `envDomainManagement`.) |
114| **Reuse existing Custom Domain** | `queryGateway(listCustomDomains)` → `manageGateway(createRoute)` | `domain` = existing custom domain; route fields | Expose a service/path on an already-bound custom domain. **No certificateId.** Prefer this when a custom domain already exists. |
115| **Bind new Custom Domain (自定义域名)** | `manageGateway(action="bindCustomDomain")` | `domain` (string), `certificateId` (string) | First-time bind of a new public HTTPS domain. Requires certId from SSL console. |
116| **Delete Custom Domain** | `manageGateway(action="deleteCustomDomain")` | `domain` (string) | Remove custom domain binding (only after routes on that domain are deleted). |
117| **Disable / enable gateway route** | `manageGateway(action="disableRoute" \| "enableRoute")` | `path` (required), prefer explicit `domain` | Toggle `Routes[].Enable` via `ModifyHTTPServiceRoute` (not `ModifyGatewayRoute`). |
118| **Disable static hosting default domain** | `queryGateway(listRoutes)` → `manageGateway(disableRoute)` | `domain` = `*.tcloudbaseapp.com` (`DomainType=STATIC_STORE`, `IsDefault=true`), usually `path="/"` | Turns off public access on the shared hosting CDN default host. **Do not use `manageHosting`.** |
119
120**Key indicators for choosing the right tool:**
121- Task mentions "自定义域名访问" but env already has a custom domain → `listCustomDomains` then `createRoute(domain=...)` (no certificateId)
122- Task mentions "certificate ID" or "SSL" **and** needs to bind a **new** domain → `manageGateway(action="bindCustomDomain")`
123- Task mentions "浏览器上传" or "CORS" or "安全域名" → Use `manageEnv(action="addSecurityDomain" / "removeSecurityDomain")`
124- Task mentions "public access" or "HTTPS" with domain → Prefer reuse via `createRoute` when possible; only `bindCustomDomain` for first-time domain bind
125- Task mentions "关闭/禁用静态托管默认域名" / `*.tcloudbaseapp.com` → `queryGateway(listRoutes)` then `manageGateway(disableRoute)` with that STATIC_STORE domain; never invent `ModifyGatewayRoute`
126
127### Error Code Troubleshooting: Route Through Official Docs
128
129When a CloudBase tool call fails and the error message contains a specific error code (pattern `Category.Code`, e.g. `OperationDenied.FreePackageDenied`, `ResourceNotFound.*`), **always route through the official docs before acting — do not guess the meaning, do not hardcode fix recipes here**:
130
1311. Extract the error code from the error message.
1322. Look it up: `searchKnowledgeBase(mode="docs", action="searchDocs", query="<错误码>")` — official docs search covers error-code pages. Act on the documented meaning and the fix steps the doc prescribes (plan limits → upgrade guidance, misconfiguration → config fix, etc.).
1333. If docs search returns nothing, fall back to the canonical error-code pages:
134 - Error code basics & self-service troubleshooting: `https://docs.cloudbase.net/error-code/basic`
135 - Control-plane cloud API error codes: `https://cloud.tencent.com/document/product/876/34823`
1364. Never assert capability-per-plan or error-code semantics from memory — official docs and the console plan comparison are the only authoritative sources. Example: for Web 安全域名 plan requirements, cite `https://cloud.tencent.com/document/product/876/127357` rather than assuming which tier unlocks it.
137
138### Recording Operation Results
139
140When a task explicitly requires recording operation steps or results to a file (e.g., `RESULT.json`): perform the tool calls first, then write a complete record containing every attempt (action, success/failure, message) plus a `summary` with total / succeeded / failed counts. Do not write the file from memory before the calls finish.
141
142## Storage and Hosting
143
1441. **Static Hosting vs Cloud Storage**:
145 - CloudBase static hosting and cloud storage are two different buckets
146 - Generally, publicly accessible files can be stored in static hosting, which provides a public web address
147 - Static hosting supports custom domain configuration (requires console operation)
148 - Cloud storage is suitable for files with privacy requirements, can get temporary access addresses via temporary file URLs
149 - If the task needs COS SDK polling, file metadata lookup, or temporary URLs for an uploaded object, use cloud storage tools (`manageStorage` / `queryStorage`), not `manageHosting(action="upload")`
150
1512. **Static Hosting Domain**:
152 - CloudBase static hosting domain and website document config can be obtained via `queryHosting(action="websiteConfig")`
153 - Combine with static hosting file paths to construct final access addresses
154 - Default shared host looks like `<envId>-<appId>.tcloudbaseapp.com` (`DomainType=STATIC_STORE`, often `IsDefault=true` in `queryGateway(listRoutes)`)
155 - To **disable** that default public host: `manageGateway(action="disableRoute", domain="<that-host>", path="/")` (or `updateRoute` with `enable=false`). Re-enable with `enableRoute`. Do **not** look for a `manageHosting` disable-default-domain action; do **not** call non-existent `ModifyGatewayRoute` — the API is `ModifyHTTPServiceRoute`
156 - **Important**: If access address is a directory, it must end with `/`
157
1583. **Cloud Storage Public URL**:
159 - **CRITICAL**: `manageStorage(action=upload)` and `queryStorage(action=url)` return `temporaryUrl` which is a temporary signed URL that expires (default 1 hour). Do NOT use this as a permanent public URL.
160 - To get the permanent public access URL for a cloud storage object:
161 1. Call `envQuery(action=info)` to get environment details
162 2. Extract the storage CDN domain from `EnvInfo.Storages[0].CdnDomain` (e.g., `your-env-id.tcb.qcloud.la`)
163 3. Construct the public URL: `https://{CdnDomain}/{cloudPath}`
164 - Example: If `CdnDomain` is `env-xxx.tcb.qcloud.la` and `cloudPath` is `uploads/avatar.jpg`, the public URL is `https://env-xxx.tcb.qcloud.la/uploads/avatar.jpg`
165 - Note: The public URL is accessible only if the storage bucket ACL allows public read (default is `PRIVATE` which requires signed URLs)
166
167## Environment and Authentication
168
1691. **SDK Initialization**:
170 - CloudBase SDK initialization requires environment ID
171 - Can query environment ID via `envQuery` tool
172 - If the user only provides an environment alias, nickname, or other short form, resolve it with `envQuery(action="list", alias=..., aliasExact=true)` first and use the returned full `EnvId`
173 - Do not pass alias-like short forms directly into SDK init, `auth.set_env`, console URLs, or generated config files
174 - For Web, always initialize synchronously:
175 - `import cloudbase from "@cloudbase/js-sdk"; const app = cloudbase.init({ env: "your-full-env-id" });`
176 - Do **not** use dynamic imports like `import("@cloudbase/js-sdk")` or async wrappers such as `initCloudBase()` with internal `initPromise`
177 - Then proceed with login using a verified method (username/password, phone, email, or WeChat)
178
1792. **Environment Management (via manageEnv)**:
180 The `manageEnv` tool provides full lifecycle management for CloudBase environments.
181
182 | Action | Description | Key Parameters |
183 |--------|-------------|----------------|
184 | `listPackages` | Query available plans | (none) |
185 | `create` | Create new environment (needs confirm) | `alias`, `packageId`, `resources`, `duration` |
186 | `modifyPlan` | Change plan (upgrade/downgrade, needs confirm) | `envId`, `packageId` |
187 | `renew` | Renew environment (needs confirm) | `envId`, `duration` |
188
189 **Creating an environment with specific resources:**
190 ```
191 manageEnv(action="create", alias="my-env", packageId="baas_personal",
192 resources=["flexdb","storage","function","postgresql"], confirm="yes")
193 ```
194
195 - **`resources`** (optional, create only): controls which CloudBase capabilities to enable:
196 - `flexdb` — Document database (NoSQL)
197 - `storage` — Cloud Storage
198 - `function` — Cloud Functions
199 - `postgresql` — PostgreSQL relational database (PG mode)
200 - Defaults to all four when omitted. MCP always sends non-empty `Resources` to CreateEnv.
201 - Do **not** pass `region`: CreateEnv does not accept Region; environment region is determined by account/package.
202 - ⚠️ **All paid operations** (create / modifyPlan / renew) require `confirm="yes"`.
203
204 **Querying available packages before creating:**
205 ```
206 manageEnv(action="listPackages")
207 ```
208
209 **Changing plan (e.g. personal → standard):**
210 ```
211 manageEnv(action="modifyPlan", envId="your-env-id", packageId="baas_pf_standard", confirm="yes")
212 ```
213
214 **Renewing an environment:**
215 ```
216 manageEnv(action="renew", envId="your-env-id", duration=1, confirm="yes")
217 ```
218
219## Authentication Best Practices
220
221**Important: Authentication methods for different platforms are completely different, must strictly distinguish!**
222
223### Web Authentication
224- **Must use SDK built-in authentication**: CloudBase Web SDK provides complete authentication features
225- **Recommended method**: SMS login with `auth.getVerification()`, for detailed, refer to web auth related docs
226- **Forbidden behavior**: Do not use cloud functions to implement login authentication logic
227- **Session management**: For route guards and login proof, use `auth.getSession()` and require `data.session`; do not use deprecated `getLoginState()` or `auth.getUser()` / `auth.getCurrentUser()` as proof of real login.
228- **Provider and login-method setup**: Use `queryAppAuth` / `manageAppAuth`, not the MCP `auth` tool
229- **Anonymous login is disabled by default.** Publishable `accessKey` alone does **not** create a gateway-authenticated anonymous session. With `@cloudbase/js-sdk` **3.x**, call `await auth.signInAnonymously()` (or an equivalent authenticated session) **before** NoSQL `app.database()` CRUD, or the gateway returns **401**. If the app uses AuthGuard or RLS for access control, ensure `is_anonymous` checks are in place when anonymous access is allowed.
230- **⚠️ PG RLS: Use `auth.uid()`, NOT `current_user`.** When writing RLS policies for CloudBase PostgreSQL, the user identity must use `auth.uid()` (returns the JWT `sub` / actual user ID as **`text`**, not `uuid` — unlike Supabase). Prefer owner columns as `varchar(64)` / `text`; if the column is `uuid`, cast with `auth.uid()::uuid` or you get `operator does not exist: uuid = text`. Do NOT use `current_user` or `current_setting(...)` — these PostgreSQL built-in functions return the database role name (e.g. `authenticated`), not the CloudBase auth user ID. CloudBase PG provides four auth helper functions: `auth.uid()`, `auth.role()`, `auth.email()`, `auth.jwt()`. Verify availability with `SELECT proname FROM pg_proc WHERE pronamespace = 'auth'::regnamespace`.
231
232### Mini Program Authentication
233- **Login-free feature**: Mini program CloudBase is naturally login-free, no login flow needed
234- **User identifier**: In cloud functions, get `wxContext.OPENID` via wx-server-sdk
235- **User management**: Manage user data in cloud functions based on openid
236- **Forbidden behavior**: Do not generate login pages or login flow code
237
238## Cloud Functions
239
2401. **Node.js Cloud Functions**:
241 - Node.js cloud functions need to include `package.json`, declaring required dependencies
242 - Can use `manageFunctions(action="createFunction")` to create functions
243 - Use `manageFunctions(action="updateFunctionCode")` to deploy cloud functions
244 - Prioritize cloud dependency installation, do not upload node_modules
245 - `functionRootPath` refers to the parent directory of function directories, e.g., `cloudfunctions` directory
246
247## Database Permissions
248
249**⚠️ CRITICAL: Always configure permissions BEFORE writing database operation code!**
250
2511. **Permission Model**:
252 - CloudBase database access has permissions
253 - Default basic permissions include:
254 - **READONLY**: Everyone can read, only creator/admin can write
255 - **PRIVATE**: Only creator/admin can read/write
256 - **ADMINWRITE**: Everyone can read, **only admin can write** (⚠️ NOT for Web SDK write!)
257 - **ADMINONLY**: Only admin can read/write
258 - **CUSTOM**: Fine-grained control with custom rules
259
2602. **Platform Compatibility** (CRITICAL):
261 - ⚠️ **Web SDK cannot use `ADMINWRITE` or `ADMINONLY` for write operations**
262 - ✅ For user-generated content in Web apps, use **CUSTOM** rules
263 - ✅ For admin-managed data (products, settings), use **READONLY**
264 - ✅ Cloud functions have full access regardless of permission type
265
2663. **Configuration Workflow**:
267 ```
268 Create collection → Configure security rules → Write code → Test
269 ```
270 - Use `managePermissions(action="updateResourcePermission")` to configure resource permissions
271 - If permissions were just changed, retry after a few seconds (typically within ~30s). Do not blind-wait 2-5 minutes. If it still fails, re-check the actual rule shape and active client write pattern first — most failures are misconfigured rules, not cache.
272 - See `no-sql-web-sdk/security-rules.md` for detailed `resourceType="noSqlDatabase"` examples only; do not treat `doc._openid`, `auth.openid`, query-subset validation, or `create` / `update` / `delete` JSON templates as generic rules for functions, storage, or SQL tables
273 - Official references:
274 - General security rules overview: `https://cloud.tencent.com/document/product/876/41802`
275 - NoSQL database security rules: `https://docs.cloudbase.net/database/security-rules`
276 - Cloud function security rules: `https://docs.cloudbase.net/cloud-function/security-rules`
277 - Storage security rules: `https://docs.cloudbase.net/storage/security-rules`
278
279Compatibility note:
280- Canonical plugin name: `permissions`
281- Legacy plugin aliases `security-rule`, `security-rules`, `secret-rule`, `secret-rules`, and `access-control` still resolve to the `permissions` plugin
282- Legacy tools `readSecurityRule` / `writeSecurityRule` are removed; prefer `queryPermissions` / `managePermissions`
283
2844. **Common Scenarios**:
285 - **E-commerce products**: `READONLY` (admin manages via cloud functions)
286 - **Shopping carts**: `CUSTOM` with `auth.uid` check (users manage their own)
287 - **Orders**: `CUSTOM` with ownership validation
288 - **System logs**: `PRIVATE` or `ADMINONLY`
289
2905. **Cross-Collection Operations**:
291 - Prefer security rules / RLS and client SDK when the permission model allows it
292 - Use cloud functions when the operation needs elevated privileges, server secrets, or multi-collection logic that rules cannot express
293 - For minimal Web demos (Todo / Notes / Kanban / 最小前后端), do **not** introduce cloud functions for CRUD — follow `../minimal-web-baas-demo/SKILL.md`
294
295## Role Management (MCP)
296
297CloudBase MCP provides role management via `queryPermissions` and `managePermissions` (CLI equivalent: `tcb role`). See each tool's schema for the full action list.
298
299**⚠️ CRITICAL: Role policies and resource permissions are two independent systems with NO automatic synchronization.**
300
301- Resource permissions (security rules) control access to specific resources (tables, collections, functions, storage)
302- Roles (identity dimension) control policy bundles and member assignments
303
304**Query** (`queryPermissions`): `listRoles`, `getRole` (by `roleId` / `roleIdentity` / `roleName`).
305**Manage** (`managePermissions`): `createRole`, `updateRole`, `deleteRoles`, `addRoleMembers`, `removeRoleMembers`, `addRolePolicies`, `removeRolePolicies`.
306
307```
308managePermissions(action="createRole", roleName="Developer", roleIdentity="developer",
309 policies=["FunctionsAccess"], memberUids=["user-uid-1"])
310```
311
312> ⚠️ Only custom roles can be deleted. System roles are read-only.
313
314See also: CLI equivalent commands in `cloudbase-cli/references/permission.md`
315
3163. **Cloud Function Optimization**:
317 - Browser CRUD should not default to a cloud-function middleware layer; prefer `@cloudbase/js-sdk` → database (see `../minimal-web-baas-demo/SKILL.md`)
318 - When cloud functions are truly required, keep the count minimal and scope each function to secrets, elevated privilege, or background work
319
320## Data Models
321
3221. **Get Data Model Operation Object**:
323 - **Mini Program**: Need `@cloudbase/wx-cloud-client-sdk`, initialize `const client = initHTTPOverCallFunction(wx.cloud)`, use `client.models`
324 - **Cloud Function**: Need `@cloudbase/node-sdk@3.10+`, initialize `const app = cloudbase.init({env})`, use `app.models`
325 - **Web**: Need `@cloudbase/js-sdk`, initialize `const app = cloudbase.init({env})`, after login use `app.models`
326
3272. **Data Model Query**:
328 - Can call MCP `manageDataModel` tool to:
329 - Query model list
330 - Get model detailed information (including Schema fields)
331 - Get specific models SDK usage documentation
332
3333. **MySQL Data Model Invocation Rules**:
334 - MySQL data models cannot use collection method invocation, must use data model SDK
335 - **Wrong**: `db.collection('model_name').get()`
336 - **Correct**: `app.models.model_name.list({ filter: { where: {} } })`
337 - Use `manageDataModel` tool's `docs` method to get specific SDK usage
338
339## Console Management
340
341After creating/deploying resources, provide corresponding console links. All console URLs follow the pattern: `https://tcb.cloud.tencent.com/dev?envId=${envId}#/{path}` — replace `${envId}` with the real EnvId resolved via `envQuery` (resolve aliases first; see Environment and Authentication below), and resource names with actual values.
342
343The CloudBase console is updated frequently. If a live, logged-in console shows a different hash path from this list, prefer the live console path over stale documentation and then update this skill to match.
344
345### Entry points (one line each)
346
347- Overview: `#/overview`
348- Template Center: `#/cloud-template/market`
349- Document Database: `#/db/doc` · Collections `#/db/doc/collection/${collectionName}` · Models `#/db/doc/model/${modelName}`
350- MySQL Database: `#/db/mysql` · Tables `#/db/mysql/table/default/` (must be enabled in console first)
351- Cloud Functions: `#/scf` · Detail `#/scf/detail?id=${functionName}&NameSpace=${envId}`
352- CloudRun: `#/platform-run`
353- Cloud Storage: `#/storage`
354- AI+: `#/ai`
355- Static Hosting: `#/static-hosting` (alt: `https://console.cloud.tencent.com/tcb/hosting`)
356- Identity Authentication: `#/identity` · Login management `#/identity/login-manage` · Token management `#/identity/token-management`
357- Weida Low-Code: `#/lowcode/apps`
358- Logs & Monitoring: `#/devops/log`
359- Environment Settings: `#/env/http-access` (security domains, CORS, env vars, quotas)
360
361For configuration pages (like login management), guide users through the setup process rather than only dropping a link.
362
363## Reference index
364
365All packaged reference files (required for skill lint reachability):
366
367- [protocols/change-safety-protocol.md](references/protocols/change-safety-protocol.md)
368- [protocols/deployment-gate.md](references/protocols/deployment-gate.md)
369- [protocols/sensitive-runtime-data-protection.md](references/protocols/sensitive-runtime-data-protection.md)