Skip to content
Documentation
On this page

Accounts and providers

Declare providers, user and app account requirements, credential placements, account health checks, and setup help in an Executor app.

An Executor app requests credentials with defineProvider and lists requirements under user.accounts or app.accounts in defineApp. Providers declare secrets or oauth2 methods, allowed hosts, outbound request placements, a health check, and Markdown setup help (guide, clientGuide, field description). This works on Local, Self-host, and Cloud.

The step that matters most: declare hosts and request on every provider so Executor keeps secret fields as sealed handles injected only on requests to those hosts.

Prerequisites and permissions: a deployable app (Build an app). Any user with app access links their own user accounts on the Accounts tab; linking app accounts requires the Local owner, or the app creator, admin, or owner on Cloud and Self-host.

You’ll know it worked when… connecting an account on the Accounts tab passes your health check and a tool call reaches the upstream API.

How to use it

The provider code is identical across Local, Self-host, and Cloud. Linking differs only in who links shared accounts: on Local, you link every slot yourself; on Cloud and Self-host, each member links their own user.accounts while an app manager links app.accounts for everyone who uses the app.

1. Define a provider with hosts and request

Call defineProvider({ name, hosts, auth, health }):

  • auth maps method names to secrets({ label, guide?, fields, request? }) or oauth2({ ..., clientGuide?, request? }).
  • hosts lists the exact hostnames (such as ["api.linear.app"]) that may receive this provider’s credentials. When hosts is declared, unmarked string fields reach app code as sealed SecretString handles that the host replaces only on outbound requests to those hosts.
  • request restricts where each secret field may be sent using bearer(token), basic(user, pass), header(name, value), query(name, value), base64(value), and the t template helper. Call account.request.headers() or account.request.url(baseUrl) inside your tools to build matching requests.
  • Wrap non-secret configuration fields (such as a base URL or workspace subdomain) with plain(string()). Wrap a secret that app code must inspect directly (such as an HMAC signing key) with raw(string()).

2. Declare user vs app requirements

Pass requirements as the first argument to defineApp:

  • user: { accounts: { github } } — each caller links their own account, read at ctx.user.accounts.github.
  • app: { accounts: { service } } — an app manager links one shared account for the whole app, read at ctx.app.accounts.service. App-scoped schedules and webhooks can use only app.accounts because they run without a caller.
  • provider.many() — lets a caller link zero or more accounts of the same provider (for example multiple workspaces). Pair provider.many() with accountRouter(ctx.user?.accounts.linear ?? [], (account) => ...) inside a factory defineApp(requirements, async (ctx) => ...) to mount one sub-router per linked account.

3. Add a health check

Add a health: async ({ account, fetch, signal, deadline }) => { ... } function to defineProvider. Make one safe authenticated read (never a write) that proves the account works. Returning resolves as healthy; throwing ProviderError (or a non-2xx HTTP failure handled by decodeJson) tells the connect form why credentials were rejected without exposing secrets. For MCP servers, use mcpHealth from apps/mcp.

4. Write setup help

Setup help belongs to your app version, not the provider’s identity, so editing text never breaks existing account links:

  • Put per-field instructions in each field’s options (string({ title: "...", description: "..." })), where description is Markdown.
  • Add guide on a secrets method for ordered setup steps, prerequisites, or warnings shown above the form.
  • Add clientGuide on an oauth2 method to explain where to create an OAuth client and which scopes or settings to pick; Executor displays its own redirect URL above your clientGuide.

Example

import {
  bearer,
  decodeJson,
  defineApp,
  defineProvider,
  object,
  plain,
  ProviderError,
  query,
  router,
  secrets,
  string,
} from "apps";

const linear = defineProvider({
  name: "Linear",
  hosts: ["api.linear.app"],
  auth: {
    apiKey: secrets({
      label: "Personal API key",
      guide: `
        1. Open [Linear Security & access](https://linear.app/settings/account/security).
        2. Create a personal API key and paste it below.
      `,
      fields: object({
        apiKey: string({ description: "Personal API key starting with `lin_api_`." }),
        teamKey: plain(
          string({ description: "Optional default team key, such as `ENG`." }),
        ).optional(),
      }),
      request: ({ apiKey }) => [bearer(apiKey)],
    }),
  },
  health: async ({ account, fetch, signal }) => {
    const res = await fetch("https://api.linear.app/graphql", {
      method: "POST",
      headers: {
        ...account.request.headers(),
        "Content-Type": "application/json",
      },
      body: JSON.stringify({ query: "{ viewer { id } }" }),
      signal,
    });
    if (res.status === 401 || res.status === 403) {
      throw new ProviderError({
        reason: res.status === 401 ? "unauthorized" : "rejected",
        status: res.status,
      });
    }
    if (!res.ok) {
      throw new ProviderError({ reason: "unavailable", status: res.status });
    }
  },
});

const requirements = { user: { accounts: { linear } } };

const viewer = query(
  {
    description: "Return the signed-in Linear viewer",
    input: object({}),
    output: object({ id: string(), name: string() }),
  },
  async ({ fetch, signal, user }) => {
    const res = await fetch("https://api.linear.app/graphql", {
      method: "POST",
      headers: {
        ...user.accounts.linear.request.headers(),
        "Content-Type": "application/json",
      },
      body: JSON.stringify({ query: "{ viewer { id name } }" }),
      signal,
    });
    const body = await decodeJson(
      res,
      object({ data: object({ viewer: object({ id: string(), name: string() }) }) }),
    );
    return body.data.viewer;
  },
);

export default defineApp(requirements, { tools: router({ viewer }) });

Limits

  • Setup help limits: guide and clientGuide allow at most 4,000 characters, and each field description allows at most 1,000 characters. Links must be absolute https: URLs; HTML tags and Markdown images are rejected. Common leading indentation is stripped automatically.
  • Sealed handle scanning: outbound request bodies over 1 MiB and streamed bodies are not scanned for sealed handles; place credentials in headers or query parameters via request instead.
  • OAuth protocol parameters: authorizationParams and authorizationUrl query strings cannot set host-owned protocol parameters (response_type, client_id, redirect_uri, state, scope, code_challenge, code_challenge_method, nonce, resource, request, request_uri). Setting pkce: false requires a confidential tokenEndpointAuthMethod (client_secret_post, client_secret_basic, or client_secret_basic_raw).
  • Health check deadline: Executor passes a deadline timestamp on AccountCheckContext; a check that is still running when deadline passes fails without its own message. Pass signal to every fetch call.
  • Account isolation: managing an app on Cloud or Self-host does not grant access to another member’s linked user.accounts. App-scoped app.accounts are shared by everyone who can use the app.

Was this page helpful?