Skip to main content
Glama

patch_file

Replace the first exact occurrence of a string in a file with a new string, preserving whitespace and indentation. Use for targeted edits without rewriting the entire file.

Instructions

Find the FIRST (and only) occurrence of old_str in a file and replace it with new_str. PREFER this over write_file for edits to existing files — only send the changed part. old_str must match EXACTLY, including whitespace and indentation. Make it specific enough that it is unique in the file. Returns the line number of the edit on success, or an error with a file preview to help you correct old_str.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
new_strYes
old_strYes
file_pathYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes
Behavior4/5

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

No annotations are provided, so the description covers behavior: finds first occurrence, returns line number on success, and returns error with file preview on failure. It also notes the exact match requirement.

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?

Four sentences, front-loaded with the core action, includes usage preference and critical details. No unnecessary words.

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

Completeness5/5

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

Given the output schema exists, the description covers the main behavior: first occurrence, return values for success and error, and usage advice. It is complete for the tool's complexity.

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

Parameters4/5

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

With 0% schema description coverage, the description adds meaning: explains old_str must be exact and unique, and implies new_str is the replacement. It effectively compensates for the schema gap.

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 tool finds and replaces the first occurrence of old_str with new_str in a file. It explicitly distinguishes from write_file, recommending this tool for edits.

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?

It advises preferring this over write_file for edits and emphasizes that old_str must match exactly. While it doesn't state exclusions, the guidance is clear.

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/ahmad-zurih/ds-mcp-server'

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