Skip to main content
Glama
anyrxo

Proton Drive MCP

by anyrxo

write_file

Create or update text files directly in Proton Drive by specifying a file path and content, enabling secure file management through AI assistants.

Instructions

Write or create a file in Proton Drive

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesFile path relative to Proton Drive root
contentYesText content to write to the file

Implementation Reference

  • Handler function for the 'write_file' tool: validates path, ensures parent directories exist, writes file content using Node.js fs/promises.writeFile, and returns success message or throws error.
    case 'write_file': {
      const writePath = validatePath(args?.path as string);
      const content = args?.content as string;
      
      try {
        // Create directory if needed
        await mkdir(dirname(writePath), { recursive: true });
        
        // Write the file
        await writeFile(writePath, content, 'utf-8');
        
        return {
          content: [
            {
              type: 'text',
              text: `Successfully wrote file: ${getRelativePath(writePath)}`,
            },
          ],
        };
      } catch (error: any) {
        throw new McpError(
          ErrorCode.InternalError,
          `Cannot write file: ${error.message}`
        );
      }
    }
  • Input schema for the 'write_file' tool defining required 'path' and 'content' string parameters.
    inputSchema: {
      type: 'object',
      properties: {
        path: { 
          type: 'string', 
          description: 'File path relative to Proton Drive root' 
        },
        content: { 
          type: 'string', 
          description: 'Text content to write to the file' 
        },
      },
      required: ['path', 'content'],
    },
  • src/index.ts:159-176 (registration)
    Registration of the 'write_file' tool in the ListTools response, including name, description, and input schema.
    {
      name: 'write_file',
      description: 'Write or create a file in Proton Drive',
      inputSchema: {
        type: 'object',
        properties: {
          path: { 
            type: 'string', 
            description: 'File path relative to Proton Drive root' 
          },
          content: { 
            type: 'string', 
            description: 'Text content to write to the file' 
          },
        },
        required: ['path', 'content'],
      },
    },
  • Helper function validatePath used in write_file handler to resolve and secure the file path within Proton Drive root.
    function validatePath(relativePath: string): string {
      // Handle empty path
      if (!relativePath) {
        return PROTON_DRIVE_PATH;
      }
      
      // Clean the path - remove leading slashes and normalize
      const cleaned = relativePath
        .split(/[/\\]+/)
        .filter(Boolean)
        .join(sep);
      
      const fullPath = resolve(PROTON_DRIVE_PATH, cleaned);
      
      // Security check - ensure we're still within Proton Drive
      if (!fullPath.startsWith(PROTON_DRIVE_PATH)) {
        throw new Error('Invalid path: Access denied outside Proton Drive');
      }
      
      return fullPath;
    }

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/anyrxo/proton-drive-mcp'

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