Skip to main content
These are AI features of the backend you ship: an agent your endpoint runs, or an MCP server other clients connect to. They are not the coding agent that writes your code. For that, see Coding agents and the Xano Engine’s MCP server. Four kinds work together: An MCP server also serves prompt() and resource() objects, and an agent or MCP server can have a connection trigger (agentTrigger, mcpServerTrigger) that decides what each connection sees.

A tool

A tool, a prompt and a resource each take tests, as an endpoint does. See Tests.

An agent, called from an endpoint

Agents have no public endpoint of their own. You run one from any stack:
  • The answer is at .result. ref("answer") is the whole run envelope (finishReason, steps and more).
  • llm picks the provider: xano-ai, anthropic, openai or google-genai, each with its own typed fields. xano-ai needs no API key: Xano bills it as Xano AI.
  • xano-free is deprecated. Xano runs a xano-free agent as xano-ai, with the default model and the workspace’s Xano AI location, on Xano’s cloud and on the Xano Engine alike. A model or location stored under it is ignored. Existing xano-free code still compiles and deploys unchanged; write xano-ai for a new agent.
  • Tools run by default. allowToolExecution defaults to true. Setting it to c.bool(false) does not hide the tools: the model still asks for one, the call never runs, and the run ends with an empty result (export() warns stack.agent-tools-off).
  • Structured output. Give the agent output: { schema: { ... } } with input.* fields and .result is typed from it at every call site.
  • Prompts are templates. String settings resolve {{ $args.NAME }} and {{ $env.NAME }} at run time.
  • Fall back when the provider fails. Wrap the run in s.try_catch. In the catch arm, caught("result") is { name: "AI_APICallError", statusCode, isRetryable, data }, so branch on withFilters(caught("result"), fl.get("statusCode")) (a 401 means the key was refused). caught("message") holds the provider’s error text.

Control each connection: agent triggers

An agentTrigger runs when a client connects to the agent it is bound to. t.toolset is the agent (t.toolset("name") reads one field) and t.tools is its list of tools, each { id, name, instructions }. What the trigger returns is the toolset and tools that connection gets, so the trigger can gate the connection, or log and annotate it on the way through:
  • The stack is a callback. A trigger has no input; its inputs arrive on t, typed to the trigger, so a wrong name is a compile error.
  • Bind with the handle. Pass the agent() def, not an id. A trigger bound to nothing deploys and never fires.
  • Omit response and the connection gets every tool unchanged.

Xano AI models

Xano AI runs models for you with no provider key. You reach it two ways: an agent with llm: { type: "xano-ai" }, or one of eight statements under s.ai that you call from any stack: Every result also carries the model that ran.
  • model is optional. Leave it out and the statement runs its suggested model. It takes any string, so a model released after your SDK version still compiles; the editor autocompletes the models that were current when the SDK was built.
  • List the current models with npx @xano/sdk ai models. It reads the live catalog, needs no sign-in, and shows each statement’s models, the suggested one, where each can run, its options and its price. --json is for agents; --all adds retired models. See ai models.
  • Values the engine would reject fail at build time. location, aspect_ratio, image_size, resolution, response_format and save_to_files are checked when you export, and a statement refuses a location its model cannot run at.
  • save_to_files stores the result as a file. On video, music and speech it needs a paid plan; on images it does not.
  • On an agent, model must be a literal name: the engine picks the model before it renders templates, so export() refuses a {{ … }} or an expression. A model the catalog does not list for agents (agent.models in ai models --json) runs the default model with no error.

Where Xano AI runs

location is "", us, global or eu. A statement’s or agent’s own location wins. Left blank, it inherits the workspace’s location; blank there too, the model runs at its default. An explicit "global" opts one call out of a workspace set to "eu". Set the workspace default in code:
Only those four lowercase values are accepted; the engine would store anything else as "". A deploy that leaves out the xano-ai block keeps the location set in the dashboard, and an empty block or location: "" clears it. A block without model clears a model set in the dashboard; the live diff shows that before you deploy. A merge with deploy --to writes no workspace settings.

Xano AI on the Xano Engine

Each deploy --local, and each engine start or restart, hands the engine a Xano AI credential from your npx @xano/sdk login sign-in. It lasts as long as the engine runs, a day at most, and the next deploy renews it. Usage is billed to you. To bill the instance owner instead (you must be the owner or a billing member), pass --ai-billing instance or set "aiBilling": "instance" under "xanosdk"."@xano/sdk" in package.json; the flag wins. The deploy prints one Xano AI: line saying it is on and who pays, or why it is off and how to fix it. It never fails the deploy, and --json carries an ai object. If it reports a sign-in without Xano AI access, run npx @xano/sdk login again: a sign-in from before 1.0.20 cannot spend AI credits. A pasted meta API token cannot either.
The Xano Engine uses the credential only from an engine release that reads it. Until that release ships, the deploy hands the credential over and the engine ignores it. An engine started by an earlier SDK needs npx @xano/sdk local stop <name>, then a deploy.

An MCP server

An MCP server exposes tools, prompts and resources to any MCP client, such as Claude, ChatGPT or another agent. Prompts and resources are their own kinds: define them, then list them on the server.

A prompt

A prompt is a reusable message a client can ask for. Its input is the prompt’s arguments; an enum’s values also answer the client’s completion requests:
To send several messages, respond with a list of { role: "user" | "assistant", content }.

Resources

A resource is data a client reads by uri. A literal uri is a static resource. A uri with a {variable} is a template: each variable is one input field, and a client reads a concrete URI such as blog://posts/42.

The server, with sign-in

List the tools, prompts and resources on the server. Add oauth to make every MCP request carry a signed-in user from your auth table:
  • Entries. tools, prompts and resources each take handles, or a { tool | prompt | resource, enabled?, auth? } wrapper. auth names the auth table and is what gives that entry’s stack a caller for auth(). A bare handle is public.
  • blogMcp.getUrl(HOST) returns the Streamable HTTP URL a client connects to. A frontend gets the same address from mcpUrl("blog_mcp", XANO_HOST) in xano/routes.gen.ts (see Typed frontend).
  • Gate every entry that needs one. The endpoint is open to browsers too: it answers every Origin, preflight included, with access-control-allow-origin: *. Per-entry auth and the server’s oauth are the only gates.
  • Names. An mcpServer and an agent with the same name collide, because both are stored as toolsets.

Hosted sign-in

With mode: "hosted", Xano is the authorization server. A client that connects is sent to your loginUrl with an mcp_request parameter. That page is also the consent screen: it shows who is asking, signs the user in, then calls an endpoint that completes the sign-in and redirects the browser to the URL it returns. Two endpoints back the page:
Declare MCP_LOGIN_URL in workspaceConfig({ env: { MCP_LOGIN_URL: "" } }) and set its value per environment in xano/.env (see Env and secrets). s.mcp.oauth.revoke ends a user’s sign-ins on a server.

Your own identity provider

To accept tokens from Auth0, Clerk, WorkOS, Entra, Okta or Cognito instead, use mode: "external". The token’s claim (default sub) is matched against a column in your auth table, here an auth0_id text column on users that holds each user’s provider id:

Control each connection: MCP server triggers

An mcpServerTrigger runs when an MCP client connects to the server it is bound to, and its response decides what that one connection lists. t carries the server’s toolset, tools, prompts and resources. Return a list filtered to narrow it; a key you leave out lists everything the server has. This one hides the resources from every connection:
  • t.auth is the signed-in user when the server has oauth: { dbo, id, extras } of the auth-table row, read as t.auth("id"). It is null on a server without sign-in, so check it before reading a field.
  • An entry you return can change its description. A returned prompt or resource’s description replaces the listed one for that connection.
  • Omit response and the connection lists all four unchanged.

Knowledge

A knowledge() item is markdown shared by every AI that builds your backend. Xano’s own AI reads it before it acts: the workspace’s builder agent, and outside agents that read the workspace through the Meta API or MCP. Your coding agent reads the same .md files in the repo, and the AGENTS.md that init writes tells it to. A deploy and a pull keep the two copies in sync. It does not reach an agent() you run with s.ai.agent.run. Put what that agent must know in its llm.systemPrompt.
mode: "always" sends the whole body on every request, and a type: "agents.md" item is always sent in full. Write the description of an auto item to match the requests it should answer.

Register them

Next