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
45 lines
1.8 KiB
JavaScript
45 lines
1.8 KiB
JavaScript
#!/usr/bin/env node
|
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
import { TorrentClawClient } from "./api-client.js";
|
|
import { config } from "./config.js";
|
|
import { registerSearchContent } from "./tools/search-content.js";
|
|
import { registerGetPopular } from "./tools/get-popular.js";
|
|
import { registerGetRecent } from "./tools/get-recent.js";
|
|
import { registerGetWatchProviders } from "./tools/get-watch-providers.js";
|
|
import { registerGetCredits } from "./tools/get-credits.js";
|
|
import { registerGetTorrentUrl } from "./tools/get-torrent-url.js";
|
|
import { registerStatsResource } from "./resources/stats.js";
|
|
import { registerPrompts } from "./prompts.js";
|
|
|
|
const client = new TorrentClawClient();
|
|
|
|
const server = new McpServer({
|
|
name: "torrentclaw",
|
|
version: config.version,
|
|
description:
|
|
"Search and discover movies and TV shows with torrent downloads, streaming availability, and cast/crew metadata. Start with search_content to find content, then use get_watch_providers or get_credits with the content_id. Use get_popular/get_recent to browse (no torrents — search for a title to get torrents).",
|
|
});
|
|
|
|
// Register tools
|
|
registerSearchContent(server, client);
|
|
registerGetPopular(server, client);
|
|
registerGetRecent(server, client);
|
|
registerGetWatchProviders(server, client);
|
|
registerGetCredits(server, client);
|
|
registerGetTorrentUrl(server, client);
|
|
|
|
// Register resources
|
|
registerStatsResource(server, client);
|
|
|
|
// Register prompts
|
|
registerPrompts(server);
|
|
|
|
// Graceful shutdown
|
|
process.on("SIGTERM", () => process.exit(0));
|
|
process.on("SIGINT", () => process.exit(0));
|
|
|
|
// Connect via STDIO
|
|
const transport = new StdioServerTransport();
|
|
await server.connect(transport);
|
|
console.error("TorrentClaw MCP server running on stdio");
|