@orellbuehler/sonarr-mcp 0.1.0 → 0.2.1
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/README.md +7 -3
- package/dist/server.js +1 -1
- package/dist/sonarr/client.js +3 -1
- package/dist/sonarr/format.js +91 -0
- package/dist/tools/blocklist.js +4 -4
- package/dist/tools/calendar.js +2 -2
- package/dist/tools/commands.js +41 -21
- package/dist/tools/episodes.js +11 -11
- package/dist/tools/history.js +6 -6
- package/dist/tools/organization.js +17 -17
- package/dist/tools/profiles.js +34 -28
- package/dist/tools/providers.js +44 -23
- package/dist/tools/queue.js +19 -16
- package/dist/tools/releases.js +7 -7
- package/dist/tools/series.js +15 -15
- package/dist/tools/settings.js +18 -7
- package/dist/tools/system.js +15 -10
- package/dist/tools/wanted.js +3 -3
- package/package.json +4 -4
package/dist/tools/profiles.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { ok, err } from "../sonarr/format.js";
|
|
2
|
+
import { ok, err, DELETE, READ, UPDATE, WRITE } from "../sonarr/format.js";
|
|
3
3
|
export function registerProfileTools(server, client) {
|
|
4
4
|
server.tool("list_quality_profiles", "List quality profiles with their id, name, cutoff and the qualities each one allows. Series are assigned a profile by id.", {
|
|
5
5
|
detailed: z
|
|
6
6
|
.boolean()
|
|
7
7
|
.optional()
|
|
8
8
|
.describe("Include the full items and formatItems arrays (large payload)"),
|
|
9
|
-
}, async ({ detailed }) => {
|
|
9
|
+
}, READ, async ({ detailed }) => {
|
|
10
10
|
try {
|
|
11
11
|
const data = (await client.get("/api/v3/qualityprofile"));
|
|
12
12
|
if (detailed)
|
|
@@ -30,7 +30,7 @@ export function registerProfileTools(server, client) {
|
|
|
30
30
|
return err(e);
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
|
-
server.tool("get_quality_profile", "Get one quality profile in full, including every quality item and custom format score.", { id: z.number().describe("Quality profile id") }, async ({ id }) => {
|
|
33
|
+
server.tool("get_quality_profile", "Get one quality profile in full, including every quality item and custom format score.", { id: z.number().int().positive().describe("Quality profile id") }, READ, async ({ id }) => {
|
|
34
34
|
try {
|
|
35
35
|
return ok(await client.get(`/api/v3/qualityprofile/${id}`));
|
|
36
36
|
}
|
|
@@ -38,7 +38,7 @@ export function registerProfileTools(server, client) {
|
|
|
38
38
|
return err(e);
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
|
-
server.tool("get_quality_profile_schema", "Get a blank quality profile with every quality Sonarr knows about — the template for create_quality_profile.", {}, async () => {
|
|
41
|
+
server.tool("get_quality_profile_schema", "Get a blank quality profile with every quality Sonarr knows about — the template for create_quality_profile.", {}, READ, async () => {
|
|
42
42
|
try {
|
|
43
43
|
return ok(await client.get("/api/v3/qualityprofile/schema"));
|
|
44
44
|
}
|
|
@@ -46,7 +46,7 @@ export function registerProfileTools(server, client) {
|
|
|
46
46
|
return err(e);
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
|
-
server.tool("create_quality_profile", "Create a quality profile. Start from get_quality_profile_schema, set name, cutoff and which items are allowed.", { profile: z.record(z.unknown()).describe("Full quality profile object") }, async ({ profile }) => {
|
|
49
|
+
server.tool("create_quality_profile", "Create a quality profile. Start from get_quality_profile_schema, set name, cutoff and which items are allowed.", { profile: z.record(z.string(), z.unknown()).describe("Full quality profile object") }, WRITE, async ({ profile }) => {
|
|
50
50
|
try {
|
|
51
51
|
return ok(await client.post("/api/v3/qualityprofile", profile));
|
|
52
52
|
}
|
|
@@ -55,9 +55,11 @@ export function registerProfileTools(server, client) {
|
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
server.tool("update_quality_profile", "Update a quality profile. Fetch it with get_quality_profile, change what you need and send the whole object back.", {
|
|
58
|
-
id: z.number().describe("Quality profile id"),
|
|
59
|
-
profile: z
|
|
60
|
-
|
|
58
|
+
id: z.number().int().positive().describe("Quality profile id"),
|
|
59
|
+
profile: z
|
|
60
|
+
.record(z.string(), z.unknown())
|
|
61
|
+
.describe("Full quality profile object including id"),
|
|
62
|
+
}, UPDATE, async ({ id, profile }) => {
|
|
61
63
|
try {
|
|
62
64
|
return ok(await client.put(`/api/v3/qualityprofile/${id}`, { ...profile, id }));
|
|
63
65
|
}
|
|
@@ -65,7 +67,7 @@ export function registerProfileTools(server, client) {
|
|
|
65
67
|
return err(e);
|
|
66
68
|
}
|
|
67
69
|
});
|
|
68
|
-
server.tool("delete_quality_profile", "Delete a quality profile. It must not be in use by any series.", { id: z.number().describe("Quality profile id") }, async ({ id }) => {
|
|
70
|
+
server.tool("delete_quality_profile", "Delete a quality profile. It must not be in use by any series.", { id: z.number().int().positive().describe("Quality profile id") }, DELETE, async ({ id }) => {
|
|
69
71
|
try {
|
|
70
72
|
return ok(await client.delete(`/api/v3/qualityprofile/${id}`));
|
|
71
73
|
}
|
|
@@ -73,7 +75,7 @@ export function registerProfileTools(server, client) {
|
|
|
73
75
|
return err(e);
|
|
74
76
|
}
|
|
75
77
|
});
|
|
76
|
-
server.tool("list_quality_definitions", "List quality definitions — the size limits (min, max, preferred MB per minute) Sonarr applies to each quality.", {}, async () => {
|
|
78
|
+
server.tool("list_quality_definitions", "List quality definitions — the size limits (min, max, preferred MB per minute) Sonarr applies to each quality.", {}, READ, async () => {
|
|
77
79
|
try {
|
|
78
80
|
const data = (await client.get("/api/v3/qualitydefinition"));
|
|
79
81
|
return ok({ count: data.length, definitions: data });
|
|
@@ -84,9 +86,9 @@ export function registerProfileTools(server, client) {
|
|
|
84
86
|
});
|
|
85
87
|
server.tool("update_quality_definitions", "Update the size limits of one or more quality definitions. Send the full definition objects from list_quality_definitions with minSize, maxSize or preferredSize changed.", {
|
|
86
88
|
definitions: z
|
|
87
|
-
.array(z.record(z.unknown()))
|
|
89
|
+
.array(z.record(z.string(), z.unknown()))
|
|
88
90
|
.describe("Full quality definition objects including id"),
|
|
89
|
-
}, async ({ definitions }) => {
|
|
91
|
+
}, UPDATE, async ({ definitions }) => {
|
|
90
92
|
try {
|
|
91
93
|
return ok(await client.put("/api/v3/qualitydefinition/update", definitions));
|
|
92
94
|
}
|
|
@@ -94,7 +96,7 @@ export function registerProfileTools(server, client) {
|
|
|
94
96
|
return err(e);
|
|
95
97
|
}
|
|
96
98
|
});
|
|
97
|
-
server.tool("list_custom_formats", "List custom formats with their specifications. Custom format scores in a quality profile decide which releases are preferred.", {}, async () => {
|
|
99
|
+
server.tool("list_custom_formats", "List custom formats with their specifications. Custom format scores in a quality profile decide which releases are preferred.", {}, READ, async () => {
|
|
98
100
|
try {
|
|
99
101
|
const data = (await client.get("/api/v3/customformat"));
|
|
100
102
|
return ok({ count: data.length, customFormats: data });
|
|
@@ -103,7 +105,7 @@ export function registerProfileTools(server, client) {
|
|
|
103
105
|
return err(e);
|
|
104
106
|
}
|
|
105
107
|
});
|
|
106
|
-
server.tool("get_custom_format", "Get one custom format with its full specification list.", { id: z.number().describe("Custom format id") }, async ({ id }) => {
|
|
108
|
+
server.tool("get_custom_format", "Get one custom format with its full specification list.", { id: z.number().int().positive().describe("Custom format id") }, READ, async ({ id }) => {
|
|
107
109
|
try {
|
|
108
110
|
return ok(await client.get(`/api/v3/customformat/${id}`));
|
|
109
111
|
}
|
|
@@ -111,7 +113,7 @@ export function registerProfileTools(server, client) {
|
|
|
111
113
|
return err(e);
|
|
112
114
|
}
|
|
113
115
|
});
|
|
114
|
-
server.tool("get_custom_format_schema", "List the specification types a custom format can use (release title regex, size, language, quality modifier, ...) with their fields.", {}, async () => {
|
|
116
|
+
server.tool("get_custom_format_schema", "List the specification types a custom format can use (release title regex, size, language, quality modifier, ...) with their fields.", {}, READ, async () => {
|
|
115
117
|
try {
|
|
116
118
|
return ok(await client.get("/api/v3/customformat/schema"));
|
|
117
119
|
}
|
|
@@ -119,7 +121,7 @@ export function registerProfileTools(server, client) {
|
|
|
119
121
|
return err(e);
|
|
120
122
|
}
|
|
121
123
|
});
|
|
122
|
-
server.tool("create_custom_format", "Create a custom format. Build the specifications from get_custom_format_schema.", { custom_format: z.record(z.unknown()).describe("Full custom format object") }, async ({ custom_format }) => {
|
|
124
|
+
server.tool("create_custom_format", "Create a custom format. Build the specifications from get_custom_format_schema.", { custom_format: z.record(z.string(), z.unknown()).describe("Full custom format object") }, WRITE, async ({ custom_format }) => {
|
|
123
125
|
try {
|
|
124
126
|
return ok(await client.post("/api/v3/customformat", custom_format));
|
|
125
127
|
}
|
|
@@ -128,9 +130,11 @@ export function registerProfileTools(server, client) {
|
|
|
128
130
|
}
|
|
129
131
|
});
|
|
130
132
|
server.tool("update_custom_format", "Update a custom format. Fetch it first and send the whole object back.", {
|
|
131
|
-
id: z.number().describe("Custom format id"),
|
|
132
|
-
custom_format: z
|
|
133
|
-
|
|
133
|
+
id: z.number().int().positive().describe("Custom format id"),
|
|
134
|
+
custom_format: z
|
|
135
|
+
.record(z.string(), z.unknown())
|
|
136
|
+
.describe("Full custom format object including id"),
|
|
137
|
+
}, UPDATE, async ({ id, custom_format }) => {
|
|
134
138
|
try {
|
|
135
139
|
return ok(await client.put(`/api/v3/customformat/${id}`, { ...custom_format, id }));
|
|
136
140
|
}
|
|
@@ -138,7 +142,7 @@ export function registerProfileTools(server, client) {
|
|
|
138
142
|
return err(e);
|
|
139
143
|
}
|
|
140
144
|
});
|
|
141
|
-
server.tool("delete_custom_format", "Delete a custom format.", { id: z.number().describe("Custom format id") }, async ({ id }) => {
|
|
145
|
+
server.tool("delete_custom_format", "Delete a custom format.", { id: z.number().int().positive().describe("Custom format id") }, DELETE, async ({ id }) => {
|
|
142
146
|
try {
|
|
143
147
|
return ok(await client.delete(`/api/v3/customformat/${id}`));
|
|
144
148
|
}
|
|
@@ -146,7 +150,7 @@ export function registerProfileTools(server, client) {
|
|
|
146
150
|
return err(e);
|
|
147
151
|
}
|
|
148
152
|
});
|
|
149
|
-
server.tool("list_release_profiles", "List release profiles — the required, ignored and preferred term rules applied to release titles.", {}, async () => {
|
|
153
|
+
server.tool("list_release_profiles", "List release profiles — the required, ignored and preferred term rules applied to release titles.", {}, READ, async () => {
|
|
150
154
|
try {
|
|
151
155
|
const data = (await client.get("/api/v3/releaseprofile"));
|
|
152
156
|
return ok({ count: data.length, releaseProfiles: data });
|
|
@@ -155,7 +159,7 @@ export function registerProfileTools(server, client) {
|
|
|
155
159
|
return err(e);
|
|
156
160
|
}
|
|
157
161
|
});
|
|
158
|
-
server.tool("create_release_profile", "Create a release profile, e.g. { name, enabled: true, required: [], ignored: ['x265'], indexerId: 0, tags: [] }.", { release_profile: z.record(z.unknown()).describe("Full release profile object") }, async ({ release_profile }) => {
|
|
162
|
+
server.tool("create_release_profile", "Create a release profile, e.g. { name, enabled: true, required: [], ignored: ['x265'], indexerId: 0, tags: [] }.", { release_profile: z.record(z.string(), z.unknown()).describe("Full release profile object") }, WRITE, async ({ release_profile }) => {
|
|
159
163
|
try {
|
|
160
164
|
return ok(await client.post("/api/v3/releaseprofile", release_profile));
|
|
161
165
|
}
|
|
@@ -164,9 +168,11 @@ export function registerProfileTools(server, client) {
|
|
|
164
168
|
}
|
|
165
169
|
});
|
|
166
170
|
server.tool("update_release_profile", "Update a release profile. Fetch it from list_release_profiles and send the whole object back.", {
|
|
167
|
-
id: z.number().describe("Release profile id"),
|
|
168
|
-
release_profile: z
|
|
169
|
-
|
|
171
|
+
id: z.number().int().positive().describe("Release profile id"),
|
|
172
|
+
release_profile: z
|
|
173
|
+
.record(z.string(), z.unknown())
|
|
174
|
+
.describe("Full release profile object including id"),
|
|
175
|
+
}, UPDATE, async ({ id, release_profile }) => {
|
|
170
176
|
try {
|
|
171
177
|
return ok(await client.put(`/api/v3/releaseprofile/${id}`, { ...release_profile, id }));
|
|
172
178
|
}
|
|
@@ -174,7 +180,7 @@ export function registerProfileTools(server, client) {
|
|
|
174
180
|
return err(e);
|
|
175
181
|
}
|
|
176
182
|
});
|
|
177
|
-
server.tool("delete_release_profile", "Delete a release profile.", { id: z.number().describe("Release profile id") }, async ({ id }) => {
|
|
183
|
+
server.tool("delete_release_profile", "Delete a release profile.", { id: z.number().int().positive().describe("Release profile id") }, DELETE, async ({ id }) => {
|
|
178
184
|
try {
|
|
179
185
|
return ok(await client.delete(`/api/v3/releaseprofile/${id}`));
|
|
180
186
|
}
|
|
@@ -182,7 +188,7 @@ export function registerProfileTools(server, client) {
|
|
|
182
188
|
return err(e);
|
|
183
189
|
}
|
|
184
190
|
});
|
|
185
|
-
server.tool("list_delay_profiles", "List delay profiles — how long Sonarr waits for a better release before grabbing, per protocol and tag.", {}, async () => {
|
|
191
|
+
server.tool("list_delay_profiles", "List delay profiles — how long Sonarr waits for a better release before grabbing, per protocol and tag.", {}, READ, async () => {
|
|
186
192
|
try {
|
|
187
193
|
const data = (await client.get("/api/v3/delayprofile"));
|
|
188
194
|
return ok({ count: data.length, delayProfiles: data });
|
|
@@ -191,7 +197,7 @@ export function registerProfileTools(server, client) {
|
|
|
191
197
|
return err(e);
|
|
192
198
|
}
|
|
193
199
|
});
|
|
194
|
-
server.tool("list_languages", "List the languages Sonarr knows, with the ids used in language profiles and episode file edits.", {}, async () => {
|
|
200
|
+
server.tool("list_languages", "List the languages Sonarr knows, with the ids used in language profiles and episode file edits.", {}, READ, async () => {
|
|
195
201
|
try {
|
|
196
202
|
const data = (await client.get("/api/v3/language"));
|
|
197
203
|
return ok({ count: data.length, languages: data });
|
package/dist/tools/providers.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { ok, err } from "../sonarr/format.js";
|
|
2
|
+
import { ok, err, redactProvider, hasRedacted, restoreRedacted, READ, WRITE, UPDATE, DELETE, REDACTED, } from "../sonarr/format.js";
|
|
3
3
|
const kinds = [
|
|
4
4
|
{
|
|
5
5
|
path: "indexer",
|
|
@@ -32,11 +32,21 @@ const kinds = [
|
|
|
32
32
|
];
|
|
33
33
|
function summarizeProvider(p) {
|
|
34
34
|
const { fields: _fields, presets: _presets, ...rest } = p;
|
|
35
|
-
return rest;
|
|
35
|
+
return redactProvider(rest);
|
|
36
|
+
}
|
|
37
|
+
const providerId = z.number().int().positive();
|
|
38
|
+
async function withStoredSecrets(client, path, config, id) {
|
|
39
|
+
if (!hasRedacted(config))
|
|
40
|
+
return config;
|
|
41
|
+
if (!providerId.safeParse(id).success) {
|
|
42
|
+
throw new Error(`The config contains ${REDACTED} placeholders and there is no saved provider to take the values from. Replace them with the real values.`);
|
|
43
|
+
}
|
|
44
|
+
const stored = (await client.get(`/api/v3/${path}/${id}`));
|
|
45
|
+
return restoreRedacted(config, stored);
|
|
36
46
|
}
|
|
37
47
|
export function registerProviderTools(server, client) {
|
|
38
48
|
for (const kind of kinds) {
|
|
39
|
-
server.tool(`list_${kind.plural}`, `List the configured ${kind.label}s.
|
|
49
|
+
server.tool(`list_${kind.plural}`, `List the configured ${kind.label}s. The 'fields' array is omitted here — use get_${kind.singular} for it.`, {}, READ, async () => {
|
|
40
50
|
try {
|
|
41
51
|
const data = (await client.get(`/api/v3/${kind.path}`));
|
|
42
52
|
return ok({ count: data.length, [kind.plural]: data.map(summarizeProvider) });
|
|
@@ -45,9 +55,9 @@ export function registerProviderTools(server, client) {
|
|
|
45
55
|
return err(e);
|
|
46
56
|
}
|
|
47
57
|
});
|
|
48
|
-
server.tool(`get_${kind.singular}`, `Get one ${kind.label} including its full 'fields' array (the implementation-specific settings).`, { id:
|
|
58
|
+
server.tool(`get_${kind.singular}`, `Get one ${kind.label} including its full 'fields' array (the implementation-specific settings). Secret values (API keys, passwords, tokens, credentials inside URLs) are returned as '${REDACTED}'.`, { id: providerId.describe(`${kind.label} id`) }, READ, async ({ id }) => {
|
|
49
59
|
try {
|
|
50
|
-
return ok(await client.get(`/api/v3/${kind.path}/${id}`));
|
|
60
|
+
return ok(redactProvider(await client.get(`/api/v3/${kind.path}/${id}`)));
|
|
51
61
|
}
|
|
52
62
|
catch (e) {
|
|
53
63
|
return err(e);
|
|
@@ -58,14 +68,14 @@ export function registerProviderTools(server, client) {
|
|
|
58
68
|
.string()
|
|
59
69
|
.optional()
|
|
60
70
|
.describe("Only the schema for this implementation, e.g. 'Newznab' or 'QBittorrent'"),
|
|
61
|
-
}, async ({ implementation }) => {
|
|
71
|
+
}, READ, async ({ implementation }) => {
|
|
62
72
|
try {
|
|
63
73
|
const data = (await client.get(`/api/v3/${kind.path}/schema`));
|
|
64
74
|
if (implementation) {
|
|
65
75
|
const q = implementation.toLowerCase();
|
|
66
76
|
const match = data.filter((s) => String(s.implementation ?? "").toLowerCase() === q ||
|
|
67
77
|
String(s.implementationName ?? "").toLowerCase() === q);
|
|
68
|
-
return ok({ count: match.length, schemas: match });
|
|
78
|
+
return ok({ count: match.length, schemas: redactProvider(match) });
|
|
69
79
|
}
|
|
70
80
|
return ok({
|
|
71
81
|
count: data.length,
|
|
@@ -81,30 +91,36 @@ export function registerProviderTools(server, client) {
|
|
|
81
91
|
return err(e);
|
|
82
92
|
}
|
|
83
93
|
});
|
|
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}.`, {
|
|
94
|
+
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}. Secrets must be real values — '${REDACTED}' placeholders are rejected.`, {
|
|
85
95
|
config: z
|
|
86
|
-
.record(z.unknown())
|
|
96
|
+
.record(z.string(), z.unknown())
|
|
87
97
|
.describe(`Full ${kind.label} resource object, based on the schema`),
|
|
88
|
-
}, async ({ config }) => {
|
|
98
|
+
}, WRITE, async ({ config }) => {
|
|
89
99
|
try {
|
|
90
|
-
|
|
100
|
+
if (hasRedacted(config)) {
|
|
101
|
+
throw new Error(`The config contains ${REDACTED} placeholders. Replace them with the real values.`);
|
|
102
|
+
}
|
|
103
|
+
return ok(redactProvider(await client.post(`/api/v3/${kind.path}`, config)));
|
|
91
104
|
}
|
|
92
105
|
catch (e) {
|
|
93
106
|
return err(e);
|
|
94
107
|
}
|
|
95
108
|
});
|
|
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:
|
|
98
|
-
config: z
|
|
99
|
-
|
|
109
|
+
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. Leave '${REDACTED}' values untouched to keep the stored secret; they are replaced with the stored value before saving.`, {
|
|
110
|
+
id: providerId.describe(`${kind.label} id`),
|
|
111
|
+
config: z
|
|
112
|
+
.record(z.string(), z.unknown())
|
|
113
|
+
.describe(`Full ${kind.label} resource object including id`),
|
|
114
|
+
}, UPDATE, async ({ id, config }) => {
|
|
100
115
|
try {
|
|
101
|
-
|
|
116
|
+
const body = await withStoredSecrets(client, kind.path, config, id);
|
|
117
|
+
return ok(redactProvider(await client.put(`/api/v3/${kind.path}/${id}`, { ...body, id })));
|
|
102
118
|
}
|
|
103
119
|
catch (e) {
|
|
104
120
|
return err(e);
|
|
105
121
|
}
|
|
106
122
|
});
|
|
107
|
-
server.tool(`delete_${kind.singular}`, `Delete a ${kind.label}.`, { id:
|
|
123
|
+
server.tool(`delete_${kind.singular}`, `Delete a ${kind.label}.`, { id: providerId.describe(`${kind.label} id`) }, DELETE, async ({ id }) => {
|
|
108
124
|
try {
|
|
109
125
|
return ok(await client.delete(`/api/v3/${kind.path}/${id}`));
|
|
110
126
|
}
|
|
@@ -112,15 +128,20 @@ export function registerProviderTools(server, client) {
|
|
|
112
128
|
return err(e);
|
|
113
129
|
}
|
|
114
130
|
});
|
|
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:
|
|
117
|
-
config: z
|
|
118
|
-
|
|
131
|
+
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. A draft may keep '${REDACTED}' values only when it carries the id of a saved ${kind.label}.`, {
|
|
132
|
+
id: providerId.optional().describe(`Existing ${kind.label} id to test`),
|
|
133
|
+
config: z
|
|
134
|
+
.record(z.string(), z.unknown())
|
|
135
|
+
.optional()
|
|
136
|
+
.describe("Draft resource object to test instead"),
|
|
137
|
+
}, WRITE, async ({ id, config }) => {
|
|
119
138
|
try {
|
|
120
139
|
if (!config && id === undefined)
|
|
121
140
|
throw new Error("Pass either id or config");
|
|
122
|
-
const body = config
|
|
123
|
-
|
|
141
|
+
const body = config
|
|
142
|
+
? await withStoredSecrets(client, kind.path, config, config.id ?? id)
|
|
143
|
+
: await client.get(`/api/v3/${kind.path}/${id}`);
|
|
144
|
+
return ok(redactProvider(await client.post(`/api/v3/${kind.path}/test`, body)));
|
|
124
145
|
}
|
|
125
146
|
catch (e) {
|
|
126
147
|
return err(e);
|
package/dist/tools/queue.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { buildQS, ok, err } from "../sonarr/format.js";
|
|
2
|
+
import { buildQS, ok, err, DELETE, READ, WRITE } from "../sonarr/format.js";
|
|
3
3
|
const sortDirection = ["default", "ascending", "descending"];
|
|
4
4
|
export function registerQueueTools(server, client) {
|
|
5
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.", {
|
|
@@ -19,7 +19,7 @@ export function registerQueueTools(server, client) {
|
|
|
19
19
|
.describe("Include downloads Sonarr could not map to a series"),
|
|
20
20
|
include_series: z.boolean().optional().describe("Include the parent series object"),
|
|
21
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, }) => {
|
|
22
|
+
}, READ, async ({ page, page_size, sort_key, sort_direction, series_ids, protocol, status, include_unknown_series_items, include_series, include_episode, }) => {
|
|
23
23
|
try {
|
|
24
24
|
const qs = buildQS({
|
|
25
25
|
page,
|
|
@@ -44,7 +44,7 @@ export function registerQueueTools(server, client) {
|
|
|
44
44
|
episode_ids: z.array(z.number()).optional().describe("Only items for these episode ids"),
|
|
45
45
|
include_series: z.boolean().optional().describe("Include the parent series object"),
|
|
46
46
|
include_episode: z.boolean().optional().describe("Include the episode object"),
|
|
47
|
-
}, async ({ series_id, episode_ids, include_series, include_episode }) => {
|
|
47
|
+
}, READ, async ({ series_id, episode_ids, include_series, include_episode }) => {
|
|
48
48
|
try {
|
|
49
49
|
const qs = buildQS({
|
|
50
50
|
seriesId: series_id,
|
|
@@ -59,7 +59,7 @@ export function registerQueueTools(server, client) {
|
|
|
59
59
|
return err(e);
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
|
-
server.tool("get_queue_status", "Get queue counts by state — total, errors, warnings and how many items need manual interaction.", {}, async () => {
|
|
62
|
+
server.tool("get_queue_status", "Get queue counts by state — total, errors, warnings and how many items need manual interaction.", {}, READ, async () => {
|
|
63
63
|
try {
|
|
64
64
|
return ok(await client.get("/api/v3/queue/status"));
|
|
65
65
|
}
|
|
@@ -67,12 +67,12 @@ export function registerQueueTools(server, client) {
|
|
|
67
67
|
return err(e);
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
|
-
server.tool("remove_queue_item", "Remove one item from the queue
|
|
71
|
-
id: z.number().describe("Queue item id"),
|
|
70
|
+
server.tool("remove_queue_item", "Remove one item from the queue. The download stays in the download client unless remove_from_client is true; optionally blocklist the release so it is not grabbed again.", {
|
|
71
|
+
id: z.number().int().positive().describe("Queue item id"),
|
|
72
72
|
remove_from_client: z
|
|
73
73
|
.boolean()
|
|
74
74
|
.optional()
|
|
75
|
-
.describe("Also remove the download from the download client (default
|
|
75
|
+
.describe("Also remove the download and its data from the download client (default false)"),
|
|
76
76
|
blocklist: z
|
|
77
77
|
.boolean()
|
|
78
78
|
.optional()
|
|
@@ -85,10 +85,10 @@ export function registerQueueTools(server, client) {
|
|
|
85
85
|
.boolean()
|
|
86
86
|
.optional()
|
|
87
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 }) => {
|
|
88
|
+
}, DELETE, async ({ id, remove_from_client, blocklist, skip_redownload, change_category }) => {
|
|
89
89
|
try {
|
|
90
90
|
const qs = buildQS({
|
|
91
|
-
removeFromClient: remove_from_client ??
|
|
91
|
+
removeFromClient: remove_from_client ?? false,
|
|
92
92
|
blocklist: blocklist ?? false,
|
|
93
93
|
skipRedownload: skip_redownload ?? false,
|
|
94
94
|
changeCategory: change_category,
|
|
@@ -99,16 +99,19 @@ export function registerQueueTools(server, client) {
|
|
|
99
99
|
return err(e);
|
|
100
100
|
}
|
|
101
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
|
|
102
|
+
server.tool("remove_queue_items", "Remove several queue items at once, with the same options and defaults as remove_queue_item.", {
|
|
103
|
+
ids: z.array(z.number().int().positive()).describe("Queue item ids"),
|
|
104
|
+
remove_from_client: z
|
|
105
|
+
.boolean()
|
|
106
|
+
.optional()
|
|
107
|
+
.describe("Also remove from the download client (default false)"),
|
|
105
108
|
blocklist: z.boolean().optional().describe("Blocklist the releases"),
|
|
106
109
|
skip_redownload: z.boolean().optional().describe("Do not search for replacements"),
|
|
107
110
|
change_category: z.boolean().optional().describe("Move to the post-import category"),
|
|
108
|
-
}, async ({ ids, remove_from_client, blocklist, skip_redownload, change_category }) => {
|
|
111
|
+
}, DELETE, async ({ ids, remove_from_client, blocklist, skip_redownload, change_category }) => {
|
|
109
112
|
try {
|
|
110
113
|
const qs = buildQS({
|
|
111
|
-
removeFromClient: remove_from_client ??
|
|
114
|
+
removeFromClient: remove_from_client ?? false,
|
|
112
115
|
blocklist: blocklist ?? false,
|
|
113
116
|
skipRedownload: skip_redownload ?? false,
|
|
114
117
|
changeCategory: change_category,
|
|
@@ -119,7 +122,7 @@ export function registerQueueTools(server, client) {
|
|
|
119
122
|
return err(e);
|
|
120
123
|
}
|
|
121
124
|
});
|
|
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 }) => {
|
|
125
|
+
server.tool("grab_queue_item", "Force Sonarr to import a queue item that is stuck pending or waiting on manual interaction.", { id: z.number().int().positive().describe("Queue item id") }, WRITE, async ({ id }) => {
|
|
123
126
|
try {
|
|
124
127
|
return ok(await client.post(`/api/v3/queue/grab/${id}`));
|
|
125
128
|
}
|
|
@@ -127,7 +130,7 @@ export function registerQueueTools(server, client) {
|
|
|
127
130
|
return err(e);
|
|
128
131
|
}
|
|
129
132
|
});
|
|
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 }) => {
|
|
133
|
+
server.tool("grab_queue_items", "Force import of several stuck queue items at once.", { ids: z.array(z.number().int().positive()).describe("Queue item ids") }, WRITE, async ({ ids }) => {
|
|
131
134
|
try {
|
|
132
135
|
return ok(await client.post("/api/v3/queue/grab/bulk", { ids }));
|
|
133
136
|
}
|
package/dist/tools/releases.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { buildQS, ok, err, summarizeRelease } from "../sonarr/format.js";
|
|
2
|
+
import { buildQS, ok, err, summarizeRelease, READ, WRITE } from "../sonarr/format.js";
|
|
3
3
|
export function registerReleaseTools(server, client) {
|
|
4
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
5
|
episode_id: z.number().optional().describe("Search for a single episode"),
|
|
@@ -13,7 +13,7 @@ export function registerReleaseTools(server, client) {
|
|
|
13
13
|
.optional()
|
|
14
14
|
.describe("Include releases Sonarr rejected (default true)"),
|
|
15
15
|
detailed: z.boolean().optional().describe("Return full release objects instead of summaries"),
|
|
16
|
-
}, async ({ episode_id, series_id, season_number, include_rejected, detailed }) => {
|
|
16
|
+
}, READ, async ({ episode_id, series_id, season_number, include_rejected, detailed }) => {
|
|
17
17
|
try {
|
|
18
18
|
const qs = buildQS({
|
|
19
19
|
episodeId: episode_id,
|
|
@@ -35,7 +35,7 @@ export function registerReleaseTools(server, client) {
|
|
|
35
35
|
server.tool("grab_release", "Send a release from search_releases to the download client.", {
|
|
36
36
|
guid: z.string().describe("Release guid from search_releases"),
|
|
37
37
|
indexer_id: z.number().describe("indexerId of the release from search_releases"),
|
|
38
|
-
}, async ({ guid, indexer_id }) => {
|
|
38
|
+
}, WRITE, async ({ guid, indexer_id }) => {
|
|
39
39
|
try {
|
|
40
40
|
return ok(await client.post("/api/v3/release", { guid, indexerId: indexer_id }));
|
|
41
41
|
}
|
|
@@ -52,7 +52,7 @@ export function registerReleaseTools(server, client) {
|
|
|
52
52
|
.boolean()
|
|
53
53
|
.optional()
|
|
54
54
|
.describe("Hide files that are already in the library (default true)"),
|
|
55
|
-
}, async ({ folder, download_id, series_id, season_number, filter_existing_files }) => {
|
|
55
|
+
}, READ, async ({ folder, download_id, series_id, season_number, filter_existing_files }) => {
|
|
56
56
|
try {
|
|
57
57
|
const qs = buildQS({
|
|
58
58
|
folder,
|
|
@@ -69,9 +69,9 @@ export function registerReleaseTools(server, client) {
|
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
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"),
|
|
72
|
+
series_id: z.number().int().positive().describe("Sonarr series id"),
|
|
73
73
|
season_number: z.number().optional().describe("Only this season number"),
|
|
74
|
-
}, async ({ series_id, season_number }) => {
|
|
74
|
+
}, READ, async ({ series_id, season_number }) => {
|
|
75
75
|
try {
|
|
76
76
|
const qs = buildQS({ seriesId: series_id, seasonNumber: season_number });
|
|
77
77
|
const data = (await client.get(`/api/v3/rename${qs}`));
|
|
@@ -84,7 +84,7 @@ export function registerReleaseTools(server, client) {
|
|
|
84
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
85
|
title: z.string().optional().describe("Release title to parse"),
|
|
86
86
|
path: z.string().optional().describe("File path to parse instead of a title"),
|
|
87
|
-
}, async ({ title, path }) => {
|
|
87
|
+
}, READ, async ({ title, path }) => {
|
|
88
88
|
try {
|
|
89
89
|
return ok(await client.get(`/api/v3/parse${buildQS({ title, path })}`));
|
|
90
90
|
}
|
package/dist/tools/series.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { buildQS, ok, err, pruneUndefined, summarizeSeries, } from "../sonarr/format.js";
|
|
2
|
+
import { buildQS, ok, err, pruneUndefined, summarizeSeries, DELETE, READ, UPDATE, WRITE, } from "../sonarr/format.js";
|
|
3
3
|
const monitorTypes = [
|
|
4
4
|
"unknown",
|
|
5
5
|
"all",
|
|
@@ -29,7 +29,7 @@ export function registerSeriesTools(server, client) {
|
|
|
29
29
|
.boolean()
|
|
30
30
|
.optional()
|
|
31
31
|
.describe("Return the full series objects instead of summaries (large payload)"),
|
|
32
|
-
}, async ({ search, monitored, tvdb_id, detailed }) => {
|
|
32
|
+
}, READ, async ({ search, monitored, tvdb_id, detailed }) => {
|
|
33
33
|
try {
|
|
34
34
|
const data = (await client.get(`/api/v3/series${buildQS({ tvdbId: tvdb_id })}`));
|
|
35
35
|
let rows = data;
|
|
@@ -48,9 +48,9 @@ export function registerSeriesTools(server, client) {
|
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
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)"),
|
|
51
|
+
id: z.number().int().positive().describe("Sonarr series id (not the TVDB id)"),
|
|
52
52
|
include_season_images: z.boolean().optional().describe("Include per-season image URLs"),
|
|
53
|
-
}, async ({ id, include_season_images }) => {
|
|
53
|
+
}, READ, async ({ id, include_season_images }) => {
|
|
54
54
|
try {
|
|
55
55
|
return ok(await client.get(`/api/v3/series/${id}${buildQS({ includeSeasonImages: include_season_images })}`));
|
|
56
56
|
}
|
|
@@ -58,7 +58,7 @@ export function registerSeriesTools(server, client) {
|
|
|
58
58
|
return err(e);
|
|
59
59
|
}
|
|
60
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 }) => {
|
|
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'") }, READ, async ({ term }) => {
|
|
62
62
|
try {
|
|
63
63
|
const data = (await client.get(`/api/v3/series/lookup${buildQS({ term })}`));
|
|
64
64
|
return ok({
|
|
@@ -102,7 +102,7 @@ export function registerSeriesTools(server, client) {
|
|
|
102
102
|
.optional()
|
|
103
103
|
.describe("Start a search for cutoff unmet episodes right after adding"),
|
|
104
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, }) => {
|
|
105
|
+
}, WRITE, 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
106
|
try {
|
|
107
107
|
const found = (await client.get(`/api/v3/series/lookup${buildQS({ term: `tvdb:${tvdb_id}` })}`));
|
|
108
108
|
const match = found.find((s) => s.tvdbId === tvdb_id) ?? found[0];
|
|
@@ -129,7 +129,7 @@ export function registerSeriesTools(server, client) {
|
|
|
129
129
|
}
|
|
130
130
|
});
|
|
131
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"),
|
|
132
|
+
id: z.number().int().positive().describe("Sonarr series id"),
|
|
133
133
|
monitored: z.boolean().optional().describe("Monitor or unmonitor the series"),
|
|
134
134
|
quality_profile_id: z.number().optional().describe("New quality profile id"),
|
|
135
135
|
series_type: z.enum(seriesTypes).optional().describe("New series type"),
|
|
@@ -145,7 +145,7 @@ export function registerSeriesTools(server, client) {
|
|
|
145
145
|
.boolean()
|
|
146
146
|
.optional()
|
|
147
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, }) => {
|
|
148
|
+
}, UPDATE, async ({ id, monitored, quality_profile_id, series_type, season_folder, monitor_new_items, root_folder_path, path, tags, move_files, }) => {
|
|
149
149
|
try {
|
|
150
150
|
const current = (await client.get(`/api/v3/series/${id}`));
|
|
151
151
|
const body = {
|
|
@@ -169,7 +169,7 @@ export function registerSeriesTools(server, client) {
|
|
|
169
169
|
}
|
|
170
170
|
});
|
|
171
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"),
|
|
172
|
+
id: z.number().int().positive().describe("Sonarr series id"),
|
|
173
173
|
delete_files: z
|
|
174
174
|
.boolean()
|
|
175
175
|
.optional()
|
|
@@ -178,7 +178,7 @@ export function registerSeriesTools(server, client) {
|
|
|
178
178
|
.boolean()
|
|
179
179
|
.optional()
|
|
180
180
|
.describe("Add an import list exclusion for this series (default false)"),
|
|
181
|
-
}, async ({ id, delete_files, add_import_list_exclusion }) => {
|
|
181
|
+
}, DELETE, async ({ id, delete_files, add_import_list_exclusion }) => {
|
|
182
182
|
try {
|
|
183
183
|
return ok(await client.delete(`/api/v3/series/${id}${buildQS({
|
|
184
184
|
deleteFiles: delete_files,
|
|
@@ -206,7 +206,7 @@ export function registerSeriesTools(server, client) {
|
|
|
206
206
|
.boolean()
|
|
207
207
|
.optional()
|
|
208
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, }) => {
|
|
209
|
+
}, UPDATE, async ({ series_ids, monitored, quality_profile_id, series_type, season_folder, monitor_new_items, root_folder_path, tags, apply_tags, move_files, }) => {
|
|
210
210
|
try {
|
|
211
211
|
const body = pruneUndefined({
|
|
212
212
|
seriesIds: series_ids,
|
|
@@ -234,7 +234,7 @@ export function registerSeriesTools(server, client) {
|
|
|
234
234
|
.boolean()
|
|
235
235
|
.optional()
|
|
236
236
|
.describe("Add import list exclusions (default false)"),
|
|
237
|
-
}, async ({ series_ids, delete_files, add_import_list_exclusion }) => {
|
|
237
|
+
}, DELETE, async ({ series_ids, delete_files, add_import_list_exclusion }) => {
|
|
238
238
|
try {
|
|
239
239
|
return ok(await client.delete("/api/v3/series/editor", {
|
|
240
240
|
seriesIds: series_ids,
|
|
@@ -246,7 +246,7 @@ export function registerSeriesTools(server, client) {
|
|
|
246
246
|
return err(e);
|
|
247
247
|
}
|
|
248
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 }) => {
|
|
249
|
+
server.tool("get_series_folder", "Get the folder path Sonarr would use for a series, given the current naming configuration.", { id: z.number().int().positive().describe("Sonarr series id") }, READ, async ({ id }) => {
|
|
250
250
|
try {
|
|
251
251
|
return ok(await client.get(`/api/v3/series/${id}/folder`));
|
|
252
252
|
}
|
|
@@ -255,13 +255,13 @@ export function registerSeriesTools(server, client) {
|
|
|
255
255
|
}
|
|
256
256
|
});
|
|
257
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"),
|
|
258
|
+
series_id: z.number().int().positive().describe("Sonarr series id"),
|
|
259
259
|
monitored: z.boolean().describe("true to monitor, false to unmonitor"),
|
|
260
260
|
season_numbers: z
|
|
261
261
|
.array(z.number())
|
|
262
262
|
.optional()
|
|
263
263
|
.describe("Season numbers to change; all seasons when omitted"),
|
|
264
|
-
}, async ({ series_id, monitored, season_numbers }) => {
|
|
264
|
+
}, UPDATE, async ({ series_id, monitored, season_numbers }) => {
|
|
265
265
|
try {
|
|
266
266
|
const current = (await client.get(`/api/v3/series/${series_id}`));
|
|
267
267
|
const seasons = (current.seasons ?? []).map((s) => season_numbers === undefined || season_numbers.includes(s.seasonNumber)
|