write
Write content to files in virtual filesystem workspaces. Use this tool to save text data to files across multiple storage providers with session, user, or shared scope access.
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)VFSTools.write: the core handler implementing file write logic, resolving path, creating parents, encoding content, and writing to VFS.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-151 (schema)Pydantic models: WriteRequest (path, content) and WriteResponse (success, path, size).class WriteRequest(BaseModel): """Request to write a file""" path: str content: str class WriteResponse(BaseModel): """Response from write operation""" success: bool path: str size: int
- src/chuk_mcp_vfs/server.py:92-95 (registration)MCP server tool registration for 'write', delegating to VFSTools instance.@server.tool async def write(request: WriteRequest): """Write content to file.""" return await vfs_tools.write(request)
- src/chuk_mcp_vfs/server.py:38-39 (registration)Instantiation of VFSTools instance used by all VFS tools including write.vfs_tools = VFSTools(workspace_manager) checkpoint_tools_instance = CheckpointTools(checkpoint_manager)