> ## Documentation Index
> Fetch the complete documentation index at: https://sdk.docs.xano.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Build

> How you and your coding agent write a Xano backend in TypeScript with the Xano SDK: tables, APIs, background work, realtime, AI agents, custom code, tests, environment variables and a typed frontend.

Write with AI. Run locally. Deploy to Xano. This section is the first step.

Your coding agent writes the database, the APIs and AI agents in TypeScript with the Xano SDK.
Each piece is a def object: a table, an endpoint, an agent, a task. You register def objects on
one `workspace()` in `xano/index.ts`, and the SDK compiles them into the backend that runs on the
Xano Engine on your machine, then on Xano when you ship.

```ts theme={null}
import { workspace, table, apiGroup, query, f, input, inp, ref, s } from "@xano/sdk";

const notes = table({ name: "notes", schema: { body: f.text({ required: true }) } });
const api = apiGroup({ name: "notes", canonical: "notes" });

const createNote = query({
  name: "create_note",
  verb: "POST",
  apiGroup: api,
  input: { body: input.text({ required: true }) },
  stack: [s.db.add({ table: notes, row: { body: inp("body") }, as: "note" })],
  response: ref("note"),
});

export default workspace("my-app")
  .registerTables([notes])
  .registerApiGroups([api])
  .registerQueries([createNote]);
```

Everything is typed. A renamed column is a compile error in every endpoint that reads it and in
the frontend that renders it, so mistakes surface in your editor rather than after a deploy.

## Which kind do I use?

Choose by who or what starts the work.

| The job | Kind | Page |
| - | - | - |
| Logic other code calls | `defineFunction`, run with `s.function.run` | [APIs, functions and middleware](/build/apis-and-middleware) |
| An HTTP endpoint a client calls | `query` in an `apiGroup` | [APIs, functions and middleware](/build/apis-and-middleware) |
| The same steps before or after many objects | `middleware` | [APIs, functions and middleware](/build/apis-and-middleware) |
| Related rows attached to returned rows | `addon` | [Data and tables](/build/data-and-tables) |
| Work that follows any change to a table's rows | `tableTrigger` | [Data and tables](/build/data-and-tables) |
| Work on a timer | `task` | [Tasks and platform events](/build/tasks) |
| Work a request starts but does not wait for | `s.function.run` with an async `runtime` | [APIs, functions and middleware](/build/apis-and-middleware#work-a-request-does-not-wait-for) |
| Reacting to Xano branch changes and new errors | `workspaceTrigger`, `errorTrigger` | [Tasks and platform events](/build/tasks) |
| Pushing to connected clients | `realtimeServer`, `realtimeChannel`, `realtimeMessage` | [Realtime](/build/realtime) |
| An action an agent or MCP client calls | `tool` | [AI agents and MCP servers](/build/ai-agents-and-mcp-servers) |
| An LLM running inside the backend | `agent`, run with `s.ai.agent.run` | [AI agents and MCP servers](/build/ai-agents-and-mcp-servers) |
| An outside AI client calling the backend | `mcpServer`, with `prompt` and `resource` | [AI agents and MCP servers](/build/ai-agents-and-mcp-servers) |
| Standing instructions for Xano's own AI | `knowledge` | [AI agents and MCP servers](/build/ai-agents-and-mcp-servers) |
| What one connection may see or do | The parent's connection trigger: `agentTrigger`, `mcpServerTrigger`, `realtimeServerTrigger`, `realtimeChannelTrigger` | The parent's page |
| Code the typed surface cannot express | A lambda, `s.api.request`, or a `microservice` | [Custom code](/build/custom-code) |
| Checking one object, or a flow across several | `tests` on the object, or a `workflowTest` | [Tests](/build/tests) |

## Pages in this section

<CardGroup cols={2}>
  <Card title="Your first change" href="/build/first-change">
    Add a table and an endpoint, deploy to the Xano Engine, and call it.
  </Card>

  <Card title="Data and tables" href="/build/data-and-tables">
    Columns, foreign keys, indexes, seed rows, queries, addons and table triggers.
  </Card>

  <Card title="APIs, functions and middleware" href="/build/apis-and-middleware">
    API groups, endpoints, reusable functions, background runs, auth and middleware.
  </Card>

  <Card title="Tasks and platform events" href="/build/tasks">
    Scheduled jobs, and triggers for Xano branch changes and new errors.
  </Card>

  <Card title="Realtime" href="/build/realtime">
    Websocket servers, channels, message handlers and their connection triggers.
  </Card>

  <Card title="AI agents and MCP servers" href="/build/ai-agents-and-mcp-servers">
    Agents, tools, MCP servers, knowledge, and what each connection sees.
  </Card>

  <Card title="Custom code" href="/build/custom-code">
    Lambdas, HTTP calls to other services, and microservice containers.
  </Card>

  <Card title="Tests" href="/build/tests">
    Unit tests and workflow tests that ship with your code.
  </Card>

  <Card title="Environment variables and secrets" href="/build/env-and-secrets">
    Declare names in code, keep values out of git, rotate safely.
  </Card>

  <Card title="Typed frontend" href="/build/typed-frontend">
    Call your endpoints with types generated from the backend.
  </Card>

  <Card title="Add-ons" href="/build/add-ons">
    Install auth, vector search, validation and more from the marketplace.
  </Card>
</CardGroup>

## Where to go next

Start with [your first change](/build/first-change). For every builder, field type and option,
see the [authoring reference](/reference/authoring) and the
[object kinds reference](/reference/object-kinds).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.