Skip to content

Function: stampRequestContextUser()

stampRequestContextUser(requestContext, attributed?): Promise<void>

Stamp the AppKit user (plus the resource id and trace metadata) onto requestContext.

Split out of MastraServer because the HTTP middleware is not the only caller that needs it: an out-of-band turn (a Teams activity arriving on another plugin’s route, a scheduled job) drives agent.generate directly, and without this stamp every user-scoped tool - ask_genie above all - fails with “invoke the tool from an agent turn served by the mastra plugin”. Those callers build a context with createRequestContext instead of a request.

The Databricks credential always comes from the ambient execution context; attributed only changes WHO the turn is attributed to when that context is the service principal (see AttributedIdentity).

Idempotent: returns immediately when the user and resource id are already present, so the middleware can call it over a context another layer stamped.

RequestContext

AttributedIdentity = {}

Promise<void>