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
| Name | Required | Description | Default |
|---|---|---|---|
| filepath | Yes | Path to the relevant file (relative to your vault root). |
Implementation Reference
- src/mcp_obsidian/tools.py:115-128 (handler)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) ) ]
- src/mcp_obsidian/tools.py:98-113 (schema)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"] } )
- src/mcp_obsidian/server.py:46-46 (registration)Registers the `GetFileContentsToolHandler` instance in the global tool_handlers dictionary used by the MCP server.add_tool_handler(tools.GetFileContentsToolHandler())
- src/mcp_obsidian/obsidian.py:70-79 (helper)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)