Skip to main content
Glama

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
NameRequiredDescriptionDefault
requestYes

Implementation Reference

  • 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))
  • Input schema for the write tool: path and content.
    class WriteRequest(BaseModel): """Request to write a file""" path: str content: str
  • Output schema for the write tool: success flag, path, and size.
    class WriteResponse(BaseModel): """Response from write operation""" success: bool path: str size: int
  • 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)

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/chrishayuk/chuk-mcp-vfs'

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