obsidian_batch_get_file_contents
Read multiple related notes simultaneously to understand connections and context before creating new atomic notes in your Zettelkasten workflow.
Instructions
Read multiple files at once, concatenated with headers.
Efficient way to read several related Zettelkasten notes together to understand
connections and context before creating new atomic notes.
Args:
params (BatchGetFilesInput): Contains:
- filepaths (List[str]): List of file paths to read (max 20)
Returns:
str: All file contents concatenated with clear separators
Example:
Reads multiple related notes to understand a concept network.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Implementation Reference
- The handler function that implements the core logic of the 'obsidian_batch_get_file_contents' tool. It iterates over the provided list of filepaths, reads each file's content using obsidian_client.read_file(), formats them with headers and error handling, concatenates the results, and applies truncation if necessary.@mcp.tool( name="obsidian_batch_get_file_contents", annotations={ "title": "Batch Get File Contents", "readOnlyHint": True, "destructiveHint": False, "idempotentHint": True, "openWorldHint": False } ) async def batch_get_files(params: BatchGetFilesInput) -> str: """Read multiple files at once, concatenated with headers. Efficient way to read several related Zettelkasten notes together to understand connections and context before creating new atomic notes. Args: params (BatchGetFilesInput): Contains: - filepaths (List[str]): List of file paths to read (max 20) Returns: str: All file contents concatenated with clear separators Example: Reads multiple related notes to understand a concept network. """ results = [] for filepath in params.filepaths: try: content = await obsidian_client.read_file(filepath) results.append(f"# File: {filepath}\n\n{content}\n\n{'='*80}\n") except ObsidianAPIError as e: results.append(f"# File: {filepath}\n\nError: {str(e)}\n\n{'='*80}\n") output = "\n".join(results) return truncate_response(output, "batch file read")
- Pydantic input schema/model for the tool, defining a list of up to 20 file paths as strings.class BatchGetFilesInput(BaseModel): """Input for batch reading multiple files.""" model_config = ConfigDict(str_strip_whitespace=True, extra='forbid') filepaths: List[str] = Field( description="List of file paths to read", min_items=1, max_items=20 )
- Utility helper function called by the handler to truncate overly long responses, ensuring they fit within limits.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
- src/custom_obsidian_mcp/server.py:515-524 (registration)The MCP tool registration decorator that registers the batch_get_files function with the name 'obsidian_batch_get_file_contents' and appropriate annotations.@mcp.tool( name="obsidian_batch_get_file_contents", annotations={ "title": "Batch Get File Contents", "readOnlyHint": True, "destructiveHint": False, "idempotentHint": True, "openWorldHint": False } )