Database
Agent
Per-user database tools for AI agents, safe by construction.
Usage
import { agentTools } from "@dapplelight/signet-db/agent"
import { createMcpServer } from "@dapplelight/signet-server/mcp"
import { notes, orders } from "./schema"
import { db } from "./db"
import { session } from "./session"
const tools = agentTools(db, {
tables: [orders, notes],
userId: session.userId,
maxRows: 50,
})
createMcpServer({ name: "app", version: "1.0.0", tools }) // or call tool.run(input) yourselfNeeds zod. Each table gets <table>_list, <table>_get and <table>_search. With allowWrites: true it also gets <table>_insert and <table>_update, which take dryRun: true.
API
| Export | What it does |
|---|---|
agentTools(db, options) | Build the tool list for one user |
jsonSchema(zodType) | Zod to JSON Schema, dates as date-time strings |
AgentTool | { name, description, annotations, input, inputSchema, run, handler } |
AgentToolsOptions | Options type |
agentTools(db, options)
| Option | Type | Default | |
|---|---|---|---|
tables | Table[] | schema module | required | Each needs a userId column |
userId | string | required | The user the agent acts for |
actor | Actor | { type: "agent", id: "agent" } | Recorded in the audit log |
allowWrites | boolean | false | Add insert and update tools |
maxRows | number | 100 | Most rows any call returns |
includeEncrypted | boolean | false | Return encrypted fields, decrypted |
Guards
- Scoped to
userId; a table without auserIdcolumn is refused. - Soft-deleted rows are hidden;
userIdis never returned. - Inputs are strict Zod objects: unknown fields fail with
BAD_INPUT. - Writes are audited as the agent actor.
Examples
Let the agent edit, after a dry run
import { agentTools } from "@dapplelight/signet-db/agent"
import { orders } from "./schema"
import { db } from "./db"
import { session } from "./session"
const orderId = "ord_1"
const tools = agentTools(db, {
tables: [orders],
userId: session.userId,
allowWrites: true,
actor: { type: "agent", id: "support-bot" },
})
const update = tools.find((t) => t.name === "orders_update")!
await update.run({ id: orderId, set: { item: "Idli" }, dryRun: true }) // { dryRun, before, after }