Skip to content
Documentation
On this page

Provider accounts · Check an account

Provider accounts · Check an account from the built-in skills in Executor 2.0.0-beta.79.

This page covers Check an account from the built-in skills shipped with Executor 2.0.0-beta.79. It contains app-authoring/accounts.md.

Previous: Provider accounts · Next: Provider accounts · OAuth sign-in

Check an account

Give a provider a health function so Executor can tell whether a saved account works before an agent’s tool call fails. Make one safe authenticated read with no side effects, such as the service’s current-user endpoint. Returning passes. Returning accountInfo also names the upstream account; Executor offers it as the account’s name and shows it beside the account. Every field is optional: externalId, displayName, username, email, avatarUrl and profileUrl.

import { ProviderError, decodeJson, defineProvider, object, secrets, string } from "apps";

const User = object({ id: string(), username: string(), name: string(), email: string() });

const vercel = defineProvider({
  name: "Vercel",
  auth: {
    apiKey: secrets({
      label: "API token",
      fields: object({ token: string({ minLength: 1 }) }),
    }),
  },
  async health({ account, fetch, signal }) {
    const response = await fetch("https://api.vercel.com/v2/user", {
      signal,
      headers: { Authorization: `Bearer ${account.fields.token}` },
    });
    // Vercel answers an unknown or revoked token with 403 and `invalidToken: true`.
    if (response.status === 403 && (await response.json()).error?.invalidToken === true)
      throw new ProviderError({ reason: "unauthorized", status: 403 });
    const { user } = await decodeJson(response, object({ user: User }));
    return {
      accountInfo: {
        externalId: user.id,
        displayName: user.name,
        username: user.username,
        email: user.email,
      },
    };
  },
});

account is typed from auth; with several methods, switch on account.method. A failed decodeJson status is classified for you: 401 means the credentials were refused, 429 and 5xx mean the service is unavailable. Otherwise throw new ProviderError({ reason, status }) with the reason the service’s evidence supports:

reason Use it when Check status
unauthorized the service refused the credentials credentials_rejected
forbidden explicit evidence of a missing permission (insufficient_scope) forbidden
rate_limited the service is limiting requests upstream_unavailable
unavailable a server error or outage upstream_unavailable
rejected the service refused without saying why, such as a bare 403 check_failed

A bare 403 is not enough for forbidden. Services that answer a bad token with something other than 401, as Vercel does, need an explicit unauthorized. Tool calls that fail with rate_limited or unavailable tell the agent to retry later. ProviderError carries only its reason and optional HTTP status, never a message.

Decode only the fields the check reads; object() drops the rest. A field the service may return as null fails both string() and string().optional(), which accepts only a missing field. There is no nullable helper, so declare it with json() and use it only when it is a string. Each accountInfo value must be a non-empty string of at most 255 characters, and its URLs must be http(s); an invalid value fails the check, so leave such fields out:

const { user } = await decodeJson(
  response,
  object({ user: object({ id: string(), name: json() }) }),
);
const name = typeof user.name === "string" && user.name !== "" ? user.name : undefined;
return {
  accountInfo: { externalId: user.id, ...(name === undefined ? {} : { displayName: name }) },
};

To tell the user why the check failed, throw an ordinary Error with a message written for them. The account form shows it after “Couldn’t verify this API token:”. Read the service’s documented error fields to choose the message; do not copy a response body, URL or credential into it. Executor replaces the checked credentials if they appear, and shortens long messages.

if (response.status === 403 && (await response.json()).error?.code === "missing_scope")
  throw new Error("This token lacks the accounts scope. Create a token with accounts:read.");

Any error or a timeout means the check could not verify the account. Executor never treats that as bad credentials. The check also receives deadline, the time in epoch milliseconds when Executor stops waiting for it. A check still running then fails without a message, so a check that waits on its own timer should end before it to say why.

Account forms run the same check on entered credentials before saving them, so the user sees whether they work, and the name they belong to, before connecting.

For an MCP server, use mcpHealth from apps/mcp instead of a REST or GraphQL read: health: (check) => mcpHealth(check, { url, headers: headers(check.account) }). It takes the account, signal and deadline from the check context; see integrations.md. It verifies an account only on a server that refuses requests without credentials. On a server that answers anyone, it reports that it could not verify the account.

Each app checks with its own health function, so two apps can verify the same account differently. Adding or editing health does not change the provider’s identity or disconnect accounts; it only makes earlier results outdated.

Tell users where to get credentials

The connect form shows what you write about each field and method. Give every field a description first: where to get the value, with a link to the page that shows or creates it, and what it looks like. The form shows it under the input, so the link sits beside the field it is for. title replaces the field’s name as its label. Give a secrets method a guide only for what no single field owns: prerequisites, setup that spans fields, or warnings. It replaces the form’s generic “Get these credentials from your Jira account settings.” line:

const jira = defineProvider({
  name: "Jira",
  hosts: ["*.atlassian.net"],
  auth: {
    token: secrets({
      label: "API token",
      guide: `
        Sign in as the Jira user the app acts as before you create the token.
        Atlassian shows a new token once, so copy it before you close the page.
      `,
      fields: object({
        email: plain(string({ description: "The address you sign in to Jira with." })),
        token: string({
          title: "API token",
          description:
            "Create one under [API tokens](https://id.atlassian.com/manage-profile/security/api-tokens). Starts with `ATATT`.",
        }),
      }),
      request: ({ email, token }) =>
        header("authorization", t`Basic ${base64(t`${email}:${token}`)}`),
    }),
  },
});

number() and boolean() take the same title and description. For OAuth, clientGuide explains where to create an OAuth client at the service. The form shows it when someone enters a client: after Executor’s own line and the redirect URL to copy, before Client ID:

oauth2({
  authorizationUrl: "https://auth.example.com/authorize",
  tokenUrl: "https://auth.example.com/token",
  scopes: ["reports:read"],
  clientGuide:
    "Create an app under [Developer settings](https://example.com/settings/apps) and choose **Web application**.",
});

Help text is Markdown; only title is plain text. Write code blocks with ~~~ fences, so a template literal needs no escaped backticks. Executor removes the indentation every line shares, so an indented template literal is fine. A deploy fails with VersionBuildFailed at the declaration stage, naming the requirement, provider, method and field, when a link is not an absolute https: URL, the text has raw HTML or an image, a guide or clientGuide is over 4,000 characters, or a description is over 1,000. A bare www.example.com counts as an http: link, so write https://.

Setup help belongs to your app’s version, not to the provider: editing it never changes the provider ID or disconnects accounts, and another app may explain the same provider differently. Agents read it in the app’s requirements (apps.get), so explain setup in chat from it before sending a connection link.

Was this page helpful?