create_file
Create new files with UTF-8 content at specified paths. The tool automatically creates parent directories and ensures files don't already exist within allowed directory boundaries.
Instructions
Create a new file with specified content.
Args: path (str): File path to create (absolute or relative to allowed directories) content (str): UTF-8 text content to write to the file
Returns: str: Success message with created file path, or error message if failed
Note: - Fails if the file already exists - Creates parent directories if they don't exist - Path must be within allowed directory roots
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | ||
| content | Yes |
Implementation Reference
- main.py:206-230 (handler)The handler function for the 'create_file' MCP tool. It is registered via the @mcp.tool decorator and implements the core logic: path resolution, directory creation, file writing with UTF-8 encoding, and error handling.@mcp.tool def create_file(path: str, content: str) -> str: """Create a new file with specified content. Args: path (str): File path to create (absolute or relative to allowed directories) content (str): UTF-8 text content to write to the file Returns: str: Success message with created file path, or error message if failed Note: - Fails if the file already exists - Creates parent directories if they don't exist - Path must be within allowed directory roots """ try: rp = _resolve(path) rp.parent.mkdir(parents=True, exist_ok=True) with rp.open("x", encoding="utf-8") as f: f.write(content) return f"Created {rp}" except Exception as e: return _human_error(e, "creating file")