write_file
Create or write text files directly to Proton Drive by specifying the file path and content using Proton Drive MCP server integration.
Instructions
Write or create a file in Proton Drive
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | Text content to write to the file | |
| path | Yes | File path relative to Proton Drive root |
Implementation Reference
- src/index.ts:335-360 (handler)The switch case handler that executes the write_file tool logic: extracts path and content arguments, validates the path, creates parent directories if necessary, writes the file using fs/promises.writeFile, returns a success text response, or throws an MCP error on failure.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}` ); } }
- src/index.ts:159-176 (registration)The tool registration object for 'write_file' returned by the ListTools handler, defining the tool's name, description, and input schema (JSON Schema object with required 'path' and 'content' string properties).{ 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'], }, },
- src/index.ts:91-111 (helper)Helper function used by write_file (and other tools) to validate and resolve relative paths to absolute paths within the Proton Drive root directory, preventing path traversal attacks.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; }
- src/index.ts:162-175 (schema)The JSON Schema defining the input parameters for the write_file tool: an object with string properties 'path' and 'content', both required.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'], },