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.")

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/mparth14/MCP-anthropic'

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