Skip to content
Documentation
On this page

Input prompts and tool approvals

Ask a person for input mid-tool with ctx.elicit and declare per-tool approval rules with always, never, Approval, withApproval, and withApprovals.

A tool can pause for a human in two ways: declare an approval rule (always(), never(), or a custom Approval<Input> function) to gate execution, or call ctx.elicit mid-tool to collect form input. Both work on Local, Self-host, and Cloud.

The step that matters most: declare approval on each query or mutation (or wrap an imported router with withApprovals), because there is no app-wide approval setting and nothing is inferred from query or readOnlyHint.

Prerequisites and permissions: an app you can edit and deploy (Local owner, or app creator, admin, or owner on Cloud and Self-host; see Build an app).

You’ll know it worked when… running the tool from the Tools tab or MCP pauses for review or form input, continues after approval, and stops when declined.

How to use it

Approval declarations and ctx.elicit code are identical across Local, Self-host, and Cloud. Where a person answers depends on how the tool was started: in the dashboard Tools tab, on the Approvals page for scheduled runs, or through the MCP connection’s elicitation mode (model, native, or browser).

1. Declare approval rules on queries and mutations

Import always and never from apps/operations/approval and set approval on an operation:

  • approval: always() asks a person before every call.
  • approval: never() runs without asking (organization, app, and account access checks still apply).
  • A custom Approval<Input> function async ({ toolName, toolInput, signal }) => ... inspects the decoded input and returns "approved", "denied", or "user-approval".

2. Reuse rules or wrap imported routers

  • Share a typed Approval<Input> function across operations, or attach a rule to an existing operation with withApproval(operation, rule).
  • Attach rules to imported MCP, OpenAPI, or GraphQL routers with withApprovals(router, picker). The picker receives each tool description (tool.kind, tool.name, and toolAnnotations(tool)) and returns an Approval or undefined.

3. Ask for input mid-tool with ctx.elicit

Call ctx.elicit({ mode: "form", message, requestedSchema }) inside a tool handler to collect missing values or confirmation details mid-call:

  • requestedSchema is a flat JSON Schema object (type: "object") with string (including enum, oneOf, and format: "email" | "uri" | "date"), number, integer, or boolean properties.
  • Check response.action: "accept" carries validated values in response.content; "decline" and "cancel" mean the user did not submit.
  • Catch ElicitationFailed (exported from apps) when the host cannot deliver a prompt (for example in a background context).

Example

import {
  defineApp,
  ElicitationFailed,
  mutation,
  number,
  object,
  router,
  string,
  type Approval,
} from "apps";
import { always } from "apps/operations/approval";

const refundApproval: Approval<{ amountCents: number }> = async ({ toolInput }) =>
  toolInput.amountCents > 10_000 ? "user-approval" : "approved";

const issueRefund = mutation(
  {
    description: "Issue a customer refund",
    input: object({
      orderId: string(),
      amountCents: number(),
    }),
    output: object({ status: string(), reason: string().optional() }),
    approval: refundApproval,
  },
  async ({ elicit }, { orderId, amountCents }) => {
    try {
      const reply = await elicit({
        mode: "form",
        message: `Enter a refund reason for order ${orderId} ($${(amountCents / 100).toFixed(2)}).`,
        requestedSchema: {
          type: "object",
          properties: {
            reason: {
              type: "string",
              title: "Reason",
              enum: ["damaged", "duplicate", "customer_request"],
            },
          },
          required: ["reason"],
        },
      });
      if (reply.action !== "accept") {
        return { status: "cancelled" };
      }
      return { status: "refunded", reason: String(reply.content?.reason ?? "") };
    } catch (error) {
      if (error instanceof ElicitationFailed) {
        return { status: `elicit_failed:${error.reason}` };
      }
      throw error;
    }
  },
);

const deleteArchive = mutation(
  {
    description: "Permanently delete archived records",
    input: object({ archiveId: string() }),
    output: object({ deleted: string() }),
    approval: always(),
  },
  async (_ctx, { archiveId }) => ({ deleted: archiveId }),
);

export default defineApp({}, { tools: router({ issueRefund, deleteArchive }) });

Limits

  • 15-minute timeout: pending tool approvals and ctx.elicit form prompts expire after 15 minutes.
  • Where ctx.elicit cannot run: ctx.elicit rejects with ElicitationFailed inside a SQLite transaction (reason: "transaction"), and in non-interactive runs such as schedules, webhooks, and workflows (reason: "unavailable").
  • App-scoped schedules cannot ask: mutations referenced by appCron or appInterval cannot declare an approval rule; only per-user schedules (userCron, userInterval) can pause for approval on the Approvals page.
  • No editing arguments in approval prompts: approval prompts show the saved call arguments (truncated to 4,000 characters in saved prompts when very large) for review only; the reviewer approves or declines the exact call rather than modifying arguments.
  • Declining does not roll back earlier calls: declining or cancelling stops only the paused tool call; earlier external effects in the same program are not undone.
  • Scope of approvals: the app’s factory setup code runs with its bound credentials before tool approvals are evaluated. Approval governs the selected tool call, not trust in the app’s code. Skill allowed-tools metadata never grants or bypasses approval.
  • App web UI calls: calling a tool that asks for approval from an app’s own web UI currently fails instead of opening an approval prompt.

Was this page helpful?