Skip to content
Documentation
On this page

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.sql rolls 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.exec and ctx.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(), and jsonSchema(rawJsonSchema).
  • Pass { title, description } to string(), number(), or boolean() (and minLength to string()), and chain .optional() or .default(value) on any schema.
  • Always declare input (use object({}) when a tool takes no arguments). Declare output whenever 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 }) }) publishes issues.list and issues.close.
  • Router options are title, description, instructions, icons, and tags (a map of tag name to description). Agents see each router’s title and description beside its tools, and instructions becomes a skill (see Ship skills with an app).
  • Use router(existingRouter, options) to override metadata on an imported router, and renameTools(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 icons on 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. Call ctx.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, and prototype are reserved. Mount each mutation at one path only.
  • No automatic approval inference: marking an operation as query or setting annotations: { 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 src must be an https: URL or a base64 data:image/svg+xml, image/png, image/webp, or image/jpeg URI.
  • 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.

Was this page helpful?