@orellbuehler/sonarr-mcp 0.1.0 → 0.2.2

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.
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { ok, err } from "../sonarr/format.js";
2
+ import { ok, err, redactSecrets, hasRedacted, READ, UPDATE, REDACTED } from "../sonarr/format.js";
3
3
  const kinds = [
4
4
  { path: "naming", name: "naming_config", label: "file and folder naming", writable: true },
5
5
  {
@@ -29,11 +29,12 @@ const kinds = [
29
29
  },
30
30
  { path: "ui", name: "ui_config", label: "UI (date format, first day of week)", writable: false },
31
31
  ];
32
+ const configId = z.number().int().positive();
32
33
  export function registerSettingsTools(server, client) {
33
34
  for (const kind of kinds) {
34
- server.tool(`get_${kind.name}`, `Get the ${kind.label} configuration.`, {}, async () => {
35
+ server.tool(`get_${kind.name}`, `Get the ${kind.label} configuration. Secret values (API key, passwords) are returned as '${REDACTED}'.`, {}, READ, async () => {
35
36
  try {
36
- return ok(await client.get(`/api/v3/config/${kind.path}`));
37
+ return ok(redactSecrets(await client.get(`/api/v3/config/${kind.path}`)));
37
38
  }
38
39
  catch (e) {
39
40
  return err(e);
@@ -41,10 +42,20 @@ export function registerSettingsTools(server, client) {
41
42
  });
42
43
  if (!kind.writable)
43
44
  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
+ 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.`, {
46
+ config: z
47
+ .record(z.string(), z.unknown())
48
+ .describe("Full configuration object including id"),
49
+ }, UPDATE, async ({ config }) => {
45
50
  try {
46
51
  const id = config.id ?? 1;
47
- return ok(await client.put(`/api/v3/config/${kind.path}/${id}`, { ...config, id }));
52
+ if (!configId.safeParse(id).success) {
53
+ throw new Error("config.id must be a positive integer");
54
+ }
55
+ if (hasRedacted(config)) {
56
+ throw new Error(`The config contains ${REDACTED} placeholders; refusing to save them.`);
57
+ }
58
+ return ok(redactSecrets(await client.put(`/api/v3/config/${kind.path}/${id}`, { ...config, id })));
48
59
  }
49
60
  catch (e) {
50
61
  return err(e);
@@ -53,10 +64,10 @@ export function registerSettingsTools(server, client) {
53
64
  }
54
65
  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
66
  config: z
56
- .record(z.unknown())
67
+ .record(z.string(), z.unknown())
57
68
  .optional()
58
69
  .describe("Draft naming config; the saved one is used when omitted"),
59
- }, async ({ config }) => {
70
+ }, READ, async ({ config }) => {
60
71
  try {
61
72
  const body = config ?? (await client.get("/api/v3/config/naming"));
62
73
  const qs = new URLSearchParams();
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
- import { buildQS, ok, err } from "../sonarr/format.js";
2
+ import { buildQS, ok, err, DESTRUCTIVE, READ } from "../sonarr/format.js";
3
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 () => {
4
+ server.tool("get_system_status", "Get version, branch, runtime, install source, OS and the paths Sonarr is using. Start here when diagnosing anything.", {}, READ, async () => {
5
5
  try {
6
6
  return ok(await client.get("/api/v3/system/status"));
7
7
  }
@@ -9,7 +9,7 @@ export function registerSystemTools(server, client) {
9
9
  return err(e);
10
10
  }
11
11
  });
12
- server.tool("get_health", "Get the active health check warnings and errors, with the wiki link explaining each one.", {}, async () => {
12
+ server.tool("get_health", "Get the active health check warnings and errors, with the wiki link explaining each one.", {}, READ, async () => {
13
13
  try {
14
14
  const data = (await client.get("/api/v3/health"));
15
15
  return ok({ count: data.length, issues: data });
@@ -18,7 +18,7 @@ export function registerSystemTools(server, client) {
18
18
  return err(e);
19
19
  }
20
20
  });
21
- server.tool("get_disk_space", "Get free and total space for every drive and root folder Sonarr can see.", {}, async () => {
21
+ server.tool("get_disk_space", "Get free and total space for every drive and root folder Sonarr can see.", {}, READ, async () => {
22
22
  try {
23
23
  const data = (await client.get("/api/v3/diskspace"));
24
24
  return ok({ count: data.length, disks: data });
@@ -27,7 +27,7 @@ export function registerSystemTools(server, client) {
27
27
  return err(e);
28
28
  }
29
29
  });
30
- server.tool("get_updates", "List available Sonarr updates for the current branch, with changelogs and whether each is installed or installable.", {}, async () => {
30
+ server.tool("get_updates", "List available Sonarr updates for the current branch, with changelogs and whether each is installed or installable.", {}, READ, async () => {
31
31
  try {
32
32
  const data = (await client.get("/api/v3/update"));
33
33
  return ok({ count: data.length, updates: data });
@@ -48,7 +48,7 @@ export function registerSystemTools(server, client) {
48
48
  .enum(["trace", "debug", "info", "warn", "error", "fatal"])
49
49
  .optional()
50
50
  .describe("Only entries at this level"),
51
- }, async ({ page, page_size, sort_key, sort_direction, level }) => {
51
+ }, READ, async ({ page, page_size, sort_key, sort_direction, level }) => {
52
52
  try {
53
53
  const qs = buildQS({
54
54
  page,
@@ -63,7 +63,7 @@ export function registerSystemTools(server, client) {
63
63
  return err(e);
64
64
  }
65
65
  });
66
- server.tool("list_log_files", "List the log files on disk with their names, sizes and download paths.", {}, async () => {
66
+ server.tool("list_log_files", "List the log files on disk with their names, sizes and download paths.", {}, READ, async () => {
67
67
  try {
68
68
  const data = (await client.get("/api/v3/log/file"));
69
69
  return ok({ count: data.length, files: data });
@@ -72,7 +72,12 @@ export function registerSystemTools(server, client) {
72
72
  return err(e);
73
73
  }
74
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 }) => {
75
+ server.tool("get_log_file", "Download the contents of one log file as text.", {
76
+ filename: z
77
+ .string()
78
+ .regex(/^(?!\.+$)[\w.-]+$/, "Must be a plain file name")
79
+ .describe("Log file name from list_log_files, e.g. 'sonarr.txt'"),
80
+ }, READ, async ({ filename }) => {
76
81
  try {
77
82
  return ok(await client.fetchText(`/api/v3/log/file/${encodeURIComponent(filename)}`));
78
83
  }
@@ -80,7 +85,7 @@ export function registerSystemTools(server, client) {
80
85
  return err(e);
81
86
  }
82
87
  });
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 () => {
88
+ 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.", {}, READ, async () => {
84
89
  try {
85
90
  const data = (await client.get("/api/v3/system/backup"));
86
91
  return ok({ count: data.length, backups: data });
@@ -89,7 +94,7 @@ export function registerSystemTools(server, client) {
89
94
  return err(e);
90
95
  }
91
96
  });
92
- server.tool("restart_sonarr", "Restart the Sonarr application. It is unreachable for a few seconds afterwards.", {}, async () => {
97
+ server.tool("restart_sonarr", "Restart the Sonarr application. It is unreachable for a few seconds afterwards.", {}, DESTRUCTIVE, async () => {
93
98
  try {
94
99
  return ok(await client.post("/api/v3/system/restart"));
95
100
  }
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { buildQS, ok, err, summarizeEpisode, summarizeList } from "../sonarr/format.js";
2
+ import { buildQS, ok, err, summarizeEpisode, summarizeList, READ } from "../sonarr/format.js";
3
3
  const sortDirection = ["default", "ascending", "descending"];
4
4
  export function registerWantedTools(server, client) {
5
5
  server.tool("get_missing_episodes", "Page through monitored episodes that have already aired but have no file — the wanted/missing list.", {
@@ -13,7 +13,7 @@ export function registerWantedTools(server, client) {
13
13
  .describe("Only monitored episodes (default true on the Sonarr side)"),
14
14
  include_series: z.boolean().optional().describe("Include the parent series object"),
15
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 }) => {
16
+ }, READ, async ({ page, page_size, sort_key, sort_direction, monitored, include_series, detailed }) => {
17
17
  try {
18
18
  const qs = buildQS({
19
19
  page,
@@ -39,7 +39,7 @@ export function registerWantedTools(server, client) {
39
39
  include_series: z.boolean().optional().describe("Include the parent series object"),
40
40
  include_episode_file: z.boolean().optional().describe("Include the current episode file"),
41
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, }) => {
42
+ }, READ, async ({ page, page_size, sort_key, sort_direction, monitored, include_series, include_episode_file, detailed, }) => {
43
43
  try {
44
44
  const qs = buildQS({
45
45
  page,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orellbuehler/sonarr-mcp",
3
- "version": "0.1.0",
3
+ "version": "0.2.2",
4
4
  "description": "Model Context Protocol server for Sonarr: series, episodes, calendar, queue, history, releases, profiles, indexers, and system management.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -23,7 +23,7 @@
23
23
  "prepare": "npm run build"
24
24
  },
25
25
  "engines": {
26
- "node": ">=20"
26
+ "node": ">=22"
27
27
  },
28
28
  "keywords": [
29
29
  "mcp",
@@ -54,8 +54,8 @@
54
54
  "access": "public"
55
55
  },
56
56
  "dependencies": {
57
- "@modelcontextprotocol/sdk": "^1.30.0",
58
- "zod": "^3.24.4"
57
+ "@modelcontextprotocol/sdk": "^1.32.2",
58
+ "zod": "^4.6.7"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@eslint/js": "^10.0.1",