Skip to main content
Glama

obsidian_get_file_contents

Read-onlyIdempotent

Read complete contents of Obsidian vault files to analyze 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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The decorated handler function implementing the core logic of obsidian_get_file_contents tool: reads file via client, formats output with header, truncates long content, handles API 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 model defining the input schema for the tool, specifying the required filepath parameter with validation.
    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 function used by the tool handler to truncate responses exceeding 25000 characters.
    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
  • Supporting method in ObsidianClient that performs the actual API GET request to retrieve file contents, 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", "")
  • The @mcp.tool decorator registering the function as an MCP tool with name and annotations.
    @mcp.tool(
        name="obsidian_get_file_contents",
        annotations={
            "title": "Get File Contents",
            "readOnlyHint": True,
            "destructiveHint": False,
            "idempotentHint": True,
            "openWorldHint": False
        }
    )
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already provide readOnlyHint=true, destructiveHint=false, idempotentHint=true, and openWorldHint=false, covering safety and idempotency. The description adds valuable context beyond this by specifying it reads 'complete contents... including frontmatter and body' and provides an example, though it doesn't mention error handling or file existence checks.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with a clear purpose statement, usage guidelines, parameter details, return value, and an example—all in four concise sentences. Each section adds value without redundancy, and information is front-loaded appropriately.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (1 parameter), rich annotations covering safety and behavior, and the presence of an output schema (specifying return type as str), the description is complete. It adequately explains the tool's purpose, usage, parameters, and output without needing to duplicate structured data.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, but the description compensates by explaining the single parameter 'filepath' in the Args section and providing an example. However, it doesn't add significant meaning beyond what the schema's properties already define (e.g., path format, length constraints).

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Read the complete contents of a single file') and resource ('from the vault'), distinguishing it from siblings like obsidian_get_frontmatter (partial content) or obsidian_batch_get_file_contents (multiple files). The mention of 'Zettelkasten notes' provides domain-specific context.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context on when to use this tool ('to read existing Zettelkasten notes, understand their structure, and find connections for creating new atomic notes'), but does not explicitly state when not to use it or name alternatives like obsidian_get_frontmatter for partial content or obsidian_batch_get_file_contents for multiple files.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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