Skip to Content
ZenoZENO

AI & agents

Let a chat sidebar and MCP clients such as Claude read and change your app's data, as the signed-in user

The reads and writes your screens already use can serve an AI agent too. You write each one once, with defineQuery, defineAction or defineFormAction from @zeno-lib/db/next, give it a name and a description, and put it on your app's agent tool list. @zeno-lib/ai then serves that list two ways:

  • In your app, as AI SDK tools for a chat sidebar: toAiSdkTools from @zeno-lib/ai/tools. See Chat sidebar.
  • To an MCP client the user brings, such as Claude, over the Model Context Protocol: createMcpRoute from @zeno-lib/ai/mcp, behind Supabase Auth's OAuth 2.1 server. See MCP server.

Either way, every tool runs as the signed-in user, under row level security: the agent never sees or changes more than the user can in the app.

Installation

pnpm add @zeno-lib/ai

Then the library of the side you use: ai (version 7) for the chat sidebar, @modelcontextprotocol/server (version 2) for MCP. Your schemas need Zod 4.2 or later, which describes them as JSON Schema for the model.

The tool policy

Three rules decide what an agent may do. The first two are enforced by the package; the third is yours to keep.

  1. Opt-in. A read or a write becomes a tool only once it has a name and description and is on your agent tool list. A new feature never reaches an agent by default.
  2. Every write waits for the user, who sees the change. Reads run freely. A write runs only after the user approves it, and the approval shows the record and each field, old → new, which the write's describeChange reads. An approval that only names the tool gets approved unread, and it is the main guard against a prompt injected through your own data. A write without describeChange is not a valid tool, and a write whose record changed after the approval is refused.
  3. Never a tool, even with approval: anything whose damage leaves the app or can't be undone. Sending email, sharing files or granting access, user administration, deletes, and anything that runs with the secret key and bypasses row level security.

An MCP client runs your tools next to its other connectors, so text a user stored in your app could ask the model to send your data through one of them. Make sure the client asks before each call to a connector that sends or shares.

Next

  • Agent tools: the tool list, agent-sized reads, and approvals that show the change.
  • MCP server: the OAuth server, the consent page, registered clients and the /mcp route.
  • Chat sidebar: a streamText route and an assistant-ui sidebar with approvals.