Skip to main content
Glama

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
NameRequiredDescriptionDefault
pathYesRelative path like 'folder/note.md'
contentYesNote content
frontmatterNoJSON string of key-value pairs to add as YAML frontmatter

Implementation Reference

  • 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)}`);
      }
    },
  • 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"),
      },
    },
  • 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)}`);
        }
      },
    );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rps321321/obsidian-mcp-pro'

If you have feedback or need assistance with the MCP directory API, please join our Discord server