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.
Declare a host allowlist and explicit request placements. Compatible app builds receive opaque handles for eligible secret strings when the resolved provider has an allowlist.
Prerequisites and permissions: a deployable app (Build an app). On Cloud and Self-host, members with app use access can maintain their own links under the connection policy. Linking an account for everyone requires app management.
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 the same across Local, Self-host, and Cloud.
1. Define a provider with hosts and request
Call defineProvider({ name, hosts, auth, health }):
authmaps method names tosecrets({ label, guide?, fields, request? })oroauth2({ ..., clientGuide?, request? }).hostsdeclares the host allowlist (exact hostnames, optional explicit ports, or single-level wildcards such as["api.linear.app"]). In compatible app builds, when the resolved provider has a host allowlist, eligible secret strings reach app code as opaqueexsec_orexsec2_handles. The fetch proxy substitutes a recognized handle only after checking the issuing app, the effective allowed destination, and the handle’s one-hour expiry. The saved account grant can narrow allowed hosts or keep them when a redeploy omits the declaration. Adding a host can require reconnecting the existing account.requestconstrains where the proxy inserts a placed secret usingbearer(token),basic(user, pass),header(name, value),query(name, value),base64(value), and thettemplate helper. Callaccount.headers()oraccount.url(baseUrl)inside your tools to render the declared placements. Placed handles require HTTPS (except permitted loopback HTTP), and the proxy handles credential-bearing redirects manually.- Non-string primitives and fields marked
plain(string())(non-secret config such as a base URL or workspace subdomain) orraw(string())(a secret app code must inspect directly, such as an HMAC signing key) reach app code as readable values. Older protocols can also receive ordinary fields directly. Instance-managed OAuth uses separate sealing and supplies its own configured header and host limits.
2. Declare user vs app requirements
Pass requirements as the first argument to defineApp:
user: { accounts: { github } }— each caller links their own account, read atctx.user.accounts.github.app: { accounts: { service } }— an app manager links one shared account for the whole app, read atctx.app.accounts.service. App-scoped schedules and app-account webhooks run without a user and useapp.accounts.provider.many()— lets a caller link zero or more accounts of the same provider (for example multiple workspaces). In an asyncdefineAppfactory, combine them withtools: await accountRouter(ctx.user?.accounts.linear ?? [], discover, { signal: ctx.signal }), wherediscover(account)returns that account’s router. Same-name tools are merged and accept{ accountId, input }. No linked accounts means no tools.
3. Add a health check
Add health: async ({ account, fetch, signal, deadline }) => { ... } to defineProvider. Make one safe authenticated read (never a write) that proves the account works. Returning marks the check healthy; throwing ProviderError or a status failure from decodeJson helps the connect form distinguish rejected credentials, insufficient access, and upstream failures. Keep secrets out of authored error messages. For MCP servers, use mcpHealth from apps/mcp.
4. Write setup help
Add setup help alongside the provider’s account fields and authorization methods.
- Put per-field instructions in top-level field options (
string({ title: "...", description: "..." })), wheredescriptionis Markdown. - Add
guideon asecretsmethod for ordered setup steps, prerequisites, or warnings shown above the form. - Add
clientGuideon anoauth2method for manual OAuth client entry. In browser redirect flows, Executor displays Redirect URL above yourclientGuide(client-credentials flows showclientGuidewithout a redirect URL).
Example
Save this as index.ts beside the pinned package.json from Build an app, deploy the app, and connect a Linear personal API key that has access to the viewer query. Linear’s GraphQL API expects Authorization: <API_KEY> (without a Bearer prefix) for personal API keys.
import {
decodeJson,
defineApp,
defineProvider,
header,
object,
plain,
ProviderError,
query,
router,
secrets,
string,
type QueryContext,
} 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 }) => [header("Authorization", apiKey)],
}),
},
health: async ({ account, fetch, signal }) => {
const res = await fetch("https://api.linear.app/graphql", {
method: "POST",
headers: {
...account.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 });
}
await decodeJson(res, object({ data: object({ viewer: object({ id: string() }) }) }));
},
});
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 }: QueryContext<typeof requirements>) => {
const res = await fetch("https://api.linear.app/graphql", {
method: "POST",
headers: {
...user.accounts.linear.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:
guideandclientGuideallow at most 4,000 characters, and each visible top-level account-fielddescriptionallows at most 1,000 characters. Links must be absolutehttps:URLs; HTML tags and Markdown images are rejected. Common leading indentation is stripped automatically. - Request body inspection and response masking: outbound JSON, form, and text request bodies are inspected up to 1 MiB; larger or unsupported bodies pass through without credential substitution. After substitution, the fetch proxy masks matching credential values in response headers and supported text, JSON, or form bodies up to 1 MiB; event streams, oversized or unsupported bodies, and unrecognized transformations can pass through. Ordinary
fetchfollows the deployment’s own network policy, and ordinary transport failures becomeNetworkUnreachable. Place credentials in declared headers or query parameters viarequest, and choose upstream hosts you trust. - Health check deadline: Executor passes a
deadlinetimestamp onAccountCheckContext. Passsignalto everyfetchcall and return or throw beforedeadlineto supply your own result; otherwise Executor may report a timeout. - Account ownership and isolation: on Cloud and Self-host, personal account management checks who connected the account, including for admins. An app-wide
app.accountslink lets authorized callers use the shared account through app tools.