Skip to main content
Glama
MarkusPfundstein

MCP server for Obsidian

obsidian_get_file_contents

Retrieve content from Obsidian vault files using the MCP server to access specific document text for processing or analysis.

Instructions

Return the content of a single file in your vault.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filepathYesPath to the relevant file (relative to your vault root).

Implementation Reference

  • The `run_tool` method of `GetFileContentsToolHandler` that executes the core tool logic: checks for filepath argument, instantiates Obsidian API client, fetches file contents, and returns as JSON-formatted TextContent.
    def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]: if "filepath" not in args: raise RuntimeError("filepath argument missing in arguments") api = obsidian.Obsidian(api_key=api_key, host=obsidian_host) content = api.get_file_contents(args["filepath"]) return [ TextContent( type="text", text=json.dumps(content, indent=2) ) ]
  • The `get_tool_description` method returning the Tool object with input schema defining the required 'filepath' parameter.
    def get_tool_description(self): return Tool( name=self.name, description="Return the content of a single file in your vault.", inputSchema={ "type": "object", "properties": { "filepath": { "type": "string", "description": "Path to the relevant file (relative to your vault root).", "format": "path" }, }, "required": ["filepath"] } )
  • Registers the `GetFileContentsToolHandler` instance in the global tool_handlers dictionary used by the MCP server.
    add_tool_handler(tools.GetFileContentsToolHandler())
  • The `get_file_contents` method in the `Obsidian` class that sends an HTTP GET request to the Obsidian API endpoint to retrieve and return the raw text content of the specified file.
    def get_file_contents(self, filepath: str) -> Any: url = f"{self.get_base_url()}/vault/{filepath}" def call_fn(): response = requests.get(url, headers=self._get_headers(), verify=self.verify_ssl, timeout=self.timeout) response.raise_for_status() return response.text 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