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
| Name | Required | Description | Default |
|---|---|---|---|
| filepaths | Yes | List of file paths to read |
Implementation Reference
- src/mcp_obsidian/tools.py:462-474 (handler)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 ) ]
- src/mcp_obsidian/tools.py:441-460 (schema)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"] } )
- src/mcp_obsidian/server.py:53-53 (registration)Registers the BatchGetFileContentsToolHandler instance with the MCP server using add_tool_handler.add_tool_handler(tools.BatchGetFileContentsToolHandler())
- src/mcp_obsidian/obsidian.py:81-100 (helper)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)