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
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | File path relative to Proton Drive root | |
| content | Yes | Text content to write to the file |
Implementation Reference
- src/index.ts:335-360 (handler)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}` ); } }
- src/index.ts:162-175 (schema)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'], }, },
- src/index.ts:91-111 (helper)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; }