readNote
Retrieve the contents of a specific note from your Obsidian vault by providing its file path.
Instructions
Read the contents of a specific note
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- src/tools/read-note.ts:25-34 (handler)Factory function that creates the readNote tool handler. The returned async function executes the tool logic: reads the note content using ObsidianAPI and returns formatted success or error response.export function createReadNoteTool(api: ObsidianAPI): ToolHandler { return async (params: { path: string }): Promise<ToolResponse> => { try { const note = await api.readNote(params.path); return formatSuccessResponse(note); } catch (error) { return formatErrorResponse(`Error reading note: ${(error as Error).message}`); } }; }
- src/tools/read-note.ts:7-9 (schema)Zod schema for validating input parameters of the readNote tool (requires a non-empty 'path' string).export const ReadNoteSchema = { path: z.string().min(1, "Note path is required") };
- src/server.ts:47-52 (registration)Registration of the readNote tool on the MCP server using server.tool() with name, description, schema, and handler factory.this.server.tool( readNoteDefinition.name, readNoteDefinition.description, readNoteDefinition.schema, createReadNoteTool(this.api) );
- src/api/obsidian-api.ts:25-39 (helper)ObsidianAPI method that performs the HTTP GET request to fetch the note content from the vault, used by the tool handler.async readNote(path: string): Promise<NoteJson> { const normalizedPath = path.startsWith("/") ? path.substring(1) : path; const response = await this.client.get( `/vault/${encodeURIComponent(normalizedPath)}`, { headers: { ...this.defaultHeaders, "Content-Type": "application/json", accept: "application/vnd.olrapi.note+json", }, } ); return response.data as NoteJson; }