Skip to main content
Glama
libra850
by libra850

find_broken_links

Detect and fix broken links in Obsidian vaults to maintain note connectivity and improve content organization.

Instructions

壊れたリンクの検出と修復支援を行います

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Primary tool handler that implements the logic to find broken links in Obsidian vault by scanning all MD files for wiki and markdown links, verifying targets, and providing similarity-based suggestions.
    async findBrokenLinks(): Promise<{
      brokenLinks: Array<{
        sourceFile: string;
        linkText: string;
        targetPath: string;
        lineNumber: number;
        suggestions: string[];
      }>;
      totalCount: number;
    }> {
      const vaultPath = this.config.vaultPath;
      const brokenLinks: Array<{
        sourceFile: string;
        linkText: string;
        targetPath: string;
        lineNumber: number;
        suggestions: string[];
      }> = [];
    
      // すべてのMarkdownファイルを取得
      const allMdFiles = await this.getAllMdFiles(vaultPath);
      const allFileBasenames = allMdFiles.map(file => path.basename(file, '.md'));
    
      const processFile = async (filePath: string) => {
        try {
          const content = await fs.readFile(filePath, 'utf-8');
          const lines = content.split('\n');
          const relativeFilePath = path.relative(vaultPath, filePath);
    
          for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
            const line = lines[lineIndex];
            
            // ウィキリンク [[]] の検出
            const wikiLinkMatches = line.matchAll(/\[\[([^\]|]+)(\|[^\]]+)?\]\]/g);
            for (const match of wikiLinkMatches) {
              const targetPath = match[1];
              const linkText = match[2] ? match[2].substring(1) : targetPath;
              
              // ターゲットファイルの存在確認
              const possiblePaths = [
                path.join(vaultPath, `${targetPath}.md`),
                path.join(vaultPath, targetPath),
              ];
    
              let exists = false;
              for (const possiblePath of possiblePaths) {
                if (await FileUtils.fileExists(possiblePath)) {
                  exists = true;
                  break;
                }
              }
    
              if (!exists) {
                // 修復候補を検索
                const suggestions = this.findSimilarFiles(targetPath, allFileBasenames);
                brokenLinks.push({
                  sourceFile: relativeFilePath,
                  linkText,
                  targetPath,
                  lineNumber: lineIndex + 1,
                  suggestions,
                });
              }
            }
    
            // Markdownリンク []() の検出
            const mdLinkMatches = line.matchAll(/\[([^\]]+)\]\(([^)]+)\)/g);
            for (const match of mdLinkMatches) {
              const linkText = match[1];
              const targetPath = match[2];
    
              // 内部リンク(.mdファイル)のみチェック
              if (targetPath.endsWith('.md') || !targetPath.includes('://')) {
                const fullTargetPath = path.resolve(path.dirname(filePath), targetPath);
                
                if (!(await FileUtils.fileExists(fullTargetPath))) {
                  const suggestions = this.findSimilarFiles(path.basename(targetPath, '.md'), allFileBasenames);
                  brokenLinks.push({
                    sourceFile: relativeFilePath,
                    linkText,
                    targetPath,
                    lineNumber: lineIndex + 1,
                    suggestions,
                  });
                }
              }
            }
          }
        } catch (error) {
          // ファイル読み込みエラーは無視
        }
      };
    
      // すべてのMarkdownファイルを処理
      for (const filePath of allMdFiles) {
        await processFile(filePath);
      }
    
      return {
        brokenLinks,
        totalCount: brokenLinks.length,
      };
    }
  • src/server.ts:192-199 (registration)
    MCP tool registration defining the name, description, and input schema for find_broken_links.
    {
      name: 'find_broken_links',
      description: '壊れたリンクの検出と修復支援を行います',
      inputSchema: {
        type: 'object',
        properties: {},
      },
    },
  • Server-side dispatch handler that invokes the ObsidianHandler's findBrokenLinks method and formats the response as MCP content.
    case 'find_broken_links':
      const brokenLinksResult = await this.obsidianHandler.findBrokenLinks();
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(brokenLinksResult, null, 2),
          },
        ],
      };
  • Helper utility to generate file name suggestions for broken links using similarity scoring.
    private findSimilarFiles(targetName: string, allFileBasenames: string[]): string[] {
      const target = targetName.toLowerCase();
      const suggestions: { name: string; score: number }[] = [];
    
      for (const filename of allFileBasenames) {
        const score = this.calculateSimilarity(target, filename.toLowerCase());
        if (score > 0.3) { // 30%以上の類似度
          suggestions.push({ name: filename, score });
        }
      }
    
      return suggestions
        .sort((a, b) => b.score - a.score)
        .slice(0, 5)
        .map(s => s.name);
    }
  • Helper to recursively collect all Markdown files in the vault.
    private async getAllMdFiles(dirPath: string): Promise<string[]> {
      const files: string[] = [];
      
      const processDirectory = async (currentPath: string) => {
        try {
          const entries = await fs.readdir(currentPath, { withFileTypes: true });
          
          for (const entry of entries) {
            const fullPath = path.join(currentPath, entry.name);
            
            if (entry.isDirectory()) {
              await processDirectory(fullPath);
            } else if (entry.isFile() && entry.name.endsWith('.md')) {
              files.push(fullPath);
            }
          }
        } catch (error) {
          // ディレクトリ読み込みエラーは無視
        }
      };
      
      await processDirectory(dirPath);
      return files;
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While it mentions detection and repair support, it lacks details on how the tool behaves: e.g., whether it's read-only or modifies data, what permissions are needed, if it has side effects like creating logs, or how repairs are implemented. This leaves significant gaps for a tool that implies potential mutations.

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 function without any fluff. It's front-loaded with the core purpose and uses minimal words, making it highly concise and well-structured for quick understanding.

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 the complexity implied by 'detection and repair support' and the lack of annotations and output schema, the description is incomplete. It doesn't explain what 'repair support' entails (e.g., automatic fixes, suggestions, or logs), what the output looks like, or any behavioral constraints. This leaves the agent with insufficient context for safe and effective use.

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

Parameters4/5

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

The input schema has 0 parameters with 100% coverage, so no parameter documentation is needed. The description doesn't add parameter details, which is appropriate here. A baseline of 4 is applied as it compensates for the lack of parameters by not introducing unnecessary complexity.

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 tool's purpose: '壊れたリンクの検出と修復支援を行います' translates to 'Detects broken links and provides repair support.' This specifies both detection and repair assistance, though it doesn't explicitly differentiate from sibling tools like 'analyze_backlinks' or 'link_notes' in terms of scope or method.

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. It doesn't mention prerequisites, context, or exclusions, leaving the agent to infer usage based on the purpose alone. For example, it doesn't clarify if this is for proactive maintenance or reactive fixes, or how it differs from 'analyze_backlinks'.

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