Skip to main content
Glama
libra850
by libra850

rename_tag

Rename tags across your Obsidian vault to maintain consistency and update terminology in your notes.

Instructions

Obsidianボルト内のタグを一括でリネームします

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
oldTagYes変更前のタグ名(#付きまたは#なし)
newTagYes変更後のタグ名(#付きまたは#なし)

Implementation Reference

  • The `renameTag` method scans all Markdown files in the Obsidian vault, replaces the old tag with the new tag in inline positions and YAML frontmatter 'tags' arrays (handling quotes), normalizes tags by prepending '#' if absent, counts and reports updated files.
    async renameTag(oldTag: string, newTag: string): Promise<string> { const vaultPath = this.config.vaultPath; let updatedFilesCount = 0; // #を自動的に追加 const oldTagNormalized = oldTag.startsWith('#') ? oldTag : `#${oldTag}`; const newTagNormalized = newTag.startsWith('#') ? newTag : `#${newTag}`; const processFile = async (filePath: string) => { try { const content = await fs.readFile(filePath, 'utf-8'); let updatedContent = content; let hasChanges = false; // インラインタグを置換 const tagPattern = new RegExp(`\\${oldTagNormalized}(?=\\s|$)`, 'g'); if (tagPattern.test(content)) { updatedContent = updatedContent.replace(tagPattern, newTagNormalized); hasChanges = true; } // YAML frontmatterのtagsフィールドを置換 const yamlMatch = content.match(/^---\s*\n([\s\S]*?)\n---/); if (yamlMatch) { const yamlContent = yamlMatch[1]; const tagsMatch = yamlContent.match(/tags:\s*\[(.*?)\]/); if (tagsMatch) { const tagsList = tagsMatch[1]; const oldTagInYaml = oldTagNormalized.substring(1); // #を除去 const newTagInYaml = newTagNormalized.substring(1); // #を除去 if (tagsList.includes(oldTagInYaml)) { const updatedTagsList = tagsList.replace( new RegExp(`(['"]?)${oldTagInYaml.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\1`, 'g'), `$1${newTagInYaml}$1` ); updatedContent = updatedContent.replace(tagsMatch[0], `tags: [${updatedTagsList}]`); hasChanges = true; } } } if (hasChanges) { await fs.writeFile(filePath, updatedContent, 'utf-8'); updatedFilesCount++; } } catch (error) { // ファイル読み込みエラーは無視 } }; const processDirectory = async (dirPath: string) => { try { const entries = await fs.readdir(dirPath, { withFileTypes: true }); for (const entry of entries) { const fullPath = path.join(dirPath, entry.name); if (entry.isDirectory()) { await processDirectory(fullPath); } else if (entry.isFile() && entry.name.endsWith('.md')) { await processFile(fullPath); } } } catch (error) { // ディレクトリ読み込みエラーは無視 } }; await processDirectory(vaultPath); return `タグ '${oldTagNormalized}' を '${newTagNormalized}' に変更しました。${updatedFilesCount}個のファイルを更新しました。`; }
  • src/server.ts:128-145 (registration)
    MCP tool registration for 'rename_tag' including name, Japanese description, and input schema defining oldTag and newTag as required strings.
    { name: 'rename_tag', description: 'Obsidianボルト内のタグを一括でリネームします', inputSchema: { type: 'object', properties: { oldTag: { type: 'string', description: '変更前のタグ名(#付きまたは#なし)', }, newTag: { type: 'string', description: '変更後のタグ名(#付きまたは#なし)', }, }, required: ['oldTag', 'newTag'], }, },
  • src/server.ts:307-314 (registration)
    Dispatcher in the CallToolRequest handler that routes 'rename_tag' calls to ObsidianHandler.renameTag with parsed arguments and returns the result as text content.
    case 'rename_tag': const renameResult = await this.obsidianHandler.renameTag( args.oldTag as string, args.newTag as string ); return { content: [{ type: 'text', text: renameResult }], };
  • Input schema for the 'rename_tag' tool defining parameters oldTag and newTag as strings (with # optional), both required.
    inputSchema: { type: 'object', properties: { oldTag: { type: 'string', description: '変更前のタグ名(#付きまたは#なし)', }, newTag: { type: 'string', description: '変更後のタグ名(#付きまたは#なし)', }, }, required: ['oldTag', 'newTag'], }, },

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

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