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
| Name | Required | Description | Default |
|---|---|---|---|
| doc_id | Yes | Id of the document that will be edited | |
| old_str | Yes | The text to replace. Must match exactly, including whitespace. | |
| new_str | Yes | The new text to insert in place of the old text. |
Implementation Reference
- mcp_server.py:33-42 (handler)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." ) - mcp_server.py:34-36 (schema)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.")