# Server Primitives

Server Primitives are APIs for storage, background work, auth, and other server features. Call them from routes, handlers, or jobs. Each package has its own configuration and server API.

Set up your app in [Installation](https://vitehub.dev/docs/getting-started/installation), save and read a value in [your first Server Primitive](https://vitehub.dev/docs/getting-started/first-server-primitive), then pick the feature your app needs below. Agents are optional.

## Pick the right primitive

| You need | Start with |
| --- | --- |
| Public, server, build-time, runtime, or secret env values | [Env](https://vitehub.dev/docs/env) |
| Application users, sessions, Better Auth routing, or guarded app routes | [Auth](https://vitehub.dev/docs/auth) |
| Provider accounts the app owns, with OAuth refresh, access rules, and call activity | [Connections](https://vitehub.dev/docs/connections) |
| GitHub App tokens and GitHub, GitLab, or Forgejo access from one set of env names | [Forge](https://vitehub.dev/docs/forge) |
| Request budgets spent before expensive server work starts | [Rate Limit](https://vitehub.dev/docs/rate-limit) |
| Outbound transactional messages with provider-neutral delivery | [Email](https://vitehub.dev/docs/email) |
| Named outbound destinations, such as Telegram or Teams, behind selected connectors | [Channels](https://vitehub.dev/docs/channels) |
| Outbound app events to outside URLs with HMAC signatures, retries, and debouncing on [supported hosts](https://vitehub.dev/docs/webhooks/hosts) | [Webhooks](https://vitehub.dev/docs/webhooks) |
| Contact, feedback, or problem-report forms with a spam guard, validation, an inbox, and email | [Forms](https://vitehub.dev/docs/forms) |
| Pinned team comments on live pages, with replies, resolution, and in-place Content text edits | [Comments](https://vitehub.dev/docs/comments) |
| App translation with no message keys, collected for translators and served in each request locale | [i18n](https://vitehub.dev/docs/i18n) |
| An app MCP server for tools, prompts, or resources in `server/mcp/`, protected with MCP OAuth | [MCP server](https://vitehub.dev/docs/mcp) |
| Small values by key: settings, flags, cursors, or light state | [KV](https://vitehub.dev/docs/kv) |
| Relational data, constraints, joins, migrations, or queryable history | [Database](https://vitehub.dev/docs/database) |
| Uploads, generated artifacts, binary files, or object metadata | [Blob](https://vitehub.dev/docs/blob) |
| Local-first synced tables with offline writes, data kept on reload, and the server as authority for every row | [Sync](https://vitehub.dev/docs/sync) |
| Stored browser reads for a signed-in account that show the last server answer, then refresh | [Device](https://vitehub.dev/docs/device) |
| Provider-backed browser sessions, screenshots, DOM inspection, or live handoff | [Browser](https://vitehub.dev/docs/browser) |
| Persistent file-tree state, snapshots, diffs, rules, or sessions | [Workspace](https://vitehub.dev/docs/workspace) |
| Collaborative Markdown editing, presence, and Workspace checkpoints | [Realtime](https://vitehub.dev/docs/realtime) |
| Read-only retrieval from files, globs, GitHub, markdown, MCP, or custom loaders | [Source](https://vitehub.dev/docs/source) |
| Parse, query, search, and serve content from Sources | [Content](https://vitehub.dev/docs/content) |
| Editable Markdown, JSON, and YAML documents published from the Console to the site or pull requests | [CMS](https://vitehub.dev/docs/cms) |
| Structured events with Evlog, and inspection of an existing log backend | [Logs](https://vitehub.dev/docs/logs) |
| Background delivery that returns before work finishes | [Queue](https://vitehub.dev/docs/queue) |
| Durable long-running work with provider-tracked run state | [Workflows](https://vitehub.dev/docs/workflows) |
| Static cron output | [Schedule](https://vitehub.dev/docs/schedule) |
| Isolated provider-managed execution | [Sandbox](https://vitehub.dev/docs/sandbox) |
| Controlled Unix-like command sessions | [Shell](https://vitehub.dev/docs/shell) |
| AI model request routing through a gateway such as Vercel AI Gateway, Cloudflare AI Gateway, OpenRouter, or Ollama | [AI Gateways](https://vitehub.dev/docs/gateways) |
| What people type, matched to declared options for filters, search facets, and command palettes | [Choices](https://vitehub.dev/docs/choices) |
| UI for people and Agents: ui-sdk parts, Agent-sent UI specs, and live pages Agents work on | [UI](https://vitehub.dev/docs/ui) |

## Call a feature from a route

Most primitives use the same import on every host. The build connects it to the selected provider.

This example uses the Nitro or Nuxt app from Installation with KV turned on. Both serve the file at `PUT /api/settings`. Keep the explicit H3 imports when you copy it:

```ts [server/api/settings.put.ts]
import { defineEventHandler, readBody } from 'h3'
import { kv } from 'vite-hub/kv'

export default defineEventHandler(async (event) => {
  const [error] = await kv.set('settings', await readBody(event))
  if (error) throw error
  return { ok: true }
})
```

The route uses the configured KV driver. The [KV tutorial](https://vitehub.dev/docs/kv/get-started) adds the configuration, a read after the write, and a request to run.

## Add a Definition when the feature needs one

A Queue needs a handler Definition, and a Database needs a schema Definition. Each tutorial shows the file to create. ViteHub finds these files in development and build.

See [Definition discovery](https://vitehub.dev/docs/development/definition-discovery) for names, [File conventions](https://vitehub.dev/docs/reference/file-conventions) for paths, and [Configuration](https://vitehub.dev/docs/reference/config-options) for more options.

## Give an Agent a selected operation

Your server calls each feature directly. An Agent needs a Capability, a grant for one selected operation. The [KV capability](https://vitehub.dev/docs/kv/agent-capability) gives access to stored values, and the [Workspace capability](https://vitehub.dev/docs/workspace/agent-capability) gives access to files.

Add a Capability only when the Agent needs it, and set its scope, write mode, and approval policy for the task. [Capabilities](https://vitehub.dev/docs/agents/capabilities) lists the operations and the constraints each supports.

## Choose a host

Your host sets the resources and limits behind an API. Pick a host in [Build and deploy](https://vitehub.dev/docs/getting-started/build-and-deploy), then read the feature's Hosts page. Check the generated bindings and resource identities before you connect production data.

<!-- vitehub-docs:section-links -->
## In this section

- [Get started](https://vitehub.dev/raw/docs/getting-started.md)
- Next steps
  - [Server Primitives](https://vitehub.dev/raw/docs/getting-started/server-primitives.md) (this page)
  - [How ViteHub works](https://vitehub.dev/raw/docs/getting-started/concepts.md)
- [Build and deploy](https://vitehub.dev/raw/docs/getting-started/build-and-deploy.md)
- [Coding agents](https://vitehub.dev/raw/docs/getting-started/ai-resources.md)

Next: [How ViteHub works](https://vitehub.dev/raw/docs/getting-started/concepts.md)

All pages: [llms.txt](https://vitehub.dev/llms.txt)
