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
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
Element | Required | Description |
---|---|---|
trigger_type | ✅ | Declares the trigger primitive type. |
trigger_name | ✅ | The unique name for the trigger. |
description | no | Optional human-readable description of the trigger’s purpose. |
trigger_specific_config | varies | Configuration specific to the trigger type (table, channel, mcp_server, etc.). |
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
table
— The table name to monitor for changesactions
— 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
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
channel
— The realtime channel to monitoractions
— 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
— The MCP server name to monitoractions
— Specifies which MCP events trigger the action
Section 1: Input
Theinput
block defines the data that will be available to the trigger. Each trigger type has its own specific input schema.
Database Trigger Input:Workspace Trigger Input:Realtime Trigger Input:MCP Server Trigger Input: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.
XanoScript
XanoScript
XanoScript
XanoScript
Section 2: Stack
Thestack
block contains the actual logic that will be executed when the trigger fires.
XanoScript
- Functions are called with their parameters
- Variables can be created and manipulated
- Conditional logic can be applied
- Database operations can be performed
Section 3: Response
Theresponse
block defines what data your trigger returns (if any). Not all trigger types require a response.
MCP Server Trigger Response:Realtime Trigger Response:
XanoScript
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.Setting | Type | Required | Description |
---|---|---|---|
actions | object | ✅ | Specifies which events trigger the action. Keys are event names, values are boolean. |
tags | array[string] | no | A list of tags used to categorize and organize the trigger in your workspace. |
XanoScript
XanoScript
XanoScript
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.