On this page

#Private tools

#What a tool sees

PlaceholderValue
$auth.subjectThe token's sub
$auth.tokenThe raw JWT, to forward to your API
$auth.claims.<name>Any custom claim

The set_tool arguments for a private tool:

{
"workspace": "acme",
"name": "my_bookings",
"description": "The visitor's upcoming bookings.",
"when_to_use": "When they ask about their own bookings.",
"access": "private",
"request": {
"method": "GET",
"base_url": "$env.API_URL",
"path": "/api/bookings",
"headers": { "Authorization": "Bearer $auth.token" }
},
"respond": {
"data": { "bookings": "bookings" }
}
}

Your endpoint verifies the same JWT with the same public key, and scopes the query to its sub.

#Verifying on your endpoint

Vatio verifies the token before it unlocks a private tool, but that does not protect your API: the endpoint is on the internet, and anyone can call it with a made-up header. Verify the forwarded token on every request and check:

  • Signature, with the public half of the key you sign with, and the algorithm pinned (ES256 or RS256), never read from the token's header.
  • aud is your workspace slug, so a token signed for another workspace is refused.
  • exp has not passed.

Then take the user from sub, and from nothing the request body says. A token that fails any check is a 401.

In Rails, vatio-sdk does all of it:

class Api::BookingsController < ApplicationController
include Vatio::Identity::Authentication
before_action :authenticate_vatio! # 401 unless the token verifies
def index
render json: Booking.where(user_id: vatio_subject)
end
end

If your app serves several workspaces, each with its own key, build a Vatio::Identity::Config per workspace and return it from vatio_identity_config in the controller; see Several workspaces.

Anywhere else, any JWT library will do. In Node, with jose, for the RSA key made in Set it up (pin ES256 instead if you sign with an EC key):

import { importSPKI, jwtVerify } from "jose";
const key = await importSPKI(process.env.VATIO_IDENTITY_PUBLIC_KEY, "RS256");
app.get("/api/bookings", async (req, res) => {
const token = req.headers.authorization?.replace(/^Bearer /i, "");
try {
const { payload } = await jwtVerify(token, key, {
audience: "acme", // your workspace slug
algorithms: ["RS256"]
});
res.json(await bookingsFor(payload.sub));
} catch {
res.status(401).json({ error: "unauthorized" });
}
});

Nothing to verify when no token is sent: public tools carry no $auth. On WhatsApp and Instagram a private tool sends the token the contact signed in with (On WhatsApp and Instagram).

#Rules

Never take the user's id as a parameter. The model fills parameters, and it can be talked into filling that one with someone else's id. A private tool declaring user_id, customer_id, account_id, member_id, patient_id or subject is refused when it is set with set_tool:

tool my_bookings: a private tool cannot take "user_id" as a parameter — the model
fills parameters and can be talked into filling that one with someone else's id.
Use $auth.subject, which comes from the verified token

Derive the user from the token instead. An endpoint that accepts an id has to remember to scope it every time, forever; one that reads the token cannot forget.

Other errors you may hit:

ErrorFix
access: private needs an auth: blockGive Vatio your public key with set_auth (Set it up)
auth.public_key ... is a PRIVATE keyPass the public half (openssl pkey -in vatio-private.pem -pubout), never the private key
auth.algorithm must be one of RS256...Sign with RS256/ES256, not HS256 — a shared secret cannot live on Vatio
access must be "public", "private", "supervisor", "developer" or "owner"Scheme names are gone; use private for signed-in users, or a team role (Access)

A rejected token — wrong key, expired, wrong aud — leaves the visitor anonymous rather than erroring, and the agent falls back to its public tools. chat_with_agent with that token as visitor_token shows the reason.

#Test a private tool

Without a token, the MCP's chat_with_agent, add_test and run_tests talk as a visitor who is not signed in: the agent has only its public tools, and a test replay that calls a private tool is marked not tested (a tool needs a signed-in visitor). Pass visitor_token to talk as a signed-in test user: a JWT signed with the private key whose public half set_auth holds, with the test user's id as sub, the workspace slug as aud and a short exp, the way your backend signs one (Authentication). For example, with the key in vatio-private.pem and jose:

Terminal window
node -e 'import("jose").then(async ({ importPKCS8, SignJWT }) => {
const key = await importPKCS8(require("fs").readFileSync("vatio-private.pem", "utf8"), "RS256");
console.log(await new SignJWT({}).setProtectedHeader({ alg: "RS256" })
.setSubject("test-user-1").setAudience("acme").setIssuedAt().setExpirationTime("15m").sign(key));
})'
  • chat_with_agent and add_test with a question take it for a new conversation: the agent talks to that user, and access: private tools run as them.
  • run_tests with it replays every test signed in as that user.

Use a test user's id, never a real person's. A token that does not verify is refused with the reason before anything runs. You can also try a private tool in your app, signed in as a test user, with the widget or the SDK given that user's token (Sessions and channels).

The chat_with_agent arguments for a new conversation as that test user:

{ "workspace": "acme", "message": "What bookings do I have?", "visitor_token": "eyJhbGciOiJSUzI1NiJ9..." }

#Let someone check a case without signing in

WhatsApp and Instagram contacts are anonymous until they sign in (see On WhatsApp and Instagram), and only public tools run. To let someone check an order without signing in, use a public tool that takes the order number plus a second detail, such as the email on the order, and have your backend verify that the two match. Or send a link to the signed-in page.

#Frequently asked questions

#Can the agent read a signed-in user's own data?

Yes, on your website or app, and on WhatsApp and Instagram once they sign in. Mark the tool access: private, give Vatio your public key with set_auth, and have your backend sign an RS256 JWT for the visitor with the private key. Vatio verifies it with your public key and forwards it to the tool, and your endpoint scopes the query to the token's sub. Vatio never holds the private key, so it can check who someone is but never claim it.

#Why can't a private tool take a user_id parameter?

The model fills parameters, and it can be talked into filling that one with someone else's id. See Rules.

#Do private tools work on WhatsApp and Instagram?

Yes, once the contact signs in. With a sign_in_url (set_auth), Vatio sends a Sign in button that opens your site, your page redirects back with the same token you put on the widget, and the conversation carries on. Until then only public tools run.

Last updated:

Latest release: 0.144.0 · Changelog · The whole contract as Markdown: /docs/docs.md