create_note
Create new notes in Obsidian with structured frontmatter and content to organize knowledge efficiently.
Instructions
Create a new note with optional frontmatter and content
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Relative path like 'folder/note.md' | |
| content | Yes | Note content | |
| frontmatter | No | JSON string of key-value pairs to add as YAML frontmatter |
Implementation Reference
- src/tools/write.ts:70-98 (handler)The handler function for the `create_note` tool. It processes input parameters, checks if the note already exists, parses optional frontmatter, and finally calls the `writeNote` library function to save the file.
async ({ path: notePath, content, frontmatter }) => { try { const resolvedPath = ensureMdExtension(notePath); if (await noteExists(vaultPath, resolvedPath)) { return errorResult(`Error: Note already exists at '${resolvedPath}'. Use append or update tools instead.`); } let finalContent: string; if (frontmatter) { let parsed: Record<string, unknown>; try { parsed = JSON.parse(frontmatter) as Record<string, unknown>; } catch { return errorResult("Error: Invalid JSON in frontmatter parameter."); } finalContent = buildFrontmatterContent(parsed, content); } else { finalContent = content; } await writeNote(vaultPath, resolvedPath, finalContent); return textResult(`Created note at '${resolvedPath}'.`); } catch (err) { console.error("create_note error:", err); return errorResult(`Error creating note: ${err instanceof Error ? err.message : String(err)}`); } }, - src/tools/write.ts:59-69 (schema)The input schema for the `create_note` tool defining the required path, content, and optional frontmatter fields.
{ description: "Create a new note with optional frontmatter and content", inputSchema: { path: z.string().min(1).describe("Relative path like 'folder/note.md'"), content: z.string().describe("Note content"), frontmatter: z .string() .optional() .describe("JSON string of key-value pairs to add as YAML frontmatter"), }, }, - src/tools/write.ts:57-99 (registration)The registration block for the `create_note` tool using `server.registerTool`.
server.registerTool( "create_note", { description: "Create a new note with optional frontmatter and content", inputSchema: { path: z.string().min(1).describe("Relative path like 'folder/note.md'"), content: z.string().describe("Note content"), frontmatter: z .string() .optional() .describe("JSON string of key-value pairs to add as YAML frontmatter"), }, }, async ({ path: notePath, content, frontmatter }) => { try { const resolvedPath = ensureMdExtension(notePath); if (await noteExists(vaultPath, resolvedPath)) { return errorResult(`Error: Note already exists at '${resolvedPath}'. Use append or update tools instead.`); } let finalContent: string; if (frontmatter) { let parsed: Record<string, unknown>; try { parsed = JSON.parse(frontmatter) as Record<string, unknown>; } catch { return errorResult("Error: Invalid JSON in frontmatter parameter."); } finalContent = buildFrontmatterContent(parsed, content); } else { finalContent = content; } await writeNote(vaultPath, resolvedPath, finalContent); return textResult(`Created note at '${resolvedPath}'.`); } catch (err) { console.error("create_note error:", err); return errorResult(`Error creating note: ${err instanceof Error ? err.message : String(err)}`); } }, );