Skip to main content
Glama
abhishekbhakat

mcp-server-code-assist

modify_file

Modify file content by replacing specified text strings to update code or configuration files programmatically.

Instructions

Modifies parts of a file using string replacements

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
replacementsYes

Implementation Reference

  • Core handler function that validates the path, reads the file, applies string replacements, writes the modified content, and generates a unified diff.
    async def modify_file(self, path: str, replacements: dict[str, str]) -> str:
        path = await self.validate_path(path)
        content = await self.read_file(path)
        original = content
    
        for old, new in replacements.items():
            content = content.replace(old, new)
    
        await self.write_file(path, content)
        return self.generate_diff(original, content)
  • Pydantic BaseModel defining the input schema for the modify_file tool: path (str or Path) and replacements (dict of str to str). Used for validation and JSON schema generation.
    class FileModify(BaseModel):
        path: str | Path
        replacements: dict[str, str]
  • Registration of the 'modify_file' tool in the MCP server's list_tools() method, specifying name, description, and input schema.
    Tool(
        name=CodeAssistTools.MODIFY_FILE,
        description="Modifies parts of a file using string replacements",
        inputSchema=FileModify.model_json_schema(),
    ),
  • Dispatch handler in the MCP server's call_tool() method that parses arguments into FileModify model and invokes the file_tools.modify_file implementation.
    case CodeAssistTools.MODIFY_FILE:
        model = FileModify(path=arguments["path"], replacements=arguments["replacements"])
        result = await file_tools.modify_file(model.path, model.replacements)
        return [TextContent(type="text", text=result)]
  • Enum constant defining the tool name 'modify_file' in CodeAssistTools.
    MODIFY_FILE = "modify_file"
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 states the tool modifies a file, implying mutation, but doesn't disclose critical behavioral traits: whether it requires write permissions, if changes are destructive or reversible, error handling (e.g., for invalid paths), or output format. The description is minimal and lacks necessary context for safe operation.

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 with zero waste. It is front-loaded with the core action and mechanism, making it easy to parse. Every word earns its place, though this conciseness comes at the cost of completeness.

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 (mutation tool with 2 parameters, 0% schema coverage, no annotations, no output schema), the description is inadequate. It doesn't explain return values, error conditions, or behavioral nuances. For a tool that modifies files, more context is needed to ensure correct and safe usage, especially with sibling tools like 'rewrite_file' present.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate. It mentions 'string replacements' which hints at the 'replacements' parameter, but doesn't explain the structure (object mapping) or the 'path' parameter's role. No details on format, constraints, or examples are provided, leaving significant gaps beyond the schema's basic property definitions.

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 ('modifies') and resource ('parts of a file') with the specific mechanism 'using string replacements'. It distinguishes from siblings like 'rewrite_file' (likely full rewrite) and 'read_file' (read-only), though it doesn't explicitly name alternatives. The purpose is specific but lacks explicit sibling differentiation.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like 'rewrite_file' or 'create_file'. It doesn't mention prerequisites (e.g., file must exist), exclusions, or typical use cases. The context is implied but not articulated, leaving the agent to infer usage from the name and description alone.

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/abhishekbhakat/mcp_server_code_assist'

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