AppServer
AppServer
(also known as TpaServer
in older versions) is the base class for creating Third Party Application (app) servers that handle webhook requests from MentraOS Cloud to manage app sessions.
Constructor
config
: Configuration options for the app server
Methods
getExpressApp()
Exposes the internal Express app instance for adding custom routes or middleware.onSession() [protected]
Override this method to handle the initiation of a new app session when a user starts your app. Implement your app’s core logic here (e.g., setting up event listeners).session
: TheAppSession
instance for this specific user sessionsessionId
: The unique identifier for this sessionuserId
: The unique identifier for the user
onStop() [protected]
Override this method to handle cleanup when an app session is stopped by the user or system.sessionId
: The unique identifier for the session being stoppeduserId
: The unique identifier for the userreason
: The reason the session was stopped (‘user_disabled’, ‘system_stop’, ‘error’)
onToolCall() [protected]
Override this method to handle tool calls from Mira AI. This is where you implement your app’s tool functionality. For a comprehensive guide on implementing AI tools, see AI Tools.toolCall
: A ToolCall object containing the tool ID, parameters, user ID, and timestamp
start()
Starts the app server, making it listen for incoming webhook requests.stop()
Gracefully shuts down the app server, cleaning up all active sessions and resources.generateToken() [protected]
Generates a JWT token suitable for app authentication, typically used for webviews. See Token Utilities for more details.userId
: The user’s identifiersessionId
: The session identifiersecretKey
: Your app’s secret key (should match the one configured in MentraOS Cloud)
addCleanupHandler() [protected]
Registers a function to be executed during the server’s graceful shutdown process.handler
: The cleanup function to add