Skip to main content
Glama
Preston-Harrison

Filesystem MCP Server

create_file

Create a new file with specified content at a given path. Automatically generates parent directories if missing. Fails if the file already exists. Operates within allowed directory roots for secure file creation.

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

Implementation Reference

  • main.py:206-230 (handler)
    Handler function for the 'create_file' tool, including decorator for registration. Resolves path safely, creates parents, writes content exclusively, returns success or human-readable error.
    @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")
  • main.py:206-206 (registration)
    The @mcp.tool decorator registers the create_file function as an MCP tool, guarded by read-only mode check.
    @mcp.tool
  • Input schema defined by type hints (path: str, content: str) and detailed docstring describing parameters, returns, and notes.
    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 """

Other Tools

Related Tools

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