Skip to main content
Glama
whyjp

Encoding MCP Server

create_empty_file

Create an empty file with specified encoding for subsequent content population, supporting UTF-8, CP949, EUC-KR, and ASCII formats to prevent character encoding issues.

Instructions

Create an empty file with specified encoding. Creates only an empty file so Agent can fill in content.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_nameYesFile name to create (e.g., hello.cpp, test.h)
directory_pathYesAbsolute path of directory to create file in
encodingNoFile encodingutf-8-bom

Implementation Reference

  • Core handler function that executes the tool logic: validates encoding, ensures directory exists, creates empty file with appropriate encoding (including BOM for utf-8-bom), and returns success/error message.
    def create_empty_file(file_path: str, encoding: str = "utf-8-bom") -> str:
        """
        Create an empty file with specified encoding.
        
        Args:
            file_path: File path
            encoding: Encoding (default: utf-8-bom)
            
        Returns:
            str: Result message
        """
        try:
            # Validate encoding
            if not validate_encoding(encoding):
                supported = ", ".join(SUPPORTED_ENCODINGS.keys())
                return f"Unsupported encoding: {encoding}. Supported: {supported}"
            
            # Create directory
            dir_result = ensure_directory(file_path)
            if "failed" in dir_result.lower() or "permission" in dir_result.lower():
                return dir_result
            
            # Create empty file by encoding
            if encoding == "utf-8-bom":
                with open(file_path, 'wb') as f:
                    f.write(UTF8_BOM)  # Write BOM only
            elif encoding == "utf-8":
                with open(file_path, 'w', encoding='utf-8', newline='\n') as f:
                    pass  # Empty file
            elif encoding == "cp949":
                with open(file_path, 'w', encoding='cp949') as f:
                    pass  # Empty file
            elif encoding == "euc-kr":
                with open(file_path, 'w', encoding='euc-kr') as f:
                    pass  # Empty file
            elif encoding == "ascii":
                with open(file_path, 'w', encoding='ascii') as f:
                    pass  # Empty file
            
            encoding_info = get_encoding_info(encoding)
            return f"Empty file created successfully: {file_path} ({encoding_info['name']})"
        
        except PermissionError:
            return f"No permission to write file: {file_path}"
        except FileNotFoundError:
            return f"Invalid file path: {file_path}"
        except OSError as e:
            return f"File system error: {str(e)}"
        except Exception as e:
            return f"Unexpected error creating file: {str(e)}"
  • Registers the create_empty_file tool in the MCP server list_tools, including name, description, and input schema definition.
    Tool(
        name="create_empty_file",
        description="Create an empty file with specified encoding. Creates only an empty file so Agent can fill in content.",
        inputSchema={
            "type": "object",
            "properties": {
                "file_name": {
                    "type": "string",
                    "description": "File name to create (e.g., hello.cpp, test.h)"
                },
                "directory_path": {
                    "type": "string", 
                    "description": "Absolute path of directory to create file in"
                },
                "encoding": {
                    "type": "string",
                    "description": "File encoding",
                    "enum": ["utf-8-bom", "utf-8", "cp949", "euc-kr", "ascii"],
                    "default": "utf-8-bom"
                }
            },
            "required": ["file_name", "directory_path"]
        }
    ),
  • MCP server call_tool dispatcher handler specifically for create_empty_file: constructs full file_path, calls the core function, formats response with icon and message.
    if name == "create_empty_file":
        file_name = arguments.get("file_name", "")
        directory_path = arguments.get("directory_path", "")
        encoding = arguments.get("encoding", "utf-8-bom")
        
        # Combine file name and directory path
        file_path = os.path.join(directory_path, file_name)
        
        result = create_empty_file(file_path, encoding)
        
        # Select icon based on result
        if "successfully" in result.lower() or "success" in result.lower():
            icon = "āœ…"
        elif "permission" in result.lower() or "failed" in result.lower() or "error" in result.lower():
            icon = "āŒ"
        else:
            icon = "āš ļø"
        
        return [
            types.TextContent(
                type="text",
                text=f"{icon} Create empty file\n\n{result}\n\nšŸ’” Agent can use write tool to fill in content."
            )
        ]
  • Input schema definition for the create_empty_file tool, specifying parameters file_name, directory_path (required), and optional encoding.
    inputSchema={
        "type": "object",
        "properties": {
            "file_name": {
                "type": "string",
                "description": "File name to create (e.g., hello.cpp, test.h)"
            },
            "directory_path": {
                "type": "string", 
                "description": "Absolute path of directory to create file in"
            },
            "encoding": {
                "type": "string",
                "description": "File encoding",
                "enum": ["utf-8-bom", "utf-8", "cp949", "euc-kr", "ascii"],
                "default": "utf-8-bom"
            }
        },
        "required": ["file_name", "directory_path"]
    }
  • Helper function used by create_empty_file to ensure the target directory exists before file creation.
    def ensure_directory(file_path: str) -> str:
        """
        Check if file's directory exists and create it if needed.
        
        Args:
            file_path: File path
            
        Returns:
            str: Success message or error message
        """
        dir_path = os.path.dirname(file_path)
        if not dir_path:
            return "Directory path not required."
        
        if os.path.exists(dir_path):
            return "Directory already exists."
        
        try:
            os.makedirs(dir_path, exist_ok=True)
            return f"Directory created: {dir_path}"
        except PermissionError:
            return f"No permission to create directory: {dir_path}"
        except OSError as e:
            return f"Directory creation failed: {dir_path} - {str(e)}"
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. While it states the tool creates an empty file, it doesn't mention important behavioral aspects like whether it overwrites existing files, what permissions are required, error conditions, or what happens on success. For a file creation tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.

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 extremely concise with just two sentences that each earn their place. The first sentence states the core functionality, and the second clarifies the purpose and scope. There's zero wasted language, and the information is front-loaded effectively.

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

Completeness3/5

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

For a file creation tool with 3 parameters, 100% schema coverage, but no annotations and no output schema, the description provides basic purpose but lacks important behavioral context. It doesn't explain what the tool returns, error conditions, or file system implications. The description is adequate but has clear gaps given the tool's complexity and lack of supporting structured data.

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

Parameters3/5

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

The schema description coverage is 100%, so the schema already fully documents all three parameters. The description mentions 'specified encoding' which aligns with the encoding parameter in the schema, but doesn't add meaningful semantic context beyond what the schema provides. The baseline score of 3 is appropriate when the schema does the heavy lifting.

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 the specific action ('Create an empty file') and resource ('file'), distinguishing it from sibling tools like convert_file_encoding or detect_file_encoding. It explicitly mentions the purpose is to create an empty file for the agent to fill in content later, which is distinct from file manipulation or analysis tools.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool ('Creates only an empty file so Agent can fill in content'), indicating it's for initial file creation rather than modification. However, it doesn't explicitly state when NOT to use it or name specific alternatives among the sibling tools, which prevents a perfect score.

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/whyjp/encoding_mcp'

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