read_file
Access and retrieve the complete contents of a file from an Obsidian vault stored in iCloud Drive. Handles multiple text encodings and provides detailed error messages for troubleshooting. Use this tool to examine specific files within allowed directories.
Instructions
Your task is to read file from /Users/username/Library/Mobile Documents/iCloud~md~obsidian/Documents/my-vault. Read the complete contents of a file from the file system. Handles various text encodings and provides detailed error messages if the file cannot be read. Use this tool when you need to examine the contents of a single file. Only works within allowed directories.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- src/file-system.ts:206-216 (handler)The main handler function for the 'read_file' tool. It parses the input arguments using ReadFileArgsSchema, reads the file content using fs.readFile, and returns the content in the expected format.export async function readFile(args?: Record<string, unknown>) { const parsed = ReadFileArgsSchema.safeParse(args) if (!parsed.success) { throw new Error(`Invalid arguments for read_file: ${parsed.error}`) } const content = await fs.readFile(parsed.data.path, 'utf-8') return { content: [{ type: 'text', text: content }] } }
- src/schemas.ts:4-6 (schema)Zod schema for validating the input arguments of the 'read_file' tool, which requires a 'path' string.export const ReadFileArgsSchema = z.object({ path: z.string() })
- src/index.ts:171-173 (registration)In the CallToolRequestSchema handler, the switch case that routes calls to the 'read_file' tool to the readFile handler function.case 'read_file': { return readFile(args) }
- src/index.ts:101-104 (registration)Tool registration in ListToolsRequestSchema response, defining the name, dynamic description from prompt, and input schema for 'read_file'.name: 'read_file', description: readFilePrompt(args), inputSchema: zodToJsonSchema(ReadFileArgsSchema) as ToolInput },