Tools, routers, and schemas
Declare queries, mutations, nested routers, dynamic routers, schemas, app icons, and caching in an Executor app.
An Executor app publishes tools by placing query and mutation operations inside its tools router in index.ts. Operations declare typed input and output schemas (object, string, number, boolean, array, record, literal, json, jsonSchema), nest under router or dynamicRouter, and can declare icons and use ctx.cache. These APIs work on Local, Self-host, and Cloud.
The step that matters most: mount tools under tools: router({ ... }) in defineApp, using query for reads and mutation for writes.
Prerequisites and permissions: an app from Build an app and edit/deploy permission (Local owner, or app creator, admin, or owner on Cloud and Self-host).
You’ll know it worked when… after executor apps deploy, the tool paths appear on the Tools tab and in tools.search, and running a query returns validated output.
How to use it
The authoring API is the same across Local, Self-host, and Cloud; deploy using your target’s workflow in Build an app.
Queries and mutations
query(options, run)declares a read operation. It receives a read-only SQL handle (ctx.sqlrolls back any statement that changes rows),ctx.fetch,ctx.cache,ctx.signal, and any declared accounts. A query can still call external APIs.mutation(options, run)declares a write operation. It receives a writable SQL handle (ctx.sql.execandctx.sql.transaction),ctx.fetch,ctx.cache,ctx.signal,ctx.elicit, and any declared accounts.
Both accept { title?, description?, annotations?, input, output?, approval? } and an async (ctx, input) => result handler. Use decodeJson(response, schema) to decode HTTP JSON responses with safe status and parse errors (ResponseStatusError and ResponseDecodeError).
Schemas
Use the schema builders exported from apps:
- Primitives and containers:
string(options?),number(options?),boolean(options?),literal("open"),array(schema),object({ ... }),record(schema),json(), andjsonSchema(rawJsonSchema). - Pass
{ title, description }tostring(),number(), orboolean()(andminLengthtostring()), and chain.optional()or.default(value)on any schema. - Always declare
input(useobject({})when a tool takes no arguments). Declareoutputwhenever the result shape is known so the host validates responses and exposes output types to agents.
Routers and dynamic routers
Mount operations and sub-routers with router(children, options?):
- Nested keys become dotted tool paths:
router({ issues: router({ list, close }) })publishesissues.listandissues.close. - Router options are
title,description,instructions,icons, andtags(a map of tag name to description). Agents see each router’stitleanddescriptionbeside its tools, andinstructionsbecomes a skill (see Ship skills with an app). - Use
router(existingRouter, options)to override metadata on an imported router, andrenameTools(source, fn)to rename tools from an imported router. - Use
dynamicRouter({ list, resolve, summaries?, describe?, meta? })when tools are discovered at runtime from an external service or connected account.
Icons and cache
- Declare
iconson the app definition (defineApp(requirements, { icons: [...], tools })) or on a router (router(children, { icons: [...] })). Each icon is{ src, mimeType?, sizes?, theme?: "light" | "dark" }. - Use
ctx.cache(get,revalidate,read,readMany,write,invalidate,forAccount) to cache expensive reads or upstream schemas across invocations. Callctx.cache.forAccount(account)so cached entries isolate per account and reset when the account is reconnected.
Example
import {
array,
decodeJson,
defineApp,
literal,
number,
object,
query,
router,
string,
} from "apps";
const issueSchema = object({
number: number(),
title: string(),
state: literal("open").optional(),
});
const listIssues = query(
{
description: "List open issues for a public GitHub repository",
input: object({
owner: string({ description: "Repository owner" }),
repo: string({ description: "Repository name" }),
}),
output: object({ issues: array(issueSchema) }),
},
async ({ cache }, { owner, repo }) => {
const issues = await cache.get({
key: ["github-issues", owner, repo],
schema: array(issueSchema),
freshFor: "5 minutes",
staleFor: "1 hour",
load: async ({ fetch, signal }) => {
const res = await fetch(
`https://api.github.com/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/issues?state=open&per_page=10`,
{
headers: {
Accept: "application/vnd.github+json",
"User-Agent": "executor-app",
},
signal,
},
);
return decodeJson(res, array(issueSchema));
},
});
return { issues };
},
);
export default defineApp(
{},
{
icons: [
{
src: "https://github.githubassets.com/favicons/favicon.svg",
mimeType: "image/svg+xml",
theme: "light",
},
],
tools: router({
issues: router(
{ list: listIssues },
{
title: "GitHub issues",
description: "Inspect issues in a public repository.",
},
),
}),
},
);
Limits
- Router keys: each key must match
/^[A-Za-z_][A-Za-z0-9_-]{0,99}$/(1 to 100 characters, no dots).__proto__,constructor, andprototypeare reserved. Mount each mutation at one path only. - No automatic approval inference: marking an operation as
queryor settingannotations: { readOnlyHint: true }does not configure approval behavior; annotations are advisory metadata only. Configure approvals explicitly as described in Input prompts and tool approvals. - App icons: an app can declare at most 8 icons totaling at most 32 KiB of JSON. Each
srcmust be anhttps:URL or a base64data:image/svg+xml,image/png,image/webp, orimage/jpegURI. - Cache bounds: the app’s cache holds at most 100,000 entries and 128,000,000 bytes in total, and each cache entry holds up to 2 MB.
- Per-statement SQL commits: unlike queries (whose SQL transaction always rolls back), mutation statements outside
ctx.sql.transaction(...)commit individually rather than rolling back as one automatic transaction; see App storage and SQLite.