media-preview
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="./assets/readme/banner-dark.svg">
<source media="(prefers-color-scheme: light)" srcset="./assets/readme/banner-light.svg">
<img alt="media-preview" src="./assets/readme/banner-light.svg" width="620">
</picture>
</p>
<p align="center">
<b>Zero-dependency inline video, waveform audio, and frame-strip previews for AI coding agents.</b><br>
Built on the <a href="https://github.com/modelcontextprotocol/ext-apps">MCP Apps (SEP-1865)</a> spec. Pure Node.js standard library. Near-zero context tokens.
</p>
<p align="center">
<b><a href="#highlights">Highlights</a></b> ·
<a href="#native-desktop-lightbox">Desktop Lightbox</a> ·
<a href="#installation">Installation</a> ·
<a href="#tool-reference">Tool Reference</a> ·
<a href="#smoke-test">Smoke Test</a>
</p>
<p align="center">
<img alt="Node >= 18" src="https://img.shields.io/badge/node-%3E%3D18.0-5CD0B3?style=flat-square&logo=nodedotjs&logoColor=white">
<img alt="Dependencies: 0" src="https://img.shields.io/badge/dependencies-0-CD853F?style=flat-square">
<img alt="MCP Apps SEP-1865" src="https://img.shields.io/badge/MCP_Apps-SEP--1865-29ABCA?style=flat-square">
<a href="./LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-78716C?style=flat-square"></a>
</p>
<p align="center">
<img alt="Inline Media Preview running inside a Google Antigravity conversation" src="./assets/readme/hero-antigravity-chat.jpg" width="100%">
</p>
<p align="center">
<img alt="Inline 9:16 and 16:9 video player in Antigravity chat" src="./assets/readme/showcase-video.jpg" width="32%">
<img alt="72-bar interactive waveform audio player in Antigravity chat" src="./assets/readme/showcase-waveform.jpg" width="32%">
<img alt="Silent agent peek micro-thumbnails and storyboard gallery strip in Antigravity chat" src="./assets/readme/showcase-gallery.jpg" width="32%">
</p>
**Playable local media inside chat, without burning context.** Most AI coding environments render `.mp4`, `.wav`, and `.png` outputs as dead file pills—while base64-inlining media into HTML artifacts blows past token caps and iframe CSP rules. `media-preview` streams local files straight from `127.0.0.1` into an MCP App view, keeping raw bytes completely out of LLM history.
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="./assets/readme/tokens-dark.svg">
<source media="(prefers-color-scheme: light)" srcset="./assets/readme/tokens-light.svg">
<img alt="LLM context token comparison: media-preview (~28 tokens) vs inline base64 PNG strip (~54,000 tokens) vs base64 HTML video artifact (1.5M+ tokens)" src="./assets/readme/tokens-light.svg" width="100%">
</picture>
</p>
<p align="center"><sub>Only a 1-line text receipt enters model context; media streams over localhost HTTP <code>206 Partial Content</code>.</sub></p>
## Highlights
- **9:16 & 16:9 aware video players.** Vertical Shorts and widescreen renders auto-fit inside inline chat height caps with a minimal overlay scrub bar, click-to-play, and fullscreen handoff that syncs playback timestamp on minimize.
- **72-bar interactive audio waveforms.** Samples normalized peak bars directly from RIFF PCM/float WAV files in `< 1 ms` with bounded memory, and decodes compressed formats (`.mp3`, `.m4a`, `.ogg`, `.opus`, `.aac`, `.flac`) via WebAudio in the client.
- **Three-tier image presentation.** Automatically chooses a video-sized showcase card for 1 image, an `82px` gallery strip for 2+ images, or right-aligned `30px` micro-thumbnails (`mode: "peek"`) when an agent silently inspects frames mid-task.
- **Session-resilient across restarts.** Ships an app-only (`0`-token) `resolve_media` tool so reopening historical chats on a new ephemeral localhost port transparently re-hydrates every player.
- **Hardened localhost streaming.** Binds strictly to `127.0.0.1:0` with a random 128-bit per-session token and serves only explicitly registered files.
- **Zero npm dependencies.** Runs out of the box on Node.js `>= 18` with no `npm install` or build step.
## Native Desktop Lightbox
Clicking any image or video fullscreen button on Linux (Wayland/X11 with GTK4) launches a **frameless translucent desktop overlay** (`src/modal.py`) outside the narrow chat iframe—supporting scroll/pinch zoom up to `8×`, drag pan, arrow-key gallery navigation, and live video timestamp sync. On macOS, Windows, or Linux setups without GTK4, `media-preview` detects availability via a startup handshake and falls back automatically to its built-in inline modal.
<p align="center">
<img alt="Frameless GTK4 translucent desktop lightbox floating over the IDE chat pane" src="./assets/readme/hero-lightbox.jpg" width="100%">
</p>
<p align="center"><sub>Frameless GTK4 desktop overlay with scroll/pinch zoom, drag pan, and keyboard navigation (automatic in-iframe fallback everywhere else).</sub></p>
## Installation
### Google Antigravity
Clone directly into your Antigravity plugins directory:
```bash
git clone <repo-url> ~/.gemini/config/plugins/media-preview
```
Antigravity discovers `plugin.json`, `mcp_config.json`, and the bundled agent workflow rules (`rules/AGENTS.md`) automatically—no build or install step required. Toggle or manage it anytime at `customization://media-preview`.
### Any MCP Apps Host (`mcp_config.json`)
Works with Claude Desktop and any client implementing [MCP Apps (`ext-apps`)](https://github.com/modelcontextprotocol/ext-apps):
```json
{
"mcpServers": {
"media-preview": {
"command": "node",
"args": ["/absolute/path/to/media-preview/src/server.mjs"]
}
}
}
```
### Optional: Linux GTK4 Overlay Packages
To enable the native desktop overlay outside the chat iframe on Linux:
```bash
# Ubuntu / Debian
sudo apt install python3-gi gir1.2-gtk-4.0 gstreamer1.0-gtk4
# Fedora
sudo dnf install python3-gobject gtk4 gstreamer1-plugin-gtk4
# Arch Linux
sudo pacman -S python-gobject gtk4 gst-plugin-gtk4
```
## Tool Reference
### `preview_media`
| Parameter | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| `paths` | `string[]` | *required* | Absolute paths or `file://` URIs to `.mp4`, `.m4v`, `.webm`, `.mov`, `.mkv`, `.wav`, `.mp3`, `.ogg`, `.opus`, `.m4a`, `.aac`, `.flac`, `.png`, `.jpg`, `.jpeg`, `.webp`, `.gif`, `.svg`, or `.avif` files. |
| `mode` | `"default" \| "peek"` | `"default"` | `"default"` renders full inline players, showcase cards, or gallery strips; `"peek"` renders tiny right-aligned micro-thumbnails for silent intermediate checks. |
| `loop` | `boolean` | `false` | Loop video or audio playback (useful for seamless Short loop checks). |
| `autoplay` | `boolean` | `false` | Autoplay on load (muted on video per browser policy). |
## Smoke Test
Verifies MCP `stdio` JSON-RPC framing, `ui://` resource delivery, WAV RIFF peak extraction, `open_modal` path validation, and HTTP `206 Partial Content` streaming:
```bash
npm test
```
## License
[MIT](./LICENSE)
TDQS
Scored across 3 tools
Each tool has a distinct action: preview_media renders inline content, resolve_media refreshes stream URLs, and open_modal launches a desktop window. preview_media and resolve_media both touch media and could be momentarily confused, but the descriptions make the render-vs-refresh distinction clear.
All three tools follow a clean verb_noun snake_case pattern (preview_media, resolve_media, open_modal). The convention is applied uniformly with no stylistic drift.
Three tools is a tight, well-scoped set for a narrow media-preview purpose, and each earns its place. It sits at the thin end of the range, with two of the three being narrow 'app-only helper' utilities.
The surface covers rendering, URL refreshing, and modal launch, but has gaps: no way to close or dismiss the modal, and no operation to discover or list local media files before previewing. Agents may hit dead ends when cleaning up or finding content to preview.