ctx is the entire platform surface a server-side handler gets. There is no raw database client, no Supabase, no request object. Every field is scoped and authorized before your code runs.
The context object
Storage
Access to schema-validated per-account and per-user state:get returns null for missing keys and expired entries. User scope throws for machine actors.
Secrets
Named credentials resolved by the host across its tiers:set() writes only to the account tier for this {account, product}. Source- and global-tier credentials are admin-issued and throw SecretAccessError if you try to write them.
Fetch
HTTP client that refuses anything outside youregress allowlist:
EgressDeniedError synchronously, before opening a socket. Redirect targets are also checked.
Logger
Structured logging with pre-bound context:{integration, accountId, actor} to every line.
Actor
Who is calling — a human user or a machine (a team workflow). Personal workflows and agents run as the user:ctx.storage.user call throws.
Gating writes on the caller’s role
The host runs every action with the account’s credential, so without a check any member can do whatever that credential allows. A user actor carriesrole: { name, hierarchyLevel } | null, the caller’s role in the account (1 owner, 2 admin, 3 member). Gate a write with actorIsAtLeast:
actorIsAtLeast refuses them. It also refuses a user whose role the host could not resolve. In tests, createMockContext() defaults to an owner; pass actor with a lower role to exercise the gate.
Identity fields
All read-only and already authorized:ctx.connection.owner is 'user' when the context is one person’s own tier: an experience invoker call, or the onTokens / onActivate of a user-level credential being connected. There ctx.secrets is that person’s tier, plus the app’s admin-issued client credentials.
ctx.connection.owner is 'source' only when a provided agent runs on a connection a Source admin made for the whole Source. Then ctx.routing names the routing key and the values routed to the team the call is for, and your tools must stay inside them. See Routing and Source connections.
Principal and identity
ctx.principal says who the call runs for. The host sets it from the session, a run’s stored invoker or a personal workflow’s owner, never from a request body:
displayName and avatarUrl are for attribution and may be null. There is no email. Key your data on userId.
ctx.identity is the calling person’s own credential tier, { userId, secrets }. It is set only when the principal is a person who has connected a user-level credential and the Source serves the level. It is never set for a machine principal (team workflow, schedule, webhook, health check) or for a call made for someone else (a workflow in agent mode, a managed agent). identity.secrets holds only that person’s values, and set writes back to it.
ctx.secrets stays the team tier. When you act as the team for a person, attribute the write to ctx.principal where the vendor allows it. See Credential levels.
Common patterns
Logging with context
Always include relevant IDs in the context object:Handling missing credentials
Not configured is an expected state — log and skip, don’t fail:Error handling
Log before throwing so errors reach your observability:Where ctx is available
- Tools —
tools[].run(ctx, args) - Webhooks —
webhooks[].handler(ctx, event) - Schedules —
schedules[].handler(ctx, invocation) - Activation hooks —
onActivate(ctx) - Actions —
actions[name].handler(ctx, input) - OAuth —
oauth.onTokens(ctx, tokens)
{account, integration}.