Skip to content

Commit 6f4aa88

Browse files
committed
feat: rdb skills
1 parent 7e58db5 commit 6f4aa88

File tree

2 files changed

+286
-0
lines changed
  • config/.claude/skills/relational-database-skills

2 files changed

+286
-0
lines changed
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
---
2+
name: CloudBase Relational Database MCP
3+
description: This is the required documentation for agents operating on the CloudBase Relational Database. It lists the only four supported tools for running SQL and managing security rules. Read the full content to understand why you must NOT use standard Application SDKs and how to safely execute INSERT, UPDATE, or DELETE operations without corrupting production data.
4+
alwaysApply: false
5+
---
6+
7+
## When to use this skill
8+
9+
Use this skill when an **agent** needs to operate on **CloudBase Relational Database via MCP tools**, for example:
10+
11+
- Inspecting or querying data in tables
12+
- Modifying data or schema (INSERT/UPDATE/DELETE/DDL)
13+
- Reading or changing table security rules
14+
15+
Do **NOT** use this skill for:
16+
17+
- Building Web or Node.js applications that talk to CloudBase Relational Database (use the Web/Node Relational Database skills)
18+
- Auth flows or user identity (use the Auth skills)
19+
20+
## How to use this skill (for a coding agent)
21+
22+
1. **Recognize MCP context**
23+
- If you can call tools like `executeReadOnlySQL`, `executeWriteSQL`, `readSecurityRule`, `writeSecurityRule`, you are in MCP context.
24+
- In this context, **never initialize SDKs for CloudBase Relational Database**; use MCP tools instead.
25+
26+
2. **Pick the right tool for the job**
27+
- Reads → `executeReadOnlySQL`
28+
- Writes/DDL → `executeWriteSQL`
29+
- Inspect rules → `readSecurityRule`
30+
- Change rules → `writeSecurityRule`
31+
32+
3. **Always be explicit about safety**
33+
- Before destructive operations (DELETE, DROP, etc.), summarize what you are about to run and why.
34+
- Prefer running read-only SELECTs first to verify assumptions.
35+
36+
---
37+
38+
## Available MCP tools (CloudBase Relational Database)
39+
40+
These tools are the **only** supported way to interact with CloudBase Relational Database via MCP:
41+
42+
### 1. `executeReadOnlySQL`
43+
44+
- **Purpose:** Run `SELECT` queries (read-only).
45+
- **Use for:**
46+
- Listing rows, aggregations, joins.
47+
- Inspecting data before changing it.
48+
49+
**Example call (conceptual):**
50+
51+
```sql
52+
SELECT id, email FROM users WHERE active = true ORDER BY created_at DESC LIMIT 50;
53+
```
54+
55+
Call this through the MCP tool instead of embedding SQL in code.
56+
57+
### 2. `executeWriteSQL`
58+
59+
- **Purpose:** Run **write or DDL** statements:
60+
- `INSERT`, `UPDATE`, `DELETE`
61+
- `CREATE TABLE`, `ALTER TABLE`, `DROP TABLE`
62+
- **Use for:**
63+
- Data migrations
64+
- Fixing or seeding data
65+
- Schema changes
66+
67+
Before calling this tool, **confirm**:
68+
69+
- The target tables and conditions are correct.
70+
- You have run a corresponding `SELECT` via `executeReadOnlySQL` when appropriate.
71+
72+
### 3. `readSecurityRule`
73+
74+
- **Purpose:** Read security rules for a given table.
75+
- **Use for:**
76+
- Understanding who can read/write a table.
77+
- Auditing permissions on sensitive tables.
78+
79+
Security rule types typically include:
80+
81+
- `READONLY` – anyone can read, no one can write
82+
- `PRIVATE` – only authenticated users can read/write
83+
- `ADMINWRITE` – anyone can read, only admins can write
84+
- `ADMINONLY` – only admins can read/write
85+
- `CUSTOM` – custom security logic
86+
87+
### 4. `writeSecurityRule`
88+
89+
- **Purpose:** Set or update security rules for a table.
90+
- **Use for:**
91+
- Hardening access to sensitive data
92+
- Opening up read access while restricting writes
93+
- Applying custom rules when needed
94+
95+
When using this tool:
96+
97+
- Clearly explain the **intent** (who should read/write what).
98+
- Prefer standard rule types (`READONLY`, `PRIVATE`, etc.) before `CUSTOM`.
99+
100+
---
101+
102+
## Scenario 1: Safely inspect data in a table
103+
104+
1. Use `executeReadOnlySQL` with a limited `SELECT`:
105+
- Include a `LIMIT` clause.
106+
- Filter by relevant conditions.
107+
2. Review the result set and confirm it matches expectations.
108+
109+
This pattern prevents accidental full-table scans and gives you context before any write operations.
110+
111+
---
112+
113+
## Scenario 2: Apply a schema change
114+
115+
1. Use `executeReadOnlySQL` to inspect the current schema or data (if needed).
116+
2. Plan the `CREATE TABLE` / `ALTER TABLE` statement.
117+
3. Run it once via `executeWriteSQL`.
118+
4. Optionally, validate by running `SELECT` again.
119+
120+
Always describe:
121+
122+
- What schema change you are making.
123+
- Why it is safe in the current context.
124+
125+
---
126+
127+
## Scenario 3: Tighten security rules on a sensitive table
128+
129+
1. Call `readSecurityRule` for the table to see current settings.
130+
2. Decide on the target rule (e.g., from `READONLY``PRIVATE`).
131+
3. Explain the change and why it matches the user’s requirements.
132+
4. Call `writeSecurityRule` with the new rule.
133+
5. Optionally, re-read the rule to confirm the update.
134+
135+
---
136+
137+
## Key principle: MCP tools vs SDKs
138+
139+
- **MCP tools** are for **agent operations** and **database management**:
140+
- Run ad-hoc SQL.
141+
- Inspect and change security rules.
142+
- Do not depend on application auth state.
143+
144+
- **SDKs** are for **application code**:
145+
- Frontend Web apps → Web Relational Database skill.
146+
- Backend Node apps → Node Relational Database quickstart.
147+
148+
When working as an MCP agent, **always prefer these MCP tools** for CloudBase Relational Database, and avoid mixing them with SDK initialization in the same flow.
149+
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
---
2+
name: CloudBase Relational Database Web
3+
description: Use when building frontend Web apps that talk to CloudBase Relational Database via @cloudbase/js-sdk – provides the canonical init pattern so you can then use Supabase-style queries from the browser.
4+
alwaysApply: false
5+
---
6+
7+
## When to use this skill
8+
9+
Use this skill whenever you need to access **CloudBase Relational Database from a browser app** (React, Vue, vanilla JS) using `@cloudbase/js-sdk`.
10+
11+
Use it when you need to:
12+
13+
- Initialize CloudBase Relational Database on the frontend
14+
- Replace an existing Supabase client with CloudBase Relational Database
15+
- Share a single `db` client across your Web app
16+
17+
**Do NOT use this skill for:**
18+
19+
- Backend/Node access to CloudBase Relational Database (use `relation-database-skill``node-sdk/quickstart.md`)
20+
- MCP/agent database management (use `relation-database-skill``mcp-tools/mcp-guide.md`)
21+
- Auth flows (use the Web/Node/Auth skills instead)
22+
23+
## How to use this skill (for a coding agent)
24+
25+
1. **Confirm environment**
26+
- Ask the user for:
27+
- `env` – CloudBase environment ID
28+
2. **Follow the initialization pattern in this file exactly**
29+
- Only change values like `env`, never the object shape.
30+
3. **After initialization, use Supabase knowledge for queries**
31+
- Treat `db` as a Supabase client – method names and patterns are identical.
32+
4. **Avoid re-initializing CloudBase**
33+
- Create a single shared `db` client and reuse it across components.
34+
35+
---
36+
37+
## Installation
38+
39+
```bash
40+
npm install @cloudbase/js-sdk
41+
```
42+
43+
## Initialization pattern (canonical)
44+
45+
```javascript
46+
import cloudbase from "@cloudbase/js-sdk";
47+
48+
const app = cloudbase.init({
49+
env: "your-env-id", // CloudBase environment ID
50+
});
51+
52+
const auth = app.auth();
53+
// Handle user authentication separately (Web Auth skill)
54+
55+
const db = app.rdb();
56+
// Use db exactly like a Supabase client
57+
```
58+
59+
**Rules:**
60+
61+
- Do **not** invent new properties on the `cloudbase.init` options.
62+
- Always call `app.rdb()` to get the database client; `app` is **not** the DB client.
63+
64+
---
65+
66+
## Scenario 1: Replace Supabase client in a React app
67+
68+
```javascript
69+
// lib/db.js (shared database client)
70+
import cloudbase from "@cloudbase/js-sdk";
71+
72+
const app = cloudbase.init({
73+
env: "your-env-id",
74+
});
75+
76+
export const db = app.rdb();
77+
```
78+
79+
```javascript
80+
// hooks/usePosts.js
81+
import { useEffect, useState } from "react";
82+
import { db } from "../lib/db";
83+
84+
export function usePosts() {
85+
const [posts, setPosts] = useState([]);
86+
87+
useEffect(() => {
88+
async function fetchPosts() {
89+
const { data } = await db.from("posts").select("*");
90+
setPosts(data || []);
91+
}
92+
fetchPosts();
93+
}, []);
94+
95+
return { posts };
96+
}
97+
```
98+
99+
---
100+
101+
## Scenario 2: Basic query pattern (Supabase-style)
102+
103+
```javascript
104+
// Fetch latest posts
105+
const { data, error } = await db
106+
.from("posts")
107+
.select("*")
108+
.order("created_at", { ascending: false });
109+
110+
if (error) {
111+
console.error("Failed to load posts", error.message);
112+
}
113+
```
114+
115+
---
116+
117+
## Scenario 3: Insert / update / delete rows
118+
119+
```javascript
120+
// Insert
121+
await db.from("posts").insert({ title: "Hello" });
122+
123+
// Update
124+
await db.from("posts").update({ title: "Updated" }).eq("id", 1);
125+
126+
// Delete
127+
await db.from("posts").delete().eq("id", 1);
128+
```
129+
130+
---
131+
132+
## Key principle: CloudBase Relational Database = Supabase API
133+
134+
- After you have `db = app.rdb()`, use **Supabase documentation and patterns** for all queries.
135+
- This skill only standardizes **Web initialization and client sharing**.
136+
- Do not duplicate Supabase docs into this skill; rely on the model's built-in Supabase knowledge for query shapes and options.
137+

0 commit comments

Comments
 (0)