Relational database tool

From bighardperson/computer-science-skills-collection · View interactive version

Relational database tool is an AI agent skill from the GitHub repository bighardperson/computer-science-skills-collection. This is the required documentation for agents operating on the CloudBase Relational Database through MCP. It defines the canonical SQL management flow with `querySqlDatabase`, `manageSqlDatabase`, `readSecurityRule`, and `writeSecurityRule`, including MySQL provisioning, destroy flow, async status c

How to use this skill

Skill file

Activation Contract

Use this first when

Read before writing code if

Then also read

Do NOT use for

Common mistakes / gotchas

When to use this skill

Use this skill when an agent needs to operate on CloudBase Relational Database via MCP tools, for example:

Do NOT use this skill for:

How to use this skill (for a coding agent)

  1. Recognize MCP context
  1. Pick the right tool for the job
  1. Always be explicit about safety

Available MCP tools (CloudBase Relational Database)

These tools are the supported way to interact with CloudBase Relational Database via MCP:

1. `querySqlDatabase`

Example flow:

{
  "action": "runQuery",
  "sql": "SELECT id, email FROM users ORDER BY created_at DESC LIMIT 50"
}

2. `manageSqlDatabase`

Important: When creating a new table, you must include the _openid column for per-user access control:

_openid VARCHAR(64) DEFAULT '' NOT NULL

Note: when a user is logged in, _openid is automatically populated by the server from the authenticated session. Do not manually fill it in normal inserts.

Before calling this tool, confirm:

When destroying MySQL, confirm:

3. `readSecurityRule`

4. `writeSecurityRule`


Recommended lifecycle flow

Scenario 1: MySQL is not provisioned yet

  1. Call querySqlDatabase(action="getInstanceInfo").
  2. If no instance exists, call manageSqlDatabase(action="provisionMySQL", confirm=true).
  3. Poll provisioning status with:
  1. Only continue when the returned lifecycle status is READY.
  2. For MySQL provisioning, prefer describeCreateResult; reserve describeTaskStatus for destroy flows whose task response carries TaskName.

Scenario 2: Safely inspect data in a table

  1. Use querySqlDatabase(action="runQuery") with a limited SELECT.
  2. Include LIMIT and relevant filters.
  3. Review the result set and confirm it matches expectations before any write operation.

Scenario 3: Apply schema initialization after provisioning

  1. Confirm MySQL is ready.
  2. Prepare ordered DDL statements.
  3. Run them through manageSqlDatabase(action="initializeSchema").
  4. After creating tables, verify security rules with readSecurityRule or writeSecurityRule.

Scenario 4: Execute a targeted write or DDL change

  1. Use querySqlDatabase(action="runQuery") to inspect current data or schema if needed.
  2. Run the mutation once with manageSqlDatabase(action="runStatement").
  3. Validate with another read-only query or by checking security rules.

Scenario 5: Destroy MySQL when the environment no longer needs it

  1. Use querySqlDatabase(action="getInstanceInfo") to confirm the current environment still has a SQL instance.
  2. Call manageSqlDatabase(action="destroyMySQL", confirm=true).
  3. Query querySqlDatabase(action="describeTaskStatus") until the destroy task completes or fails.
  4. If the task succeeds, optionally call querySqlDatabase(action="getInstanceInfo") to confirm the instance no longer exists.
  5. If the task fails, treat the returned error as the terminal result and let the caller decide whether to retry.

Key principle: MCP tools vs SDKs

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.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.