Skip to main content
Glama

obsidian_get_file_contents

Read complete contents of files from your Obsidian vault to access Zettelkasten notes, understand their structure, and identify connections for creating new atomic notes.

Instructions

Read the complete contents of a single file from the vault.

Use this to read existing Zettelkasten notes, understand their structure, and find connections for creating new atomic notes. Args: params (GetFileInput): Contains: - filepath (str): Path to file relative to vault root Returns: str: File contents including frontmatter and body Example: For filepath="Zettelkasten/202411061234.md", returns the full note content.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Implementation Reference

  • Handler function decorated with @mcp.tool that implements the obsidian_get_file_contents tool. Reads file contents via obsidian_client.read_file, adds a header, truncates if necessary, and handles errors.
    @mcp.tool( name="obsidian_get_file_contents", annotations={ "title": "Get File Contents", "readOnlyHint": True, "destructiveHint": False, "idempotentHint": True, "openWorldHint": False } ) async def get_file_contents(params: GetFileInput) -> str: """Read the complete contents of a single file from the vault. Use this to read existing Zettelkasten notes, understand their structure, and find connections for creating new atomic notes. Args: params (GetFileInput): Contains: - filepath (str): Path to file relative to vault root Returns: str: File contents including frontmatter and body Example: For filepath="Zettelkasten/202411061234.md", returns the full note content. """ try: content = await obsidian_client.read_file(params.filepath) # Add filepath header for context output = f"# File: {params.filepath}\n\n{content}" return truncate_response(output, f"file {params.filepath}") except ObsidianAPIError as e: return json.dumps({ "error": str(e), "filepath": params.filepath, "success": False }, indent=2)
  • Pydantic input model defining the schema for the tool's parameters: filepath (required string).
    class GetFileInput(BaseModel): """Input for getting file contents.""" model_config = ConfigDict(str_strip_whitespace=True, extra='forbid') filepath: str = Field( description="Path to the file relative to vault root (e.g., 'Notes/zettelkasten/202411061234.md')", min_length=1, max_length=500 )
  • Helper method in ObsidianClient that performs the HTTP GET request to retrieve file contents from the Obsidian REST API, called by the tool handler.
    async def read_file(self, filepath: str) -> str: """Read file content from the vault.""" result = await self.get(f"/vault/{filepath}") return result.get("content", "")
  • Utility helper function used by the tool handler to truncate long file contents if exceeding the character limit.
    def truncate_response(content: str, description: str = "response") -> str: """Truncate content if it exceeds CHARACTER_LIMIT.""" if len(content) <= CHARACTER_LIMIT: return content truncated = content[:CHARACTER_LIMIT] message = f"\n\n[Response truncated at {CHARACTER_LIMIT} characters. Original {description} was {len(content)} characters. Use filters or pagination to reduce results.]" return truncated + message

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

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