Skip to main content
Glama
masx200
by masx200

webdav_range_request

Read specific byte ranges from files on remote WebDAV servers using HTTP partial content requests to download portions of large files without transferring the entire file.

Instructions

Read a specific byte range from a file on a remote WebDAV server (similar to HTTP 206 Partial Content)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
rangeYesByte range in format "bytes=0-499" (first 500 bytes), "bytes=500-" (from byte 500 to end), or "0-499" (range from start to end)

Implementation Reference

  • MCP tool registration for 'webdav_range_request', including schema validation with Zod and the complete inline handler function that orchestrates the range request.
    server.tool(
      "webdav_range_request",
      "Read a specific byte range from a file on a remote WebDAV server (similar to HTTP 206 Partial Content)",
      {
        path: z.string().min(1, "Path must not be empty"),
        range: z.string().describe(
          'Byte range in format "bytes=0-499" (first 500 bytes), "bytes=500-" (from byte 500 to end), or "0-499" (range from start to end)',
        ),
      },
      async ({ path, range }) => {
        try {
          // Check if file exists first
          const exists = await webdavService.exists(path);
          if (!exists) {
            return {
              content: [{
                type: "text",
                text: `Error: File does not exist at ${path}`,
              }],
              isError: true,
            };
          }
    
          // Check if range requests are supported
          const supportsRanges = await webdavService.supportsRangeRequests(path);
          if (!supportsRanges) {
            return {
              content: [{
                type: "text",
                text:
                  `Error: Range requests are not supported for this file or server`,
              }],
              isError: true,
            };
          }
    
          // Perform the range request
          const result = await webdavService.readFileWithRange(path, range);
    
          // Format the response similar to HTTP 206 response
          const response = [
            `=== HTTP 206 Partial Content Simulation ===`,
            `File: ${path}`,
            `Content-Range: ${result.contentRange}`,
            `Accept-Ranges: ${result.acceptRanges ? "bytes" : "none"}`,
            `Content-Length: ${result.content.length}`,
            `Total-Size: ${result.totalSize}`,
            `Range-Request: ${range}`,
            ``,
            `=== Content ===`,
            result.content,
          ].join("\n");
    
          return {
            content: [{
              type: "text",
              text: response,
            }],
          };
        } catch (error) {
          return {
            content: [{
              type: "text",
              text: `Error performing range request: ${(error as Error).message}`,
            }],
            isError: true,
          };
        }
      },
    );
  • The handler function that implements the tool logic: input validation is implicit via schema, checks preconditions, delegates to WebDAV service, formats output as simulated HTTP partial content response.
    async ({ path, range }) => {
      try {
        // Check if file exists first
        const exists = await webdavService.exists(path);
        if (!exists) {
          return {
            content: [{
              type: "text",
              text: `Error: File does not exist at ${path}`,
            }],
            isError: true,
          };
        }
    
        // Check if range requests are supported
        const supportsRanges = await webdavService.supportsRangeRequests(path);
        if (!supportsRanges) {
          return {
            content: [{
              type: "text",
              text:
                `Error: Range requests are not supported for this file or server`,
            }],
            isError: true,
          };
        }
    
        // Perform the range request
        const result = await webdavService.readFileWithRange(path, range);
    
        // Format the response similar to HTTP 206 response
        const response = [
          `=== HTTP 206 Partial Content Simulation ===`,
          `File: ${path}`,
          `Content-Range: ${result.contentRange}`,
          `Accept-Ranges: ${result.acceptRanges ? "bytes" : "none"}`,
          `Content-Length: ${result.content.length}`,
          `Total-Size: ${result.totalSize}`,
          `Range-Request: ${range}`,
          ``,
          `=== Content ===`,
          result.content,
        ].join("\n");
    
        return {
          content: [{
            type: "text",
            text: response,
          }],
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Error performing range request: ${(error as Error).message}`,
          }],
          isError: true,
        };
      }
    },
  • Input schema using Zod for path (required string) and range (string with description of supported formats).
    {
      path: z.string().min(1, "Path must not be empty"),
      range: z.string().describe(
        'Byte range in format "bytes=0-499" (first 500 bytes), "bytes=500-" (from byte 500 to end), or "0-499" (range from start to end)',
      ),
    },
  • Supporting helper method in WebDAVService that handles the low-level range request: parses range string, validates against file size, creates read stream with range, buffers content, computes Content-Range header.
    async readFileWithRange(
      path: string,
      range: string,
    ): Promise<{
      content: string;
      contentRange: string;
      acceptRanges: boolean;
      totalSize: number;
    }> {
      const fullPath = this.getFullPath(path);
      logger.debug(`Reading file with range: ${fullPath}`, { range });
    
      try {
        // Parse the range header
        const parsedRange = this.parseRangeHeader(range);
        if (!parsedRange) {
          throw new Error("Invalid range format");
        }
    
        // Get file stats first to check total size
        const stats = await this.stat(fullPath);
        const totalSize = stats.size || 0;
    
        // Validate range against file size
        if (parsedRange.start >= totalSize) {
          throw new Error(
            `Range start (${parsedRange.start}) is beyond file size (${totalSize})`,
          );
        }
    
        // Calculate actual end position
        const end = parsedRange.end === undefined
          ? totalSize - 1
          : Math.min(parsedRange.end, totalSize - 1);
    
        // Use createReadStream with range options
        const stream = this.client.createReadStream(fullPath, {
          range: {
            start: parsedRange.start,
            end: parsedRange.end,
          },
        });
    
        // Convert stream to string
        const chunks: Buffer[] = [];
    
        return new Promise((resolve, reject) => {
          stream.on("data", (chunk: Buffer) => {
            chunks.push(chunk);
          });
    
          stream.on("end", () => {
            try {
              const content = Buffer.concat(chunks).toString("utf8");
              const contentRange =
                `bytes ${parsedRange.start}-${end}/${totalSize}`;
    
              logger.debug(`Range request completed: ${fullPath}`, {
                range,
                contentLength: content.length,
                totalSize,
              });
    
              resolve({
                content,
                contentRange,
                acceptRanges: true,
                totalSize,
              });
            } catch (error) {
              reject(
                new Error(
                  `Failed to process stream content: ${(error as Error).message}`,
                ),
              );
            }
          });
    
          stream.on("error", (error) => {
            logger.error(`Stream error for ${fullPath}:`, error);
            reject(new Error(`Stream error: ${error.message}`));
          });
        });
      } catch (error) {
        logger.error(`Error reading file with range ${fullPath}:`, error);
        throw new Error(
          `Failed to read file with range: ${(error as Error).message}`,
        );
      }
    }
  • Helper method that checks if range requests are supported by attempting to stat the file (assumes support if stat succeeds).
    async supportsRangeRequests(path: string = "/"): Promise<boolean> {
      const fullPath = this.getFullPath(path);
      logger.debug(`Checking range request support for: ${fullPath}`);
    
      try {
        // For WebDAV servers, we'll assume range requests are supported
        // if we can successfully read file metadata
        const stats = await this.stat(fullPath);
        return true;
      } catch (error) {
        logger.debug(`Range request support check failed for ${fullPath}`, error);
        return false;
      }
    }
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses the read-only nature ('Read') and the partial content behavior, but lacks details on authentication needs, rate limits, error handling, or what happens with invalid ranges. It adds some context beyond the schema but is incomplete for a tool interacting with remote servers.

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?

The description is a single, efficient sentence that front-loads the core action and context. Every word earns its place, with no redundancy or fluff, making it easy for an agent to parse quickly.

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

Completeness3/5

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

Given no annotations, no output schema, and low schema coverage, the description is moderately complete. It covers the basic purpose and behavior but lacks details on authentication, errors, or return values. For a tool with remote operations and two parameters, more context would be helpful for safe and effective use.

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 description coverage is 50% (only 'range' has a description). The description adds no explicit parameter semantics, but the tool's purpose inherently clarifies that 'path' is the file location and 'range' specifies bytes. This compensates partially for the low schema coverage, though format examples are only in the schema.

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?

The description clearly states the verb ('Read'), resource ('a specific byte range from a file'), and context ('on a remote WebDAV server'), with the analogy to HTTP 206 Partial Content adding technical specificity. It distinguishes this tool from siblings like webdav_get_remote_file or webdav_read_remote_file by emphasizing partial content retrieval.

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?

The description implies usage for partial file reading, but does not explicitly state when to use this tool versus alternatives like webdav_get_remote_file (full file) or webdav_read_remote_file (full read). No exclusions or prerequisites are mentioned, leaving the agent to infer context from the 'byte range' focus.

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/masx200/mcp-webdav-server'

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