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
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions 'naming convention enforced on creation only', which adds some behavioral context about constraints. However, it doesn't disclose critical traits like whether this operation overwrites or appends content, requires specific permissions, has side effects, or what happens on errors. For a mutation tool with zero annotation coverage, this is a significant gap.

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 a single, efficient sentence that is front-loaded with the core purpose ('Write to an existing file') and includes a clarifying note. There is zero waste—every word earns its place, making it easy to parse quickly.

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 complexity of a file write operation (a mutation with potential side effects), no annotations, and no output schema, the description is incomplete. It lacks details on behavior (e.g., overwrite vs. append), error handling, permissions, or return values. The naming convention note is helpful but insufficient for safe and effective use by an AI agent.

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?

Schema description coverage is 100%, with both parameters ('path' and 'content') clearly documented in the schema. The description doesn't add any meaning beyond what the schema provides—it doesn't explain parameter formats, constraints, or examples. Baseline 3 is appropriate when the schema does the heavy lifting, but no extra value is added.

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

Purpose4/5

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

The description clearly states the verb ('Write to') and resource ('an existing file'), making the purpose immediately understandable. It distinguishes from 'create_file' by specifying 'existing file', though it doesn't explicitly mention all siblings like 'delete_file' or 'read_file'. The naming convention note adds specificity but isn't essential to the core purpose.

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

Usage Guidelines3/5

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

The description implies usage by specifying 'existing file', which distinguishes it from 'create_file' for new files. However, it doesn't provide explicit guidance on when to use this versus alternatives like 'read_file' or 'delete_file', nor does it mention prerequisites or exclusions. The context is implied rather than explicitly stated.

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

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