Skip to main content
Glama
abhishekbhakat

mcp-server-code-assist

rewrite_file

Replace entire file content with new text to update code or documentation quickly. Specify file path and new content to rewrite files completely.

Instructions

Rewrites entire file content

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
contentYes

Implementation Reference

  • Core implementation of the rewrite_file tool: validates path, reads original content, overwrites with new content, generates and returns unified diff.
    async def rewrite_file(self, path: str, content: str) -> str:
        path = await self.validate_path(path)
        original = await self.read_file(path) if path.exists() else ""
        await self.write_file(path, content)
        return self.generate_diff(original, content)
  • Pydantic model defining the input schema (path and content) for the rewrite_file tool, used in tool registration.
    class FileRewrite(BaseModel):
        path: str | Path
        content: str
  • MCP tool registration in list_tools(): defines name, description, and input schema for rewrite_file.
    ),
    Tool(
        name=CodeAssistTools.REWRITE_FILE,
        description="Rewrites entire file content",
        inputSchema=FileRewrite.model_json_schema(),
  • MCP server call_tool handler: parses arguments into FileRewrite model and delegates to file_tools.rewrite_file.
    case CodeAssistTools.REWRITE_FILE:
        model = FileRewrite(path=arguments["path"], content=arguments["content"])
        result = await file_tools.rewrite_file(model.path, model.content)
        return [TextContent(type="text", text=result)]
  • Static helper method used by rewrite_file (and modify_file) to generate unified diff output.
    @staticmethod
    def generate_diff(original: str, modified: str) -> str:
        diff = difflib.unified_diff(original.splitlines(keepends=True), modified.splitlines(keepends=True), fromfile="original", tofile="modified")
        return "".join(diff)
Behavior2/5

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

With no annotations, the description carries the full burden of behavioral disclosure. 'Rewrites entire file content' implies a destructive mutation (overwrites existing content), but it doesn't address permissions, error handling (e.g., if file doesn't exist), or side effects. This is a significant gap for a mutation tool with zero annotation coverage.

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's appropriately sized and front-loaded, making it easy to parse quickly, though it sacrifices detail for brevity.

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 (a destructive file operation), no annotations, no output schema, and low schema coverage, the description is incomplete. It lacks details on behavior, error cases, and output, making it insufficient for safe and effective tool invocation by an agent.

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 for undocumented parameters. It mentions 'file content' which hints at the 'content' parameter, but doesn't explain 'path' or add meaning beyond the schema's basic titles. With 2 parameters and no schema descriptions, this is inadequate.

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

Purpose3/5

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

The description 'Rewrites entire file content' clearly states the action (rewrites) and target (file content), but it's vague about scope and lacks differentiation from sibling tools like 'modify_file'. It doesn't specify whether this replaces all content or handles partial updates, making it adequate but with clear gaps.

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?

No guidance is provided on when to use this tool versus alternatives like 'modify_file' or 'create_file'. The description implies a full rewrite but doesn't mention prerequisites (e.g., file must exist), exclusions, or specific contexts, leaving the agent without usage direction.

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