@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,74 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ok, err } from "../sonarr/format.js";
|
|
3
|
+
const kinds = [
|
|
4
|
+
{ path: "naming", name: "naming_config", label: "file and folder naming", writable: true },
|
|
5
|
+
{
|
|
6
|
+
path: "mediamanagement",
|
|
7
|
+
name: "media_management_config",
|
|
8
|
+
label: "media management (import, file handling, permissions)",
|
|
9
|
+
writable: true,
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
path: "indexer",
|
|
13
|
+
name: "indexer_config",
|
|
14
|
+
label: "indexer (RSS interval, retention, availability delay)",
|
|
15
|
+
writable: true,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
path: "downloadclient",
|
|
19
|
+
name: "download_client_config",
|
|
20
|
+
label: "download client (completed and failed download handling)",
|
|
21
|
+
writable: true,
|
|
22
|
+
},
|
|
23
|
+
{ path: "importlist", name: "import_list_config", label: "import list", writable: true },
|
|
24
|
+
{
|
|
25
|
+
path: "host",
|
|
26
|
+
name: "host_config",
|
|
27
|
+
label: "host (port, URL base, proxy, logging)",
|
|
28
|
+
writable: false,
|
|
29
|
+
},
|
|
30
|
+
{ path: "ui", name: "ui_config", label: "UI (date format, first day of week)", writable: false },
|
|
31
|
+
];
|
|
32
|
+
export function registerSettingsTools(server, client) {
|
|
33
|
+
for (const kind of kinds) {
|
|
34
|
+
server.tool(`get_${kind.name}`, `Get the ${kind.label} configuration.`, {}, async () => {
|
|
35
|
+
try {
|
|
36
|
+
return ok(await client.get(`/api/v3/config/${kind.path}`));
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
return err(e);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
if (!kind.writable)
|
|
43
|
+
continue;
|
|
44
|
+
server.tool(`update_${kind.name}`, `Update the ${kind.label} configuration. Fetch it with get_${kind.name} first, change what you need and send the whole object back.`, { config: z.record(z.unknown()).describe("Full configuration object including id") }, async ({ config }) => {
|
|
45
|
+
try {
|
|
46
|
+
const id = config.id ?? 1;
|
|
47
|
+
return ok(await client.put(`/api/v3/config/${kind.path}/${id}`, { ...config, id }));
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
return err(e);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
server.tool("get_naming_examples", "Preview the filenames a naming format would produce, without saving it. Pass a naming config object to try a draft format.", {
|
|
55
|
+
config: z
|
|
56
|
+
.record(z.unknown())
|
|
57
|
+
.optional()
|
|
58
|
+
.describe("Draft naming config; the saved one is used when omitted"),
|
|
59
|
+
}, async ({ config }) => {
|
|
60
|
+
try {
|
|
61
|
+
const body = config ?? (await client.get("/api/v3/config/naming"));
|
|
62
|
+
const qs = new URLSearchParams();
|
|
63
|
+
for (const [k, v] of Object.entries(body)) {
|
|
64
|
+
if (v === undefined || v === null)
|
|
65
|
+
continue;
|
|
66
|
+
qs.set(k, String(v));
|
|
67
|
+
}
|
|
68
|
+
return ok(await client.get(`/api/v3/config/naming/examples?${qs.toString()}`));
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
return err(e);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { buildQS, ok, err } from "../sonarr/format.js";
|
|
3
|
+
export function registerSystemTools(server, client) {
|
|
4
|
+
server.tool("get_system_status", "Get version, branch, runtime, install source, OS and the paths Sonarr is using. Start here when diagnosing anything.", {}, async () => {
|
|
5
|
+
try {
|
|
6
|
+
return ok(await client.get("/api/v3/system/status"));
|
|
7
|
+
}
|
|
8
|
+
catch (e) {
|
|
9
|
+
return err(e);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
server.tool("get_health", "Get the active health check warnings and errors, with the wiki link explaining each one.", {}, async () => {
|
|
13
|
+
try {
|
|
14
|
+
const data = (await client.get("/api/v3/health"));
|
|
15
|
+
return ok({ count: data.length, issues: data });
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
return err(e);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
server.tool("get_disk_space", "Get free and total space for every drive and root folder Sonarr can see.", {}, async () => {
|
|
22
|
+
try {
|
|
23
|
+
const data = (await client.get("/api/v3/diskspace"));
|
|
24
|
+
return ok({ count: data.length, disks: data });
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
return err(e);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
server.tool("get_updates", "List available Sonarr updates for the current branch, with changelogs and whether each is installed or installable.", {}, async () => {
|
|
31
|
+
try {
|
|
32
|
+
const data = (await client.get("/api/v3/update"));
|
|
33
|
+
return ok({ count: data.length, updates: data });
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
return err(e);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
server.tool("list_logs", "Page through Sonarr's log entries, newest first by default. Filter by level to find errors quickly.", {
|
|
40
|
+
page: z.number().optional().describe("Page number (default 1)"),
|
|
41
|
+
page_size: z.number().optional().describe("Entries per page (default 10 on the Sonarr side)"),
|
|
42
|
+
sort_key: z.string().optional().describe("Field to sort by, e.g. 'time'"),
|
|
43
|
+
sort_direction: z
|
|
44
|
+
.enum(["default", "ascending", "descending"])
|
|
45
|
+
.optional()
|
|
46
|
+
.describe("Sort direction"),
|
|
47
|
+
level: z
|
|
48
|
+
.enum(["trace", "debug", "info", "warn", "error", "fatal"])
|
|
49
|
+
.optional()
|
|
50
|
+
.describe("Only entries at this level"),
|
|
51
|
+
}, async ({ page, page_size, sort_key, sort_direction, level }) => {
|
|
52
|
+
try {
|
|
53
|
+
const qs = buildQS({
|
|
54
|
+
page,
|
|
55
|
+
pageSize: page_size,
|
|
56
|
+
sortKey: sort_key ?? "time",
|
|
57
|
+
sortDirection: sort_direction ?? "descending",
|
|
58
|
+
level,
|
|
59
|
+
});
|
|
60
|
+
return ok(await client.get(`/api/v3/log${qs}`));
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
return err(e);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
server.tool("list_log_files", "List the log files on disk with their names, sizes and download paths.", {}, async () => {
|
|
67
|
+
try {
|
|
68
|
+
const data = (await client.get("/api/v3/log/file"));
|
|
69
|
+
return ok({ count: data.length, files: data });
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
return err(e);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
server.tool("get_log_file", "Download the contents of one log file as text.", { filename: z.string().describe("Log file name from list_log_files, e.g. 'sonarr.txt'") }, async ({ filename }) => {
|
|
76
|
+
try {
|
|
77
|
+
return ok(await client.fetchText(`/api/v3/log/file/${encodeURIComponent(filename)}`));
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
return err(e);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
server.tool("list_backups", "List the database backups Sonarr has taken, with their type, size and date. Run the Backup command to create a new one.", {}, async () => {
|
|
84
|
+
try {
|
|
85
|
+
const data = (await client.get("/api/v3/system/backup"));
|
|
86
|
+
return ok({ count: data.length, backups: data });
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
return err(e);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
server.tool("restart_sonarr", "Restart the Sonarr application. It is unreachable for a few seconds afterwards.", {}, async () => {
|
|
93
|
+
try {
|
|
94
|
+
return ok(await client.post("/api/v3/system/restart"));
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
return err(e);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { buildQS, ok, err, summarizeEpisode, summarizeList } from "../sonarr/format.js";
|
|
3
|
+
const sortDirection = ["default", "ascending", "descending"];
|
|
4
|
+
export function registerWantedTools(server, client) {
|
|
5
|
+
server.tool("get_missing_episodes", "Page through monitored episodes that have already aired but have no file — the wanted/missing list.", {
|
|
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. 'airDateUtc'"),
|
|
9
|
+
sort_direction: z.enum(sortDirection).optional().describe("Sort direction"),
|
|
10
|
+
monitored: z
|
|
11
|
+
.boolean()
|
|
12
|
+
.optional()
|
|
13
|
+
.describe("Only monitored episodes (default true on the Sonarr side)"),
|
|
14
|
+
include_series: z.boolean().optional().describe("Include the parent series object"),
|
|
15
|
+
detailed: z.boolean().optional().describe("Return full episode objects instead of summaries"),
|
|
16
|
+
}, async ({ page, page_size, sort_key, sort_direction, monitored, include_series, detailed }) => {
|
|
17
|
+
try {
|
|
18
|
+
const qs = buildQS({
|
|
19
|
+
page,
|
|
20
|
+
pageSize: page_size,
|
|
21
|
+
sortKey: sort_key,
|
|
22
|
+
sortDirection: sort_direction,
|
|
23
|
+
monitored,
|
|
24
|
+
includeSeries: include_series ?? true,
|
|
25
|
+
});
|
|
26
|
+
const data = await client.get(`/api/v3/wanted/missing${qs}`);
|
|
27
|
+
return ok(summarizeList(data, summarizeEpisode, detailed));
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
return err(e);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
server.tool("get_cutoff_unmet_episodes", "Page through episodes that have a file but have not reached their quality profile cutoff — candidates for an upgrade.", {
|
|
34
|
+
page: z.number().optional().describe("Page number (default 1)"),
|
|
35
|
+
page_size: z.number().optional().describe("Items per page (default 10 on the Sonarr side)"),
|
|
36
|
+
sort_key: z.string().optional().describe("Field to sort by, e.g. 'airDateUtc'"),
|
|
37
|
+
sort_direction: z.enum(sortDirection).optional().describe("Sort direction"),
|
|
38
|
+
monitored: z.boolean().optional().describe("Only monitored episodes"),
|
|
39
|
+
include_series: z.boolean().optional().describe("Include the parent series object"),
|
|
40
|
+
include_episode_file: z.boolean().optional().describe("Include the current episode file"),
|
|
41
|
+
detailed: z.boolean().optional().describe("Return full episode objects instead of summaries"),
|
|
42
|
+
}, async ({ page, page_size, sort_key, sort_direction, monitored, include_series, include_episode_file, detailed, }) => {
|
|
43
|
+
try {
|
|
44
|
+
const qs = buildQS({
|
|
45
|
+
page,
|
|
46
|
+
pageSize: page_size,
|
|
47
|
+
sortKey: sort_key,
|
|
48
|
+
sortDirection: sort_direction,
|
|
49
|
+
monitored,
|
|
50
|
+
includeSeries: include_series ?? true,
|
|
51
|
+
includeEpisodeFile: include_episode_file,
|
|
52
|
+
});
|
|
53
|
+
const data = await client.get(`/api/v3/wanted/cutoff${qs}`);
|
|
54
|
+
return ok(summarizeList(data, summarizeEpisode, detailed));
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
return err(e);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@orellbuehler/sonarr-mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Model Context Protocol server for Sonarr: series, episodes, calendar, queue, history, releases, profiles, indexers, and system management.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"sonarr-mcp": "dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"!dist/__tests__"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc -p tsconfig.build.json",
|
|
15
|
+
"start": "node dist/index.js",
|
|
16
|
+
"test": "vitest run",
|
|
17
|
+
"test:watch": "vitest",
|
|
18
|
+
"typecheck": "tsc --noEmit",
|
|
19
|
+
"lint": "eslint src",
|
|
20
|
+
"format": "prettier --write .",
|
|
21
|
+
"format:check": "prettier --check .",
|
|
22
|
+
"spec:update": "bash scripts/update-openapi.sh",
|
|
23
|
+
"prepare": "npm run build"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=20"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"mcp",
|
|
30
|
+
"mcp-server",
|
|
31
|
+
"model-context-protocol",
|
|
32
|
+
"sonarr",
|
|
33
|
+
"tv",
|
|
34
|
+
"pvr",
|
|
35
|
+
"media-management",
|
|
36
|
+
"arr",
|
|
37
|
+
"servarr",
|
|
38
|
+
"claude",
|
|
39
|
+
"ai-agents",
|
|
40
|
+
"llm",
|
|
41
|
+
"ai"
|
|
42
|
+
],
|
|
43
|
+
"author": "Orell Bühler",
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "git+https://github.com/OrellBuehler/sonarr-mcp.git"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://github.com/OrellBuehler/sonarr-mcp#readme",
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/OrellBuehler/sonarr-mcp/issues"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
58
|
+
"zod": "^3.24.4"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@eslint/js": "^10.0.1",
|
|
62
|
+
"@types/node": "^22.15.3",
|
|
63
|
+
"eslint": "^10.4.1",
|
|
64
|
+
"eslint-config-prettier": "^10.1.8",
|
|
65
|
+
"prettier": "^3.8.3",
|
|
66
|
+
"typescript": "^5.8.3",
|
|
67
|
+
"typescript-eslint": "^8.60.0",
|
|
68
|
+
"vitest": "^4.1.0"
|
|
69
|
+
}
|
|
70
|
+
}
|