Skip to main content
Glama
ToKiDoO

Advanced Obsidian MCP Server

by ToKiDoO

obsidian_patch_file

Insert content into existing Obsidian notes relative to headings, block references, or frontmatter fields using append, prepend, or replace operations.

Instructions

Insert content into an existing note relative to a heading, block reference, or frontmatter field.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filepathYesPath to the file (relative to vault root)
operationYesOperation to perform (append, prepend, or replace)
target_typeYesType of target to patch
targetYesTarget identifier (heading path, block reference, or frontmatter field)
contentYesContent to insert

Implementation Reference

  • The run_tool method of PatchContentToolHandler, which validates input arguments and calls the underlying api.patch_content to perform the patching operation, then returns a success message.
    def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]: if not all(k in args for k in ["filepath", "operation", "target_type", "target", "content"]): raise RuntimeError("filepath, operation, target_type, target and content arguments required") api.patch_content( args.get("filepath", ""), args.get("operation", ""), args.get("target_type", ""), args.get("target", ""), args.get("content", "") ) return [ TextContent( type="text", text=f"Successfully patched content in {args['filepath']}" ) ]
  • The get_tool_description method defining the tool's name, description, and input schema for validation.
    def get_tool_description(self): return Tool( name=self.name, description="Insert content into an existing note relative to a heading, block reference, or frontmatter field.", inputSchema={ "type": "object", "properties": { "filepath": { "type": "string", "description": "Path to the file (relative to vault root)", "format": "path" }, "operation": { "type": "string", "description": "Operation to perform (append, prepend, or replace)", "enum": ["append", "prepend", "replace"] }, "target_type": { "type": "string", "description": "Type of target to patch", "enum": ["heading", "block", "frontmatter"] }, "target": { "type": "string", "description": "Target identifier (heading path, block reference, or frontmatter field)" }, "content": { "type": "string", "description": "Content to insert" } }, "required": ["filepath", "operation", "target_type", "target", "content"] } )
  • TOOL_MAPPING dictionary that maps the tool name TOOL_PATCH_CONTENT ("obsidian_patch_file") to its PatchContentToolHandler class, used for registration.
    TOOL_MAPPING = { tools.TOOL_LIST_FILES_IN_DIR: tools.ListFilesInDirToolHandler, tools.TOOL_SIMPLE_SEARCH: tools.SearchToolHandler, tools.TOOL_PATCH_CONTENT: tools.PatchContentToolHandler, tools.TOOL_PUT_CONTENT: tools.PutContentToolHandler, tools.TOOL_APPEND_CONTENT: tools.AppendContentToolHandler, tools.TOOL_DELETE_FILE: tools.DeleteFileToolHandler, tools.TOOL_COMPLEX_SEARCH: tools.ComplexSearchToolHandler, tools.TOOL_BATCH_GET_FILES: tools.BatchGetFilesToolHandler, tools.TOOL_PERIODIC_NOTES: tools.PeriodicNotesToolHandler, tools.TOOL_RECENT_PERIODIC_NOTES: tools.RecentPeriodicNotesToolHandler, tools.TOOL_RECENT_CHANGES: tools.RecentChangesToolHandler, tools.TOOL_UNDERSTAND_VAULT: tools.UnderstandVaultToolHandler, tools.TOOL_GET_ACTIVE_NOTE: tools.GetActiveNoteToolHandler, tools.TOOL_OPEN_FILES: tools.OpenFilesToolHandler, tools.TOOL_LIST_COMMANDS: tools.ListCommandsToolHandler, tools.TOOL_EXECUTE_COMMANDS: tools.ExecuteCommandsToolHandler, }
  • The core Obsidian API client method that performs the HTTP PATCH request to patch content in a file relative to a target (heading/block/frontmatter) using specific headers.
    def patch_content(self, filepath: str, operation: str, target_type: str, target: str, content: str) -> Any: url = f"{self.get_base_url()}/vault/{filepath}" headers = self._get_headers() | { 'Content-Type': 'text/markdown', 'Operation': operation, 'Target-Type': target_type, 'Target': urllib.parse.quote(target) } def call_fn(): response = requests.patch(url, headers=headers, data=content, verify=self.verify_ssl, timeout=self.timeout) response.raise_for_status() return None return self._safe_call(call_fn)
  • Constant defining the tool name "obsidian_patch_file" used throughout the codebase.
    TOOL_PATCH_CONTENT = "obsidian_patch_file"

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/ToKiDoO/mcp-obsidian-advanced'

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