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'],
      },
    },
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'batch rename' but lacks details on permissions needed, whether changes are reversible, potential side effects (e.g., affecting multiple notes), or error handling. This is a significant gap for a mutation tool.

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 in Japanese that directly states the tool's purpose without any wasted words. It is appropriately sized and front-loaded with the core action.

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 this is a mutation tool with no annotations and no output schema, the description is incomplete. It should explain more about behavioral traits (e.g., what 'batch' entails, success/failure responses) to compensate for the lack of structured data, but it does not.

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 100%, so the schema already documents both parameters ('oldTag' and 'newTag') with details on format ('with or without #'). The description adds no additional meaning beyond what the schema provides, meeting the baseline for high coverage.

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 ('renames') and resource ('tags in Obsidian vault') with a specific scope ('batch'). However, it doesn't explicitly differentiate from sibling tools like 'update_note' or 'link_notes' that might also modify tags indirectly, leaving some ambiguity about uniqueness.

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. For example, it doesn't specify if this should be used instead of manually editing notes or other tools like 'update_note' for tag changes, nor does it mention prerequisites or exclusions.

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

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