set_file
Define the file to work with in the editor-mcp server. This is the initial step to enable actions like reading or selecting content in the specified file. Input the filepath to proceed.
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
| Name | Required | Description | Default |
|---|---|---|---|
| filepath | Yes |
Implementation Reference
- src/text_editor/server.py:385-385 (registration)Registration of the set_file tool using the FastMCP decorator @self.mcp.tool()@self.mcp.tool()
- src/text_editor/server.py:386-417 (handler)The main handler function for the 'set_file' tool. It validates the file exists, checks against protected paths using fnmatch, sets self.current_file_path if valid, and returns success or error message.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}'"
- src/text_editor/server.py:386-391 (schema)Input schema: filepath (str). Output: str (success message or error). Documented in the function docstring.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.