Skip to main content
Glama

edit_document

Replace specific text in documents by identifying exact strings to modify and inserting new content. Use this tool to update document content through precise text substitution.

Instructions

Edit a document by replacing a string in the documents content with a new string.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
doc_idYesId of the document that will be edited
old_strYesThe text to replace. Must match exactly, including whitespace.
new_strYesThe new text to insert in place of the old text.

Implementation Reference

  • The edit_document function that executes the tool logic. It takes doc_id, old_str, and new_str parameters, validates the document exists, performs string replacement on the document content, and returns the updated content.
    def edit_document(
        doc_id: str = Field(description="Id of the document that will be edited"),
        old_str: str = Field(description="The text to replace. Must match exactly, including whitespace."),
        new_str: str = Field(description="The new text to insert in place of the old text.")
    ):
        if doc_id not in docs:
            raise ValueError(f"Doc with id {doc_id} not found")
        
        docs[doc_id] = docs[doc_id].replace(old_str, new_str)
        return docs[doc_id]
  • mcp_server.py:29-32 (registration)
    Registration of the edit_document tool using the @mcp.tool decorator with name='edit_document' and description.
    @mcp.tool(
        name="edit_document",
        description="Edit a document by replacing a string in the documents content with a new string."
    )
  • Input schema definitions using Pydantic Field() for the three parameters: doc_id (document to edit), old_str (text to replace), and new_str (replacement text), each with descriptive metadata.
    doc_id: str = Field(description="Id of the document that will be edited"),
    old_str: str = Field(description="The text to replace. Must match exactly, including whitespace."),
    new_str: str = Field(description="The new text to insert in place of the old text.")

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A3.7/5.0
Behavior2/5

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

No annotations are present, so the description must disclose behavioral traits. It only states 'replacing a string' without indicating whether it replaces all occurrences, behavior on missing string, or side effects like auto-save. Missing important mutation details.

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 sentence that is concise and front-loaded with the essential action and resource. No wasted words.

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

Completeness3/5

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

For a simple edit tool with fully documented parameters, the description is adequate but lacks details on error handling (e.g., what if old_str not found) and whether it replaces all occurrences or just the first.

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?

Schema description coverage is 100%, and the description adds value by clarifying that old_str must match exactly including whitespace. This goes beyond the schema's basic descriptions.

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 action (edit), resource (document), and method (string replacement). It effectively distinguishes from the sibling tool 'read_doc_contents' which is read-only.

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 does not explicitly state when to use this tool vs alternatives. While the sibling tool name implies a read vs. edit distinction, no further guidance is provided on prerequisites or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.