AppServer class. It handles webhooks, manages WebSocket connections, and routes sessions to your code.
Basic Setup
What AppServer Does
| Responsibility | Details |
|---|---|
| HTTP Server | Listens for webhooks from MentraOS Cloud |
| WebSocket Client | Maintains connection to MentraOS Cloud |
| Session Manager | Creates AppSession for each user connection |
| Lifecycle Handler | Calls onSession() and onStop() at appropriate times |
Configuration
Required Settings
packageName
packageName
Unique identifier for your app.
- Format: Reverse domain notation (e.g.,
com.company.appname) - Set in Developer Console
- Used to route sessions to your app
apiKey
apiKey
Secret key for authentication.
- Generated in Developer Console
- Authenticates your server with MentraOS Cloud
- Store in environment variables, never hardcode
port
port
HTTP port for webhook server.
- Your server listens on this port
- MentraOS Cloud sends webhooks here
- Must be accessible from the internet (production)
Getting Credentials
- Go to Developer Console
- Create or select your app
- Package Name: Set during app creation (e.g.,
com.example.myapp) - API Key: Click “Generate API Key” or copy existing key
Starting Your Server
- Listens for webhooks on
http://localhost:3000/webhook - Connects to MentraOS Cloud via WebSocket
- Waits for users to start your app
Multiple Users
AppServer handles many users simultaneously. Each user gets their ownAppSession:
- Unique
sessionId - Separate
AppSessioninstance - Isolated event subscriptions
- Independent state
Key Methods
onSession() (Required)
Called when a user starts your app:
onStop() (Optional)
Called when a session ends:
onToolCall() (Optional)
Called when AI assistant invokes your app’s tools:
Tool calls happen outside of active sessions. Learn more in AI Tools.
Complete Example
Next Steps
AppSession
Work with user sessions
App Lifecycle
Understand the full lifecycle
API Reference
Complete AppServer documentation
Quick Start
Build your first app

