@orellbuehler/sonarr-mcp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +131 -0
- package/dist/config.js +19 -0
- package/dist/index.js +13 -0
- package/dist/server.js +33 -0
- package/dist/sonarr/client.js +73 -0
- package/dist/sonarr/format.js +108 -0
- package/dist/tools/blocklist.js +47 -0
- package/dist/tools/calendar.js +38 -0
- package/dist/tools/commands.js +142 -0
- package/dist/tools/episodes.js +129 -0
- package/dist/tools/history.js +96 -0
- package/dist/tools/organization.js +158 -0
- package/dist/tools/profiles.js +203 -0
- package/dist/tools/providers.js +130 -0
- package/dist/tools/queue.js +138 -0
- package/dist/tools/releases.js +95 -0
- package/dist/tools/series.js +287 -0
- package/dist/tools/settings.js +74 -0
- package/dist/tools/system.js +100 -0
- package/dist/tools/wanted.js +60 -0
- package/package.json +70 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ok, err } from "../sonarr/format.js";
|
|
3
|
+
const kinds = [
|
|
4
|
+
{
|
|
5
|
+
path: "indexer",
|
|
6
|
+
singular: "indexer",
|
|
7
|
+
plural: "indexers",
|
|
8
|
+
label: "indexer",
|
|
9
|
+
extra: "enableRss, enableAutomaticSearch, enableInteractiveSearch, priority, protocol",
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
path: "downloadclient",
|
|
13
|
+
singular: "download_client",
|
|
14
|
+
plural: "download_clients",
|
|
15
|
+
label: "download client",
|
|
16
|
+
extra: "enable, protocol, priority, removeCompletedDownloads, removeFailedDownloads",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
path: "importlist",
|
|
20
|
+
singular: "import_list",
|
|
21
|
+
plural: "import_lists",
|
|
22
|
+
label: "import list",
|
|
23
|
+
extra: "enableAutomaticAdd, shouldMonitor, rootFolderPath, qualityProfileId, seriesType",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
path: "notification",
|
|
27
|
+
singular: "notification",
|
|
28
|
+
plural: "notifications",
|
|
29
|
+
label: "notification connection",
|
|
30
|
+
extra: "onGrab, onDownload, onUpgrade, onHealthIssue and the other event toggles",
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
function summarizeProvider(p) {
|
|
34
|
+
const { fields: _fields, presets: _presets, ...rest } = p;
|
|
35
|
+
return rest;
|
|
36
|
+
}
|
|
37
|
+
export function registerProviderTools(server, client) {
|
|
38
|
+
for (const kind of kinds) {
|
|
39
|
+
server.tool(`list_${kind.plural}`, `List the configured ${kind.label}s. Secret field values are masked by Sonarr; the 'fields' array is omitted here — use get_${kind.singular} for it.`, {}, async () => {
|
|
40
|
+
try {
|
|
41
|
+
const data = (await client.get(`/api/v3/${kind.path}`));
|
|
42
|
+
return ok({ count: data.length, [kind.plural]: data.map(summarizeProvider) });
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
return err(e);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
server.tool(`get_${kind.singular}`, `Get one ${kind.label} including its full 'fields' array (the implementation-specific settings).`, { id: z.number().describe(`${kind.label} id`) }, async ({ id }) => {
|
|
49
|
+
try {
|
|
50
|
+
return ok(await client.get(`/api/v3/${kind.path}/${id}`));
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
return err(e);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
server.tool(`get_${kind.singular}_schema`, `List every ${kind.label} implementation Sonarr supports, with the fields each one takes. Use this as the template for create_${kind.singular}.`, {
|
|
57
|
+
implementation: z
|
|
58
|
+
.string()
|
|
59
|
+
.optional()
|
|
60
|
+
.describe("Only the schema for this implementation, e.g. 'Newznab' or 'QBittorrent'"),
|
|
61
|
+
}, async ({ implementation }) => {
|
|
62
|
+
try {
|
|
63
|
+
const data = (await client.get(`/api/v3/${kind.path}/schema`));
|
|
64
|
+
if (implementation) {
|
|
65
|
+
const q = implementation.toLowerCase();
|
|
66
|
+
const match = data.filter((s) => String(s.implementation ?? "").toLowerCase() === q ||
|
|
67
|
+
String(s.implementationName ?? "").toLowerCase() === q);
|
|
68
|
+
return ok({ count: match.length, schemas: match });
|
|
69
|
+
}
|
|
70
|
+
return ok({
|
|
71
|
+
count: data.length,
|
|
72
|
+
implementations: data.map((s) => ({
|
|
73
|
+
implementation: s.implementation,
|
|
74
|
+
implementationName: s.implementationName,
|
|
75
|
+
configContract: s.configContract,
|
|
76
|
+
infoLink: s.infoLink,
|
|
77
|
+
})),
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
return err(e);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
server.tool(`create_${kind.singular}`, `Add a new ${kind.label}. Build the body from get_${kind.singular}_schema: it needs name, implementation, configContract and the fields array, plus ${kind.extra}.`, {
|
|
85
|
+
config: z
|
|
86
|
+
.record(z.unknown())
|
|
87
|
+
.describe(`Full ${kind.label} resource object, based on the schema`),
|
|
88
|
+
}, async ({ config }) => {
|
|
89
|
+
try {
|
|
90
|
+
return ok(await client.post(`/api/v3/${kind.path}`, config));
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
return err(e);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
server.tool(`update_${kind.singular}`, `Update an existing ${kind.label}. Fetch it with get_${kind.singular} first, change what you need and send the whole object back.`, {
|
|
97
|
+
id: z.number().describe(`${kind.label} id`),
|
|
98
|
+
config: z.record(z.unknown()).describe(`Full ${kind.label} resource object including id`),
|
|
99
|
+
}, async ({ id, config }) => {
|
|
100
|
+
try {
|
|
101
|
+
return ok(await client.put(`/api/v3/${kind.path}/${id}`, { ...config, id }));
|
|
102
|
+
}
|
|
103
|
+
catch (e) {
|
|
104
|
+
return err(e);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
server.tool(`delete_${kind.singular}`, `Delete a ${kind.label}.`, { id: z.number().describe(`${kind.label} id`) }, async ({ id }) => {
|
|
108
|
+
try {
|
|
109
|
+
return ok(await client.delete(`/api/v3/${kind.path}/${id}`));
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
return err(e);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
server.tool(`test_${kind.singular}`, `Test a ${kind.label} configuration without saving it. Pass a config object to test a draft, or an id to test an existing one.`, {
|
|
116
|
+
id: z.number().optional().describe(`Existing ${kind.label} id to test`),
|
|
117
|
+
config: z.record(z.unknown()).optional().describe("Draft resource object to test instead"),
|
|
118
|
+
}, async ({ id, config }) => {
|
|
119
|
+
try {
|
|
120
|
+
if (!config && id === undefined)
|
|
121
|
+
throw new Error("Pass either id or config");
|
|
122
|
+
const body = config ?? (await client.get(`/api/v3/${kind.path}/${id}`));
|
|
123
|
+
return ok(await client.post(`/api/v3/${kind.path}/test`, body));
|
|
124
|
+
}
|
|
125
|
+
catch (e) {
|
|
126
|
+
return err(e);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { buildQS, ok, err } from "../sonarr/format.js";
|
|
3
|
+
const sortDirection = ["default", "ascending", "descending"];
|
|
4
|
+
export function registerQueueTools(server, client) {
|
|
5
|
+
server.tool("get_queue", "List the download queue — everything Sonarr is currently downloading or waiting to import, with progress, status and any error messages.", {
|
|
6
|
+
page: z.number().optional().describe("Page number (default 1)"),
|
|
7
|
+
page_size: z.number().optional().describe("Items per page (default 10 on the Sonarr side)"),
|
|
8
|
+
sort_key: z.string().optional().describe("Field to sort by, e.g. 'timeleft', 'progress'"),
|
|
9
|
+
sort_direction: z.enum(sortDirection).optional().describe("Sort direction"),
|
|
10
|
+
series_ids: z.array(z.number()).optional().describe("Only items for these series ids"),
|
|
11
|
+
protocol: z.enum(["unknown", "usenet", "torrent"]).optional().describe("Filter by protocol"),
|
|
12
|
+
status: z
|
|
13
|
+
.array(z.string())
|
|
14
|
+
.optional()
|
|
15
|
+
.describe("Filter by queue status, e.g. ['downloading', 'completed', 'warning']"),
|
|
16
|
+
include_unknown_series_items: z
|
|
17
|
+
.boolean()
|
|
18
|
+
.optional()
|
|
19
|
+
.describe("Include downloads Sonarr could not map to a series"),
|
|
20
|
+
include_series: z.boolean().optional().describe("Include the parent series object"),
|
|
21
|
+
include_episode: z.boolean().optional().describe("Include the episode object"),
|
|
22
|
+
}, async ({ page, page_size, sort_key, sort_direction, series_ids, protocol, status, include_unknown_series_items, include_series, include_episode, }) => {
|
|
23
|
+
try {
|
|
24
|
+
const qs = buildQS({
|
|
25
|
+
page,
|
|
26
|
+
pageSize: page_size,
|
|
27
|
+
sortKey: sort_key,
|
|
28
|
+
sortDirection: sort_direction,
|
|
29
|
+
seriesIds: series_ids,
|
|
30
|
+
protocol,
|
|
31
|
+
status,
|
|
32
|
+
includeUnknownSeriesItems: include_unknown_series_items,
|
|
33
|
+
includeSeries: include_series,
|
|
34
|
+
includeEpisode: include_episode,
|
|
35
|
+
});
|
|
36
|
+
return ok(await client.get(`/api/v3/queue${qs}`));
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
return err(e);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
server.tool("get_queue_details", "Get the full, unpaged queue with per-episode detail. Useful for finding the queue item id of a specific episode.", {
|
|
43
|
+
series_id: z.number().optional().describe("Only items for this series id"),
|
|
44
|
+
episode_ids: z.array(z.number()).optional().describe("Only items for these episode ids"),
|
|
45
|
+
include_series: z.boolean().optional().describe("Include the parent series object"),
|
|
46
|
+
include_episode: z.boolean().optional().describe("Include the episode object"),
|
|
47
|
+
}, async ({ series_id, episode_ids, include_series, include_episode }) => {
|
|
48
|
+
try {
|
|
49
|
+
const qs = buildQS({
|
|
50
|
+
seriesId: series_id,
|
|
51
|
+
episodeIds: episode_ids,
|
|
52
|
+
includeSeries: include_series,
|
|
53
|
+
includeEpisode: include_episode,
|
|
54
|
+
});
|
|
55
|
+
const data = (await client.get(`/api/v3/queue/details${qs}`));
|
|
56
|
+
return ok({ count: data.length, items: data });
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
return err(e);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
server.tool("get_queue_status", "Get queue counts by state — total, errors, warnings and how many items need manual interaction.", {}, async () => {
|
|
63
|
+
try {
|
|
64
|
+
return ok(await client.get("/api/v3/queue/status"));
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
return err(e);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
server.tool("remove_queue_item", "Remove one item from the queue, optionally also removing it from the download client and blocklisting the release so it is not grabbed again.", {
|
|
71
|
+
id: z.number().describe("Queue item id"),
|
|
72
|
+
remove_from_client: z
|
|
73
|
+
.boolean()
|
|
74
|
+
.optional()
|
|
75
|
+
.describe("Also remove the download from the download client (default true)"),
|
|
76
|
+
blocklist: z
|
|
77
|
+
.boolean()
|
|
78
|
+
.optional()
|
|
79
|
+
.describe("Blocklist the release so Sonarr does not grab it again (default false)"),
|
|
80
|
+
skip_redownload: z
|
|
81
|
+
.boolean()
|
|
82
|
+
.optional()
|
|
83
|
+
.describe("Do not immediately search for a replacement (default false)"),
|
|
84
|
+
change_category: z
|
|
85
|
+
.boolean()
|
|
86
|
+
.optional()
|
|
87
|
+
.describe("Move the download to the post-import category instead of deleting it"),
|
|
88
|
+
}, async ({ id, remove_from_client, blocklist, skip_redownload, change_category }) => {
|
|
89
|
+
try {
|
|
90
|
+
const qs = buildQS({
|
|
91
|
+
removeFromClient: remove_from_client ?? true,
|
|
92
|
+
blocklist: blocklist ?? false,
|
|
93
|
+
skipRedownload: skip_redownload ?? false,
|
|
94
|
+
changeCategory: change_category,
|
|
95
|
+
});
|
|
96
|
+
return ok(await client.delete(`/api/v3/queue/${id}${qs}`));
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
return err(e);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
server.tool("remove_queue_items", "Remove several queue items at once, with the same options as remove_queue_item.", {
|
|
103
|
+
ids: z.array(z.number()).describe("Queue item ids"),
|
|
104
|
+
remove_from_client: z.boolean().optional().describe("Also remove from the download client"),
|
|
105
|
+
blocklist: z.boolean().optional().describe("Blocklist the releases"),
|
|
106
|
+
skip_redownload: z.boolean().optional().describe("Do not search for replacements"),
|
|
107
|
+
change_category: z.boolean().optional().describe("Move to the post-import category"),
|
|
108
|
+
}, async ({ ids, remove_from_client, blocklist, skip_redownload, change_category }) => {
|
|
109
|
+
try {
|
|
110
|
+
const qs = buildQS({
|
|
111
|
+
removeFromClient: remove_from_client ?? true,
|
|
112
|
+
blocklist: blocklist ?? false,
|
|
113
|
+
skipRedownload: skip_redownload ?? false,
|
|
114
|
+
changeCategory: change_category,
|
|
115
|
+
});
|
|
116
|
+
return ok(await client.delete(`/api/v3/queue/bulk${qs}`, { ids }));
|
|
117
|
+
}
|
|
118
|
+
catch (e) {
|
|
119
|
+
return err(e);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
server.tool("grab_queue_item", "Force Sonarr to import a queue item that is stuck pending or waiting on manual interaction.", { id: z.number().describe("Queue item id") }, async ({ id }) => {
|
|
123
|
+
try {
|
|
124
|
+
return ok(await client.post(`/api/v3/queue/grab/${id}`));
|
|
125
|
+
}
|
|
126
|
+
catch (e) {
|
|
127
|
+
return err(e);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
server.tool("grab_queue_items", "Force import of several stuck queue items at once.", { ids: z.array(z.number()).describe("Queue item ids") }, async ({ ids }) => {
|
|
131
|
+
try {
|
|
132
|
+
return ok(await client.post("/api/v3/queue/grab/bulk", { ids }));
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
return err(e);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { buildQS, ok, err, summarizeRelease } from "../sonarr/format.js";
|
|
3
|
+
export function registerReleaseTools(server, client) {
|
|
4
|
+
server.tool("search_releases", "Run an interactive indexer search and return the releases found, with quality, size, seeders, custom format score and any rejection reasons. Pass the guid and indexerId of the one you want to grab_release. This can take a while — indexers are queried live.", {
|
|
5
|
+
episode_id: z.number().optional().describe("Search for a single episode"),
|
|
6
|
+
series_id: z.number().optional().describe("Series id; combine with season_number"),
|
|
7
|
+
season_number: z
|
|
8
|
+
.number()
|
|
9
|
+
.optional()
|
|
10
|
+
.describe("Season number to search for; requires series_id"),
|
|
11
|
+
include_rejected: z
|
|
12
|
+
.boolean()
|
|
13
|
+
.optional()
|
|
14
|
+
.describe("Include releases Sonarr rejected (default true)"),
|
|
15
|
+
detailed: z.boolean().optional().describe("Return full release objects instead of summaries"),
|
|
16
|
+
}, async ({ episode_id, series_id, season_number, include_rejected, detailed }) => {
|
|
17
|
+
try {
|
|
18
|
+
const qs = buildQS({
|
|
19
|
+
episodeId: episode_id,
|
|
20
|
+
seriesId: series_id,
|
|
21
|
+
seasonNumber: season_number,
|
|
22
|
+
});
|
|
23
|
+
let rows = (await client.get(`/api/v3/release${qs}`));
|
|
24
|
+
if (include_rejected === false)
|
|
25
|
+
rows = rows.filter((r) => !r.rejected);
|
|
26
|
+
return ok({
|
|
27
|
+
count: rows.length,
|
|
28
|
+
releases: detailed ? rows : rows.map(summarizeRelease),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
return err(e);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
server.tool("grab_release", "Send a release from search_releases to the download client.", {
|
|
36
|
+
guid: z.string().describe("Release guid from search_releases"),
|
|
37
|
+
indexer_id: z.number().describe("indexerId of the release from search_releases"),
|
|
38
|
+
}, async ({ guid, indexer_id }) => {
|
|
39
|
+
try {
|
|
40
|
+
return ok(await client.post("/api/v3/release", { guid, indexerId: indexer_id }));
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
return err(e);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
server.tool("get_manual_import_candidates", "List files in a folder or a stuck download with the series and episodes Sonarr would map them to, plus any rejection reasons. Use this to diagnose imports that need manual interaction.", {
|
|
47
|
+
folder: z.string().optional().describe("Absolute path of a folder to inspect"),
|
|
48
|
+
download_id: z.string().optional().describe("Download client id of a stuck download"),
|
|
49
|
+
series_id: z.number().optional().describe("Force mapping to this series id"),
|
|
50
|
+
season_number: z.number().optional().describe("Force mapping to this season number"),
|
|
51
|
+
filter_existing_files: z
|
|
52
|
+
.boolean()
|
|
53
|
+
.optional()
|
|
54
|
+
.describe("Hide files that are already in the library (default true)"),
|
|
55
|
+
}, async ({ folder, download_id, series_id, season_number, filter_existing_files }) => {
|
|
56
|
+
try {
|
|
57
|
+
const qs = buildQS({
|
|
58
|
+
folder,
|
|
59
|
+
downloadId: download_id,
|
|
60
|
+
seriesId: series_id,
|
|
61
|
+
seasonNumber: season_number,
|
|
62
|
+
filterExistingFiles: filter_existing_files,
|
|
63
|
+
});
|
|
64
|
+
const data = (await client.get(`/api/v3/manualimport${qs}`));
|
|
65
|
+
return ok({ count: data.length, items: data });
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
return err(e);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
server.tool("get_rename_preview", "Preview which existing files would be renamed under the current naming configuration, showing the old and new paths. Run the RenameFiles command to apply.", {
|
|
72
|
+
series_id: z.number().describe("Sonarr series id"),
|
|
73
|
+
season_number: z.number().optional().describe("Only this season number"),
|
|
74
|
+
}, async ({ series_id, season_number }) => {
|
|
75
|
+
try {
|
|
76
|
+
const qs = buildQS({ seriesId: series_id, seasonNumber: season_number });
|
|
77
|
+
const data = (await client.get(`/api/v3/rename${qs}`));
|
|
78
|
+
return ok({ count: data.length, files: data });
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
return err(e);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
server.tool("parse_release_title", "Parse a release title or file path the way Sonarr does, showing the series, season and episodes it maps to and the detected quality.", {
|
|
85
|
+
title: z.string().optional().describe("Release title to parse"),
|
|
86
|
+
path: z.string().optional().describe("File path to parse instead of a title"),
|
|
87
|
+
}, async ({ title, path }) => {
|
|
88
|
+
try {
|
|
89
|
+
return ok(await client.get(`/api/v3/parse${buildQS({ title, path })}`));
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
return err(e);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { buildQS, ok, err, pruneUndefined, summarizeSeries, } from "../sonarr/format.js";
|
|
3
|
+
const monitorTypes = [
|
|
4
|
+
"unknown",
|
|
5
|
+
"all",
|
|
6
|
+
"future",
|
|
7
|
+
"missing",
|
|
8
|
+
"existing",
|
|
9
|
+
"firstSeason",
|
|
10
|
+
"lastSeason",
|
|
11
|
+
"latestSeason",
|
|
12
|
+
"pilot",
|
|
13
|
+
"recent",
|
|
14
|
+
"monitorSpecials",
|
|
15
|
+
"unmonitorSpecials",
|
|
16
|
+
"none",
|
|
17
|
+
"skip",
|
|
18
|
+
];
|
|
19
|
+
const seriesTypes = ["standard", "daily", "anime"];
|
|
20
|
+
export function registerSeriesTools(server, client) {
|
|
21
|
+
server.tool("list_series", "List all series in the Sonarr library as compact summaries (id, title, year, status, monitored, quality profile, path, statistics). Use get_series for the full object with seasons, images and alternate titles.", {
|
|
22
|
+
search: z
|
|
23
|
+
.string()
|
|
24
|
+
.optional()
|
|
25
|
+
.describe("Case-insensitive substring matched against the series title"),
|
|
26
|
+
monitored: z.boolean().optional().describe("Only monitored (true) or unmonitored (false)"),
|
|
27
|
+
tvdb_id: z.number().optional().describe("Look up a single series by its TVDB id"),
|
|
28
|
+
detailed: z
|
|
29
|
+
.boolean()
|
|
30
|
+
.optional()
|
|
31
|
+
.describe("Return the full series objects instead of summaries (large payload)"),
|
|
32
|
+
}, async ({ search, monitored, tvdb_id, detailed }) => {
|
|
33
|
+
try {
|
|
34
|
+
const data = (await client.get(`/api/v3/series${buildQS({ tvdbId: tvdb_id })}`));
|
|
35
|
+
let rows = data;
|
|
36
|
+
if (search) {
|
|
37
|
+
const q = search.toLowerCase();
|
|
38
|
+
rows = rows.filter((s) => String(s.title ?? "")
|
|
39
|
+
.toLowerCase()
|
|
40
|
+
.includes(q));
|
|
41
|
+
}
|
|
42
|
+
if (monitored !== undefined)
|
|
43
|
+
rows = rows.filter((s) => s.monitored === monitored);
|
|
44
|
+
return ok({ count: rows.length, series: detailed ? rows : rows.map(summarizeSeries) });
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
return err(e);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
server.tool("get_series", "Get the full series object for one series, including seasons with their per-season statistics and monitored flags.", {
|
|
51
|
+
id: z.number().describe("Sonarr series id (not the TVDB id)"),
|
|
52
|
+
include_season_images: z.boolean().optional().describe("Include per-season image URLs"),
|
|
53
|
+
}, async ({ id, include_season_images }) => {
|
|
54
|
+
try {
|
|
55
|
+
return ok(await client.get(`/api/v3/series/${id}${buildQS({ includeSeasonImages: include_season_images })}`));
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
return err(e);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
server.tool("lookup_series", "Search TVDB for series to add, by title or by an id term such as 'tvdb:121361' or 'imdb:tt0944947'. Returns candidates with tvdbId, title, year and overview — pass the tvdbId to add_series.", { term: z.string().describe("Search term, e.g. 'Breaking Bad' or 'tvdb:81189'") }, async ({ term }) => {
|
|
62
|
+
try {
|
|
63
|
+
const data = (await client.get(`/api/v3/series/lookup${buildQS({ term })}`));
|
|
64
|
+
return ok({
|
|
65
|
+
count: data.length,
|
|
66
|
+
results: data.map((s) => pruneUndefined({
|
|
67
|
+
title: s.title,
|
|
68
|
+
year: s.year,
|
|
69
|
+
tvdbId: s.tvdbId,
|
|
70
|
+
imdbId: s.imdbId,
|
|
71
|
+
status: s.status,
|
|
72
|
+
network: s.network,
|
|
73
|
+
seriesType: s.seriesType,
|
|
74
|
+
runtime: s.runtime,
|
|
75
|
+
overview: s.overview,
|
|
76
|
+
seasonCount: s.seasons?.length,
|
|
77
|
+
alreadyAdded: s.id ? s.id : undefined,
|
|
78
|
+
})),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
return err(e);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
server.tool("add_series", "Add a new series to the library by TVDB id. Resolves the series metadata via lookup, then posts it with the given root folder and quality profile. Use list_root_folders and list_quality_profiles first to get valid ids.", {
|
|
86
|
+
tvdb_id: z.number().describe("TVDB id of the series, from lookup_series"),
|
|
87
|
+
quality_profile_id: z.number().describe("Quality profile id, from list_quality_profiles"),
|
|
88
|
+
root_folder_path: z.string().describe("Root folder path, from list_root_folders"),
|
|
89
|
+
monitored: z.boolean().optional().describe("Monitor the series (default true)"),
|
|
90
|
+
monitor: z
|
|
91
|
+
.enum(monitorTypes)
|
|
92
|
+
.optional()
|
|
93
|
+
.describe("Which episodes to monitor when adding (default 'all')"),
|
|
94
|
+
season_folder: z.boolean().optional().describe("Use season folders (default true)"),
|
|
95
|
+
series_type: z.enum(seriesTypes).optional().describe("Series type (default 'standard')"),
|
|
96
|
+
search_for_missing_episodes: z
|
|
97
|
+
.boolean()
|
|
98
|
+
.optional()
|
|
99
|
+
.describe("Start a search for missing episodes right after adding (default false)"),
|
|
100
|
+
search_for_cutoff_unmet_episodes: z
|
|
101
|
+
.boolean()
|
|
102
|
+
.optional()
|
|
103
|
+
.describe("Start a search for cutoff unmet episodes right after adding"),
|
|
104
|
+
tags: z.array(z.number()).optional().describe("Tag ids to apply, from list_tags"),
|
|
105
|
+
}, async ({ tvdb_id, quality_profile_id, root_folder_path, monitored, monitor, season_folder, series_type, search_for_missing_episodes, search_for_cutoff_unmet_episodes, tags, }) => {
|
|
106
|
+
try {
|
|
107
|
+
const found = (await client.get(`/api/v3/series/lookup${buildQS({ term: `tvdb:${tvdb_id}` })}`));
|
|
108
|
+
const match = found.find((s) => s.tvdbId === tvdb_id) ?? found[0];
|
|
109
|
+
if (!match)
|
|
110
|
+
throw new Error(`No series found on TVDB for tvdbId ${tvdb_id}`);
|
|
111
|
+
const body = {
|
|
112
|
+
...match,
|
|
113
|
+
qualityProfileId: quality_profile_id,
|
|
114
|
+
rootFolderPath: root_folder_path,
|
|
115
|
+
monitored: monitored ?? true,
|
|
116
|
+
seasonFolder: season_folder ?? true,
|
|
117
|
+
...(series_type ? { seriesType: series_type } : {}),
|
|
118
|
+
...(tags ? { tags } : {}),
|
|
119
|
+
addOptions: {
|
|
120
|
+
monitor: monitor ?? "all",
|
|
121
|
+
searchForMissingEpisodes: search_for_missing_episodes ?? false,
|
|
122
|
+
searchForCutoffUnmetEpisodes: search_for_cutoff_unmet_episodes ?? false,
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
return ok(summarizeSeries((await client.post("/api/v3/series", body))));
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
return err(e);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
server.tool("update_series", "Update settings on an existing series. Fetches the current series, merges the given fields and puts it back — only the fields you pass are changed.", {
|
|
132
|
+
id: z.number().describe("Sonarr series id"),
|
|
133
|
+
monitored: z.boolean().optional().describe("Monitor or unmonitor the series"),
|
|
134
|
+
quality_profile_id: z.number().optional().describe("New quality profile id"),
|
|
135
|
+
series_type: z.enum(seriesTypes).optional().describe("New series type"),
|
|
136
|
+
season_folder: z.boolean().optional().describe("Use season folders"),
|
|
137
|
+
monitor_new_items: z
|
|
138
|
+
.enum(["all", "none"])
|
|
139
|
+
.optional()
|
|
140
|
+
.describe("Whether newly added seasons are monitored"),
|
|
141
|
+
root_folder_path: z.string().optional().describe("New root folder path"),
|
|
142
|
+
path: z.string().optional().describe("New series folder path"),
|
|
143
|
+
tags: z.array(z.number()).optional().describe("Replace the tag ids on this series"),
|
|
144
|
+
move_files: z
|
|
145
|
+
.boolean()
|
|
146
|
+
.optional()
|
|
147
|
+
.describe("Move existing files when the path or root folder changes (default false)"),
|
|
148
|
+
}, async ({ id, monitored, quality_profile_id, series_type, season_folder, monitor_new_items, root_folder_path, path, tags, move_files, }) => {
|
|
149
|
+
try {
|
|
150
|
+
const current = (await client.get(`/api/v3/series/${id}`));
|
|
151
|
+
const body = {
|
|
152
|
+
...current,
|
|
153
|
+
...pruneUndefined({
|
|
154
|
+
monitored,
|
|
155
|
+
qualityProfileId: quality_profile_id,
|
|
156
|
+
seriesType: series_type,
|
|
157
|
+
seasonFolder: season_folder,
|
|
158
|
+
monitorNewItems: monitor_new_items,
|
|
159
|
+
rootFolderPath: root_folder_path,
|
|
160
|
+
path,
|
|
161
|
+
tags,
|
|
162
|
+
}),
|
|
163
|
+
};
|
|
164
|
+
const res = await client.put(`/api/v3/series/${id}${buildQS({ moveFiles: move_files })}`, body);
|
|
165
|
+
return ok(summarizeSeries(res));
|
|
166
|
+
}
|
|
167
|
+
catch (e) {
|
|
168
|
+
return err(e);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
server.tool("delete_series", "Remove a series from the library. Optionally delete its files from disk and add an import list exclusion so lists do not re-add it.", {
|
|
172
|
+
id: z.number().describe("Sonarr series id"),
|
|
173
|
+
delete_files: z
|
|
174
|
+
.boolean()
|
|
175
|
+
.optional()
|
|
176
|
+
.describe("Also delete the series folder and files from disk (default false)"),
|
|
177
|
+
add_import_list_exclusion: z
|
|
178
|
+
.boolean()
|
|
179
|
+
.optional()
|
|
180
|
+
.describe("Add an import list exclusion for this series (default false)"),
|
|
181
|
+
}, async ({ id, delete_files, add_import_list_exclusion }) => {
|
|
182
|
+
try {
|
|
183
|
+
return ok(await client.delete(`/api/v3/series/${id}${buildQS({
|
|
184
|
+
deleteFiles: delete_files,
|
|
185
|
+
addImportListExclusion: add_import_list_exclusion,
|
|
186
|
+
})}`));
|
|
187
|
+
}
|
|
188
|
+
catch (e) {
|
|
189
|
+
return err(e);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
server.tool("edit_series_bulk", "Apply the same change to many series at once (the series editor): monitoring, quality profile, series type, season folders, root folder or tags.", {
|
|
193
|
+
series_ids: z.array(z.number()).describe("Sonarr series ids to edit"),
|
|
194
|
+
monitored: z.boolean().optional().describe("Monitor or unmonitor all of them"),
|
|
195
|
+
quality_profile_id: z.number().optional().describe("Quality profile id to set"),
|
|
196
|
+
series_type: z.enum(seriesTypes).optional().describe("Series type to set"),
|
|
197
|
+
season_folder: z.boolean().optional().describe("Use season folders"),
|
|
198
|
+
monitor_new_items: z.enum(["all", "none"]).optional().describe("Monitoring for new seasons"),
|
|
199
|
+
root_folder_path: z.string().optional().describe("Move all of them to this root folder"),
|
|
200
|
+
tags: z.array(z.number()).optional().describe("Tag ids to add, remove or replace"),
|
|
201
|
+
apply_tags: z
|
|
202
|
+
.enum(["add", "remove", "replace"])
|
|
203
|
+
.optional()
|
|
204
|
+
.describe("How to apply 'tags' (default 'add')"),
|
|
205
|
+
move_files: z
|
|
206
|
+
.boolean()
|
|
207
|
+
.optional()
|
|
208
|
+
.describe("Move files when changing the root folder (default false)"),
|
|
209
|
+
}, async ({ series_ids, monitored, quality_profile_id, series_type, season_folder, monitor_new_items, root_folder_path, tags, apply_tags, move_files, }) => {
|
|
210
|
+
try {
|
|
211
|
+
const body = pruneUndefined({
|
|
212
|
+
seriesIds: series_ids,
|
|
213
|
+
monitored,
|
|
214
|
+
qualityProfileId: quality_profile_id,
|
|
215
|
+
seriesType: series_type,
|
|
216
|
+
seasonFolder: season_folder,
|
|
217
|
+
monitorNewItems: monitor_new_items,
|
|
218
|
+
rootFolderPath: root_folder_path,
|
|
219
|
+
tags,
|
|
220
|
+
applyTags: tags ? (apply_tags ?? "add") : undefined,
|
|
221
|
+
moveFiles: move_files,
|
|
222
|
+
});
|
|
223
|
+
const res = (await client.put("/api/v3/series/editor", body));
|
|
224
|
+
return ok({ count: res.length, series: res.map(summarizeSeries) });
|
|
225
|
+
}
|
|
226
|
+
catch (e) {
|
|
227
|
+
return err(e);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
server.tool("delete_series_bulk", "Remove many series from the library at once, optionally deleting their files and adding import list exclusions.", {
|
|
231
|
+
series_ids: z.array(z.number()).describe("Sonarr series ids to delete"),
|
|
232
|
+
delete_files: z.boolean().optional().describe("Also delete files from disk (default false)"),
|
|
233
|
+
add_import_list_exclusion: z
|
|
234
|
+
.boolean()
|
|
235
|
+
.optional()
|
|
236
|
+
.describe("Add import list exclusions (default false)"),
|
|
237
|
+
}, async ({ series_ids, delete_files, add_import_list_exclusion }) => {
|
|
238
|
+
try {
|
|
239
|
+
return ok(await client.delete("/api/v3/series/editor", {
|
|
240
|
+
seriesIds: series_ids,
|
|
241
|
+
deleteFiles: delete_files ?? false,
|
|
242
|
+
addImportListExclusion: add_import_list_exclusion ?? false,
|
|
243
|
+
}));
|
|
244
|
+
}
|
|
245
|
+
catch (e) {
|
|
246
|
+
return err(e);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
server.tool("get_series_folder", "Get the folder path Sonarr would use for a series, given the current naming configuration.", { id: z.number().describe("Sonarr series id") }, async ({ id }) => {
|
|
250
|
+
try {
|
|
251
|
+
return ok(await client.get(`/api/v3/series/${id}/folder`));
|
|
252
|
+
}
|
|
253
|
+
catch (e) {
|
|
254
|
+
return err(e);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
server.tool("set_season_monitored", "Monitor or unmonitor whole seasons of a series. Pass season numbers (0 is specials); omit them to apply to every season.", {
|
|
258
|
+
series_id: z.number().describe("Sonarr series id"),
|
|
259
|
+
monitored: z.boolean().describe("true to monitor, false to unmonitor"),
|
|
260
|
+
season_numbers: z
|
|
261
|
+
.array(z.number())
|
|
262
|
+
.optional()
|
|
263
|
+
.describe("Season numbers to change; all seasons when omitted"),
|
|
264
|
+
}, async ({ series_id, monitored, season_numbers }) => {
|
|
265
|
+
try {
|
|
266
|
+
const current = (await client.get(`/api/v3/series/${series_id}`));
|
|
267
|
+
const seasons = (current.seasons ?? []).map((s) => season_numbers === undefined || season_numbers.includes(s.seasonNumber)
|
|
268
|
+
? { ...s, monitored }
|
|
269
|
+
: s);
|
|
270
|
+
const res = (await client.put(`/api/v3/series/${series_id}`, {
|
|
271
|
+
...current,
|
|
272
|
+
seasons,
|
|
273
|
+
}));
|
|
274
|
+
return ok({
|
|
275
|
+
id: res.id,
|
|
276
|
+
title: res.title,
|
|
277
|
+
seasons: (res.seasons ?? []).map((s) => ({
|
|
278
|
+
seasonNumber: s.seasonNumber,
|
|
279
|
+
monitored: s.monitored,
|
|
280
|
+
})),
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
catch (e) {
|
|
284
|
+
return err(e);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
}
|