Skip to main content
Glama
Preston-Harrison

Filesystem MCP Server

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
NameRequiredDescriptionDefault
pathYes
contentYes

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")

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/Preston-Harrison/fs-mcp-py'

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