Skip to main content
Glama
nojiritakeshi

Obsidian Translation MCP Server

translate_obsidian_note

Translate an Obsidian note from its obsidian:// URL and update the original file. Choose replace, append, or parallel mode for the target language translation.

Instructions

Translate an Obsidian note from obsidian:// URL and update the original file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesObsidian URL in format: obsidian://open?vault=VaultName&file=path/to/note.md
targetLanguageNoTarget language for translation (default: 日本語)日本語
modeNoTranslation mode: replace original, append translation, or create parallel versionreplace

Implementation Reference

  • The main handler/execute method for the translate_obsidian_note tool. It parses the obsidian URL, validates the vault/path, reads the file, creates a backup, calls the translation service, and updates the file based on the mode (replace/append/parallel).
    async execute(request: TranslationRequest): Promise<TranslationResult> {
      try {
        // URLを解析
        const parsedUrl = ObsidianUrlParser.parse(request.url);
        
        // Vaultの検証
        ObsidianUrlParser.validateVault(parsedUrl.vault, this.configuredVault);
        
        // パスの検証
        ObsidianUrlParser.validatePath(parsedUrl.path);
        
        // ファイルの存在確認
        if (!(await this.fileSystem.exists(parsedUrl.path))) {
          throw new Error(`${ErrorCode.FILE_NOT_FOUND}: File '${parsedUrl.path}' not found`);
        }
    
        // 元のファイルを読み込み
        const originalContent = await this.fileSystem.readFile(parsedUrl.path);
        
        // バックアップを作成
        const backupInfo = await this.fileSystem.createBackup(parsedUrl.path);
        
        // 翻訳を実行
        const translatedContent = await this.translationService.translateContent(
          originalContent,
          request.targetLanguage || '日本語'
        );
    
        // 翻訳モードに応じてファイルを更新
        await this.updateFileByMode(
          parsedUrl.path,
          originalContent,
          translatedContent,
          request.mode || 'replace'
        );
    
        // 古いバックアップをクリーンアップ
        await this.fileSystem.cleanupOldBackups(parsedUrl.path.split('/').slice(0, -1).join('/'));
    
        return {
          originalContent,
          translatedContent,
          backupPath: backupInfo.backupPath,
          timestamp: backupInfo.timestamp
        };
      } catch (error) {
        if (error instanceof Error) {
          throw error;
        }
        throw new Error(`${ErrorCode.TRANSLATION_FAILED}: Unknown error occurred`);
      }
    }
    
    /**
     * 翻訳モードに応じてファイルを更新
     * @param filePath ファイルパス
     * @param originalContent 元のコンテンツ
     * @param translatedContent 翻訳されたコンテンツ
     * @param mode 翻訳モード
     */
    private async updateFileByMode(
      filePath: string,
      originalContent: string,
      translatedContent: string,
      mode: 'replace' | 'append' | 'parallel'
    ): Promise<void> {
      switch (mode) {
        case 'replace':
          await this.fileSystem.writeFile(filePath, translatedContent);
          break;
    
        case 'append':
          const appendedContent = originalContent + '\\n\\n---\\n\\n# 翻訳版\\n\\n' + translatedContent;
          await this.fileSystem.writeFile(filePath, appendedContent);
          break;
    
        case 'parallel':
          // 並列表示用の新しいファイルを作成
          const parallelPath = filePath.replace(/\\.md$/, '.ja.md');
          await this.fileSystem.writeFile(parallelPath, translatedContent);
          break;
    
        default:
          throw new Error(`${ErrorCode.TRANSLATION_FAILED}: Invalid mode '${mode}'`);
      }
    }
  • The MCP server's handler function that receives the tool call for 'translate_obsidian_note', extracts url/targetLanguage/mode from args, calls translateTool.execute(), and formats the result as a text response.
    private async handleTranslateNote(args: any) {
      const { url, targetLanguage, mode } = args;
      
      if (!url) {
        throw new McpError(ErrorCode.InvalidParams, 'URL is required');
      }
    
      const result = await this.translateTool.execute({
        url,
        targetLanguage,
        mode
      });
    
      return {
        content: [
          {
            type: 'text',
            text: `✅ 翻訳が完了しました\\n\\n` +
                  `📁 ファイル: ${url}\\n` +
                  `🔄 バックアップ: ${result.backupPath}\\n` +
                  `⏰ 実行時刻: ${result.timestamp}\\n\\n` +
                  `翻訳後のコンテンツ:\\n${result.translatedContent.substring(0, 500)}${result.translatedContent.length > 500 ? '...' : ''}`
          }
        ]
      };
    }
  • The tool definition (schema) for translate_obsidian_note, including name, description, and inputSchema defining 'url' (required), 'targetLanguage' (optional, default 日本語), and 'mode' (optional, enum: replace/append/parallel).
    static getToolDefinition(): Tool {
      return {
        name: 'translate_obsidian_note',
        description: 'Translate an Obsidian note from obsidian:// URL and update the original file',
        inputSchema: {
          type: 'object',
          properties: {
            url: {
              type: 'string',
              description: 'Obsidian URL in format: obsidian://open?vault=VaultName&file=path/to/note.md'
            },
            targetLanguage: {
              type: 'string',
              description: 'Target language for translation (default: 日本語)',
              default: '日本語'
            },
            mode: {
              type: 'string',
              enum: ['replace', 'append', 'parallel'],
              description: 'Translation mode: replace original, append translation, or create parallel version',
              default: 'replace'
            }
          },
          required: ['url']
        }
      };
    }
  • src/index.ts:108-109 (registration)
    Registration of translate_obsidian_note in the switch case of CallToolRequestSchema, dispatching to handleTranslateNote.
    case 'translate_obsidian_note':
      return await this.handleTranslateNote(args);
  • Helper method that updates the file according to the translation mode: 'replace' overwrites, 'append' adds at the end, 'parallel' creates a .ja.md file.
    private async updateFileByMode(
      filePath: string,
      originalContent: string,
      translatedContent: string,
      mode: 'replace' | 'append' | 'parallel'
    ): Promise<void> {
      switch (mode) {
        case 'replace':
          await this.fileSystem.writeFile(filePath, translatedContent);
          break;
    
        case 'append':
          const appendedContent = originalContent + '\\n\\n---\\n\\n# 翻訳版\\n\\n' + translatedContent;
          await this.fileSystem.writeFile(filePath, appendedContent);
          break;
    
        case 'parallel':
          // 並列表示用の新しいファイルを作成
          const parallelPath = filePath.replace(/\\.md$/, '.ja.md');
          await this.fileSystem.writeFile(parallelPath, translatedContent);
          break;
    
        default:
          throw new Error(`${ErrorCode.TRANSLATION_FAILED}: Invalid mode '${mode}'`);
      }
    }
Behavior2/5

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

The description says 'update the original file,' but the schema includes modes 'append' and 'parallel' that do not solely update the original. This omission may mislead agents about the actual behavior. No disclosure of side effects, failure modes, or limitations.

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

Conciseness4/5

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

The description is a single sentence with no redundant information. It is concise, but could be slightly more informative without becoming verbose.

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?

Given three parameters (including an enum) and no output schema, the description fails to explain the effects of different modes, translation behavior (e.g., handling of formatting/links), or what success looks like. The agent may not properly invoke the tool with correct mode expectations.

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% with parameter descriptions, so baseline is 3. The description adds no extra meaning to the parameters (e.g., does not explain the URL format beyond the schema or elaborate on mode differences).

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 tool translates an Obsidian note from an obsidian:// URL and updates the original file. The verb 'translate' and resource 'Obsidian note' are specific, distinguishing it from sibling tools like create, read, search, or update.

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?

No guidance is provided on when to use this tool versus alternatives (e.g., update_obsidian_note). There is no mention of when to avoid it or prerequisites like ensuring the note exists.

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