Skip to main content
Glama

set_file

Select a file to enable reading, editing, and managing operations within the editor-mcp server workflow.

Instructions

Set the current file to work with.

This is always the first step in the workflow. You must set a file before you can use other tools like read, select etc.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filepathYes

Implementation Reference

  • The handler function for the 'set_file' tool. It validates the file path (existence and protected paths), sets the current file path in the server instance, and returns a success or error message.
    @self.mcp.tool()
    async def set_file(filepath: str) -> str:
        """
        Set the current file to work with.
    
        This is always the first step in the workflow. You must set a file
        before you can use other tools like read, select etc.
        """
    
        if not os.path.isfile(filepath):
            return f"Error: File not found at '{filepath}'"
    
        # Check if the file path matches any of the protected paths
        for pattern in self.protected_paths:
            pattern = pattern.strip()
            if not pattern:
                continue
            # Check for absolute path match
            if filepath == pattern:
                return f"Error: Access to '{filepath}' is denied due to PROTECTED_PATHS configuration"
            # Check for glob pattern match (e.g., *.env, .env*, etc.)
            if "*" in pattern:
                # First try matching the full path
                if fnmatch.fnmatch(filepath, pattern):
                    return f"Error: Access to '{filepath}' is denied due to PROTECTED_PATHS configuration (matches pattern '{pattern}')"
    
                # Then try matching just the basename
                basename = os.path.basename(filepath)
                if fnmatch.fnmatch(basename, pattern):
                    return f"Error: Access to '{filepath}' is denied due to PROTECTED_PATHS configuration (matches pattern '{pattern}')"
    
        self.current_file_path = filepath
        return f"File set to: '{filepath}'"

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