Skip to main content
Glama
GILSMON

MCP Policy Gatekeeper

by GILSMON

write_file

Write content to existing files while ensuring compliance with organizational policies. The MCP Policy Gatekeeper validates file operations against naming conventions and security standards before execution.

Instructions

Write to an existing file (naming convention enforced on creation only)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesFile path
contentYesFile content

Implementation Reference

  • Handler implementation for the 'write_file' tool. Resolves the path, checks if the file exists, writes the provided content to it, and returns a success message.
    elif name == "write_file": path = resolve_path(arguments["path"]) if not path.exists(): return [TextContent( type="text", text=f"Error: File '{arguments['path']}' does not exist. Use create_file to create new files." )] with open(path, 'w', encoding='utf-8') as f: f.write(arguments["content"]) return [TextContent(type="text", text=f"✓ File updated: {arguments['path']}")]
  • server.py:100-111 (registration)
    Registration of the 'write_file' tool in the list_tools handler, defining its name, description, and input schema.
    Tool( name="write_file", description="Write to an existing file (naming convention enforced on creation only)", inputSchema={ "type": "object", "properties": { "path": {"type": "string", "description": "File path"}, "content": {"type": "string", "description": "File content"} }, "required": ["path", "content"] } ),
  • Helper function used by write_file (and other tools) to resolve relative paths to absolute paths within the protected directory and enforce security boundaries.
    def resolve_path(relative_path: str) -> Path: full_path = (PROTECTED_DIR / relative_path).resolve() if not str(full_path).startswith(str(PROTECTED_DIR)): raise ValueError("Access denied: Path outside protected directory") return full_path

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/GILSMON/mcpServer_as_gatekeeper'

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