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.

Tokens
62.2K
Snippets
294
Records
419
Agent score
56%

What's inside Mentra

  1. Overview of the MentraOS OEM Display Protocol

    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.
  2. 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.
  3. 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.
  4. Overview of mentra-miniapp CLI

    The @mentra/miniapp-cli provides the mentra-miniapp command 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 bun or bunx. Do not use npx or Node.js.
    • Installation: It is typically installed as a dev dependency in scaffolded projects and called via package.json scripts (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>
  5. 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)
  6. 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.
  7. Monitor phone battery level

    Use session.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}`);
    });
  8. Use the session object to access Mentra glasses capabilities

    The session object is the central handle for all interactions with the glasses hardware and system. It is provided to the registerMiniapp handler when a miniapp connects. All capabilities (display, audio, sensors, storage) are organized as modules on the session object.
    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 },
        ]);
      });
    });
  9. 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 commit command 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_display wipes the current scene and frees all retained element IDs. A batch without clear_display amends the existing scene.
    • Color: The display is monochrome. All drawables use an intensity value from 0 (off/transparent) to 15 (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 atomically
  10. Use session.storage for persistent key-value storage

    session.storage is 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"
  11. 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 the dev branch. The primary source of truth for setup, architecture, builds, and tests is the documentation located within each specific module's directory.
  12. 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 the miniapp.json configuration file and handled in the background layer. These actions map 1:1 to Model Context Protocol (MCP) tools, where id maps to name, description remains the same, parameters maps to inputSchema, and outputSchema is preserved.