Closed by default
A table without a policy has no routes. Unknown and closed tables answer the same 404.
A backend on Cloudflare that is closed by default.
One Worker and one D1 database in your account serve a REST API for your tables. Every route is protected by policies written in TypeScript and compiled to SQL, and an MCP server lets AI agents see exactly what production enforces.
Free & open source · MIT · Your Cloudflare account, no hosted service
A table without a policy has no routes. Unknown and closed tables answer the same 404.
Rules compile to WHERE clauses, so pagination and counts stay correct.
Every create and update is verified on the stored row, atomically. Server-set columns never come from the client.
Better Auth (email, GitHub), roles and API keys, checked against D1 on every request.
Read and write tools on the same engine and write path as REST, with scoped tokens and an audit log.
One Worker and one D1 database in your Cloudflare account. No hosted service in between.


Create a new project:
npm create @castra-kit@latest my-appA policy. Any table not listed is never exposed:
import { authenticated, defineConfig, isPublic, owner, role } from "@castra-kit/core";
export default defineConfig({
database: "d1",
roles: ["admin", "editor"],
tables: {
posts: {
read: isPublic().where((q) => q.eb("status", "=", "published")).or(owner("author_id")),
create: authenticated(),
update: owner("author_id").or(role("editor", "admin")),
delete: role("admin"),
fields: { author_id: { setBy: "server" } },
},
},
});
// Any table not listed here is never exposed.Castra is early. It is deployed and tested, but only writes are rate limited and D1 has a single writer. See status and limits and the security model.
MIT licensed, published on npm as @castra-kit. Issues and contributions welcome.