Skip to main content
Glama
opensubtitles

OpenSubtitles MCP Server

Official

download_subtitle

Download subtitle files from OpenSubtitles.com using file IDs. Supports format conversion, time shifting, and direct file downloads with authentication options.

Instructions

Download subtitle content by file ID. Downloads in original format with force_download=true by default for direct file download.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_idYesFile ID from search results (found in files array of subtitle results)
file_nameNoDesired file name for the downloaded subtitle
in_fpsNoInput FPS for subtitle conversion (must use with out_fps)
out_fpsNoOutput FPS for subtitle conversion (must use with in_fps)
timeshiftNoTime shift in seconds to add/remove (e.g. 2.5 or -1)
force_downloadNoSet subtitle file headers to 'application/force-download' for direct file download (default: true)
user_api_keyNoYour OpenSubtitles API key for authenticated downloads
usernameNoOpenSubtitles.com username (alternative to API key)
passwordNoOpenSubtitles.com password (use with username)

Implementation Reference

  • The primary handler function that implements the download_subtitle tool logic. It validates inputs using Zod, handles authentication (API key or username/password login), requests download link from OpenSubtitles API, fetches subtitle content, and returns formatted JSON response with error handling.
    export async function downloadSubtitle(args: unknown) {
      try {
        // Validate input arguments
        const validatedArgs = DownloadArgsSchema.parse(args);
        
        // Extract authentication parameters from args
        const { user_api_key, username, password, file_id, file_name, in_fps, out_fps, timeshift, force_download } = validatedArgs;
        
        // Create API client
        const client = new OpenSubtitlesKongClient();
        
        // Handle authentication
        let authValue: string | undefined = user_api_key;
        let isToken = false;
        
        // If username/password provided, login to get token
        if (username && password && !user_api_key) {
          try {
            const loginResponse = await client.login({ username, password });
            authValue = loginResponse.token;
            isToken = true;
            console.error(`DEBUG: Successfully logged in user ${username}, got token`);
          } catch (loginError) {
            console.error("DEBUG: Login failed:", loginError);
            // Continue with default API key (authValue will be undefined)
          }
        }
        
        // Request download link
        const downloadParams: any = {
          file_id: file_id,
        };
        
        // Add optional parameters
        if (file_name) downloadParams.file_name = file_name;
        if (in_fps !== undefined) downloadParams.in_fps = in_fps;
        if (out_fps !== undefined) downloadParams.out_fps = out_fps;
        if (timeshift !== undefined) downloadParams.timeshift = timeshift;
        // Always set force_download to ensure direct file download with proper headers
        downloadParams.force_download = force_download;
        
        const downloadInfo = await client.downloadSubtitle(
          downloadParams,
          authValue,
          isToken
        );
        
        // Download the actual subtitle content
        const subtitleContent = await client.downloadSubtitleContent(downloadInfo.link);
        
        // Format response
        const response = {
          file_id: file_id,
          file_name: downloadInfo.file_name,
          content: subtitleContent,
          force_download: force_download,
          download_info: {
            requests_used: downloadInfo.requests,
            requests_remaining: downloadInfo.remaining,
            reset_time: downloadInfo.reset_time,
            reset_time_utc: downloadInfo.reset_time_utc,
            message: downloadInfo.message,
          },
        };
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(response, null, 2),
            },
          ],
        };
    
      } catch (error) {
        console.error("Download subtitle error:", error);
        
        let errorMessage = "Failed to download subtitle";
        if (error instanceof z.ZodError) {
          errorMessage = `Invalid parameters: ${error.errors.map(e => `${e.path.join('.')}: ${e.message}`).join(', ')}`;
        } else if (error instanceof Error) {
          errorMessage = error.message;
        }
    
        // Provide helpful error messages based on common issues
        if (errorMessage.includes("429")) {
          errorMessage += "\n\nTo download subtitles, you need an OpenSubtitles API key. Get one free at: https://www.opensubtitles.com/api";
        } else if (errorMessage.includes("401")) {
          errorMessage += "\n\nYour API key may be invalid. Please check it at: https://www.opensubtitles.com/api";
        }
    
        return {
          content: [
            {
              type: "text",
              text: `Error: ${errorMessage}`,
            },
          ],
        };
      }
    }
  • Zod schema used for input validation within the download_subtitle handler.
    const DownloadArgsSchema = z.object({
      file_id: z.number(),
      file_name: z.string().optional(),
      in_fps: z.number().optional(),
      out_fps: z.number().optional(),
      timeshift: z.number().optional(),
      force_download: z.boolean().optional().default(true), // Default to true for direct file download
      user_api_key: z.string().optional(),
      username: z.string().optional(),
      password: z.string().optional(),
    });
  • src/server.ts:110-156 (registration)
    MCP tool registration defining the download_subtitle tool, including its name, description, and JSON input schema for the server.
    {
      name: "download_subtitle",
      description: "Download subtitle content by file ID. Downloads in original format with force_download=true by default for direct file download.",
      inputSchema: {
        type: "object",
        properties: {
          file_id: {
            type: "number",
            description: "File ID from search results (found in files array of subtitle results)"
          },
          file_name: {
            type: "string",
            description: "Desired file name for the downloaded subtitle"
          },
          in_fps: {
            type: "number",
            description: "Input FPS for subtitle conversion (must use with out_fps)"
          },
          out_fps: {
            type: "number", 
            description: "Output FPS for subtitle conversion (must use with in_fps)"
          },
          timeshift: {
            type: "number",
            description: "Time shift in seconds to add/remove (e.g. 2.5 or -1)"
          },
          force_download: {
            type: "boolean",
            description: "Set subtitle file headers to 'application/force-download' for direct file download (default: true)"
          },
          user_api_key: {
            type: "string",
            description: "Your OpenSubtitles API key for authenticated downloads"
          },
          username: {
            type: "string",
            description: "OpenSubtitles.com username (alternative to API key)"
          },
          password: {
            type: "string",
            description: "OpenSubtitles.com password (use with username)"
          }
        },
        required: ["file_id"],
        additionalProperties: false
      }
    },
  • src/server.ts:341-343 (registration)
    Handler dispatch in the server's handleToolCall method that routes calls to the downloadSubtitle function.
    case "download_subtitle":
      console.error("DEBUG: Calling downloadSubtitle");
      return await downloadSubtitle(args);
  • Import statement that brings the downloadSubtitle handler into the server module.
    import { downloadSubtitle } from "./tools/download-subtitle.js";
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the default 'force_download=true' and that it downloads 'in original format', which adds some context. However, it fails to disclose critical behaviors: authentication requirements (implied by parameters but not stated), rate limits, error handling, or what the output looks like (e.g., file data vs. metadata). For a download tool with 9 parameters, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core action ('Download subtitle content by file ID') and adds a useful detail about defaults. There's no wasted verbiage, and it's appropriately sized for the tool's complexity. However, it could be slightly more structured by separating the default behavior into a second sentence for clarity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (9 parameters, no annotations, no output schema), the description is incomplete. It lacks information on authentication (though parameters hint at it), output format (e.g., binary file vs. text), error cases, and how parameters interact. Without annotations or output schema, the description should compensate more to guide the agent effectively, but it falls short.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds minimal value beyond the schema: it implies 'file_id' is the primary identifier and mentions the default for 'force_download'. However, it doesn't explain relationships between parameters (e.g., 'in_fps' and 'out_fps' must be used together) or provide additional semantic context, meeting the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('download') and resource ('subtitle content by file ID'), making the purpose unambiguous. It distinguishes from sibling tools like 'calculate_file_hash' and 'search_subtitles' by focusing on downloading rather than hashing or searching. However, it doesn't explicitly mention what distinguishes it from potential non-sibling alternatives beyond the basic action.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It mentions a default behavior ('force_download=true by default') but doesn't explain when to override this or when to use other tools like 'search_subtitles' first. There's no context about prerequisites or typical workflows, leaving the agent with no usage direction.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/opensubtitles/mcp.opensubtitles.com'

If you have feedback or need assistance with the MCP directory API, please join our Discord server