Skip to main content
Glama
MarkusPfundstein

MCP server for Obsidian

obsidian_batch_get_file_contents

Retrieve and combine content from multiple Obsidian vault files at once to streamline research and content management workflows.

Instructions

Return the contents of multiple files in your vault, concatenated with headers.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filepathsYesList of file paths to read

Implementation Reference

  • The run_tool method that executes the core logic of the 'obsidian_batch_get_file_contents' tool. It validates input, instantiates the Obsidian API client, fetches batch file contents, and returns them wrapped in TextContent.
    def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]: if "filepaths" not in args: raise RuntimeError("filepaths argument missing in arguments") api = obsidian.Obsidian(api_key=api_key, host=obsidian_host) content = api.get_batch_file_contents(args["filepaths"]) return [ TextContent( type="text", text=content ) ]
  • Defines the Tool schema including name, description, and inputSchema requiring an array of filepaths.
    def get_tool_description(self): return Tool( name=self.name, description="Return the contents of multiple files in your vault, concatenated with headers.", inputSchema={ "type": "object", "properties": { "filepaths": { "type": "array", "items": { "type": "string", "description": "Path to a file (relative to your vault root)", "format": "path" }, "description": "List of file paths to read" }, }, "required": ["filepaths"] } )
  • Registers the BatchGetFileContentsToolHandler instance with the MCP server using add_tool_handler.
    add_tool_handler(tools.BatchGetFileContentsToolHandler())
  • Supporting utility in Obsidian class that implements the batch file reading logic: loops through filepaths, fetches individual contents, formats with headers and separators, handles errors gracefully.
    def get_batch_file_contents(self, filepaths: list[str]) -> str: """Get contents of multiple files and concatenate them with headers. Args: filepaths: List of file paths to read Returns: String containing all file contents with headers """ result = [] for filepath in filepaths: try: content = self.get_file_contents(filepath) result.append(f"# {filepath}\n\n{content}\n\n---\n\n") except Exception as e: # Add error message but continue processing other files result.append(f"# {filepath}\n\nError reading file: {str(e)}\n\n---\n\n") return "".join(result)

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