audiobookshelf-mcp 0.1.3 → 0.2.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/README.md CHANGED
@@ -4,19 +4,24 @@
4
4
  [![npm version](https://img.shields.io/npm/v/audiobookshelf-mcp)](https://www.npmjs.com/package/audiobookshelf-mcp)
5
5
  [![npm downloads](https://img.shields.io/npm/dm/audiobookshelf-mcp)](https://www.npmjs.com/package/audiobookshelf-mcp)
6
6
  [![node](https://img.shields.io/node/v/audiobookshelf-mcp)](https://nodejs.org)
7
- [![Container](https://img.shields.io/badge/ghcr.io-ni--c%2Faudiobookshelf--mcp-2496ED?logo=docker&logoColor=white)](https://github.com/ni-c/audiobookshelf-mcp/pkgs/container/audiobookshelf-mcp)
8
7
  [![license](https://img.shields.io/npm/l/audiobookshelf-mcp)](LICENSE)
9
- [![Docs](https://img.shields.io/badge/docs-audiobookshelf--mcp.ni--c.de-4f46e5)](https://audiobookshelf-mcp.ni-c.de)
8
+ [![container](https://img.shields.io/badge/ghcr.io-ni--c%2Faudiobookshelf--mcp-blue)](https://github.com/ni-c/audiobookshelf-mcp/pkgs/container/audiobookshelf-mcp)
9
+ [![docs](https://img.shields.io/badge/docs-audiobookshelf--mcp.ni--c.de-informational)](https://audiobookshelf-mcp.ni-c.de)
10
+ [![sponsor](https://img.shields.io/badge/sponsor-ni--c-ea4aaa?logo=githubsponsors&logoColor=white)](https://github.com/sponsors/ni-c)
10
11
 
11
- An [MCP](https://modelcontextprotocol.io) server for
12
+ A [Model Context Protocol](https://modelcontextprotocol.io) (MCP) server for
12
13
  [Audiobookshelf](https://www.audiobookshelf.org/), the self-hosted audiobook and
13
- podcast server. It lets an AI assistant browse your libraries, answer questions
14
- about what you own and what you have listened to, and — unless you switch it off —
15
- keep your listening progress, bookmarks, collections and playlists up to date.
14
+ podcast server.
16
15
 
17
- 44 tools: 29 read, 15 write.
16
+ Lets MCP clients like Claude Code, Claude Desktop or Codex browse your libraries,
17
+ answer questions about what you own and what you have listened to, and — unless you
18
+ switch it off — keep your listening progress, bookmarks, collections and playlists up
19
+ to date: 44 tools, 29 read and 15 write.
18
20
 
19
- 📖 **Full documentation: <https://audiobookshelf-mcp.ni-c.de>**
21
+ Forty-four tools is the ceiling, not the floor: `AUDIOBOOKSHELF_ALLOW_TOOLS=essential`
22
+ registers a curated eight instead, and a model picks the right tool far more
23
+ reliably from eight than from forty-four — see
24
+ [choosing which tools load](#choosing-which-tools-load).
20
25
 
21
26
  <!-- <picture> is resolved against the colour scheme of the page showing it, so GitHub
22
27
  picks the variant that matches its own theme toggle. npm strips <picture> and
@@ -52,11 +57,35 @@ once, at creation.
52
57
  | `AUDIOBOOKSHELF_API_KEY` | yes | API key, sent as `Authorization: Bearer …` |
53
58
  | `AUDIOBOOKSHELF_READ_ONLY` | no | `true` registers only the 29 read tools |
54
59
  | `AUDIOBOOKSHELF_INSECURE_TLS` | no | `true` accepts self-signed certificates — scoped to this connection, not process-wide |
60
+ | `AUDIOBOOKSHELF_ALLOW_TOOLS` | no | Comma-separated tool names, `list_*` prefixes, or `essential` for a curated preset |
61
+ | `AUDIOBOOKSHELF_DENY_TOOLS` | no | Same syntax; removed from whatever `AUDIOBOOKSHELF_ALLOW_TOOLS` left |
55
62
 
56
63
  The server starts without configuration: it completes the MCP handshake and lists
57
64
  its tools, and every call then fails with the setup instructions. That is
58
65
  deliberate, so registries and sandbox inspectors can introspect it.
59
66
 
67
+ ### Choosing which tools load
68
+
69
+ `AUDIOBOOKSHELF_ALLOW_TOOLS` and `AUDIOBOOKSHELF_DENY_TOOLS` take comma-separated tool names;
70
+ a trailing `*` matches a whole family. `essential` is a curated preset of
71
+ eight: `list_libraries`, `search_library`, `list_library_items`, `get_library_item`, `get_item_chapters`, `list_items_in_progress`, `get_media_progress`, `set_media_progress`.
72
+
73
+ ```sh
74
+ AUDIOBOOKSHELF_ALLOW_TOOLS=essential
75
+ AUDIOBOOKSHELF_ALLOW_TOOLS=search_library,get_library_item,set_media_progress
76
+ AUDIOBOOKSHELF_DENY_TOOLS=delete_*
77
+ ```
78
+
79
+ An entry that matches no tool aborts startup and names it, so a typo cannot
80
+ silently hide a tool — an absent tool is not something anyone traces back to an
81
+ environment variable. A filtered tool is never registered, so it is absent from
82
+ `tools/list` and unknown to `tools/call` alike, exactly like a write tool under
83
+ `AUDIOBOOKSHELF_READ_ONLY`.
84
+
85
+ If you run several of these servers at once, [mcp-hub](https://mcp-hub.ni-c.de)
86
+ is the other answer — its `/hub` endpoint replaces every server's tools with six
87
+ meta-tools.
88
+
60
89
  ## Install
61
90
 
62
91
  ```sh
package/dist/config.d.ts CHANGED
@@ -7,7 +7,15 @@ export interface Config {
7
7
  url: string | undefined;
8
8
  apiKey: string | undefined;
9
9
  insecureTls: boolean;
10
- readOnly: boolean;
10
+ readOnly: boolean; /**
11
+ * Raw value of `AUDIOBOOKSHELF_ALLOW_TOOLS` — comma-separated tool names, `list_*`
12
+ * prefixes, or `essential`. Kept unparsed on purpose: this file is a mirror of
13
+ * the environment, and the names can only be checked against the tool
14
+ * catalogue, which `buildToolFilter` does.
15
+ */
16
+ allowTools: string | undefined;
17
+ /** Raw value of `AUDIOBOOKSHELF_DENY_TOOLS`, same shape, subtracted from the above. */
18
+ denyTools: string | undefined;
11
19
  }
12
20
  /** Shown when the configuration is incomplete — at startup and on every API call. */
13
21
  export declare function missingConfigMessage(missing: string[]): string;
package/dist/config.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { internalHostKind } from './hosts.js';
1
2
  /** Shown when the configuration is incomplete — at startup and on every API call. */
2
3
  export function missingConfigMessage(missing) {
3
4
  return (`missing required environment variable(s): ${missing.join(', ')}\n` +
@@ -27,6 +28,8 @@ export function loadConfig(env = process.env) {
27
28
  const apiKey = env.AUDIOBOOKSHELF_API_KEY;
28
29
  const insecureTls = env.AUDIOBOOKSHELF_INSECURE_TLS === 'true';
29
30
  const readOnly = env.AUDIOBOOKSHELF_READ_ONLY === 'true';
31
+ const allowTools = env.AUDIOBOOKSHELF_ALLOW_TOOLS;
32
+ const denyTools = env.AUDIOBOOKSHELF_DENY_TOOLS;
30
33
  // Don't keep the key in the environment for the process lifetime — it is
31
34
  // visible to child processes and in /proc/<pid>/environ. This happens before
32
35
  // any branch on purpose: the paths below either exit or return early, and
@@ -43,7 +46,14 @@ export function loadConfig(env = process.env) {
43
46
  console.error(`audiobookshelf-mcp: ${missingConfigMessage(missing)}`);
44
47
  }
45
48
  if (!url) {
46
- return { url: undefined, apiKey, insecureTls, readOnly };
49
+ return {
50
+ url: undefined,
51
+ apiKey,
52
+ insecureTls,
53
+ readOnly,
54
+ allowTools,
55
+ denyTools,
56
+ };
47
57
  }
48
58
  let parsed;
49
59
  try {
@@ -75,16 +85,14 @@ export function loadConfig(env = process.env) {
75
85
  apiKey,
76
86
  insecureTls,
77
87
  readOnly,
88
+ allowTools,
89
+ denyTools,
78
90
  };
79
91
  }
80
92
  function isLoopbackHost(hostname) {
81
- // URL.hostname keeps the brackets around an IPv6 literal, so comparing against
82
- // a bare '::1' never matches and the plain-http warning fires on a loopback
83
- // URL written as http://[::1]:13378.
84
- const host = hostname.replace(/^\[|\]$/g, '');
85
- return (host === 'localhost' ||
86
- host.endsWith('.localhost') ||
87
- host.startsWith('127.') ||
88
- host === '::1');
93
+ // The shared classifier, so every spelling of a loopback address is
94
+ // recognised including http://[::ffff:127.0.0.1] and 'localhost.' with its
95
+ // root label, which the string comparison this replaced did not see.
96
+ return internalHostKind(hostname) === 'loopback';
89
97
  }
90
98
  //# sourceMappingURL=config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAYA,qFAAqF;AACrF,MAAM,UAAU,oBAAoB,CAAC,OAAiB;IACpD,OAAO,CACL,6CAA6C,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;QACnE,uFAAuF;QACvF,yEAAyE;QACzE,kDAAkD;QAClD,qEAAqE;QACrE,qEAAqE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CAAC,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpE,OAAO,CAAC,KAAK,CACX,wFAAwF;YACtF,6DAA6D,CAChE,CAAC;IACJ,CAAC;IAED,OAAO;QACL,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;QAC5B,MAAM;QACN,WAAW;QACX,QAAQ;QACR,UAAU;QACV,SAAS;KACV,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,QAAgB;IACtC,oEAAoE;IACpE,6EAA6E;IAC7E,qEAAqE;IACrE,OAAO,gBAAgB,CAAC,QAAQ,CAAC,KAAK,UAAU,CAAC;AACnD,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Why a host is only reachable from the machine it is named on: `loopback`
3
+ * addresses that machine itself, `link-local` covers 169.254/16, fe80::/10 and
4
+ * the handful of addresses cloud providers put their metadata service on.
5
+ */
6
+ export type InternalHostKind = 'loopback' | 'link-local';
7
+ /**
8
+ * Classifies a hostname that addresses the machine itself, its link-local
9
+ * range, or a cloud metadata service — or returns null for anything routable.
10
+ *
11
+ * It does the job numerically rather than by comparing strings, because the
12
+ * spellings differ more than they look. `URL` canonicalises an IPv4-mapped IPv6
13
+ * literal into hex — `http://[::ffff:127.0.0.1]/` arrives here as
14
+ * `[::ffff:7f00:1]` — while every dual-stack client dials it as plain
15
+ * 127.0.0.1, and `localhost.` with its root label is the same name as
16
+ * `localhost`. String comparison misses both.
17
+ *
18
+ * Takes a hostname from anywhere, not only from `URL`: a resolver hands back
19
+ * `::ffff:127.0.0.1` in dotted form and may attach a `%zone` suffix, so both
20
+ * are handled here rather than assumed away.
21
+ */
22
+ export declare function internalHostKind(hostname: string): InternalHostKind | null;
package/dist/hosts.js ADDED
@@ -0,0 +1,144 @@
1
+ import { isIP } from 'node:net';
2
+ /**
3
+ * Names for the cloud metadata service, which resolve on an instance and
4
+ * nowhere else.
5
+ */
6
+ const METADATA_NAMES = new Set([
7
+ 'metadata',
8
+ 'metadata.google.internal',
9
+ 'metadata.goog',
10
+ 'instance-data',
11
+ 'instance-data.ec2.internal',
12
+ ]);
13
+ /**
14
+ * Metadata endpoints that sit outside 169.254/16.
15
+ *
16
+ * Alibaba Cloud answers on 100.100.100.200, which is carrier-grade NAT space,
17
+ * and Oracle's legacy endpoint is 192.0.0.192, which is IETF protocol
18
+ * assignments. Neither is link-local by address, but both are the same thing by
19
+ * purpose, and neither is somewhere a legitimate target lives.
20
+ */
21
+ const METADATA_ADDRESSES = new Set(['100.100.100.200', '192.0.0.192']);
22
+ /**
23
+ * Classifies a hostname that addresses the machine itself, its link-local
24
+ * range, or a cloud metadata service — or returns null for anything routable.
25
+ *
26
+ * It does the job numerically rather than by comparing strings, because the
27
+ * spellings differ more than they look. `URL` canonicalises an IPv4-mapped IPv6
28
+ * literal into hex — `http://[::ffff:127.0.0.1]/` arrives here as
29
+ * `[::ffff:7f00:1]` — while every dual-stack client dials it as plain
30
+ * 127.0.0.1, and `localhost.` with its root label is the same name as
31
+ * `localhost`. String comparison misses both.
32
+ *
33
+ * Takes a hostname from anywhere, not only from `URL`: a resolver hands back
34
+ * `::ffff:127.0.0.1` in dotted form and may attach a `%zone` suffix, so both
35
+ * are handled here rather than assumed away.
36
+ */
37
+ export function internalHostKind(hostname) {
38
+ const host = bareHost(hostname);
39
+ if (host === 'localhost' || host.endsWith('.localhost'))
40
+ return 'loopback';
41
+ if (METADATA_NAMES.has(host))
42
+ return 'link-local';
43
+ if (METADATA_ADDRESSES.has(host))
44
+ return 'link-local';
45
+ const version = isIP(host);
46
+ if (version === 4)
47
+ return ipv4Kind(host.split('.').map(Number));
48
+ if (version !== 6)
49
+ return null;
50
+ const groups = expandIpv6(host);
51
+ if (groups === null)
52
+ return null;
53
+ const explicit = ipv6Kind(groups);
54
+ if (explicit !== null)
55
+ return explicit;
56
+ const embedded = embeddedIpv4(groups);
57
+ return embedded === null ? null : ipv4Kind(embedded);
58
+ }
59
+ function bareHost(hostname) {
60
+ return (hostname
61
+ .toLowerCase()
62
+ // URL.hostname keeps the brackets around an IPv6 literal, so a bare '::1'
63
+ // would never match.
64
+ .replace(/^\[|]$/g, '')
65
+ // A scope id belongs to the interface, not to the address. `isIP` accepts
66
+ // it, so leaving it on would desynchronise every check below from what
67
+ // `isIP` just agreed was an address.
68
+ .replace(/%.*$/, '')
69
+ // 'localhost.' is the same name as 'localhost' — the root label is what
70
+ // makes it fully qualified, not a different host.
71
+ .replace(/\.+$/, ''));
72
+ }
73
+ /** Expands an IPv6 literal into its eight 16-bit groups. */
74
+ function expandIpv6(address) {
75
+ let text = address;
76
+ // A literal may end in dotted-quad notation (::ffff:127.0.0.1). Fold that tail
77
+ // into the two hex groups it stands for so the rest of this is uniform.
78
+ const dotted = /:(\d{1,3}(?:\.\d{1,3}){3})$/.exec(text);
79
+ if (dotted !== null) {
80
+ const [a = 0, b = 0, c = 0, d = 0] = (dotted[1] ?? '')
81
+ .split('.')
82
+ .map(Number);
83
+ const high = ((a << 8) | b).toString(16);
84
+ const low = ((c << 8) | d).toString(16);
85
+ text = `${text.slice(0, dotted.index)}:${high}:${low}`;
86
+ }
87
+ const [head = '', tail] = text.split('::');
88
+ const left = head === '' ? [] : head.split(':');
89
+ const right = tail === undefined ? null : tail === '' ? [] : tail.split(':');
90
+ if (right === null)
91
+ return toGroups(left);
92
+ const missing = 8 - left.length - right.length;
93
+ if (missing < 0)
94
+ return null;
95
+ return toGroups([...left, ...Array(missing).fill('0'), ...right]);
96
+ }
97
+ function toGroups(groups) {
98
+ if (groups.length !== 8)
99
+ return null;
100
+ // Tested rather than left to `parseInt`, which stops at the first character it
101
+ // does not like and returns a number for '7f00xyz' just as happily.
102
+ if (!groups.every((group) => /^[0-9a-f]{1,4}$/.test(group)))
103
+ return null;
104
+ return groups.map((group) => parseInt(group, 16));
105
+ }
106
+ /**
107
+ * Extracts the IPv4 address an IPv6 literal carries, for the prefixes whose
108
+ * whole purpose is to stand in for one.
109
+ */
110
+ function embeddedIpv4(groups) {
111
+ const [a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0] = groups;
112
+ const carriesIpv4 =
113
+ // ::a.b.c.d (IPv4-compatible) and ::ffff:a.b.c.d (IPv4-mapped, RFC 4291).
114
+ ((a | b | c | d | e) === 0 && (f === 0 || f === 0xffff)) ||
115
+ // ::ffff:0:a.b.c.d — IPv4-translated (RFC 2765).
116
+ ((a | b | c | d) === 0 && e === 0xffff && f === 0) ||
117
+ // 64:ff9b::a.b.c.d — the well-known NAT64 prefix (RFC 6052).
118
+ (a === 0x64 && b === 0xff9b && (c | d | e | f) === 0);
119
+ return carriesIpv4 ? [g >> 8, g & 0xff, h >> 8, h & 0xff] : null;
120
+ }
121
+ function ipv4Kind(octets) {
122
+ const [a = 0, b = 0] = octets;
123
+ // 0.0.0.0/8 ('this host', RFC 1122) and 127/8 both reach the machine itself.
124
+ if (a === 0 || a === 127)
125
+ return 'loopback';
126
+ // 169.254/16, which holds 169.254.169.254 — the AWS/GCP/Azure metadata service.
127
+ if (a === 169 && b === 254)
128
+ return 'link-local';
129
+ return null;
130
+ }
131
+ function ipv6Kind(groups) {
132
+ // `::` and `::1` are also caught by the IPv4-compatible unwrapping below, but
133
+ // they are named here so that removing that unwrapping cannot silently take
134
+ // the two most obvious loopback literals with it.
135
+ if (groups.every((group) => group === 0))
136
+ return 'loopback'; // ::
137
+ if (groups.slice(0, 7).every((group) => group === 0) && groups[7] === 1) {
138
+ return 'loopback'; // ::1
139
+ }
140
+ if (((groups[0] ?? 0) & 0xffc0) === 0xfe80)
141
+ return 'link-local'; // fe80::/10
142
+ return null;
143
+ }
144
+ //# sourceMappingURL=hosts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosts.js","sourceRoot":"","sources":["../src/hosts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAShC;;;GAGG;AACH,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC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AK,EAAE,EAAE,CAAC,KAAK,KAAK,CAAC,CAAC;QAAE,OAAO,UAAU,CAAC,CAAC,KAAK;IAClE,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;QACxE,OAAO,UAAU,CAAC,CAAC,MAAM;IAC3B,CAAC;IACD,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,MAAM;QAAE,OAAO,YAAY,CAAC,CAAC,YAAY;IAC7E,OAAO,IAAI,CAAC;AACd,CAAC"}
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
3
3
  import { loadConfig } from './config.js';
4
4
  import { createServer } from './server.js';
5
+ import { ToolFilterError } from './tool-filter.js';
5
6
  async function main() {
6
7
  const config = loadConfig();
7
8
  if (config.insecureTls) {
@@ -10,7 +11,19 @@ async function main() {
10
11
  if (config.readOnly) {
11
12
  console.error('audiobookshelf-mcp: AUDIOBOOKSHELF_READ_ONLY=true — write tools are not registered');
12
13
  }
13
- const server = createServer(config);
14
+ let server;
15
+ try {
16
+ server = createServer(config);
17
+ }
18
+ catch (error) {
19
+ // A bad tool list is operator feedback, not a crash: print the
20
+ // sentence on its own rather than behind "fatal error:".
21
+ if (error instanceof ToolFilterError) {
22
+ console.error(`audiobookshelf-mcp: ${error.message}`);
23
+ process.exit(1);
24
+ }
25
+ throw error;
26
+ }
14
27
  // stdout belongs to the protocol; everything human-readable goes to stderr.
15
28
  await server.connect(new StdioServerTransport());
16
29
  console.error(config.url
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,O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AE5B,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,OAAO,CAAC,KAAK,CACX,iIAAiI,CAClI,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACpB,OAAO,CAAC,KAAK,CACX,oFAAoF,CACrF,CAAC;IACJ,CAAC;IAED,IAAI,MAAM,CAAC;IACX,IAAI,CAAC;QACH,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,+DAA+D;QAC/D,yDAAyD;QACzD,IAAI,KAAK,YAAY,eAAe,EAAE,CAAC;YACrC,OAAO,CAAC,KAAK,CAAC,uBAAuB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YACtD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;IACD,4EAA4E;IAC5E,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,oBAAoB,EAAE,CAAC,CAAC;IACjD,OAAO,CAAC,KAAK,CACX,MAAM,CAAC,GAAG;QACR,CAAC,CAAC,4CAA4C,MAAM,CAAC,GAAG,EAAE;QAC1D,CAAC,CAAC,iGAAiG,CACtG,CAAC;AACJ,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC9B,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAC;IACzD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
package/dist/server.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createRequire } from 'node:module';
2
2
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
  import { AudiobookshelfApi } from './api.js';
4
+ import { buildToolFilter, installToolFilter } from './tool-filter.js';
4
5
  import { ConfirmationStore } from './confirm.js';
5
6
  import { registerCollectionReadTools, registerCollectionWriteTools, } from './tools/collections.js';
6
7
  import { registerItemReadTools } from './tools/items.js';
@@ -19,12 +20,18 @@ function packageVersion() {
19
20
  }
20
21
  }
21
22
  export function createServer(config) {
23
+ // Before anything is built: an unusable tool list should fail on the
24
+ // way in, not leave a server running with tools quietly missing.
25
+ const filter = buildToolFilter(config);
22
26
  const api = new AudiobookshelfApi(config);
23
27
  const confirmations = new ConfirmationStore();
24
28
  const server = new McpServer({
25
29
  name: 'audiobookshelf-mcp',
26
30
  version: packageVersion(),
27
31
  });
32
+ // Wraps server.registerTool, so it has to sit before the first
33
+ // register call and does not care how they are organised.
34
+ installToolFilter(server, filter);
28
35
  registerLibraryReadTools(server, api);
29
36
  registerItemReadTools(server, api);
30
37
  registerMeReadTools(server, api);
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,GAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EACL,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,GAC3B,MAAM,qBAAqB,CAAC;AAE7B,SAAS,cAAc;IACrB,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC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,CAAC,CAAC;IAElC,wBAAwB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACtC,qBAAqB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACnC,mBAAmB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,2BAA2B,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACzC,yBAAyB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAEvC,6EAA6E;IAC7E,8EAA8E;IAC9E,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrB,0BAA0B,CAAC,MAAM,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC;QACvD,0BAA0B,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACxC,4BAA4B,CAAC,MAAM,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC;QACzD,0BAA0B,CAAC,MAAM,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC;IACzD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,45 @@
1
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ /**
3
+ * A tool list that names something this server does not have.
4
+ *
5
+ * Thrown rather than `process.exit(1)`: `createServer` is called in-process by
6
+ * the tests, and an exiting constructor cannot be tested. `src/index.ts` turns
7
+ * it back into an exit code.
8
+ */
9
+ export declare class ToolFilterError extends Error {
10
+ constructor(message: string);
11
+ }
12
+ export interface ToolFilter {
13
+ /** False when neither variable was set — then nothing is wrapped at all. */
14
+ readonly active: boolean;
15
+ /** The tools that survive. Only meaningful while `active`. */
16
+ readonly selected: ReadonlySet<string>;
17
+ }
18
+ /**
19
+ * Reads `<PREFIX>_ALLOW_TOOLS` / `<PREFIX>_DENY_TOOLS` and works out which
20
+ * tools survive.
21
+ *
22
+ * Every entry has to match at least one tool in the catalogue. An entry that
23
+ * matches nothing is fatal rather than ignored, because the failure it produces
24
+ * otherwise — a tool quietly missing from `tools/list` — is invisible: nobody
25
+ * looks for the cause of an absence in an environment variable.
26
+ */
27
+ export declare function buildToolFilter(config: {
28
+ allowTools: string | undefined;
29
+ denyTools: string | undefined;
30
+ readOnly: boolean;
31
+ }): ToolFilter;
32
+ /**
33
+ * Makes `server` register only the tools the filter selected.
34
+ *
35
+ * The tool is registered and then removed again rather than skipped. Skipping
36
+ * looks cheaper and breaks one case: the SDK installs its `tools/list` handler
37
+ * from inside the registration path, so a server whose every tool was skipped
38
+ * would answer `tools/list` with "method not found" instead of an empty list.
39
+ * `remove()` deletes the entry from the SDK's tool map outright, which makes a
40
+ * filtered tool answer `Tool X not found` — exactly what a tool the read-only
41
+ * mode never registered already does. `disable()` would be wrong: it hides the
42
+ * tool from `tools/list` but still answers a call with "disabled", which is the
43
+ * advertising-a-refusal this server avoids everywhere else.
44
+ */
45
+ export declare function installToolFilter(server: McpServer, filter: ToolFilter): void;
@@ -0,0 +1,171 @@
1
+ import { ALL_TOOLS, ESSENTIAL_TOOLS, READ_TOOLS } from './tools/catalogue.js';
2
+ /**
3
+ * A tool list that names something this server does not have.
4
+ *
5
+ * Thrown rather than `process.exit(1)`: `createServer` is called in-process by
6
+ * the tests, and an exiting constructor cannot be tested. `src/index.ts` turns
7
+ * it back into an exit code.
8
+ */
9
+ export class ToolFilterError extends Error {
10
+ constructor(message) {
11
+ super(message);
12
+ this.name = 'ToolFilterError';
13
+ }
14
+ }
15
+ /** The `essential` preset is spelled out here so it cannot collide with a tool name. */
16
+ const PRESET = 'essential';
17
+ /**
18
+ * Splits a comma-separated value into entries.
19
+ *
20
+ * Empty entries are dropped, so `a,,b` and a trailing comma are both fine, and
21
+ * a value that is empty or only whitespace counts as *unset* — `X_ALLOW_TOOLS=`
22
+ * in a compose file must not mean "allow nothing". Entries are lowercased: the
23
+ * catalogue is entirely lowercase, so this is lossless, and a shell that
24
+ * upper-cased a name should not take the server down.
25
+ */
26
+ function entriesOf(raw) {
27
+ if (raw === undefined)
28
+ return undefined;
29
+ const entries = raw
30
+ .split(',')
31
+ .map((entry) => entry.trim().toLowerCase())
32
+ .filter((entry) => entry.length > 0);
33
+ return entries.length > 0 ? entries : undefined;
34
+ }
35
+ /**
36
+ * Expands one entry to the catalogue tools it names.
37
+ *
38
+ * A pattern is a literal prefix plus exactly one trailing `*`. Anything else is
39
+ * rejected outright: `*_zone` and `list_*_x` look plausible, match nothing, and
40
+ * would otherwise be silent forever.
41
+ */
42
+ function expand(entry, variable) {
43
+ const star = entry.indexOf('*');
44
+ if (star !== -1) {
45
+ if (star !== entry.length - 1) {
46
+ throw new ToolFilterError(`${variable}: "${entry}" is not a valid entry — a pattern is a prefix ` +
47
+ 'followed by a single trailing "*", for example "list_*". Everything ' +
48
+ 'else is an exact tool name.');
49
+ }
50
+ const prefix = entry.slice(0, -1);
51
+ return ALL_TOOLS.filter((tool) => tool.startsWith(prefix));
52
+ }
53
+ return ALL_TOOLS.filter((tool) => tool === entry);
54
+ }
55
+ /** The full catalogue, for the "these are the names that exist" half of an error. */
56
+ function catalogueList() {
57
+ return [...ALL_TOOLS].sort().join(', ');
58
+ }
59
+ /**
60
+ * Reads `<PREFIX>_ALLOW_TOOLS` / `<PREFIX>_DENY_TOOLS` and works out which
61
+ * tools survive.
62
+ *
63
+ * Every entry has to match at least one tool in the catalogue. An entry that
64
+ * matches nothing is fatal rather than ignored, because the failure it produces
65
+ * otherwise — a tool quietly missing from `tools/list` — is invisible: nobody
66
+ * looks for the cause of an absence in an environment variable.
67
+ */
68
+ export function buildToolFilter(config) {
69
+ const allow = entriesOf(config.allowTools);
70
+ const deny = entriesOf(config.denyTools);
71
+ if (allow === undefined && deny === undefined) {
72
+ return { active: false, selected: new Set() };
73
+ }
74
+ // What would be registered without any filter. In read-only mode the write
75
+ // tools never reach `registerTool`, but they stay in the catalogue so that a
76
+ // name from that half is answered with "read-only suppresses it", never with
77
+ // "no such tool".
78
+ const registered = new Set(config.readOnly ? READ_TOOLS : ALL_TOOLS);
79
+ // Set when an allow entry named real tools and read-only suppressed all of
80
+ // them, so that "nothing is left" can name the reason rather than shrugging.
81
+ let suppressedByReadOnly = false;
82
+ let selected;
83
+ if (allow === undefined) {
84
+ selected = new Set(registered);
85
+ }
86
+ else {
87
+ selected = new Set();
88
+ for (const entry of allow) {
89
+ if (entry === PRESET) {
90
+ // Preset members are not names the operator typed, so a member that
91
+ // read-only suppresses is dropped silently rather than being an error.
92
+ for (const tool of ESSENTIAL_TOOLS) {
93
+ if (registered.has(tool))
94
+ selected.add(tool);
95
+ }
96
+ continue;
97
+ }
98
+ const matches = expand(entry, 'AUDIOBOOKSHELF_ALLOW_TOOLS');
99
+ if (matches.length === 0) {
100
+ throw new ToolFilterError(`AUDIOBOOKSHELF_ALLOW_TOOLS: no tool matches "${entry}". ` +
101
+ `Valid tools: ${catalogueList()}. "${PRESET}" selects the curated preset.`);
102
+ }
103
+ const survivors = matches.filter((tool) => registered.has(tool));
104
+ if (survivors.length === 0) {
105
+ if (entry.endsWith('*')) {
106
+ // A pattern is a template, not a claim about one tool: warn, continue.
107
+ console.error(`audiobookshelf-mcp: AUDIOBOOKSHELF_ALLOW_TOOLS: "${entry}" matches only write ` +
108
+ 'tools, which AUDIOBOOKSHELF_READ_ONLY suppresses — it contributes nothing.');
109
+ suppressedByReadOnly = true;
110
+ continue;
111
+ }
112
+ // An exact name, though, was typed by someone who believes it is exposed.
113
+ throw new ToolFilterError(`AUDIOBOOKSHELF_ALLOW_TOOLS: "${entry}" is a write tool, but AUDIOBOOKSHELF_READ_ONLY ` +
114
+ 'is set — it is never registered. Remove it from AUDIOBOOKSHELF_ALLOW_TOOLS, ' +
115
+ `or unset AUDIOBOOKSHELF_READ_ONLY. Available in read-only mode: ${[...READ_TOOLS].sort().join(', ')}.`);
116
+ }
117
+ for (const tool of survivors)
118
+ selected.add(tool);
119
+ }
120
+ }
121
+ for (const entry of deny ?? []) {
122
+ // Deny lists are written defensively — "never expose delete_*, whatever
123
+ // else is on" — so matching nothing that survives is fine. Matching nothing
124
+ // in the catalogue is still a typo.
125
+ const matches = expand(entry, 'AUDIOBOOKSHELF_DENY_TOOLS');
126
+ if (matches.length === 0) {
127
+ throw new ToolFilterError(`AUDIOBOOKSHELF_DENY_TOOLS: no tool matches "${entry}". Valid tools: ${catalogueList()}.`);
128
+ }
129
+ for (const tool of matches)
130
+ selected.delete(tool);
131
+ }
132
+ if (selected.size === 0) {
133
+ throw new ToolFilterError(suppressedByReadOnly
134
+ ? 'AUDIOBOOKSHELF_ALLOW_TOOLS selects only write tools, but AUDIOBOOKSHELF_READ_ONLY is ' +
135
+ 'set — the server would start with an empty tool list.'
136
+ : 'AUDIOBOOKSHELF_ALLOW_TOOLS/AUDIOBOOKSHELF_DENY_TOOLS leave no tools registered — the ' +
137
+ 'server would start with an empty tool list.');
138
+ }
139
+ return { active: true, selected };
140
+ }
141
+ /**
142
+ * Makes `server` register only the tools the filter selected.
143
+ *
144
+ * The tool is registered and then removed again rather than skipped. Skipping
145
+ * looks cheaper and breaks one case: the SDK installs its `tools/list` handler
146
+ * from inside the registration path, so a server whose every tool was skipped
147
+ * would answer `tools/list` with "method not found" instead of an empty list.
148
+ * `remove()` deletes the entry from the SDK's tool map outright, which makes a
149
+ * filtered tool answer `Tool X not found` — exactly what a tool the read-only
150
+ * mode never registered already does. `disable()` would be wrong: it hides the
151
+ * tool from `tools/list` but still answers a call with "disabled", which is the
152
+ * advertising-a-refusal this server avoids everywhere else.
153
+ */
154
+ export function installToolFilter(server, filter) {
155
+ if (!filter.active)
156
+ return;
157
+ const register = server.registerTool.bind(server);
158
+ // An object literal rather than a plain function so the method picks up the
159
+ // SDK's generic signature by contextual typing — the call sites keep their
160
+ // typed handler arguments and nothing needs a cast.
161
+ const wrapper = {
162
+ registerTool(name, config, cb) {
163
+ const tool = register(name, config, cb);
164
+ if (!filter.selected.has(name))
165
+ tool.remove();
166
+ return tool;
167
+ },
168
+ };
169
+ server.registerTool = wrapper.registerTool;
170
+ }
171
+ //# sourceMappingURL=tool-filter.js.map
@@ -0,0 +1 @@
1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AAI,CAAC;QACd,CAAC;KACF,CAAC;IACF,MAAM,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The tools this server can register, declared rather than discovered.
3
+ *
4
+ * Declared, because the tool filter has to answer "is this a name you have?"
5
+ * *before* anything is registered — and in read-only mode the write tools are
6
+ * never registered at all. Deriving the catalogue from what actually reached
7
+ * `registerTool` would make `AUDIOBOOKSHELF_ALLOW_TOOLS=add_books_to_collection` report
8
+ * "unknown tool" under `AUDIOBOOKSHELF_READ_ONLY=true`, which is the one answer that
9
+ * is wrong.
10
+ *
11
+ * This is also the full tool surface, hard-coded on purpose: a tool that appears
12
+ * or disappears by accident is a change to the server's contract and has to be a
13
+ * deliberate edit here. `test/tool-filter.test.ts` asserts that these lists and
14
+ * the tools the server really registers are the same set.
15
+ */
16
+ /** Registered always. Every one carries `readOnlyHint: true`. */
17
+ export declare const READ_TOOLS: readonly ["get_author", "get_collection", "get_item_chapters", "get_library", "get_library_filter_data", "get_library_item", "get_library_stats", "get_listening_stats", "get_me", "get_media_progress", "get_personalized_shelves", "get_playlist", "get_podcast_episode", "get_series", "get_server_status", "get_year_stats", "list_authors", "list_bookmarks", "list_collections", "list_genres", "list_items_in_progress", "list_libraries", "list_library_items", "list_listening_sessions", "list_playlists", "list_recent_episodes", "list_series", "list_tags", "search_library"];
18
+ /** Registered unless `AUDIOBOOKSHELF_READ_ONLY` is set. */
19
+ export declare const WRITE_TOOLS: readonly ["add_books_to_collection", "add_items_to_playlist", "create_bookmark", "create_collection", "create_playlist", "delete_bookmark", "delete_collection", "delete_media_progress", "delete_playlist", "remove_books_from_collection", "remove_items_from_playlist", "set_media_progress", "update_bookmark", "update_collection", "update_playlist"];
20
+ /** Every tool, read-only mode aside. */
21
+ export declare const ALL_TOOLS: readonly string[];
22
+ /**
23
+ * What `AUDIOBOOKSHELF_ALLOW_TOOLS=essential` selects: find, inspect, resume.
24
+ *
25
+ * 8 of 44. Left out on purpose: the collection, playlist and bookmark CRUD, and every statistics tool —
26
+ * organisational and retrospective rather than operational.
27
+ */
28
+ export declare const ESSENTIAL_TOOLS: readonly string[];
@@ -0,0 +1,84 @@
1
+ /**
2
+ * The tools this server can register, declared rather than discovered.
3
+ *
4
+ * Declared, because the tool filter has to answer "is this a name you have?"
5
+ * *before* anything is registered — and in read-only mode the write tools are
6
+ * never registered at all. Deriving the catalogue from what actually reached
7
+ * `registerTool` would make `AUDIOBOOKSHELF_ALLOW_TOOLS=add_books_to_collection` report
8
+ * "unknown tool" under `AUDIOBOOKSHELF_READ_ONLY=true`, which is the one answer that
9
+ * is wrong.
10
+ *
11
+ * This is also the full tool surface, hard-coded on purpose: a tool that appears
12
+ * or disappears by accident is a change to the server's contract and has to be a
13
+ * deliberate edit here. `test/tool-filter.test.ts` asserts that these lists and
14
+ * the tools the server really registers are the same set.
15
+ */
16
+ /** Registered always. Every one carries `readOnlyHint: true`. */
17
+ export const READ_TOOLS = [
18
+ 'get_author',
19
+ 'get_collection',
20
+ 'get_item_chapters',
21
+ 'get_library',
22
+ 'get_library_filter_data',
23
+ 'get_library_item',
24
+ 'get_library_stats',
25
+ 'get_listening_stats',
26
+ 'get_me',
27
+ 'get_media_progress',
28
+ 'get_personalized_shelves',
29
+ 'get_playlist',
30
+ 'get_podcast_episode',
31
+ 'get_series',
32
+ 'get_server_status',
33
+ 'get_year_stats',
34
+ 'list_authors',
35
+ 'list_bookmarks',
36
+ 'list_collections',
37
+ 'list_genres',
38
+ 'list_items_in_progress',
39
+ 'list_libraries',
40
+ 'list_library_items',
41
+ 'list_listening_sessions',
42
+ 'list_playlists',
43
+ 'list_recent_episodes',
44
+ 'list_series',
45
+ 'list_tags',
46
+ 'search_library',
47
+ ];
48
+ /** Registered unless `AUDIOBOOKSHELF_READ_ONLY` is set. */
49
+ export const WRITE_TOOLS = [
50
+ 'add_books_to_collection',
51
+ 'add_items_to_playlist',
52
+ 'create_bookmark',
53
+ 'create_collection',
54
+ 'create_playlist',
55
+ 'delete_bookmark',
56
+ 'delete_collection',
57
+ 'delete_media_progress',
58
+ 'delete_playlist',
59
+ 'remove_books_from_collection',
60
+ 'remove_items_from_playlist',
61
+ 'set_media_progress',
62
+ 'update_bookmark',
63
+ 'update_collection',
64
+ 'update_playlist',
65
+ ];
66
+ /** Every tool, read-only mode aside. */
67
+ export const ALL_TOOLS = [...READ_TOOLS, ...WRITE_TOOLS];
68
+ /**
69
+ * What `AUDIOBOOKSHELF_ALLOW_TOOLS=essential` selects: find, inspect, resume.
70
+ *
71
+ * 8 of 44. Left out on purpose: the collection, playlist and bookmark CRUD, and every statistics tool —
72
+ * organisational and retrospective rather than operational.
73
+ */
74
+ export const ESSENTIAL_TOOLS = [
75
+ 'list_libraries',
76
+ 'search_library',
77
+ 'list_library_items',
78
+ 'get_library_item',
79
+ 'get_item_chapters',
80
+ 'list_items_in_progress',
81
+ 'get_media_progress',
82
+ 'set_media_progress',
83
+ ];
84
+ //# sourceMappingURL=catalogue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalogue.js","sourceRoot":"","sources":["../../src/tools/catalogue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,iEAAiE;AACjE,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,YAAY;IACZ,gBAAgB;IAChB,mBAAmB;IACnB,aAAa;IACb,yBAAyB;IACzB,kBAAkB;IAClB,mBAAmB;IACnB,qBAAqB;IACrB,QAAQ;IACR,oBAAoB;IACpB,0BAA0B;IAC1B,cAAc;IACd,qBAAqB;IACrB,YAAY;IACZ,mBAAmB;IACnB,gBAAgB;IAChB,cAAc;IACd,gBAAgB;IAChB,kBAAkB;IAClB,aAAa;IACb,wBAAwB;IACxB,gBAAgB;IAChB,oBAAoB;IACpB,yBAAyB;IACzB,gBAAgB;IAChB,sBAAsB;IACtB,aAAa;IACb,WAAW;IACX,gBAAgB;CACR,CAAC;AAEX,2DAA2D;AAC3D,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,yBAAyB;IACzB,uBAAuB;IACvB,iBAAiB;IACjB,mBAAmB;IACnB,iBAAiB;IACjB,iBAAiB;IACjB,mBAAmB;IACnB,uBAAuB;IACvB,iBAAiB;IACjB,8BAA8B;IAC9B,4BAA4B;IAC5B,oBAAoB;IACpB,iBAAiB;IACjB,mBAAmB;IACnB,iBAAiB;CACT,CAAC;AAEX,wCAAwC;AACxC,MAAM,CAAC,MAAM,SAAS,GAAsB,CAAC,GAAG,UAAU,EAAE,GAAG,WAAW,CAAC,CAAC;AAE5E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAsB;IAChD,gBAAgB;IAChB,gBAAgB;IAChB,oBAAoB;IACpB,kBAAkB;IAClB,mBAAmB;IACnB,wBAAwB;IACxB,oBAAoB;IACpB,oBAAoB;CACrB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "audiobookshelf-mcp",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "mcpName": "io.github.ni-c/audiobookshelf-mcp",
5
5
  "description": "MCP server for Audiobookshelf, the self-hosted audiobook and podcast server",
6
6
  "keywords": [
@@ -21,6 +21,7 @@
21
21
  "url": "https://github.com/ni-c/audiobookshelf-mcp/issues"
22
22
  },
23
23
  "homepage": "https://github.com/ni-c/audiobookshelf-mcp#readme",
24
+ "funding": "https://github.com/sponsors/ni-c",
24
25
  "type": "module",
25
26
  "bin": {
26
27
  "audiobookshelf-mcp": "dist/index.js"
@@ -54,7 +55,7 @@
54
55
  "@eslint/js": "^10.0.1",
55
56
  "@resvg/resvg-js": "^2.6.2",
56
57
  "@types/node": "^26.2.0",
57
- "@vitest/coverage-v8": "4.1.10",
58
+ "@vitest/coverage-v8": "4.1.11",
58
59
  "eslint": "^10.8.1",
59
60
  "prettier": "^3.9.6",
60
61
  "typescript": "^6.0.3",