Skip to main content
Glama

create_note

Create new notes in your Obsidian vault with specified content, file paths, tags, and optional overwrite functionality for organized knowledge management.

Instructions

Create a new note in the vault

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYes
overwriteNo
pathYes
tagsNo

Implementation Reference

  • MCP tool handler for 'create_note'. Registers the tool and implements the logic by calling the vault's create_note method, including input validation and frontmatter handling for tags.
    @mcp.tool(name="create_note", description="Create a new note in the vault")
    def create_note(
        path: str, content: str, tags: list[str] | None = None, overwrite: bool = False
    ) -> str:
        """
        Create a new note.
    
        Args:
            path: Relative path for the new note (e.g., "Projects/New Idea.md")
            content: Content of the note
            tags: Optional list of tags to add to frontmatter
            overwrite: If true, overwrite existing note
    
        Returns:
            Success message
        """
        if not path or not path.strip():
            return "Error: Path cannot be empty"
        if len(path) > 1000:
            return "Error: Path too long"
        if len(content) > 1_000_000:
            return "Error: Content too large (max 1MB)"
    
        context = _get_context()
    
        try:
            # Build frontmatter if tags provided
            frontmatter = None
            if tags:
                frontmatter = {"tags": tags}
    
            context.vault.create_note(path, content, frontmatter, overwrite)
            return f"✓ Created note: {path}"
    
        except FileExistsError:
            return f"Error: Note already exists: {path} (use overwrite=true to replace)"
        except VaultSecurityError as e:
            return f"Error: Security violation: {e}"
        except Exception as e:
            logger.exception(f"Error creating note {path}")
            return f"Error creating note: {e}"
  • Core implementation in ObsidianVault class that creates the note file, handles frontmatter insertion, directory creation, and security validation.
    def create_note(
        self,
        relative_path: str,
        content: str,
        frontmatter: dict[str, Any] | None = None,
        overwrite: bool = False,
    ) -> None:
        """
        Create a new note in the vault.
    
        Args:
            relative_path: Path where to create the note
            content: Content of the note
            frontmatter: Optional frontmatter dict
            overwrite: If True, overwrite existing file
    
        Raises:
            VaultSecurityError: If path is invalid
            FileExistsError: If note already exists and overwrite=False
        """
        file_path = self._validate_path(relative_path)
    
        # Check if already exists
        if file_path.exists() and not overwrite:
            raise FileExistsError(f"Note already exists: {relative_path}")
    
        # Ensure parent directory exists
        file_path.parent.mkdir(parents=True, exist_ok=True)
    
        # Build full content with frontmatter
        full_content = ""
        if frontmatter:
            full_content = "---\n"
            full_content += yaml.dump(frontmatter, default_flow_style=False, sort_keys=False)
            full_content += "---\n"
    
        full_content += content
    
        # Write file
        file_path.write_text(full_content, encoding="utf-8")
        logger.info(f"Created note: {relative_path}")
  • The @mcp.tool decorator registers the 'create_note' tool with FastMCP, defining its name, description, and input schema from function signature.
    @mcp.tool(name="create_note", description="Create a new note in the vault")
    def create_note(
        path: str, content: str, tags: list[str] | None = None, overwrite: bool = False
    ) -> str:
        """
        Create a new note.
    
        Args:
            path: Relative path for the new note (e.g., "Projects/New Idea.md")
            content: Content of the note
            tags: Optional list of tags to add to frontmatter
            overwrite: If true, overwrite existing note
    
        Returns:
            Success message
        """
        if not path or not path.strip():
            return "Error: Path cannot be empty"
        if len(path) > 1000:
            return "Error: Path too long"
        if len(content) > 1_000_000:
            return "Error: Content too large (max 1MB)"
    
        context = _get_context()
    
        try:
            # Build frontmatter if tags provided
            frontmatter = None
            if tags:
                frontmatter = {"tags": tags}
    
            context.vault.create_note(path, content, frontmatter, overwrite)
            return f"✓ Created note: {path}"
    
        except FileExistsError:
            return f"Error: Note already exists: {path} (use overwrite=true to replace)"
        except VaultSecurityError as e:
            return f"Error: Security violation: {e}"
        except Exception as e:
            logger.exception(f"Error creating note {path}")
            return f"Error creating note: {e}"

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/getglad/obsidian_mcp'

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