lampac-mcp
README.md
# lampac-mcp (Alpha)
A client-neutral MCP server for [Lampa](https://github.com/yumata/lampa-source) behind
[Lampac](https://github.com/lampac-nextgen/lampac). The rows of Lampa's main screen are curated by AI —
from the web cabinet (an idea in plain words → an LLM proposes titles → TMDB confirms them) or by
an MCP client — and Lampa shows them instead of its usual TMDB rows. The same service can stand in for
CUB, Lampa's cloud service, so that Lampa's CUB requests stay on your network.

<p>
<img src="docs/cabinet-rows.jpg" width="49%" alt="Rows: order, edit, regenerate from the idea">
<img src="docs/cabinet-ai.jpg" width="49%" alt="AI provider keys and models">
</p>
<sub>Screenshots are taken from a demo instance with invented rows and generated posters.</sub>
Rows are stored by this service as JSON. It does not write to CUB, Lampac `catalog/card`, or Lampa's own data.
## What is included
- MCP endpoint at `/mcp` using JSON-RPC over Streamable HTTP (2025-11-25).
- `get_ai_rows` — read the main-screen rows in display order.
- `set_ai_row` — create or replace one row: `id`, `title`, `kind` (`movies`, `series`, `cartoons`, `anime`),
`style` (`poster` or `wide` 16:9 cards), TMDB cards, optional `position`. Disabled by default (see below).
- `delete_ai_row` — remove a row. Disabled by default.
- `inspect_title_sources` — a read-only `/lite/events` request to a configured Lampac instance for one TMDB
title. This is a snapshot, not a root-cause diagnosis or an automatic fix.
- `get_tvctl_log` — optionally read the latest reports from `EX.TvCtl`; it sends no commands to a device.
- `GET /api/collection` — read-only feed for the Lampa plugin: `rows`, plus the first row as `title`/`items`
for older plugin builds.
- `GET /api/tmdb/<path>` — read-only TMDB for TV front-ends (e.g. Glint): the server adds its `TMDB_API_KEY`, so the key
never reaches the TV; only list/title/season/person/search paths, answers cached for 30 minutes, CORS `*`.
- `/cub/*` — local CUB stand-in (see below) and `GET /api/cub-log` with the last requested paths.
- `plugin/lampac-mcp.js` — Lampa 3 plugin that builds the main screen from the rows.
- `/cabinet` — web cabinet (Ukrainian UI): rows (order, edit, delete, regenerate from the stored idea),
new rows from an idea, AI provider keys and models, MCP token, users, CUB log.
## Cabinet
Open `http://<host>:8787/cabinet/`. On first start there is one user `admin` with the password
`admin` (or `CABINET_ADMIN_PASSWORD`); until that default password is changed, the server refuses
everything except changing it. More users can be added in the cabinet.
- **AI providers:** Gemini (Google AI Studio key), and through one OpenAI-compatible client: Groq,
OpenRouter (with a free-only model filter), Mistral, a local Ollama (no key; nothing leaves your network)
or any other server with `/chat/completions`. Keys are stored in `data/settings.json` (mode 600) and never
sent back to the browser; the model list comes from the provider. Only the idea and the proposed titles go
to the provider. After a 429 the request is repeated once after the wait the provider asks for; output is
capped (Groq: `max_completion_tokens`, `reasoning_effort: low` for gpt-oss models).
- **Generation:** the model proposes titles (original and English title, year, type); each one is looked
up in TMDB with `TMDB_API_KEY`. Titles TMDB does not know, namesakes from another year and titles without
a translation in `TMDB_LANGUAGE` are dropped. Cards without images get them from TMDB when the cabinet
shows the rows.
- **MCP token:** "Issue a new token" replaces `MCP_TOKEN` at once; the token is shown once, with the
`claude mcp add --transport http …` command.
- **Hardening:** sessions in `HttpOnly; SameSite=Strict` cookies, same-origin check on writes, login
attempts limited, `Content-Security-Policy` without inline scripts, optional `CABINET_HOSTS` allowlist
against DNS rebinding. Keep the cabinet on a trusted network or behind your own login.
## Run
### Docker
```sh
docker build -t lampac-mcp .
docker run -d --name lampac-mcp --restart unless-stopped \
-e MCP_TOKEN=... -e MCP_ENABLE_WRITES=false \
-v "$PWD/data:/data" -p 8787:8787 lampac-mcp
```
The image listens on all interfaces inside the container (`HOST=0.0.0.0`) and keeps rows in `/data`.
Publish the port only where you need it.
### Node
Requires Node.js 20 or later; only Node's built-in modules are used, there are no runtime dependencies.
```sh
cp .env.example .env # set MCP_TOKEN to a random value of at least 32 characters
set -a; . ./.env; set +a
npm start
```
The MCP URL is `http://<host>:8787/mcp`. The server rejects a present `Origin` that is not in
`ALLOWED_ORIGINS` and requires bearer authentication on `/mcp`. Keep it on a trusted network; do not expose it
through a public reverse proxy without HTTPS, the token and an extra login in front.
## Tests
`npm test` starts temporary server processes on loopback with a temporary data file; it does not contact Lampac.
## Enable row writes
Writes are off by default. Set `MCP_ENABLE_WRITES=true` only after configuring the MCP host to show a human
approval prompt for tool calls. `set_ai_row` and `delete_ai_row` also require this exact phrase:
```text
I have reviewed and approve changing the AI rows.
```
MCP itself does not enforce a confirmation UI; the host's approval prompt is part of the safety boundary.
The phrase is an additional guard, not proof that a human approved the call.
Rows are saved to `./data/collections.json` (`/data/collections.json` in Docker); set `COLLECTIONS_FILE` to
change it. A file from the first alpha (one `{ title, items }` collection) is read as one wide row.
The feed is public to the Lampa plugin; do not put private notes in card fields.
## Connect Lampa
The recommended way is through Lampac, so that Lampa reads the feed from its own origin (no CORS, no mixed
http/https): module `EX.Mcp` and the plugin from [lampac-extra](https://github.com/TrueNihilisme/lampac-extra#rows).
```json
"EX.Mcp": { "collectionUrl": "http://<lampac-mcp host>:8787/api/collection" }
```
The plugin replaces the main screen of Lampa's TMDB source with the rows; rows of Lampa itself and other
plugins ("Continue watching", episode releases) follow at the bottom. Card details (poster or backdrop,
title, overview, rating) come from Lampa's own TMDB source and are cached on the device for a day.
Without rows, or when the feed is unreachable, the usual TMDB main screen is shown.
Checked with Lampa 3.3.4 on Samsung Tizen 4.0 and Android TV.
## Local CUB stand-in
Lampac's `CubProxy` forwards Lampa's `/cub/red/<path>` requests to `{cub.scheme}://{cub.domain}/<path>`.
Point it at this service to keep them local:
```json
"cub": { "scheme": "http", "domain": "<lampac-mcp host>:8787/cub", "useproxy": false }
```
Keep `cub.api_key` and `cub.mirror` as they are: other Lampac modules read them from the same section.
The stand-in answers 404 to API calls (Lampa then shows no comments, reactions or CUB collections), an empty
script for `/cub/plugin/*`, and accepts POSTs (logs, reactions) without storing them. `GET /api/cub-log`
lists the last 200 requested paths without query strings.
Some requests do not go through Lampac: Lampa 3.3.4 sends `https://tmdb.cub.best/watch?id=…` when a title
enters the history, ads requests and WebSocket connections straight from the device. Turn off what Lampa allows in
`lampainit.js` (`lampa_settings.socket_use`, `account_use`, `disable_features.discuss` and others) and block
the CUB domains in your DNS for the rest.
## Read-only diagnostics
Set `LAMPAC_URL` to the Lampac base URL, then call `inspect_title_sources` with the TMDB id, `movie` or `tv`,
and the title. Optional fields: original title/language, year, IMDb id, `is_anime`.
`get_tvctl_log` needs `LAMPAC_ROOT_PASSWORD` from your secret manager. It calls the read-only `/tvctl/log`
route and returns at most 200 lines. Do not put the password in source control, tool arguments or logs.
## Configuration
| Variable | Default | Purpose |
| --- | --- | --- |
| `MCP_TOKEN` | none | Required bearer token; at least 32 characters |
| `ALLOWED_ORIGINS` | none | Comma-separated exact origins allowed on `/mcp` |
| `HOST` | `127.0.0.1` (`0.0.0.0` in Docker) | Listen address |
| `PORT` | `8787` | Listen port |
| `LAMPAC_URL` | none | Lampac base URL for source inspection |
| `LAMPAC_ROOT_PASSWORD` | none | Lampac root password for optional read-only EX.TvCtl log access |
| `MCP_ENABLE_WRITES` | `false` | Enables `set_ai_row` and `delete_ai_row` over MCP (the cabinet can always edit rows) |
| `COLLECTIONS_FILE` | `./data/collections.json` | JSON persistence path; `users.json` and `settings.json` live next to it |
| `TMDB_API_KEY` | none | TMDB key for row generation and card images in the cabinet |
| `TMDB_BASE` | `<LAMPAC_URL>/tmdb/api/3` if `LAMPAC_URL` is set, else `https://api.themoviedb.org/3` | TMDB API base (Lampac's TMDB proxy works) |
| `TMDB_IMG_BASE` | `<LAMPAC_URL>/tmdb/img/t/p/` or `https://image.tmdb.org/t/p/` | Poster base for the cabinet |
| `TMDB_LANGUAGE` | `uk-UA` | Language of titles and the translation check |
| `CABINET_ADMIN_PASSWORD` | none (`admin`) | Password of the first user on first start |
| `CABINET_HOSTS` | none (any) | Comma-separated `Host` values the cabinet answers to, e.g. `10.0.0.5:8787,lampa-ai.example.org` |
## Protocol and safety notes
- The endpoint implements initialization, `tools/list`, `tools/call`, `ping`, and notifications needed by the
2025-11-25 Streamable HTTP flow. GET on `/mcp` returns 405; there is no server-to-client SSE stream.
- `Origin` is checked when present, as required by the
[MCP transport specification](https://modelcontextprotocol.io/specification/2025-11-25/basic/transports).
Authentication is bearer-token based.
- Use trusted MCP clients. Tool metadata and server-side phrases cannot replace the host's approval UI.
## Support
If this project is useful to you, you can support its development with a crypto donation:
| Network | Address |
|---|---|
| Bitcoin (BTC) | `bc1q0sw0w9mqtghrxfyyqw834sjs7t7rr7futulgv4` |
| Ethereum (ETH) | `0xAb3a04a4b52547a7f8B00abb0088D3d9d11CA461` |
| Solana (SOL) | `2QBoKrUaiAcAKxNJ7o9oe9Q16ptjLQohR8KyPX2tpJhZ` |
Send each coin only on the network named in its row: a transfer made on another network cannot be recovered.
## License
GNU Affero General Public License v3.0 only. See [LICENSE](LICENSE).