Skip to main content
Glama
sureshsankaran

Obsidian Tools MCP Server

update_frontmatter

Modify or add YAML frontmatter properties in Obsidian notes to organize metadata, update tags, or remove outdated information.

Instructions

Update or add frontmatter (YAML) properties in a note

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the note
propertiesYesKey-value pairs to set in frontmatter. Use null to delete a property.

Implementation Reference

  • The handler function that executes the update_frontmatter tool: reads the note, parses frontmatter, updates properties (deleting if null), serializes new frontmatter, appends body, and writes back to file.
    async function handleUpdateFrontmatter(args: { path: string; properties: Record<string, unknown>; }): Promise<string> { const fullPath = resolvePath(args.path); if (!(await fileExists(fullPath))) { throw new Error(`Note not found at ${args.path}`); } const content = await fs.readFile(fullPath, "utf-8"); const { frontmatter, body } = parseFrontmatter(content); const newFrontmatter = { ...(frontmatter || {}), ...args.properties }; // Remove null values for (const [key, value] of Object.entries(newFrontmatter)) { if (value === null) { delete newFrontmatter[key]; } } const newContent = serializeFrontmatter(newFrontmatter) + body; await fs.writeFile(fullPath, newContent, "utf-8"); return `Successfully updated frontmatter in ${args.path}`; }
  • Input schema defining parameters: path (string) and properties (object of key-value pairs, null to delete).
    inputSchema: { type: "object", properties: { path: { type: "string", description: "Path to the note", }, properties: { type: "object", description: "Key-value pairs to set in frontmatter. Use null to delete a property.", }, }, required: ["path", "properties"], },
  • src/index.ts:300-318 (registration)
    Tool registration in the tools array used for listing available tools.
    { name: "update_frontmatter", description: "Update or add frontmatter (YAML) properties in a note", inputSchema: { type: "object", properties: { path: { type: "string", description: "Path to the note", }, properties: { type: "object", description: "Key-value pairs to set in frontmatter. Use null to delete a property.", }, }, required: ["path", "properties"], }, },
  • src/index.ts:930-934 (registration)
    Registration/dispatch in the switch statement for tool calls.
    case "update_frontmatter": result = await handleUpdateFrontmatter( args as { path: string; properties: Record<string, unknown> } ); break;
  • Helper function to serialize a JavaScript object to YAML frontmatter format, used in the handler.
    function serializeFrontmatter(obj: Record<string, unknown>): string { const lines: string[] = []; for (const [key, value] of Object.entries(obj)) { if (value === null || value === undefined) continue; if (Array.isArray(value)) { lines.push(`${key}: [${value.join(", ")}]`); } else { lines.push(`${key}: ${value}`); } } return `---\n${lines.join("\n")}\n---\n`; }

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/sureshsankaran/obsidian-tools-mcp'

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