Skip to main content
Glama
julien-nc

C411 MCP Server

by julien-nc

download_c411_torrent

Download .torrent files from c411.org using infoHash and save them to a specified directory for torrent management.

Instructions

Download a .torrent file from c411.org by its infoHash and save it to disk.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
infoHashYesThe 40-character hex infoHash of the torrent
outputDirNoDirectory where the .torrent file should be saved. Defaults to /tmp.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
errorNo
successYes
filenameNo
savedPathNo

Implementation Reference

  • The `downloadTorrent` method in `C411Client` handles the actual logic for downloading a .torrent file from the c411 API and saving it to the specified output directory.
    async downloadTorrent(infoHash: string, outputDir = '/tmp'): Promise<DownloadResult> {
      if (!infoHash || !/^[a-fA-F0-9]{40}$/.test(infoHash)) {
        return { success: false, error: 'Invalid infoHash. Must be a 40-character hex string.' };
      }
    
      try {
        return await this.withAuthentication<DownloadResult>(async () => {
          const response = await this.client.get<ArrayBuffer>(`/api/torrents/${infoHash}/download`, {
            responseType: 'arraybuffer',
            headers: {
              'Accept': 'application/x-bittorrent, application/octet-stream, */*',
              'Referer': `${this.baseUrl}/torrents/${infoHash}`,
            },
          });
    
          const contentType = getContentType(response.headers as Record<string, unknown>);
          const responseUrl = getResponseUrl(response.request);
    
          if (isMaintenanceResponse(response.status, response.data, contentType)) {
            throw new MaintenanceError();
          }
    
          if (isAuthenticationFailureResponse(response.status, response.data, contentType, responseUrl)) {
            return { type: 'reauth' };
          }
    
          if (response.status === 404) {
            return { type: 'success', value: { success: false, error: 'Torrent not found.' } };
          }
    
          if (response.status >= 400) {
            const errorMessage = getErrorMessageFromResponse(
              response.data,
              contentType
            ) || `HTTP ${response.status}`;
            return { type: 'success', value: { success: false, error: `Download failed - ${errorMessage}` } };
          }
    
          const buffer = Buffer.isBuffer(response.data)
            ? response.data
            : Buffer.from(response.data);
    
          if (!this.isValidTorrentFile(buffer)) {
            const errorMessage = getErrorMessageFromResponse(response.data, contentType);
            const responseDescription = errorMessage
              ? `Unexpected download response: ${errorMessage}`
              : `Unexpected download response with content type ${contentType ?? 'unknown'}`;
    
            return {
              type: 'success',
              value: {
                success: false,
                error: `${responseDescription}. The payload does not look like a valid .torrent file.`,
              },
            };
          }
    
          const contentDisposition = typeof response.headers['content-disposition'] === 'string'
            ? response.headers['content-disposition']
            : undefined;
          let filename = `${infoHash}.torrent`;
          if (contentDisposition) {
            const match = contentDisposition.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
            if (match && match[1]) {
              filename = match[1].replace(/['"]/g, '').trim();
            }
          }
    
          const safeFilename = path.basename(filename) || `${infoHash}.torrent`;
          const resolvedOutputDir = path.resolve(outputDir);
          const savedPath = path.join(resolvedOutputDir, safeFilename);
    
          await mkdir(resolvedOutputDir, { recursive: true });
          await writeFile(savedPath, buffer);
    
          return {
            type: 'success',
            value: {
              success: true,
              filename: safeFilename,
              savedPath,
            },
          };
        }, 'Unable to authenticate. Check C411_USERNAME and C411_PASSWORD environment variables.');
      } catch (error) {
        const message = getSafeErrorMessage(error, this.requestTimeoutMs);
        console.error(`Error downloading torrent: ${message}`);
        return { success: false, error: message };
      }
    }
  • Registration of the 'download_c411_torrent' tool, which maps the MCP tool request to the `client.downloadTorrent` implementation.
    server.registerTool('download_c411_torrent', {
      description: 'Download a .torrent file from c411.org by its infoHash and save it to disk.',
      inputSchema: downloadToolSchema,
      outputSchema: downloadToolOutputSchema,
    }, async (args) => {
      const result = await client.downloadTorrent(args.infoHash, args.outputDir ?? '/tmp');
      return result.success
        ? textWithStructuredContent(result.savedPath || `Saved ${result.filename}`, {
          success: true,
          filename: result.filename || `${args.infoHash}.torrent`,
          savedPath: result.savedPath || `Saved ${result.filename}`,
        })
        : errorContent(result.error || 'Download failed', {
          success: false,
          ...(result.filename ? { filename: result.filename } : {}),
          ...(result.savedPath ? { savedPath: result.savedPath } : {}),
          error: result.error || 'Download failed',
        });
    });
Behavior3/5

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

No annotations provided, so description carries full disclosure burden. Successfully discloses the side effect ('save to disk'), indicating filesystem mutation. However, lacks details on idempotency, network requirements, error handling (e.g., invalid hash), or output structure despite having an output schema available.

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

Conciseness5/5

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

Single, dense sentence with zero waste. Front-loaded with the action verb, immediately communicating purpose. Every clause earns its place: source domain, identification method, and persistence mechanism are all efficiently packed.

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

Completeness4/5

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

Appropriate for a 2-parameter tool with full schema coverage and existing output schema. Covers the essential 'what' and 'where to' aspects. Minor gap: could briefly mention the return value indicates success/failure or file path since annotations are absent.

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

Parameters4/5

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

Schema coverage is 100%, establishing a baseline of 3. Description adds value by clarifying the infoHash's role in identifying the specific torrent to retrieve ('by its infoHash'), and implicitly connects the outputDir to the 'save to disk' action. Could mention the default /tmp behavior explicitly, but overall adds meaningful usage context.

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

Purpose5/5

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

Excellent specificity: states the verb ('Download'), resource ('.torrent file'), source ('c411.org'), identifier ('by its infoHash'), and side effect ('save to disk'). Clearly distinguishes from siblings 'get_c411_torrent_info' and 'search_c411' through the explicit action of downloading vs retrieving metadata or searching.

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

Usage Guidelines3/5

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

Provides implied usage context through the specific action ('download... save to disk'), but lacks explicit when-to-use guidance contrasting with siblings. Does not state prerequisites (e.g., valid c411.org infoHash) or error conditions.

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/julien-nc/mcp-server-c411'

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