Skip to main content
Glama
GongRzhe

Terminal Controller for MCP

delete_file_content

Delete specific rows or substrings from a file using row numbers or substring matching.

Instructions

Delete content at specific row(s) from a file

Args:
    path: Path to the file
    row: Row number to delete (0-based, optional)
    rows: List of row numbers to delete (0-based, optional)
    substring: If provided, only delete this substring within the specified row(s), not the entire row (optional)

Returns:
    Operation result information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
rowNo
rowsNo
substringNo

Implementation Reference

  • Tool registration via @mcp.tool() decorator on the delete_file_content function
    @mcp.tool()
    async def delete_file_content(path: str, row: int = None, rows: list = None, substring: str = None) -> str:
  • Main handler function that deletes content from a file. Supports: deleting a single row, multiple rows, substring removal within rows, or clearing entire file when no params specified.
    async def delete_file_content(path: str, row: int = None, rows: list = None, substring: str = None) -> str:
        """
        Delete content at specific row(s) from a file
        
        Args:
            path: Path to the file
            row: Row number to delete (0-based, optional)
            rows: List of row numbers to delete (0-based, optional)
            substring: If provided, only delete this substring within the specified row(s), not the entire row (optional)
        
        Returns:
            Operation result information
        """
        try:
            if not os.path.exists(path):
                return f"Error: File '{path}' does not exist."
                
            if not os.path.isfile(path):
                return f"Error: '{path}' is not a file."
                
            with open(path, 'r', encoding='utf-8', errors='replace') as file:
                lines = file.readlines()
            
            total_lines = len(lines)
            deleted_rows = []
            modified_rows = []
            
            # Handle substring deletion (doesn't delete entire rows)
            if substring is not None:
                # For multiple rows
                if rows is not None:
                    if not isinstance(rows, list):
                        return "Error: 'rows' parameter must be a list of integers."
                    
                    for r in rows:
                        if not isinstance(r, int) or r < 0:
                            return "Error: Row numbers must be non-negative integers."
                            
                        if r < total_lines and substring in lines[r]:
                            original_line = lines[r]
                            lines[r] = lines[r].replace(substring, '')
                            # Ensure line ends with newline if original did
                            if original_line.endswith('\n') and not lines[r].endswith('\n'):
                                lines[r] += '\n'
                            modified_rows.append(r)
                
                # For single row
                elif row is not None:
                    if not isinstance(row, int) or row < 0:
                        return "Error: Row number must be a non-negative integer."
                        
                    if row >= total_lines:
                        return f"Error: Row {row} is out of range (file has {total_lines} lines)."
                        
                    if substring in lines[row]:
                        original_line = lines[row]
                        lines[row] = lines[row].replace(substring, '')
                        # Ensure line ends with newline if original did
                        if original_line.endswith('\n') and not lines[row].endswith('\n'):
                            lines[row] += '\n'
                        modified_rows.append(row)
                
                # For entire file
                else:
                    for i in range(len(lines)):
                        if substring in lines[i]:
                            original_line = lines[i]
                            lines[i] = lines[i].replace(substring, '')
                            # Ensure line ends with newline if original did
                            if original_line.endswith('\n') and not lines[i].endswith('\n'):
                                lines[i] += '\n'
                            modified_rows.append(i)
                
                # Write back to the file
                with open(path, 'w', encoding='utf-8') as file:
                    file.writelines(lines)
                    
                if not modified_rows:
                    return f"No occurrences of '{substring}' found in the specified rows."
                return f"Successfully removed '{substring}' from {len(modified_rows)} rows ({modified_rows}) in '{path}'."
            
            # Handle deleting multiple rows
            elif rows is not None:
                if not isinstance(rows, list):
                    return "Error: 'rows' parameter must be a list of integers."
                    
                # Sort rows in descending order to avoid changing indices during deletion
                rows = sorted(rows, reverse=True)
                
                for r in rows:
                    if not isinstance(r, int) or r < 0:
                        return "Error: Row numbers must be non-negative integers."
                        
                    if r < total_lines:
                        lines.pop(r)
                        deleted_rows.append(r)
                
                # Write back to the file
                with open(path, 'w', encoding='utf-8') as file:
                    file.writelines(lines)
                    
                if not deleted_rows:
                    return f"No rows were within range to delete (file has {total_lines} lines)."
                return f"Successfully deleted {len(deleted_rows)} rows ({deleted_rows}) from '{path}'."
                
            # Handle deleting a single row
            elif row is not None:
                if not isinstance(row, int) or row < 0:
                    return "Error: Row number must be a non-negative integer."
                    
                if row >= total_lines:
                    return f"Error: Row {row} is out of range (file has {total_lines} lines)."
                    
                # Delete the specified row
                lines.pop(row)
                
                # Write back to the file
                with open(path, 'w', encoding='utf-8') as file:
                    file.writelines(lines)
                    
                return f"Successfully deleted row {row} from '{path}'."
            
            # If neither row nor rows specified, clear the file
            else:
                with open(path, 'w', encoding='utf-8') as file:
                    pass
                return f"Successfully cleared all content from '{path}'."
                
        except PermissionError:
            return f"Error: No permission to modify file '{path}'."
        except Exception as e:
            return f"Error deleting content: {str(e)}"
Behavior2/5

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

No annotations are provided, so the description must fully disclose behavior. It states it deletes content but fails to mention consequences such as whether deletion is permanent, what happens if both row and rows are specified, or required permissions. This is insufficient for a destructive operation.

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

Conciseness3/5

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

The description is fairly direct but redundantly repeats the main action in the Args section. It could be more concise by eliminating the title line and integrating parameter descriptions more efficiently.

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

Completeness2/5

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

Given the lack of annotations and output schema, the description covers parameter meanings but omits critical behavioral details like error handling, return value format, and interaction between row, rows, and substring. It is not complete enough for an agent to confidently invoke the tool.

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?

With schema coverage at 0%, the description compensates well by explaining each parameter: path is required, row is 0-based, rows is a list, and substring can delete part of a row. This adds meaning beyond the schema's type and default fields.

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

Purpose5/5

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

The description clearly states 'Delete content at specific row(s) from a file', providing a specific verb and resource. It effectively distinguishes itself from sibling tools like update_file_content or insert_file_content by focusing on deletion.

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

Usage Guidelines2/5

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

No explicit guidance on when to use this tool versus alternatives, or when to use row vs rows vs substring. The description implies deletion but does not provide context for choosing among parameters or other file manipulation tools.

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/GongRzhe/terminal-controller-mcp'

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