Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34b6e36787 |
No files matched your search
@@ -226,23 +226,56 @@ def t_manual_scan(a):
|
||||
return get("/api/v1/manualimport", path=a["path"], platform=a.get("platform"))
|
||||
|
||||
|
||||
def t_import_path(a):
|
||||
"""Adopt one file or directory with an explicit platform, bypassing the queue.
|
||||
def t_indexer_schema(_):
|
||||
return get("/api/v1/indexer/schema")
|
||||
|
||||
`POST /api/v1/manualimport` is the action half of Manual Import: the
|
||||
platform given here wins over the header guess, which is the whole point --
|
||||
an ISO9660 PS2 disc reports itself as psx, so a guess cannot be trusted.
|
||||
|
||||
def _secret_from(body, field, literal, env_name):
|
||||
"""Set a credential field, optionally resolved from the server's own env.
|
||||
|
||||
Passing a key by *reference* means the value never enters the transcript: the
|
||||
gateway already exposes Prowlarr's and SABnzbd's keys to this process, so the
|
||||
caller names the variable instead of quoting the secret.
|
||||
"""
|
||||
path = (a.get("path") or "").strip()
|
||||
platform = (a.get("platform") or "").strip()
|
||||
if not path:
|
||||
raise ToolError("path is required (a file or directory on ROMarr's host)")
|
||||
if not platform:
|
||||
raise ToolError("platform is required (e.g. ps2) -- the header guess is unreliable")
|
||||
body = {"path": path, "platform": platform}
|
||||
if a.get("force"):
|
||||
body["force"] = True
|
||||
return post("/api/v1/manualimport", body)
|
||||
if env_name:
|
||||
value = os.environ.get(env_name, "")
|
||||
if not value:
|
||||
raise ToolError(f"{env_name} is not set in this server's environment")
|
||||
body[field] = value
|
||||
elif literal:
|
||||
body[field] = literal
|
||||
|
||||
|
||||
def t_indexer_save(a):
|
||||
kind = (a.get("type") or "").strip()
|
||||
if not kind:
|
||||
raise ToolError("type is required (see indexer_schema), e.g. 'prowlarr'")
|
||||
body = dict(a.get("extra") or {})
|
||||
body["type"] = kind
|
||||
for field in ("name", "url", "enable", "id"):
|
||||
if a.get(field) not in (None, ""):
|
||||
body[field] = a[field]
|
||||
_secret_from(body, "api_key", a.get("api_key"), a.get("api_key_env"))
|
||||
return post("/api/v1/indexer", body)
|
||||
|
||||
|
||||
def t_client_schema(_):
|
||||
return get("/api/v1/downloadclient/schema")
|
||||
|
||||
|
||||
def t_client_save(a):
|
||||
kind = (a.get("type") or "").strip()
|
||||
if not kind:
|
||||
raise ToolError("type is required (see download_client_schema), e.g. 'qbittorrent'")
|
||||
body = dict(a.get("extra") or {})
|
||||
body["type"] = kind
|
||||
for field in ("name", "host", "port", "use_ssl", "url_base", "username",
|
||||
"category", "id"):
|
||||
if a.get(field) not in (None, ""):
|
||||
body[field] = a[field]
|
||||
_secret_from(body, "password", a.get("password"), a.get("password_env"))
|
||||
_secret_from(body, "api_key", a.get("api_key"), a.get("api_key_env"))
|
||||
return post("/api/v1/downloadclient", body)
|
||||
|
||||
|
||||
def _obj(props, required=None):
|
||||
@@ -422,14 +455,6 @@ TOOLS = [
|
||||
"write": True,
|
||||
"fn": t_import_finished,
|
||||
},
|
||||
{
|
||||
"name": "import_path",
|
||||
"description": "Adopt a file or folder into the library with an explicit platform, bypassing queue matching. Use when a finished download never imported.",
|
||||
"schema": _obj({"path": {"type": "string"}, "platform": P_PLATFORM,
|
||||
"force": {"type": "boolean"}}, ["path", "platform"]),
|
||||
"write": True,
|
||||
"fn": t_import_path,
|
||||
},
|
||||
{
|
||||
"name": "manual_scan",
|
||||
"description": "Scan a directory on ROMarr's host for files it could adopt, without importing them.",
|
||||
@@ -437,6 +462,64 @@ TOOLS = [
|
||||
"write": False,
|
||||
"fn": t_manual_scan,
|
||||
},
|
||||
{
|
||||
"name": "indexer_schema",
|
||||
"description": "Every indexer type ROMarr supports, with the fields each one needs — read this before indexer_save.",
|
||||
"schema": _obj({}),
|
||||
"write": False,
|
||||
"fn": t_indexer_schema,
|
||||
},
|
||||
{
|
||||
"name": "indexer_save",
|
||||
"description": "Create or update an indexer. Prefer api_key_env over api_key: the server resolves the variable from its own environment, so the secret never appears in the call.",
|
||||
"schema": _obj(
|
||||
{
|
||||
"type": {"type": "string", "description": "Indexer type, e.g. 'prowlarr', 'torznab', 'newznab'."},
|
||||
"name": {"type": "string"},
|
||||
"url": {"type": "string", "description": "Base URL, e.g. http://127.0.0.1:9696 for Prowlarr."},
|
||||
"api_key": {"type": "string", "description": "Inline key. Avoid: prefer api_key_env."},
|
||||
"api_key_env": {"type": "string", "description": "Name of an env var holding the key, e.g. 'PROWLARR_API_KEY'."},
|
||||
"enable": {"type": "boolean"},
|
||||
"id": {"type": "string", "description": "Existing indexer id to update."},
|
||||
"extra": {"type": "object", "description": "Any other fields the type needs, verbatim."},
|
||||
},
|
||||
["type"],
|
||||
),
|
||||
"write": True,
|
||||
"fn": t_indexer_save,
|
||||
},
|
||||
{
|
||||
"name": "download_client_schema",
|
||||
"description": "Every download client type ROMarr supports, with its fields and default port.",
|
||||
"schema": _obj({}),
|
||||
"write": False,
|
||||
"fn": t_client_schema,
|
||||
},
|
||||
{
|
||||
"name": "download_client_save",
|
||||
"description": "Create or update a torrent/usenet download client. Credentials may be passed by reference (password_env / api_key_env) instead of inline.",
|
||||
"schema": _obj(
|
||||
{
|
||||
"type": {"type": "string", "description": "Client type, e.g. 'qbittorrent', 'sabnzbd', 'transmission'."},
|
||||
"name": {"type": "string"},
|
||||
"host": {"type": "string"},
|
||||
"port": {"type": "integer"},
|
||||
"use_ssl": {"type": "boolean"},
|
||||
"url_base": {"type": "string"},
|
||||
"username": {"type": "string"},
|
||||
"password": {"type": "string", "description": "Inline. Avoid: prefer password_env."},
|
||||
"password_env": {"type": "string"},
|
||||
"api_key": {"type": "string", "description": "Inline. Avoid: prefer api_key_env."},
|
||||
"api_key_env": {"type": "string", "description": "e.g. 'SABNZBD_API_KEY'."},
|
||||
"category": {"type": "string"},
|
||||
"id": {"type": "string", "description": "Existing client id to update."},
|
||||
"extra": {"type": "object", "description": "Any other fields the type needs, verbatim."},
|
||||
},
|
||||
["type"],
|
||||
),
|
||||
"write": True,
|
||||
"fn": t_client_save,
|
||||
},
|
||||
]
|
||||
|
||||
BY_NAME = {t["name"]: t for t in TOOLS}
|
||||
|
||||
@@ -28,15 +28,6 @@ buildNpmPackage rec {
|
||||
# working endpoint. Upstream publishes no sources in the npm tarball, so this patches
|
||||
# the compiled dist/ directly; drop it once upstream restores runScan().
|
||||
patch -p1 < ${./romm-mcp-scan.patch}
|
||||
|
||||
# RomM 5.x only deletes the file when POST /api/roms/delete carries delete_from_fs[];
|
||||
# 1.0.5 exposes no delete tool at all (client.deleteRoms sends roms[] alone and no
|
||||
# tool calls it), so a cleanup from MCP was impossible. This patch adds
|
||||
# romm_delete_rom (row + file, delete_from_fs on by default) and
|
||||
# romm_delete_rom_file (drop one duplicate of a multi-file ROM). Both are pure
|
||||
# insertions guarded by confirm_delete, and both were exercised against RomM 5.4.1:
|
||||
# dist-only again, so drop the patch when upstream ships the tools.
|
||||
patch -p1 < ${./romm-mcp-delete.patch}
|
||||
'';
|
||||
|
||||
# dist/*.js (tsc output) ships inside the npm tarball, so there is nothing to
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
--- a/dist/client.js 1985-10-26 09:15:00.000000000 +0100
|
||||
+++ b/dist/client.js 2026-11-14 21:42:42.155986145 +0100
|
||||
@@ -132,0 +133,11 @@
|
||||
+ async deleteRomsFromFs(ids, confirm = false) {
|
||||
+ if (!confirm)
|
||||
+ throw new Error("Delete requires confirm=true. NEVER delete without explicit confirmation.");
|
||||
+ return this.request("/api/roms/delete", {
|
||||
+ method: "POST",
|
||||
+ body: JSON.stringify({ roms: ids, delete_from_fs: ids }),
|
||||
+ });
|
||||
+ }
|
||||
+ async deleteRomFile(romId, fileId) {
|
||||
+ return this.request("/api/roms/" + romId + "/files/" + fileId, { method: "DELETE" });
|
||||
+ }
|
||||
--- a/dist/server.js 1985-10-26 09:15:00.000000000 +0100
|
||||
+++ b/dist/server.js 2026-11-14 21:42:42.156429699 +0100
|
||||
@@ -481,0 +482,49 @@
|
||||
+ // ─── romm_delete_rom ─────────────────────────────
|
||||
+ // RomM 5.x splits "drop the row" from "drop the file": POST /api/roms/delete takes
|
||||
+ // roms[] plus delete_from_fs[]. Sending only roms[] leaves the file on disk and the
|
||||
+ // next library scan resurrects the entry, which is the opposite of a cleanup.
|
||||
+ server.tool("romm_delete_rom", "Delete ROMs from the library. delete_from_fs (default true) also removes the files on disk; without it RomM only drops the database rows and the next scan re-adds them. Requires confirm_delete=true.", {
|
||||
+ ids: z.array(z.number()).describe("ROM ids to delete (from romm_browse_roms or romm_search_roms)"),
|
||||
+ delete_from_fs: z.boolean().optional().describe("Also delete the files on disk (default true)"),
|
||||
+ confirm_delete: z.boolean().optional().describe("Must be true: deletion cannot be undone"),
|
||||
+ }, { readOnlyHint: false, destructiveHint: true, idempotentHint: true }, async (params) => {
|
||||
+ requireWrite();
|
||||
+ if (!params.confirm_delete)
|
||||
+ throw new Error("Delete requires confirm_delete=true. NEVER delete without explicit confirmation.");
|
||||
+ const ids = params.ids || [];
|
||||
+ if (ids.length === 0)
|
||||
+ throw new Error("ids must contain at least one ROM id");
|
||||
+ if (params.delete_from_fs === false) {
|
||||
+ await client.deleteRoms(ids, true);
|
||||
+ }
|
||||
+ else {
|
||||
+ await client.deleteRomsFromFs(ids, true);
|
||||
+ }
|
||||
+ return {
|
||||
+ content: [{
|
||||
+ type: "text",
|
||||
+ text: "Deleted " + ids.length + " ROM(s): " + ids.join(", ") + "\n" +
|
||||
+ (params.delete_from_fs === false
|
||||
+ ? "Database rows only: the files are still on disk and a rescan brings them back."
|
||||
+ : "Files removed from disk as well."),
|
||||
+ }],
|
||||
+ };
|
||||
+ });
|
||||
+ // ─── romm_delete_rom_file ───────────────────────────
|
||||
+ // For duplicates: remove one file of a ROM without touching the game entry itself.
|
||||
+ server.tool("romm_delete_rom_file", "Delete ONE file belonging to a ROM, e.g. a duplicate copy, without removing the game entry. File ids come from romm_get_rom. Requires confirm_delete=true.", {
|
||||
+ rom_id: z.number().describe("ROM id"),
|
||||
+ file_id: z.number().describe("ROM file id"),
|
||||
+ confirm_delete: z.boolean().optional().describe("Must be true: deletion cannot be undone"),
|
||||
+ }, { readOnlyHint: false, destructiveHint: true, idempotentHint: true }, async (params) => {
|
||||
+ requireWrite();
|
||||
+ if (!params.confirm_delete)
|
||||
+ throw new Error("Delete requires confirm_delete=true.");
|
||||
+ await client.deleteRomFile(params.rom_id, params.file_id);
|
||||
+ return {
|
||||
+ content: [{
|
||||
+ type: "text",
|
||||
+ text: "Deleted file #" + params.file_id + " from ROM #" + params.rom_id,
|
||||
+ }],
|
||||
+ };
|
||||
+ });
|
||||
Reference in new issue
Block a user