Skip to main content
Glama
MarkusPfundstein

MCP server for Obsidian

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
NameRequiredDescriptionDefault
filepathYesPath to the relevant file (relative to your vault root)
contentYesContent of the file you would like to upload

Implementation Reference

  • 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']}" ) ]
  • 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"] } )
  • 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())
  • 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)

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

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