readNote
Retrieve and display the contents of a specific note from your Obsidian vault using the Obsidian MCP server. Simplify accessing and managing your notes with structured input.
Instructions
Read the contents of a specific note
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"path": {
"minLength": 1,
"type": "string"
}
},
"required": [
"path"
],
"type": "object"
}
Implementation Reference
- src/tools/read-note.ts:25-34 (handler)Factory function that returns the tool handler executing the readNote logic: reads note via ObsidianAPI, handles errors, formats 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:6-18 (schema)Zod input schema and ToolDefinition for the readNote tool.// Schema for read-note tool parameters export const ReadNoteSchema = { path: z.string().min(1, "Note path is required") }; /** * Tool definition for reading a note */ export const readNoteDefinition: ToolDefinition = { name: "readNote", description: "Read the contents of a specific note", schema: ReadNoteSchema };
- src/server.ts:46-52 (registration)Registers the readNote tool on the MCP server using its definition and handler factory.// 1. readNote - Read the contents of a specific note this.server.tool( readNoteDefinition.name, readNoteDefinition.description, readNoteDefinition.schema, createReadNoteTool(this.api) );
- src/api/obsidian-api.ts:25-39 (helper)Low-level helper method in ObsidianAPI that fetches note content via HTTP GET to the vault endpoint.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; }