AI
AI skills
The NordBase Agent Skill for Claude Code and other tools that read skills, an AGENTS.md section for Codex and a Cursor rule, with the full text of each.
Coding agents write a lot of database code. Left alone, some of it concatenates values into SQL, hard-codes secrets or asks for more access than it needs. The NordBase skill gives an agent the rules up front, in the form each tool reads.
The rules are the same everywhere:
- Read the Connection URL from
NORDBASE_URL. Never hard-code or print it. - Write parameterized SQL only, through the NordBase library.
- Give every Credential the least privilege that works.
- Manage NordBase through the MCP server, not by guessing API calls.
Agent Skill for Claude Code
Claude Code, and other tools that read Agent Skills, load a skill from a folder with a SKILL.md file. The NordBase skill package, SKILL.md with short reference files for each language, is published from the NordBase repository; its link will appear here.
Until then, save this as .claude/skills/nordbase/SKILL.md in your project, or as ~/.claude/skills/nordbase/SKILL.md for every project:
---
name: nordbase
description: Work with NordBase managed databases (PostgreSQL and MongoDB-compatible). Use when a project has NORDBASE_URL, imports the nordbase library, or the user asks to create, connect to, grant access to or restore a NordBase database.
---
# NordBase
NordBase runs the database; the app holds one Connection URL in `NORDBASE_URL`. Terms: Database, Credential (connects to one Database, has a Permission set), Access token (manages the account through the API or MCP, never connects to a Database), Replica, Restore point.
## Always
1. Read the connection from `NORDBASE_URL` (or `NORDBASE_KEY_FILE`). Never write a Connection URL, secret (`nbs_…`) or Access token (`nbt_…`) into code, commits, logs or chat. Put it in `.env` and make sure `.env` is git-ignored.
2. Create one client per process from the environment: Node `createClient()`, Python `connect()` (or `connect_async()`), Rust `Client::from_env()?`. Pass every value as a parameter with the library's template form:
- Node: ``await db.sql`select * from orders where id = ${id}` ``
- Python 3.14: `db.sql(t"select * from orders where id = {id}")`; older Python: `db.sql("select * from orders where id = {id}", id=id)` (never an f-string: on older Python it cannot be told apart and gets through)
- Rust: `db.query(sql!("select * from orders where id = {id}")).await?`
Never build SQL with string concatenation, f-strings, `format!` or `+`. Table and column names that come from variables go through `sql.id(name)`.
3. `db.unsafe(...)` and `db.unsafeScript(...)` only for trusted text you wrote yourself (migrations, and on Python before 3.14 fixed statements with no values). Never with user input.
4. Never pass a request body straight into the builder's `insert` or `update`: pick the fields you accept.
5. Document Databases: use the library's collection wrapper; build operators with `op.*` helpers; never pass an object from a request body as a filter. `$where`, `$function` and `$accumulator` are refused; write patterns with `op.regex()`.
6. One Credential per app or job, with the smallest preset that works: `read_only` for analytics and reports, `read_write` for app servers, `schema` only for the migration runner (it is as strong as `owner`: it can change any table's permissions), `owner` only for people.
7. After a write, reads on the same client go to the Primary for 2 s. If a later read must see a write from another process, use `consistency: "strong"` for that call; do the same after a `select` that calls a function which writes.
8. Migrations, `LISTEN/NOTIFY`, session `SET` and advisory locks need the Direct port (5433). The default URL (5432) pools transactions.
## With the MCP server
If the NordBase MCP server is connected, use it to manage the account instead of asking the user to click:
- `list_databases`, `describe_schema`, `get_usage` to look around.
- `create_database`, `add_replica`, `create_credential` (pick the least-privilege preset), `revoke_credential` to change things; say what you will create before you do it.
- `run_sql` is read-only unless the token has `sql:write` and you pass the write flag; prefer migrations in code for schema changes.
- `restore_to_time` with `new_database` first; restore in place only when the user explicitly asks, after naming the exact second.
## When something fails
- `PermissionError` / SQLSTATE `42501`: the Credential lacks a Grant. Do not switch to an owner Credential to get around it; tell the user which permission is missing.
- `ReadOnlyLockError`: the account's storage is full; Writes are refused until space is freed or the plan grows. Tell the user; do not retry.
- `TooManyConnectionsError` / `53300`: reuse one client per process.
- A Write with an unknown outcome is never retried automatically; check before retrying.
Docs: `/docs` on the NordBase site (`quickstart`, `safe-sql`, `credentials`, `replicas-and-consistency`, `restore`, `mcp`).AGENTS.md for Codex
Codex, and other agents that read AGENTS.md, take instructions from that file at the root of your repository. Add this section:
## Database: NordBase
- The database URL is in `NORDBASE_URL`. Never print, commit or hard-code it.
- Every value in SQL is a parameter: use `db.sql` templates (Node), t-strings or named placeholders (Python), `sql!` (Rust). No string-built SQL.
- Identifiers from variables go through `sql.id()`. `db.unsafe` only for our own migration text.
- Document queries use `op.*` helpers; never pass request bodies as filters or straight into `insert`/`update`.
- Each app gets its own least-privilege Credential; migrations run with a `schema` Credential on the Direct port 5433.
- Use the NordBase MCP server (if connected) to manage databases; restore to a new database first.Cursor rule
Cursor reads project rules from .cursor/rules. Save this as .cursor/rules/nordbase.mdc:
---
description: NordBase database rules
alwaysApply: true
---
## Database: NordBase
- The database URL is in `NORDBASE_URL`. Never print, commit or hard-code it.
- Every value in SQL is a parameter: use `db.sql` templates (Node), t-strings or named placeholders (Python), `sql!` (Rust). No string-built SQL.
- Identifiers from variables go through `sql.id()`. `db.unsafe` only for our own migration text.
- Document queries use `op.*` helpers; never pass request bodies as filters or straight into `insert`/`update`.
- Each app gets its own least-privilege Credential; migrations run with a `schema` Credential on the Direct port 5433.
- Use the NordBase MCP server (if connected) to manage databases; restore to a new database first.Pair it with the MCP server
The skill tells the agent how to write code; the MCP server gives it the tools to manage your Account. Use both, and keep the Access token's scopes as narrow as the task.