obsidian_patch_content
Insert content into Obsidian notes relative to headings, blocks, 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
| Name | Required | Description | Default |
|---|---|---|---|
| filepath | Yes | Path to the file (relative to vault root) | |
| operation | Yes | Operation to perform (append, prepend, or replace) | |
| target_type | Yes | Type of target to patch | |
| target | Yes | Target identifier (heading path, block reference, or frontmatter field) | |
| content | Yes | Content to insert |
Implementation Reference
- src/mcp_obsidian/server.py:48-48 (registration)Registers the PatchContentToolHandler for the 'obsidian_patch_content' tool.add_tool_handler(tools.PatchContentToolHandler())
- src/mcp_obsidian/tools.py:270-288 (handler)Executes the tool by validating arguments and calling obsidian.patch_content API method.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 = obsidian.Obsidian(api_key=api_key, host=obsidian_host) 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']}" ) ]
- src/mcp_obsidian/tools.py:235-268 (schema)Defines the input schema and description for the obsidian_patch_content tool.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"] } )