guessit-js 5.2.0 → 5.3.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 +16 -0
- package/bin/mcp-core.mjs +204 -18
- package/dist/guessit-js.cjs +1 -1
- package/dist/guessit-js.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -266,6 +266,14 @@ tool. Three read-only tools:
|
|
|
266
266
|
| `guessit_batch` | `{"filenames": [...], "options": {...}}` | `{"results": [{input_string, result} \| {input_string, error}]}` |
|
|
267
267
|
| `guessit_properties` | `{}` | every property with its possible values |
|
|
268
268
|
|
|
269
|
+
[](https://insiders.vscode.dev/redirect/mcp/install?name=guessit&config=%7B%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22guessit-js%22%2C%22--mcp%22%5D%7D)
|
|
270
|
+
[](https://cursor.com/en/install-mcp?name=guessit&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsImd1ZXNzaXQtanMiLCItLW1jcCJdfQ==)
|
|
271
|
+
[](https://github.com/opensubtitles/guessit-js/releases/latest/download/guessit-js.mcpb)
|
|
272
|
+
[](https://registry.modelcontextprotocol.io/v0/servers?search=com.opensubtitles/guessit-js)
|
|
273
|
+
|
|
274
|
+
**Claude Desktop**: download [`guessit-js.mcpb`](https://github.com/opensubtitles/guessit-js/releases/latest/download/guessit-js.mcpb)
|
|
275
|
+
from the latest release and open it (Settings → Extensions). Runs locally, offline.
|
|
276
|
+
|
|
269
277
|
**Local (stdio)**, no server to run:
|
|
270
278
|
|
|
271
279
|
```bash
|
|
@@ -279,6 +287,8 @@ claude mcp add guessit -- npx -y guessit-js --mcp # Claude Code
|
|
|
279
287
|
(Claude Desktop `claude_desktop_config.json`, Cursor `.cursor/mcp.json`, VS Code
|
|
280
288
|
`.vscode/mcp.json` with `"servers"` instead of `"mcpServers"`.)
|
|
281
289
|
|
|
290
|
+
Docker: `docker run -i --rm ghcr.io/opensubtitles/guessit-js node bin/cli.mjs --mcp`
|
|
291
|
+
|
|
282
292
|
**Remote (Streamable HTTP)**, nothing to install: `https://guessit.opensubtitles.com/mcp`
|
|
283
293
|
(demo tier, same limits as the hosted API), or `POST /mcp` on a self-hosted
|
|
284
294
|
`npm start` server.
|
|
@@ -287,6 +297,12 @@ claude mcp add guessit -- npx -y guessit-js --mcp # Claude Code
|
|
|
287
297
|
claude mcp add --transport http guessit https://guessit.opensubtitles.com/mcp
|
|
288
298
|
```
|
|
289
299
|
|
|
300
|
+
Protocol: dual-era. Stateless MCP `2026-07-28` (`server/discover`, per-request
|
|
301
|
+
`_meta`, no handshake) and the `initialize` handshake of `2025-11-25` back to
|
|
302
|
+
`2024-11-05`, on both stdio and HTTP. Every tool has an `outputSchema` and
|
|
303
|
+
returns `structuredContent`. Listed in the [official MCP Registry](https://registry.modelcontextprotocol.io)
|
|
304
|
+
as `com.opensubtitles/guessit-js`.
|
|
305
|
+
|
|
290
306
|
For language models reading about the project: [`llms.txt`](https://opensubtitles.github.io/guessit-js/llms.txt)
|
|
291
307
|
(also at `/llms.txt` on the hosted API) and the [OpenAPI spec](https://opensubtitles.github.io/guessit-js/openapi.json).
|
|
292
308
|
|
package/bin/mcp-core.mjs
CHANGED
|
@@ -3,9 +3,36 @@
|
|
|
3
3
|
// Cloudflare worker and server.ts (HTTP POST /mcp). No Node-only imports, no
|
|
4
4
|
// dependencies.
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// Dual-era: "modern" revisions (2026-07-28+) are stateless and carry the
|
|
7
|
+
// protocol version in every request's _meta; "legacy" revisions open with an
|
|
8
|
+
// initialize handshake. The server itself keeps no state either way.
|
|
9
|
+
const MODERN_PROTOCOLS = ['2026-07-28'];
|
|
10
|
+
const LEGACY_PROTOCOLS = ['2025-11-25', '2025-06-18', '2025-03-26', '2024-11-05'];
|
|
11
|
+
const SUPPORTED_PROTOCOLS = [...MODERN_PROTOCOLS, ...LEGACY_PROTOCOLS];
|
|
7
12
|
const MAX_FILENAME_LENGTH = 4096;
|
|
8
13
|
|
|
14
|
+
const META = 'io.modelcontextprotocol/';
|
|
15
|
+
// The tool list only changes with a new release; clients and shared caches may keep it.
|
|
16
|
+
const CACHEABLE = { ttlMs: 3_600_000, cacheScope: 'public' };
|
|
17
|
+
|
|
18
|
+
const INSTRUCTIONS =
|
|
19
|
+
'guessit-js extracts metadata (title, year, season, episode, resolution, codecs, '
|
|
20
|
+
+ 'languages, release group, ...) from movie and TV filenames. Use guessit for one '
|
|
21
|
+
+ 'name, guessit_batch for many. Output matches Python guessit; pass '
|
|
22
|
+
+ 'options.output="codes" for ISO language codes with regions.';
|
|
23
|
+
|
|
24
|
+
const serverInfo = (api) => ({
|
|
25
|
+
name: 'guessit-js',
|
|
26
|
+
title: 'guessit-js',
|
|
27
|
+
version: api.version,
|
|
28
|
+
description: 'Parse movie and TV filenames: title, year, season, episode, codecs, languages, release group.',
|
|
29
|
+
websiteUrl: 'https://opensubtitles.github.io/guessit-js/',
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Error codes (2026-07-28 reserves -32020..-32099 for the MCP specification).
|
|
33
|
+
const HEADER_MISMATCH = -32020;
|
|
34
|
+
const UNSUPPORTED_PROTOCOL_VERSION = -32022;
|
|
35
|
+
|
|
9
36
|
const OPTIONS_SCHEMA = {
|
|
10
37
|
type: 'object',
|
|
11
38
|
description:
|
|
@@ -35,6 +62,20 @@ const TOOLS = [
|
|
|
35
62
|
required: ['filename'],
|
|
36
63
|
additionalProperties: false,
|
|
37
64
|
},
|
|
65
|
+
outputSchema: {
|
|
66
|
+
type: 'object',
|
|
67
|
+
description: 'Python guessit JSON: only the properties found; several values become an array. '
|
|
68
|
+
+ 'guessit_properties lists every property. Full schema: '
|
|
69
|
+
+ 'https://github.com/opensubtitles/guessit-js/blob/main/docs/output-schema.json',
|
|
70
|
+
properties: {
|
|
71
|
+
type: { type: 'string', enum: ['movie', 'episode'] },
|
|
72
|
+
title: {},
|
|
73
|
+
year: {},
|
|
74
|
+
season: {},
|
|
75
|
+
episode: {},
|
|
76
|
+
},
|
|
77
|
+
additionalProperties: true,
|
|
78
|
+
},
|
|
38
79
|
annotations: { readOnlyHint: true, openWorldHint: false, idempotentHint: true },
|
|
39
80
|
},
|
|
40
81
|
{
|
|
@@ -53,6 +94,25 @@ const TOOLS = [
|
|
|
53
94
|
required: ['filenames'],
|
|
54
95
|
additionalProperties: false,
|
|
55
96
|
},
|
|
97
|
+
outputSchema: {
|
|
98
|
+
type: 'object',
|
|
99
|
+
properties: {
|
|
100
|
+
results: {
|
|
101
|
+
type: 'array',
|
|
102
|
+
description: 'One entry per input name, in order',
|
|
103
|
+
items: {
|
|
104
|
+
type: 'object',
|
|
105
|
+
properties: {
|
|
106
|
+
input_string: { type: 'string' },
|
|
107
|
+
result: { type: 'object', additionalProperties: true },
|
|
108
|
+
error: { type: 'string' },
|
|
109
|
+
},
|
|
110
|
+
required: ['input_string'],
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
required: ['results'],
|
|
115
|
+
},
|
|
56
116
|
annotations: { readOnlyHint: true, openWorldHint: false, idempotentHint: true },
|
|
57
117
|
},
|
|
58
118
|
{
|
|
@@ -62,6 +122,11 @@ const TOOLS = [
|
|
|
62
122
|
'List every property guessit can return with its possible values (enum values such as '
|
|
63
123
|
+ 'source: ["Blu-ray", "Web", ...]; [null] for free-form ones such as title).',
|
|
64
124
|
inputSchema: { type: 'object', properties: {}, additionalProperties: false },
|
|
125
|
+
outputSchema: {
|
|
126
|
+
type: 'object',
|
|
127
|
+
description: 'Property name -> possible values',
|
|
128
|
+
additionalProperties: { type: 'array' },
|
|
129
|
+
},
|
|
65
130
|
annotations: { readOnlyHint: true, openWorldHint: false, idempotentHint: true },
|
|
66
131
|
},
|
|
67
132
|
];
|
|
@@ -107,9 +172,25 @@ function validOptions(options) {
|
|
|
107
172
|
* message is a notification (or anything else that takes no answer).
|
|
108
173
|
* @param {{ guessit: Function, guessitMany: Function, properties: Function, version: string }} api
|
|
109
174
|
*/
|
|
175
|
+
/** The protocol version a request's _meta declares (modern revisions), if any. */
|
|
176
|
+
function requestedVersion(msg) {
|
|
177
|
+
const meta = msg && msg.params && msg.params._meta;
|
|
178
|
+
return meta && typeof meta === 'object' ? meta[`${META}protocolVersion`] : undefined;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Modern requests declare their version per request; server/discover exists only there. */
|
|
182
|
+
export function isModernRequest(msg) {
|
|
183
|
+
return !!msg && typeof msg === 'object'
|
|
184
|
+
&& (requestedVersion(msg) !== undefined || msg.method === 'server/discover');
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Answer one JSON-RPC message. Returns the response object, or null when the
|
|
189
|
+
* message is a notification (or anything else that takes no answer).
|
|
190
|
+
* @param {{ guessit: Function, guessitMany: Function, properties: Function, version: string, maxBatch: number }} api
|
|
191
|
+
*/
|
|
110
192
|
export function handleMcpMessage(api, msg) {
|
|
111
|
-
const
|
|
112
|
-
const fail = (id, code, message) => ({ jsonrpc: '2.0', id, error: { code, message } });
|
|
193
|
+
const fail = (id, code, message, data) => ({ jsonrpc: '2.0', id, error: data === undefined ? { code, message } : { code, message, data } });
|
|
113
194
|
|
|
114
195
|
function callTool(name, args) {
|
|
115
196
|
args = args ?? {};
|
|
@@ -139,31 +220,62 @@ export function handleMcpMessage(api, msg) {
|
|
|
139
220
|
}
|
|
140
221
|
const { id, method, params } = msg;
|
|
141
222
|
const isNotification = id === undefined || id === null;
|
|
223
|
+
if (isNotification) return null; // notifications/initialized, cancelled, ... take no answer
|
|
224
|
+
|
|
225
|
+
// Modern (stateless) requests: validate the per-request _meta first.
|
|
226
|
+
const modern = isModernRequest(msg);
|
|
227
|
+
const requested = requestedVersion(msg);
|
|
228
|
+
let modernShape = false;
|
|
229
|
+
if (modern) {
|
|
230
|
+
if (typeof requested !== 'string') {
|
|
231
|
+
return fail(id, -32602, `Invalid params: _meta["${META}protocolVersion"] is required`);
|
|
232
|
+
}
|
|
233
|
+
if (!SUPPORTED_PROTOCOLS.includes(requested)) {
|
|
234
|
+
return fail(id, UNSUPPORTED_PROTOCOL_VERSION, 'Unsupported protocol version', { supported: SUPPORTED_PROTOCOLS, requested });
|
|
235
|
+
}
|
|
236
|
+
modernShape = MODERN_PROTOCOLS.includes(requested);
|
|
237
|
+
const caps = params._meta[`${META}clientCapabilities`];
|
|
238
|
+
if (modernShape && (!caps || typeof caps !== 'object' || Array.isArray(caps))) {
|
|
239
|
+
return fail(id, -32602, `Invalid params: _meta["${META}clientCapabilities"] is required`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
// Modern results say they are complete and name the server (there is no handshake).
|
|
243
|
+
const reply = (result) => ({
|
|
244
|
+
jsonrpc: '2.0',
|
|
245
|
+
id,
|
|
246
|
+
result: modernShape
|
|
247
|
+
? { resultType: 'complete', ...result, _meta: { [`${META}serverInfo`]: serverInfo(api) } }
|
|
248
|
+
: result,
|
|
249
|
+
});
|
|
250
|
+
|
|
142
251
|
switch (method) {
|
|
252
|
+
case 'server/discover':
|
|
253
|
+
return reply({
|
|
254
|
+
supportedVersions: SUPPORTED_PROTOCOLS,
|
|
255
|
+
capabilities: { tools: {} },
|
|
256
|
+
instructions: INSTRUCTIONS,
|
|
257
|
+
...CACHEABLE,
|
|
258
|
+
});
|
|
143
259
|
case 'initialize': {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
260
|
+
// The legacy handshake negotiates a legacy revision only.
|
|
261
|
+
const asked = params && params.protocolVersion;
|
|
262
|
+
return reply({
|
|
263
|
+
protocolVersion: LEGACY_PROTOCOLS.includes(asked) ? asked : LEGACY_PROTOCOLS[0],
|
|
147
264
|
capabilities: { tools: { listChanged: false } },
|
|
148
|
-
serverInfo:
|
|
149
|
-
instructions:
|
|
150
|
-
'guessit-js extracts metadata (title, year, season, episode, resolution, codecs, '
|
|
151
|
-
+ 'languages, release group, ...) from movie and TV filenames. Use guessit for one '
|
|
152
|
-
+ 'name, guessit_batch for many. Output matches Python guessit; pass '
|
|
153
|
-
+ 'options.output="codes" for ISO language codes with regions.',
|
|
265
|
+
serverInfo: serverInfo(api),
|
|
266
|
+
instructions: INSTRUCTIONS,
|
|
154
267
|
});
|
|
155
268
|
}
|
|
156
269
|
case 'ping':
|
|
157
|
-
return
|
|
270
|
+
return reply({});
|
|
158
271
|
case 'tools/list':
|
|
159
|
-
return reply(
|
|
272
|
+
return reply(modernShape ? { tools: toolsFor(api), ...CACHEABLE } : { tools: toolsFor(api) });
|
|
160
273
|
case 'tools/call': {
|
|
161
274
|
const result = callTool(params && params.name, params && params.arguments);
|
|
162
|
-
return result === null ? fail(id, -32602, `Unknown tool: ${params && params.name}`) : reply(
|
|
275
|
+
return result === null ? fail(id, -32602, `Unknown tool: ${params && params.name}`) : reply(result);
|
|
163
276
|
}
|
|
164
277
|
default:
|
|
165
|
-
|
|
166
|
-
return isNotification ? null : fail(id, -32601, `Method not found: ${method}`);
|
|
278
|
+
return fail(id, -32601, `Method not found: ${method}`);
|
|
167
279
|
}
|
|
168
280
|
}
|
|
169
281
|
|
|
@@ -182,4 +294,78 @@ export function handleMcpPayload(api, text) {
|
|
|
182
294
|
return handleMcpMessage(api, msg);
|
|
183
295
|
}
|
|
184
296
|
|
|
185
|
-
|
|
297
|
+
/** Decode an Mcp-Name / Mcp-Param-* header value ("=?base64?...?=" sentinel or plain ASCII). */
|
|
298
|
+
function decodeHeaderValue(v) {
|
|
299
|
+
const m = /^=\?base64\?([A-Za-z0-9+/=]*)\?=$/.exec(v);
|
|
300
|
+
if (!m) return v;
|
|
301
|
+
try {
|
|
302
|
+
return new TextDecoder('utf-8', { fatal: true }).decode(Uint8Array.from(atob(m[1]), (c) => c.charCodeAt(0)));
|
|
303
|
+
} catch {
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Streamable HTTP POST /mcp, shared by server.ts and the Cloudflare worker.
|
|
310
|
+
* Stateless: every request is answered with plain JSON, notifications with 202.
|
|
311
|
+
* @param {string} text the request body
|
|
312
|
+
* @param {(name: string) => string | null | undefined} header case-insensitive header lookup
|
|
313
|
+
* @returns {{ status: number, body: unknown }} body null means "no body"
|
|
314
|
+
*/
|
|
315
|
+
export function handleMcpHttp(api, text, header) {
|
|
316
|
+
let msg;
|
|
317
|
+
try {
|
|
318
|
+
msg = JSON.parse(text);
|
|
319
|
+
} catch {
|
|
320
|
+
return { status: 400, body: { jsonrpc: '2.0', id: null, error: { code: -32700, message: 'Parse error' } } };
|
|
321
|
+
}
|
|
322
|
+
const mismatch = (message) => ({
|
|
323
|
+
status: 400,
|
|
324
|
+
body: { jsonrpc: '2.0', id: msg && typeof msg === 'object' && 'id' in msg ? msg.id : null, error: { code: HEADER_MISMATCH, message } },
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
// Modern request: the mirrored headers must be present and match the body.
|
|
328
|
+
if (!Array.isArray(msg) && isModernRequest(msg)) {
|
|
329
|
+
const version = requestedVersion(msg);
|
|
330
|
+
const hv = header('mcp-protocol-version');
|
|
331
|
+
if (!hv) return mismatch('Header mismatch: MCP-Protocol-Version header is required');
|
|
332
|
+
if (typeof version === 'string' && hv !== version) {
|
|
333
|
+
return mismatch(`Header mismatch: MCP-Protocol-Version header value '${hv}' does not match body value '${version}'`);
|
|
334
|
+
}
|
|
335
|
+
const hm = header('mcp-method');
|
|
336
|
+
if (!hm) return mismatch('Header mismatch: Mcp-Method header is required');
|
|
337
|
+
if (hm !== msg.method) return mismatch(`Header mismatch: Mcp-Method header value '${hm}' does not match body value '${msg.method}'`);
|
|
338
|
+
if (msg.method === 'tools/call') {
|
|
339
|
+
const raw = header('mcp-name');
|
|
340
|
+
if (!raw) return mismatch('Header mismatch: Mcp-Name header is required for tools/call');
|
|
341
|
+
const name = decodeHeaderValue(raw);
|
|
342
|
+
if (name === null) return mismatch('Header mismatch: Mcp-Name header is not valid Base64 UTF-8');
|
|
343
|
+
if (name !== (msg.params && msg.params.name)) return mismatch('Header mismatch: Mcp-Name header does not match params.name');
|
|
344
|
+
}
|
|
345
|
+
const answer = handleMcpMessage(api, msg);
|
|
346
|
+
if (!answer) return { status: 202, body: null };
|
|
347
|
+
if (!answer.error) return { status: 200, body: answer };
|
|
348
|
+
const { code } = answer.error;
|
|
349
|
+
return { status: code === -32601 ? 404 : code === -32603 ? 500 : 400, body: answer };
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// Legacy (initialize handshake) revisions: as before, JSON-RPC errors ride on 200,
|
|
353
|
+
// except an MCP-Protocol-Version header this server cannot speak.
|
|
354
|
+
const hv = header('mcp-protocol-version');
|
|
355
|
+
if (hv && !SUPPORTED_PROTOCOLS.includes(hv)) {
|
|
356
|
+
return {
|
|
357
|
+
status: 400,
|
|
358
|
+
body: {
|
|
359
|
+
jsonrpc: '2.0',
|
|
360
|
+
id: msg && typeof msg === 'object' && 'id' in msg ? msg.id : null,
|
|
361
|
+
error: { code: UNSUPPORTED_PROTOCOL_VERSION, message: 'Unsupported protocol version', data: { supported: SUPPORTED_PROTOCOLS, requested: hv } },
|
|
362
|
+
},
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
const answer = Array.isArray(msg)
|
|
366
|
+
? (() => { const out = msg.map((m) => handleMcpMessage(api, m)).filter(Boolean); return out.length ? out : null; })()
|
|
367
|
+
: handleMcpMessage(api, msg);
|
|
368
|
+
return answer ? { status: 200, body: answer } : { status: 202, body: null };
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export { TOOLS, SUPPORTED_PROTOCOLS, MODERN_PROTOCOLS, LEGACY_PROTOCOLS };
|