Skip to main content
Glama
takuya0206

Obsidian MCP

by takuya0206

patchNote

Modify existing notes by inserting content relative to headings, block references, or frontmatter fields using append, prepend, or replace operations.

Instructions

Inserts content into an existing note relative to a heading, block reference, or frontmatter field.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
operationYesOperation to perform (append, prepend, or replace)
targetTypeYesType of target to patch (heading, block, or frontmatter)
targetYesTarget identifier - For heading: Use a heading path string. For nested headings, use '::' as a delimiter (e.g., '## Heading 1 ### Subheading 1' must be 'Heading 1::Subheading 1'). The path should match the exact heading text. For headings with special characters, use URL encoding. - For block: Use the block ID (e.g., '2d9b4a'). - For frontmatter: Use the frontmatter field name (e.g., 'tags', 'date', 'title').
contentYesContent to be inserted or used for replacement
targetDelimiterNo
trimTargetWhitespaceNo
contentTypeNo

Implementation Reference

  • Factory function createPatchNoteTool that returns the ToolHandler for executing the patchNote tool logic. It destructures params, calls ObsidianAPI.patchNote, and formats success/error responses.
    export function createPatchNoteTool(api: ObsidianAPI): ToolHandler {
      return async (params: {
        path: string;
        operation: "append" | "prepend" | "replace";
        targetType: "heading" | "block" | "frontmatter";
        target: string;
        content: string;
        targetDelimiter?: string;
        trimTargetWhitespace?: boolean;
        contentType?: string;
      }): Promise<ToolResponse> => {
        try {
          const { path, content, ...patchOptions } = params;
          await api.patchNote(path, content, patchOptions as PatchNoteOptions);
          return formatSuccessResponse({ success: true, message: "Note patched successfully" });
        } catch (error) {
          return formatErrorResponse(`Error patching note: ${(error as Error).message}`);
        }
      };
    }
  • ToolDefinition for patchNote tool, including name, description, and reference to input schema.
    export const patchNoteDefinition: ToolDefinition = {
      name: "patchNote",
      description: "Inserts content into an existing note relative to a heading, block reference, or frontmatter field.",
      schema: PatchNoteSchema
    };
  • Zod schema (PatchNoteSchema) defining input parameters and validation for the patchNote tool.
    export const PatchNoteSchema = {
      path: z.string().min(1, "Note path is required"),
      operation: z.enum(["append", "prepend", "replace"], {
        description: "Operation to perform (append, prepend, or replace)",
      }),
      targetType: z.enum(["heading", "block", "frontmatter"], {
        description: "Type of target to patch (heading, block, or frontmatter)",
      }),
      target: z
        .string()
        .min(1, "Target is required")
        .describe(`Target identifier
          - For heading: Use a heading path string. For nested headings, use '::' as a delimiter (e.g., '## Heading 1 ### Subheading 1' must be 'Heading 1::Subheading 1'). The path should match the exact heading text. For headings with special characters, use URL encoding.
          - For block: Use the block ID (e.g., '2d9b4a').
          - For frontmatter: Use the frontmatter field name (e.g., 'tags', 'date', 'title').`),
      content: z
        .string()
        .min(1, "Content is required")
        .describe("Content to be inserted or used for replacement"),
      targetDelimiter: z.string().optional(),
      trimTargetWhitespace: z.boolean().optional(),
      contentType: z.string().optional(),
    };
  • src/server.ts:71-76 (registration)
    Registration of the patchNote tool on the MCP server using server.tool() with definition and created handler.
    this.server.tool(
      patchNoteDefinition.name,
      patchNoteDefinition.description,
      patchNoteDefinition.schema,
      createPatchNoteTool(this.api)
    );
  • ObsidianAPI.patchNote method implementing the core patching logic via HTTP PATCH request to the Obsidian Local REST API.
    async patchNote(
      path: string,
      content: string,
      patchOptions: PatchNoteOptions
    ): Promise<void> {
      const normalizedPath = path.startsWith("/") ? path.substring(1) : path;
      const processedContent = content;
      const {
        operation,
        targetType,
        target,
        targetDelimiter = "::",
        trimTargetWhitespace = false,
        contentType = "text/markdown",
      } = patchOptions;
    
      // ターゲットを日本語で指定するとエラーになるため
      const encodedTarget = containsNonASCII(target)
        ? encodeURIComponent(target)
        : target;
    
      try {
        const response = await this.client.patch(
          `/vault/${encodeURIComponent(normalizedPath)}`,
          processedContent,
          {
            headers: {
              ...this.defaultHeaders,
              Operation: operation,
              "Target-Type": targetType,
              Target: encodedTarget,
              "Target-Delimiter": targetDelimiter,
              "Trim-Target-Whitespace": trimTargetWhitespace,
              "Content-Type": contentType,
            },
          }
        );
        return response.data;
      } catch (error: any) {
        throw error;
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but lacks critical behavioral details. It states 'inserts content' implying mutation, but doesn't disclose permissions needed, whether changes are reversible, error handling, or rate limits. The description is minimal and misses key operational context for a tool with 8 parameters and no output schema.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose without redundancy. Every word contributes to understanding the tool's function, making it appropriately sized for its complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with 8 parameters, 50% schema coverage, no annotations, and no output schema, the description is inadequate. It lacks details on behavioral traits, error cases, return values, and doesn't fully address parameter semantics. The agent would struggle to use this tool correctly without additional context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 50%, with detailed descriptions for 'target' and 'content' but none for 'targetDelimiter', 'trimTargetWhitespace', or 'contentType'. The description mentions 'heading, block reference, or frontmatter field' which aligns with targetType enum values, adding slight context. However, it doesn't explain parameter interactions or compensate for the low coverage gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('inserts content') and target ('existing note'), specifying the insertion points ('relative to a heading, block reference, or frontmatter field'). It distinguishes from sibling tools like 'listNotes' or 'readNote' by focusing on modification rather than retrieval, though it doesn't explicitly name alternatives.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'searchWithJsonLogic' or 'readActiveNote'. It mentions the insertion points but doesn't specify scenarios, prerequisites, or exclusions, leaving the agent to infer usage from the operation and targetType parameters alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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

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