write
Save content to files in virtual workspaces using the chuk-mcp-vfs server. This tool enables writing data to various storage providers including memory, filesystem, SQLite, and S3.
Instructions
Write content to file.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| request | Yes |
Implementation Reference
- src/chuk_mcp_vfs/vfs_tools.py:69-99 (handler)The main handler function for the 'write' tool. It resolves the path, ensures parent directories exist, encodes content to bytes, writes to VFS, and returns a WriteResponse.async def write(self, request: WriteRequest) -> WriteResponse: """ Write content to file. Args: request: WriteRequest with path and content Returns: WriteResponse with success status """ from pathlib import PurePosixPath vfs = self.workspace_manager.get_current_vfs() resolved_path = self.workspace_manager.resolve_path(request.path) # Ensure all parent directories exist # Use PurePosixPath to ensure forward slashes on all platforms parent = str(PurePosixPath(resolved_path).parent) if parent != "/": # Create all parent directories if they don't exist parts = [p for p in parent.split("/") if p] current_path = "" for part in parts: current_path += f"/{part}" if not await vfs.exists(current_path): await vfs.mkdir(current_path) content_bytes = request.content.encode("utf-8") await vfs.write_file(resolved_path, content_bytes) return WriteResponse(success=True, path=resolved_path, size=len(content_bytes))
- src/chuk_mcp_vfs/models.py:138-143 (schema)Input schema for the write tool: path and content.class WriteRequest(BaseModel): """Request to write a file""" path: str content: str
- src/chuk_mcp_vfs/models.py:145-151 (schema)Output schema for the write tool: success flag, path, and size.class WriteResponse(BaseModel): """Response from write operation""" success: bool path: str size: int
- src/chuk_mcp_vfs/server.py:93-96 (registration)MCP tool registration for 'write', delegating to VFSTools.write method.async def write(request: WriteRequest): """Write content to file.""" return await vfs_tools.write(request)