Documentation Index
Fetch the complete documentation index at: https://docs.xpander.ai/llms.txt
Use this file to discover all available pages before exploring further.
@on_auth_event registers a handler that fires whenever the agent runtime emits an authentication event: for example, when an MCP server requires the end-user to log in via OAuth. Use it to surface the OAuth URL to your UI, kick off external auth flows, or log auth attempts.
Backend.aget_args(...) call routes auth events through registered handlers automatically.
Required signature
The function must accept exactly three parameters:agent, task, event. Names are flexible; arity matters. Sync or async are both accepted.
| Parameter | Type | Description |
|---|---|---|
agent | Agent | The agent processing the task. |
task | Task | The current task. |
event | TaskUpdateEvent | event.type == "auth_event". event.data holds the auth payload. |
event.type is always "auth_event" for handlers registered with this decorator.
Event payload shapes
event.data is one of the MCP OAuth response variants. Switch on event.data.type:
type | event.data.data |
|---|---|
MCPOAuthResponseType.LOGIN_REQUIRED ("login_required") | MCPOAuthGetTokenLoginRequiredResponse(url, server_url, server_name) |
MCPOAuthResponseType.TOKEN_READY ("token_ready") | MCPOAuthGetTokenTokenReadyResponse(access_token) |
MCPOAuthResponseType.TOKEN_ISSUE ("token_issue") | MCPOAuthGetTokenGenericResponse(message) |
MCPOAuthResponseType.NOT_SUPPORTED ("not_supported") | MCPOAuthGetTokenGenericResponse(message) |
Examples
Show the OAuth URL to the user
Multiple handlers stack
Combine with a per-call callback
You can pass an additional one-off callback toBackend.aget_args(auth_events_callback=...): it runs in addition to every globally-registered handler.
global_handler and per_call fire when an auth event happens during the resulting agent’s run.
Helper functions
The module also exposes two helpers for testing and management:xpander_sdk package: import from the decorator module directly.
