Skip to main content

Introduction

Triggers in XanoScript allow you to define automated responses to specific events across your application. Unlike other primitives, triggers come in several different types, each responding to different kinds of events. XanoScript supports four types of triggers:
  • Database triggers — Respond to table changes (insert, update, delete)
  • Workspace triggers — Respond to workspace events (branch changes, deployments)
  • Realtime triggers — Respond to realtime channel events (messages, joins)
  • MCP server triggers — Respond to MCP server connection events
Each trigger type has its own unique structure and input schema, but they all follow a similar pattern of declaration, input, stack, and response.

Anatomy

Every XanoScript trigger follows a predictable structure, though the specific components vary by trigger type. Here’s a quick visual overview of the main building blocks — from declaration at the top to settings at the bottom.

You can find more detail about each section by continuing below.

Declaration

Every trigger starts with a declarative header that specifies its type, name, and trigger-specific configuration.
XanoScript

Trigger Types

Database Triggers

Database triggers respond to changes in database tables. They can be configured to fire on insert, update, delete, or truncate operations.
XanoScript
Database Trigger Configuration:
  • table — The table name to monitor for changes
  • actions — Specifies which database operations trigger the event

Workspace Triggers

Workspace triggers respond to workspace-level events like branch changes, deployments, and other administrative actions.
XanoScript
Workspace Trigger Configuration:
  • actions — Specifies which workspace events trigger the action

Realtime Triggers

Realtime triggers respond to events in realtime channels, such as messages or user joins.
XanoScript
Realtime Trigger Configuration:
  • channel — The realtime channel to monitor
  • actions — Specifies which realtime events trigger the action

MCP Server Triggers

MCP server triggers respond to MCP server connection events and can modify the toolset and tools available to the server.
XanoScript
MCP Server Trigger Configuration:
  • mcp_server — The MCP server name to monitor
  • actions — Specifies which MCP events trigger the action

Section 1: Input

The input block defines the data that will be available to the trigger. Each trigger type has its own specific input schema.
Database Trigger Input:
XanoScript
Workspace Trigger Input:
XanoScript
Realtime Trigger Input:
XanoScript
MCP Server Trigger Input:
XanoScript
Each trigger type provides different input data based on the event that triggered it. The input schema is automatically provided by Xano based on the trigger type.

Section 2: Stack

The stack block contains the actual logic that will be executed when the trigger fires.
XanoScript
The stack works exactly like other XanoScript primitives:
  • Functions are called with their parameters
  • Variables can be created and manipulated
  • Conditional logic can be applied
  • Database operations can be performed
The main difference is that triggers have access to the specific input data provided by the triggering event.

Section 3: Response

The response block defines what data your trigger returns (if any). Not all trigger types require a response.
MCP Server Trigger Response:
XanoScript
Realtime Trigger Response:
XanoScript
  • Database triggers typically don’t need responses
  • Workspace triggers typically don’t need responses
  • Realtime triggers can return data to the channel
  • MCP server triggers must return modified toolset and tools

Settings

Trigger primitives support several optional settings that control which events trigger the action and how the trigger is organized.
Actions Configuration Examples:Database Trigger Actions:
XanoScript
Workspace Trigger Actions:
XanoScript
Realtime Trigger Actions:
XanoScript
MCP Server Trigger Actions:
XanoScript

Detailed Examples

Database Trigger Example

XanoScript

MCP Server Trigger Example

XanoScript

Workspace Trigger Example

XanoScript

Realtime Trigger Example

XanoScript

What’s Next

Now that you understand how to define triggers in XanoScript, here are a few great next steps:

Explore the function reference

Learn about the built-in functions available in the stack to start writing more complex trigger logic.

Try it out in VS Code

Use the XanoScript VS Code extension with Copilot to write XanoScript in your favorite IDE.

Learn about APIs

Create APIs that can be called by your triggers to build complete automated workflows.