Skip to main content
Glama

new_file

Create a new text file at a specified path, automatically generating parent directories and selecting the first line for immediate editing.

Instructions

Creates a new file.

After creating new file, the first line is automatically selected for editing. Automatically creates parent directories if they don't exist.

Args: filepath (str): Path of the new file Returns: dict: Status message with selection info

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filepathYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'new_file' tool. It sets the current file path, checks if the file exists and is empty, creates parent directories if needed, writes a header to the new file, selects the first line for editing, computes its ID, and returns a success response with selection details.
    async def new_file(filepath: str) -> Dict[str, Any]:
        """
        Creates a new file.
    
        After creating new file, the first line is automatically selected for editing.
        Automatically creates parent directories if they don't exist.
    
        Args:
            filepath (str): Path of the new file
        Returns:
            dict: Status message with selection info
    
        """
        self.current_file_path = filepath
    
        if (
            os.path.exists(self.current_file_path)
            and os.path.getsize(self.current_file_path) > 0
        ):
            return {
                "error": "Cannot create new file. Current file exists and is not empty."
            }
    
        try:
            # Create parent directories if they don't exist
            directory = os.path.dirname(self.current_file_path)
            if directory:
                os.makedirs(directory, exist_ok=True)
    
            text = "# NEW_FILE - REMOVE THIS HEADER"
            with open(self.current_file_path, "w", encoding="utf-8") as file:
                file.write(text)
    
            # Automatically select the first line for editing
            self.selected_start = 1
            self.selected_end = 1
            self.selected_id = calculate_id(text, 1, 1)
    
            result = {
                "status": "success",
                "text": text,
                "current_file_path": self.current_file_path,
                "id": self.selected_id,
                "selected_start": self.selected_start,
                "selected_end": self.selected_end,
                "message": "File created successfully. First line is now selected for editing.",
            }
    
            return result
        except Exception as e:
            return {"error": f"Error creating file: {str(e)}"}
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden and does well by disclosing key behavioral traits: it creates a file, automatically selects the first line for editing, and creates parent directories if missing. This covers mutation behavior and side effects, though it doesn't mention permissions, error handling, or rate limits, which are gaps for a tool with no annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded: the first sentence states the core purpose, followed by important behavioral details, and ends with structured Args and Returns sections. Every sentence adds value without redundancy, making it efficient and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (file creation with side effects), no annotations, and an output schema present, the description is fairly complete. It explains the action, behavioral traits, and parameter semantics, but could improve by addressing error cases or interaction with siblings. The output schema handles return values, so the description's focus on other aspects is appropriate.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds meaningful context for the single parameter 'filepath' by explaining it's the 'Path of the new file', which clarifies its purpose beyond the schema's basic type definition. With 0% schema description coverage and only one parameter, this compensation is effective, though it doesn't detail format constraints or examples.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with the verb 'creates' and resource 'new file', making it immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'overwrite' or 'set_file', which might also involve file creation or modification, leaving room for ambiguity in tool selection.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for creating new files and automatically handling parent directories, but provides no explicit guidance on when to use this tool versus alternatives like 'overwrite' or 'set_file'. It mentions automatic post-creation actions (first line selection), which hints at context, but lacks clear when-to-use or when-not-to-use directives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/danielpodrazka/editor-mcp'

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