Mentra Miniapp SDK
website·Indexed 33 days ago
https://docs.mentraglass.com/Developer documentation for building on-device apps for smart glasses using the Mentra Miniapp SDK. Covers core concepts including a two-layer architecture (background and UI), hardware integration for camera, IMU, LED, and microphone, as well as real-time transcription, translation, and navigation. Includes guides on the mentra-miniapp CLI, miniapp.json manifest, and Bluetooth SDK integration for Android.
What's inside Mentra
- The MentraOS OEM Display Protocol is a firmware-side contract that allows MentraOS (running on a smartphone) to drive the display and functionality of OEM smart glasses. In this architecture, the phone manages all application logic and screen layouts, while the glasses act as a thin client that renders streamed commands. The glasses also maintain a small firmware-resident home screen for use when disconnected from the phone.
Overview of the Mentra OEM Integration Engine
The Mentra OEM Integration Engine is a library that embeds MentraOS phone-side logic into a third-party application. It allows OEMs to maintain their own branding and user relationship while providing users with the Mentra Miniapp Store, miniapp runtime, and developer ecosystem. The engine manages the logic between the smart glasses and Mentra's backend services, including display rendering, audio routing, and backend connectivity for transcription, translation, and streaming.Overview of Mentra Miniapp SDK
The Mentra Miniapp SDK (
@mentra/miniapp) allows developers to build on-device apps that run within the Mentra App on a user's phone to drive smart glasses.Key Constraints & Status:
- Beta Status: The SDK is currently in beta; APIs are subject to change.
- Distribution: Public distribution via the Mentra Miniapp Store is not available in MentraOS 3.0. Distribution is planned for a future release via the Mentra Developer Console.
- Developer Tools: Access tools in the Mentra App under Settings → Miniapp Developer Settings.
- Alternative: For apps connecting directly to glasses over Bluetooth (BLE), use the Mentra Bluetooth SDK instead of the Miniapp SDK.
Overview of mentra-miniapp CLI
The
@mentra/miniapp-cliprovides thementra-miniappcommand for developing, packing, and releasing Mentra miniapps.Critical Requirements:
- Runtime: The CLI is Bun-only. It is written in TypeScript and must be run using
bunorbunx. Do not usenpxor Node.js. - Installation: It is typically installed as a dev dependency in scaffolded projects and called via
package.jsonscripts (e.g.,"dev": "mentra-miniapp dev"). - Beta Status: The SDK is currently in beta. Distribution via the Mentra Developer Console or Miniapp Store is not yet supported in MentraOS 3.0.
mentra-miniapp <command>- Runtime: The CLI is Bun-only. It is written in TypeScript and must be run using
Overview of common Mentra SDK commands
The Mentra SDK provides commands across several functional areas:
- Connection:
scan,startScan,stopScan,connect,connectDefault,disconnect,forget - Wi-Fi/Hotspot:
requestWifiScan,sendWifiCredentials,forgetWifiNetwork,setHotspotState - Camera:
requestPhoto, gallery mode, video recording defaults, camera field of view - Streaming:
startStream,stopStream - Audio:
setMicState, VAD settings, audio callbacks, local transcription, media volume - System:
requestVersionInfo,checkForOtaUpdate,startOtaUpdate - LEDs:
rgbLedControl(supported hardware only)
- Connection:
Overview of Mentra Bluetooth SDK
The Mentra Bluetooth SDK allows Android, iOS, and React Native applications to connect directly to Mentra Live glasses over Bluetooth. It provides programmatic access to device scanning, pairing, status monitoring, microphone audio, camera capture, speaker playback, streaming, Wi-Fi management, and hardware events. This SDK is intended for apps that manage the mobile experience and require a direct phone-to-glasses connection.Monitor phone battery level
Usesession.phone.onBattery()to receive updates about the phone's battery status. This does not require any special permissions.session.phone.onBattery((data) => { // data is of type BatteryData console.log(`Battery Level: ${data.level}, Charging: ${data.charging}`); });Use the session object to access Mentra glasses capabilities
Thesessionobject is the central handle for all interactions with the glasses hardware and system. It is provided to theregisterMiniapphandler when a miniapp connects. All capabilities (display, audio, sensors, storage) are organized as modules on thesessionobject.import { registerMiniapp } from "@mentra/miniapp/background"; registerMiniapp((session) => { // Access modules via session session.transcription.on((data) => { session.display.render([ { type: "text", id: "caption", box: { x: 0, y: 0, w: 576, h: 288 }, text: data.text }, ]); }); });Understand the Glasses Drawing Model
The glasses use a queued drawing model where commands are accumulated in a pending batch and only rendered to the panel when a
commitcommand is received. This ensures atomic updates and prevents the wearer from seeing half-applied frames.Key rules:
- Layering: Commands are processed in the order sent; later commands paint over earlier ones.
- Clearing:
clear_displaywipes the current scene and frees all retained element IDs. A batch withoutclear_displayamends the existing scene. - Color: The display is monochrome. All drawables use an
intensityvalue from0(off/transparent) to15(brightest). - Bitmaps: Unset pixels in bitmaps are transparent, allowing them to layer over other elements without erasing them.
- Pacing: The phone is responsible for flow control and coalescing frames; the firmware simply renders what it receives.
clear_display // Wipe existing scene draw_rect { ... } // Queue rectangle draw_text { ... } // Queue text (paints over rect) commit { } // Render all queued ops atomicallyUse session.storage for persistent key-value storage
session.storageis a phone-local, persistent key-value store scoped to the user and the specific miniapp. Data survives restarts and keys do not collide between different miniapps. Both keys and values must be strings. All methods are asynchronous as they round-trip to the phone. No special permissions or hardware are required to use this API.await session.storage.set("lastNote", "buy milk"); const note = await session.storage.get("lastNote"); // "buy milk"Contribute to MentraOS open source project
MentraOS is open source and accepts contributions across several modules. All pull requests must be based on and target thedevbranch. The primary source of truth for setup, architecture, builds, and tests is the documentation located within each specific module's directory.Expose miniapp actions to Mentra AI
Miniapps can expose typed, described capabilities called 'actions' that Mentra AI can invoke to drive the app. Actions are declared in theminiapp.jsonconfiguration file and handled in the background layer. These actions map 1:1 to Model Context Protocol (MCP) tools, whereidmaps toname,descriptionremains the same,parametersmaps toinputSchema, andoutputSchemais preserved.