MiniAppServer. It handles webhooks from the MentraOS Cloud, manages WebSocket connections, and gives you a MentraSession for each user who opens your app.
Basic Setup
What MiniAppServer Does
| Responsibility | Details |
|---|---|
| HTTP Server | Listens for webhooks from MentraOS Cloud (Hono-based) |
| WebSocket Client | Maintains a connection to MentraOS Cloud per user session |
| Session Manager | Creates a MentraSession for each user who starts your app |
| Lifecycle Handler | Calls your onSession and onStop callbacks at the right times |
Configuration
Required Settings
packageName
packageName
Unique identifier for your app.
- Format: Reverse domain notation (e.g.,
com.company.appname) - Set in the Developer Console
- Used to route sessions to your app
apiKey
apiKey
Your app’s API key.
- Found in the Developer Console under your app’s settings
- Keep this secret - use environment variables, not hardcoded strings
port
port
The port your server listens on.
- Defaults to
80if not set - Must match the port in your deployment configuration and ngrok tunnel
Optional Settings
cookieSecret
cookieSecret
Lifecycle Callbacks
onSession
Called when a user starts your app on their glasses. This is where your app logic lives.MentraSession object is your connection to that user. Everything you do with their glasses goes through it. See MentraSession for the full API.
onStop
Called when a user session ends. Receives the session (if available) and a reason string.onToolCall
Called when the MentraOS AI system invokes one of your app’s registered tools.Custom Routes
MiniAppServer is built on Hono, so you can add your own HTTP routes directly:
Authenticated Routes
If your app has a webview that needs to make authenticated API calls:Migrating from AppServer
If you’re updating from v2, see the Migration Guide. The key change is moving from class inheritance to callbacks:AppServer class still works in v3.0 for backward compatibility. It will be removed in v3.1.
