obsidian_put_content
Create or update files in your Obsidian vault by specifying file paths and content. This tool helps manage your knowledge base through direct file operations.
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
- src/mcp_obsidian/tools.py:315-327 (handler)The run_tool method of PutContentToolHandler implements the core logic of the 'obsidian_put_content' tool. It validates the required arguments (filepath and content), instantiates the Obsidian API client, calls api.put_content to upload the file content to the Obsidian vault, and returns a success message.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 = obsidian.Obsidian(api_key=api_key, host=obsidian_host) api.put_content(args.get("filepath", ""), args["content"]) return [ TextContent( type="text", text=f"Successfully uploaded content to {args['filepath']}" ) ]
- src/mcp_obsidian/tools.py:294-313 (schema)The get_tool_description method defines the tool schema, including name, description, and inputSchema specifying required 'filepath' and 'content' parameters.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"] } )
- src/mcp_obsidian/server.py:50-50 (registration)The PutContentToolHandler instance is registered in the tool_handlers dictionary via add_tool_handler, making the 'obsidian_put_content' tool available to the MCP server.add_tool_handler(tools.PutContentToolHandler())
- src/mcp_obsidian/obsidian.py:149-163 (helper)The put_content method in the Obsidian class performs the actual HTTP PUT request to the Obsidian API endpoint /vault/{filepath} to create or update the file with the provided 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)