Skip to main content
Glama
masx200
by masx200

webdav_create_remote_file

Create a new file on a remote WebDAV server at a specified path with content, optionally overwriting existing files.

Instructions

Create a new file on a remote WebDAV server at the specified path

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYes
overwriteNo
pathYes

Implementation Reference

  • The core handler function that implements the tool logic. It checks if the file exists (respecting overwrite flag), writes the content using WebDAVService, and returns appropriate success or error messages in MCP content format.
    },
    async ({ path, content, overwrite }) => {
      try {
        // Check if file exists and respect overwrite flag
        const exists = await webdavService.exists(path);
        if (exists && !overwrite) {
          return {
            content: [{
              type: "text",
              text:
                `Error: File already exists at ${path}. Use overwrite=true to replace it.`,
            }],
            isError: true,
          };
        }
    
        await webdavService.writeFile(path, content);
    
        return {
          content: [{
            type: "text",
            text: `File created successfully at ${path}`,
          }],
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Error creating file: ${(error as Error).message}`,
          }],
          isError: true,
        };
      }
    },
  • Zod input schema defining parameters: path (required string), content (string), overwrite (optional boolean default false). Used for validation in the tool registration.
    {
      path: z.string().min(1, "Path must not be empty"),
      content: z.string(),
      overwrite: z.boolean().optional().default(false),
    },
  • MCP tool registration via server.tool(), including name, description, schema, and handler reference. This is called within setupToolHandlers which is invoked during server setup.
    server.tool(
      "webdav_create_remote_file",
      "Create a new file on a remote WebDAV server at the specified path",
      {
        path: z.string().min(1, "Path must not be empty"),
        content: z.string(),
        overwrite: z.boolean().optional().default(false),
      },
      async ({ path, content, overwrite }) => {
        try {
          // Check if file exists and respect overwrite flag
          const exists = await webdavService.exists(path);
          if (exists && !overwrite) {
            return {
              content: [{
                type: "text",
                text:
                  `Error: File already exists at ${path}. Use overwrite=true to replace it.`,
              }],
              isError: true,
            };
          }
    
          await webdavService.writeFile(path, content);
    
          return {
            content: [{
              type: "text",
              text: `File created successfully at ${path}`,
            }],
          };
        } catch (error) {
          return {
            content: [{
              type: "text",
              text: `Error creating file: ${(error as Error).message}`,
            }],
            isError: true,
          };
        }
      },
    );
  • Supporting utility in WebDAVService class that performs the actual remote file write operation using the WebDAV client's putFileContents method, with path normalization, logging, and error handling.
    async writeFile(path: string, content: string | Buffer): Promise<void> {
      const fullPath = this.getFullPath(path);
      const contentLength = typeof content === "string"
        ? content.length
        : content.length;
      logger.debug(`Writing file: ${fullPath}`, { contentLength });
    
      try {
        // putFileContents in v5.x returns a boolean indicating success
        const result = await this.client.putFileContents(fullPath, content);
    
        // Check result based on type
        if (typeof result === "boolean" && !result) {
          throw new Error("Failed to write file: server returned failure status");
        } else if (
          this.isResponseData(result) &&
          result.status !== undefined &&
          result.status !== 201 &&
          result.status !== 204
        ) {
          throw new Error(
            `Failed to write file: server returned status ${result.status}`,
          );
        }
    
        logger.debug(`Successfully wrote file: ${fullPath}`);
      } catch (error) {
        logger.error(`Error writing to file ${fullPath}:`, error);
        throw new Error(`Failed to write file: ${(error as Error).message}`);
      }
  • Helper method used by the handler to check if the target file already exists before writing.
    async exists(path: string): Promise<boolean> {
      const fullPath = this.getFullPath(path);
      logger.debug(`Checking if exists: ${fullPath}`);
    
      try {
        const result = await this.client.exists(fullPath);
    
        // Handle both boolean and object responses
        let exists = false;
    
        if (typeof result === "boolean") {
          exists = result;
        } else if (result && typeof result === "object") {
          // Use type guard for better type safety
          const responseData = result as ResponseData;
          if (responseData.status !== undefined) {
            exists = responseData.status < 400; // If status is less than 400, the resource exists
          }
        }
    
        logger.debug(`Exists check for ${fullPath}: ${exists}`);
        return exists;
      } catch (error) {
        logger.error(`Error checking existence of ${fullPath}:`, error);
        return false;
      }
    }
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 creating a file but lacks critical details: it doesn't specify whether this requires authentication, what happens if the path doesn't exist (e.g., parent directories), error handling for conflicts, or the response format. The 'overwrite' parameter hints at some behavior but isn't explained in the description.

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 directly states the tool's purpose without unnecessary words. It's appropriately sized for a basic operation, though more detail would be needed for completeness.

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 complexity of a file creation operation with no annotations, no output schema, and 0% schema description coverage, the description is inadequate. It doesn't cover authentication needs, error scenarios, response details, or parameter usage, making it insufficient for safe and effective tool invocation.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate for undocumented parameters. It mentions 'path' but doesn't explain its format or requirements. It omits 'content' entirely and provides no context for 'overwrite' (e.g., default behavior or implications). This leaves key parameters semantically unclear beyond the schema.

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 'create' and the resource 'new file on a remote WebDAV server at the specified path', which distinguishes it from siblings like webdav_create_remote_directory (creates directories) and webdav_update_remote_file (updates existing files). However, it doesn't explicitly mention the 'content' parameter, which is a key aspect of file creation.

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. For example, it doesn't mention when to choose this over webdav_update_remote_file (for updating existing files) or webdav_edit_remote_file (for modifying files), nor does it specify prerequisites like server connectivity or authentication needs.

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