obsidian_put_file
Create or update files in your Obsidian vault through AI agents using the Local REST API.
Instructions
Create a new file in your vault or update the content of an existing one in your vault.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filepath | Yes | Path to the relevant file (relative to your vault root) | |
| content | Yes | Content of the file you would like to upload |
Implementation Reference
- The PutContentToolHandler class provides the core implementation of the 'obsidian_put_file' tool. It defines the tool schema and executes the logic by calling api.put_content with filepath and content arguments.class PutContentToolHandler(ToolHandler): def __init__(self): super().__init__(TOOL_PUT_CONTENT) def get_tool_description(self): return Tool( name=self.name, description="Create a new file in your vault or update the content of an existing one in your vault.", inputSchema={ "type": "object", "properties": { "filepath": { "type": "string", "description": "Path to the relevant file (relative to your vault root)", "format": "path" }, "content": { "type": "string", "description": "Content of the file you would like to upload" } }, "required": ["filepath", "content"] } ) def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]: if "filepath" not in args or "content" not in args: raise RuntimeError("filepath and content arguments required") api.put_content(args.get("filepath", ""), args["content"]) return [ TextContent( type="text", text=f"Successfully uploaded content to {args['filepath']}" ) ]
- Input schema definition for the obsidian_put_file tool, specifying filepath and content parameters.return Tool( name=self.name, description="Create a new file in your vault or update the content of an existing one in your vault.", inputSchema={ "type": "object", "properties": { "filepath": { "type": "string", "description": "Path to the relevant file (relative to your vault root)", "format": "path" }, "content": { "type": "string", "description": "Content of the file you would like to upload" } }, "required": ["filepath", "content"] } )
- src/mcp_obsidian_advanced/server.py:26-43 (registration)TOOL_MAPPING dictionary registers 'obsidian_put_file' (TOOL_PUT_CONTENT) with its handler class PutContentToolHandler.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, }
- src/mcp_obsidian_advanced/server.py:95-109 (registration)register_tools function instantiates handlers from TOOL_MAPPING (including obsidian_put_file) and adds them to the server.def register_tools(): """Register the selected tools with the server.""" tools_to_include = parse_include_tools() registered_count = 0 for tool_name in tools_to_include: if tool_name in TOOL_MAPPING: handler_class = TOOL_MAPPING[tool_name] handler_instance = handler_class() add_tool_handler(handler_instance) registered_count += 1 logger.debug(f"Registered tool: {tool_name}") logger.info(f"Successfully registered {registered_count} tools")
- The underlying api.put_content method that performs the HTTP PUT request to the Obsidian API to create or update the file content.def put_content(self, filepath: str, content: str) -> Any: url = f"{self.get_base_url()}/vault/{filepath}" def call_fn(): response = requests.put( url, headers=self._get_headers() | {'Content-Type': 'text/markdown'}, data=content, verify=self.verify_ssl, timeout=self.timeout ) response.raise_for_status() return None return self._safe_call(call_fn)