feat: initial release of torrentclaw-mcp server
MCP (Model Context Protocol) server that wraps the TorrentClaw REST API, enabling LLMs (Claude Desktop, Claude Code, Cursor, etc.) to search movies and TV shows with torrent downloads and streaming availability. ## Tools (6) - search_content: primary search with filters (title, genre, year, rating, quality, language, sort). Returns content metadata + torrent magnet links. - get_popular: trending content ranked by clicks - get_recent: most recently added content - get_watch_providers: streaming availability by country (Netflix, Disney+, etc.) - get_credits: director and top 10 cast members - get_torrent_url: .torrent file download URL from info_hash ## Resources - torrentclaw://stats: catalog statistics (content/torrent counts, sources) ## Prompts (4) - search_movie, search_show, whats_new, where_to_watch ## LLM Usability - Server description with workflow guidance for tool chaining - Tool descriptions include trigger phrases, cross-tool references, and explicit parameter examples - Formatted output includes info_hash for tool chaining and call-syntax cross-references (e.g. "use with get_watch_providers(content_id=42)") - Popular/recent output hints to use search_content for torrents - Error messages include status-specific recovery guidance (400, 404, 429, 5xx) - Prompts reference tools by name for reliable LLM execution ## Security - SSRF protection: validates TORRENTCLAW_API_URL against private IPs, localhost, link-local, and IPv6 loopback addresses - Protocol whitelist: only http/https allowed - Error body sanitization: 4xx truncated to 200 chars, 5xx bodies omitted - Input validation: control char filter on queries, regex on country codes, genre character whitelist, content_id bounds ## Testing - 85 tests across 13 test files - Coverage: 99.5% statements, 95.2% branches, 98.1% functions, 99.5% lines - Vitest v4 with v8 coverage provider, 80% thresholds enforced ## Stack - TypeScript ESM, Node.js >= 18 (native fetch) - @modelcontextprotocol/sdk v1.12, zod v3.24 - STDIO transport, runnable via npx torrentclaw-mcp
This commit is contained in:
commit
d471c9b695
36 changed files with 6000 additions and 0 deletions
101
tests/formatters/providers.test.ts
Normal file
101
tests/formatters/providers.test.ts
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
import { describe, it, expect } from "vitest";
|
||||
import { formatWatchProviders } from "../../src/formatters/providers.js";
|
||||
import type { WatchProvidersResponse } from "../../src/types.js";
|
||||
|
||||
describe("formatWatchProviders", () => {
|
||||
it("formats providers by availability type", () => {
|
||||
const data: WatchProvidersResponse = {
|
||||
contentId: 42,
|
||||
country: "ES",
|
||||
providers: {
|
||||
flatrate: [
|
||||
{ providerId: 8, name: "Netflix", logo: null, link: null, displayPriority: 1 },
|
||||
{ providerId: 337, name: "Disney+", logo: null, link: null, displayPriority: 2 },
|
||||
],
|
||||
rent: [
|
||||
{ providerId: 2, name: "Apple TV", logo: null, link: null, displayPriority: 1 },
|
||||
],
|
||||
buy: [
|
||||
{ providerId: 3, name: "Google Play", logo: null, link: null, displayPriority: 1 },
|
||||
],
|
||||
free: [],
|
||||
},
|
||||
attribution: "Watch provider data provided by JustWatch via TMDB.",
|
||||
};
|
||||
|
||||
const text = formatWatchProviders(data);
|
||||
expect(text).toContain("Watch providers for content #42 in ES");
|
||||
expect(text).toContain("Stream: Netflix, Disney+");
|
||||
expect(text).toContain("Rent: Apple TV");
|
||||
expect(text).toContain("Buy: Google Play");
|
||||
expect(text).not.toContain("Free:");
|
||||
expect(text).toContain("JustWatch");
|
||||
});
|
||||
|
||||
it("handles no providers", () => {
|
||||
const data: WatchProvidersResponse = {
|
||||
contentId: 10,
|
||||
country: "US",
|
||||
providers: { flatrate: [], rent: [], buy: [], free: [] },
|
||||
attribution: "JustWatch",
|
||||
};
|
||||
|
||||
const text = formatWatchProviders(data);
|
||||
expect(text).toContain("No watch providers found in US");
|
||||
});
|
||||
|
||||
it("shows VPN suggestion when available", () => {
|
||||
const data: WatchProvidersResponse = {
|
||||
contentId: 5,
|
||||
country: "AR",
|
||||
providers: { flatrate: [], rent: [], buy: [], free: [] },
|
||||
vpnSuggestion: {
|
||||
availableIn: ["US", "ES", "FR"],
|
||||
affiliateUrl: "https://example.com/vpn",
|
||||
},
|
||||
attribution: "JustWatch",
|
||||
};
|
||||
|
||||
const text = formatWatchProviders(data);
|
||||
expect(text).toContain("Available in other countries: US, ES, FR");
|
||||
});
|
||||
|
||||
it("sorts providers by display priority", () => {
|
||||
const data: WatchProvidersResponse = {
|
||||
contentId: 1,
|
||||
country: "GB",
|
||||
providers: {
|
||||
flatrate: [
|
||||
{ providerId: 2, name: "Second", logo: null, link: null, displayPriority: 20 },
|
||||
{ providerId: 1, name: "First", logo: null, link: null, displayPriority: 1 },
|
||||
],
|
||||
rent: [],
|
||||
buy: [],
|
||||
free: [],
|
||||
},
|
||||
attribution: "JustWatch",
|
||||
};
|
||||
|
||||
const text = formatWatchProviders(data);
|
||||
expect(text).toContain("Stream: First, Second");
|
||||
});
|
||||
|
||||
it("shows free providers", () => {
|
||||
const data: WatchProvidersResponse = {
|
||||
contentId: 1,
|
||||
country: "US",
|
||||
providers: {
|
||||
flatrate: [],
|
||||
rent: [],
|
||||
buy: [],
|
||||
free: [
|
||||
{ providerId: 100, name: "Tubi", logo: null, link: null, displayPriority: 1 },
|
||||
],
|
||||
},
|
||||
attribution: "JustWatch",
|
||||
};
|
||||
|
||||
const text = formatWatchProviders(data);
|
||||
expect(text).toContain("Free: Tubi");
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue