Skip to main content
Glama
nojiritakeshi

Obsidian Translation MCP Server

update_obsidian_note

Update an existing Obsidian note by replacing, appending, or prepending content with optional backup to preserve previous version.

Instructions

Update an existing Obsidian note

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the note (relative to vault root)
contentYesNew content for the note
modeNoUpdate mode: replace, append, or prepend contentreplace
createBackupNoWhether to create a backup before updating

Implementation Reference

  • Core handler method `updateNote()` that executes the update logic for an Obsidian note. It checks file existence, optionally creates a backup, reads existing content, applies the update mode (replace/append/prepend), updates frontmatter with a new modified timestamp, and writes back to disk.
    async updateNote(
      path: string,
      newContent: string,
      mode: 'replace' | 'append' | 'prepend' = 'replace',
      createBackup: boolean = true
    ): Promise<NoteMetadata> {
      try {
        // ファイルの存在確認
        if (!(await this.fileSystem.exists(path))) {
          throw new Error(`${ErrorCode.FILE_NOT_FOUND}: File '${path}' not found`);
        }
    
        // バックアップを作成
        if (createBackup) {
          await this.fileSystem.createBackup(path);
        }
    
        // 既存のコンテンツを読み取り
        const { content: existingContent, frontmatter } = await this.readNote(path);
    
        // 更新モードに応じてコンテンツを結合
        let finalContent: string;
        switch (mode) {
          case 'replace':
            finalContent = newContent;
            break;
          case 'append':
            finalContent = existingContent + '\\n\\n' + newContent;
            break;
          case 'prepend':
            finalContent = newContent + '\\n\\n' + existingContent;
            break;
          default:
            throw new Error(`${ErrorCode.TRANSLATION_FAILED}: Invalid mode '${mode}'`);
        }
    
        // Frontmatterを更新
        const updatedFrontmatter = {
          ...frontmatter,
          modified: new Date().toISOString()
        };
    
        // ファイルを更新
        const noteContent = matter.stringify(finalContent, updatedFrontmatter);
        await this.fileSystem.writeFile(path, noteContent);
    
        return {
          title: frontmatter.title || path.split('/').pop()?.replace('.md', '') || 'Untitled',
          path,
          tags: frontmatter.tags || [],
          lastModified: new Date(),
          created: new Date(frontmatter.created || new Date())
        };
      } catch (error) {
        if (error instanceof Error) {
          throw error;
        }
        throw new Error(`${ErrorCode.PERMISSION_DENIED}: Failed to update note '${path}'`);
      }
    }
  • MCP request handler `handleUpdateNote()` that extracts path, content, mode, and createBackup from `args` and delegates to `notesTool.updateNote()`. It validates required parameters and formats the success response.
    private async handleUpdateNote(args: any) {
      const { path, content, mode, createBackup } = args;
      
      if (!path || !content) {
        throw new McpError(ErrorCode.InvalidParams, 'Path and content are required');
      }
    
      const result = await this.notesTool.updateNote(path, content, mode, createBackup);
    
      return {
        content: [
          {
            type: 'text',
            text: `✅ ノートが更新されました\\n\\n` +
                  `📁 パス: ${result.path}\\n` +
                  `📝 タイトル: ${result.title}\\n` +
                  `🔄 更新モード: ${mode || 'replace'}\\n` +
                  `⏰ 更新日時: ${result.lastModified.toISOString()}`
          }
        ]
      };
    }
  • Tool definition `getUpdateNoteToolDefinition()` returning the schema for 'update_obsidian_note': defines input properties (path, content, mode with enum replace/append/prepend, createBackup) with required fields path and content.
    static getUpdateNoteToolDefinition(): Tool {
      return {
        name: 'update_obsidian_note',
        description: 'Update an existing Obsidian note',
        inputSchema: {
          type: 'object',
          properties: {
            path: {
              type: 'string',
              description: 'Path to the note (relative to vault root)'
            },
            content: {
              type: 'string',
              description: 'New content for the note'
            },
            mode: {
              type: 'string',
              enum: ['replace', 'append', 'prepend'],
              description: 'Update mode: replace, append, or prepend content',
              default: 'replace'
            },
            createBackup: {
              type: 'boolean',
              description: 'Whether to create a backup before updating',
              default: true
            }
          },
          required: ['path', 'content']
        }
      };
  • src/index.ts:89-98 (registration)
    Tool registration in `ListToolsRequestSchema` handler: the 'update_obsidian_note' tool is listed via `NotesTool.getUpdateNoteToolDefinition()` on line 95, making it available to clients.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          TranslateTool.getToolDefinition(),
          NotesTool.getCreateNoteToolDefinition(),
          NotesTool.getReadNoteToolDefinition(),
          NotesTool.getUpdateNoteToolDefinition(),
          SearchTool.getSearchToolDefinition(),
          SearchTool.getSearchByTagsToolDefinition(),
        ],
  • src/index.ts:117-118 (registration)
    Tool dispatch in `CallToolRequestSchema` handler: the switch-case on line 117 routes the name 'update_obsidian_note' to `handleUpdateNote()`.
    case 'update_obsidian_note':
      return await this.handleUpdateNote(args);
Behavior2/5

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

No annotations are given, so the description must fully convey behavior. It only says 'Update an existing Obsidian note' without disclosing error handling, return value, or confirmation behavior. The schema hints at backup defaults and modes, but the description adds no extra context.

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 sentence with no redundant information, perfectly concise for a straightforward update tool.

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?

With no output schema and 4 parameters, the description lacks critical details: what is returned (e.g., success status), error scenarios (e.g., note not found), and when to use each mode. It is incomplete for an agent to invoke correctly without additional knowledge.

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 coverage is 100%, so the baseline is 3. The description adds no additional meaning beyond the schema; it does not explain parameter purpose or provide examples.

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

Purpose5/5

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

The description clearly states the action ('Update') and the resource ('an existing Obsidian note'), distinguishing it from siblings like create or read.

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

Usage Guidelines3/5

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

No explicit when-to-use or when-not-to-use guidance is provided. The description does not differentiate between modes (replace, append, prepend) or compare with create/read, leaving usage implied.

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/nojiritakeshi/obsidian-translate-mcp-server'

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