Initialization
src/lib/mio/server.ts
Mio.init is idempotent on the server. Call it during module evaluation or process startup and reuse Mio.getInstance() everywhere else.Config parameters
OAuth application ID from the Mio dashboard.
Absolute URL where Mio sends users back after the connection flow. Must match the redirect configured in Mio.
Confidential secret used only on the server when exchanging or refreshing tokens.
Methods
exchangeCodeForTokens(code: string): Promise<MioOauth2TokenResponse>
Swaps an authorization code for tokens using the confidential client credentials.
Authorization code provided by the Mio auth workflow.
MioOauth2TokenResponse containing accessToken, refreshToken, expiresIn, tokenType, and idToken.refreshTokens(refreshToken: string): Promise<MioOauth2TokenResponse>
Mint a new access token (and refresh token) without user interaction.
The token you persisted from the previous exchange.
MioOauth2TokenResponse containing accessToken, refreshToken, expiresIn, tokenType, and idToken.getContext({ query, accessToken }): Promise<string>
Server-side wrapper that shares the same implementation as the client version. Use it when you run long operations or batch context requests on the backend.
Returns
The refined and personalized user summary, based on your query
getContextSummary({ accessToken }): Promise<string | null>
Retrieves the latest Mio Context summary for the given user.
Return the user summary if Mio has one, else return null.
Error matrix
| Method | Error | Description |
|---|---|---|
exchangeCodeForTokens | invalid_grant | Redirect URL or client credentials mismatch |
exchangeCodeForTokens | invalid_request | Missing code body parameter |
refreshTokens | invalid_grant | Expired or revoked refresh token |
getContext/getContextSummary | 401 Unauthorized | Access token expired or malformed |
All methods throw standard
Error objects. Wrap calls with try/catch and map them to HTTP status codes that make sense for your API surface.