write_file
Create or overwrite files in your workspace. Specify the file path and content to write, with optional overwrite control.
Instructions
Write a file within the workspace.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | ||
| content | Yes | ||
| overwrite | No |
Implementation Reference
- The write_file tool handler function decorated with @mcp.tool(). It resolves the path safely, checks overwrite flag, creates parent directories if needed, writes the file content, and returns path + byte count.
@mcp.tool() def write_file(path: str, content: str, overwrite: bool = True) -> dict: """Write a file within the workspace.""" target = _resolve_path(path) if target.exists() and not overwrite: raise ValueError(f"'{path}' already exists and overwrite is disabled.") target.parent.mkdir(parents=True, exist_ok=True) target.write_text(content, encoding="utf-8") return { "path": str(target), "bytes_written": len(content.encode("utf-8")), } - src/friday_mcp_server/tools/__init__.py:10-10 (registration)The register_all_tools function calls workspace.register(mcp, config=config) which decorates all workspace tools (including write_file) onto the MCP server.
workspace.register(mcp, config=config) - src/friday_mcp_server/tools/workspace.py:9-9 (registration)The register function in workspace.py is called to register all workspace tools (list_workspace, read_file, write_file, run_bash) onto the MCP server instance via @mcp.tool() decorator.
def register(mcp, *, config) -> None: - The _resolve_path helper resolves a given path relative to the workspace root, enforces security boundaries, and returns the resolved absolute Path.
def _resolve_path(path: str) -> Path: raw_path = Path(path).expanduser() resolved = ( raw_path.resolve() if raw_path.is_absolute() else (config.workspace_root / raw_path).resolve() ) if config.allow_external_paths: return resolved if resolved != config.workspace_root and config.workspace_root not in resolved.parents: raise ValueError( f"Path '{path}' is outside the workspace root {config.workspace_root}." ) return resolved