Typed tools from live schema
Generate narrow typed tools from the live schema instead of exposing raw SQL. db.asTools() emits per-table selects, inserts, updates, deletes, and safety primitives — each call maps to metered, auditable queries against a single branch.
import { PerSQL } from "@persql/sdk";import Anthropic from "@anthropic-ai/sdk";
const persql = new PerSQL({ token: process.env.PERSQL_TOKEN! });const db = persql.database("acme", "tasks");const tools = await db.asTools();
const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY! });const result = await client.messages.create({ model: "claude-3-5-sonnet-latest", tools: tools.anthropic, messages: [{ role: "user", content: "List all pending tasks" }],});
for (const block of result.content) { if (block.type === "tool_use") { const rows = await tools.run(block.name, block.input); console.log(block.name, rows); }}The agent gets type-safe tool names and validated parameters, while approval rules and row-level scope stay under the schema owner’s control. Every mutating tool call routes through the same metered, auditable query pipeline as raw SQL.