Skip to main content
Glama

validate_documentation_links

Check for broken internal links in documentation files to maintain content integrity and improve user navigation.

Instructions

Check for broken internal links in documentation files.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathNo
basePathNo
recursiveNo

Implementation Reference

  • The main handler function that implements the logic for the 'validate_documentation_links' tool. It scans all markdown files in the specified base path (recursively or not), finds internal markdown links, resolves them relative to the file, and checks if the target files exist, collecting broken links.
    async validateLinks(basePath = "", recursive = true): Promise<ToolResponse> {
      try {
        const validBasePath = await this.validatePath(basePath || this.docsDir);
    
        // Find all markdown files
        const pattern = recursive ? "**/*.md" : "*.md";
        const files = await glob(pattern, { cwd: validBasePath });
    
        const brokenLinks: Array<{
          file: string;
          link: string;
          lineNumber: number;
        }> = [];
    
        // Check each file for links
        for (const file of files) {
          const filePath = path.join(validBasePath, file);
          const content = await fs.readFile(filePath, "utf-8");
          const lines = content.split("\n");
    
          // Find markdown links: [text](path)
          const linkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
    
          for (let i = 0; i < lines.length; i++) {
            const line = lines[i];
            let match;
    
            while ((match = linkRegex.exec(line)) !== null) {
              const [, , linkPath] = match;
    
              // Skip external links and anchors
              if (
                linkPath.startsWith("http://") ||
                linkPath.startsWith("https://") ||
                linkPath.startsWith("#") ||
                linkPath.startsWith("mailto:")
              ) {
                continue;
              }
    
              // Resolve the link path relative to the current file
              const fileDir = path.dirname(filePath);
              const resolvedPath = path.resolve(fileDir, linkPath);
    
              // Check if the link target exists
              try {
                await fs.access(resolvedPath);
              } catch {
                brokenLinks.push({
                  file: path.relative(this.docsDir, filePath),
                  link: linkPath,
                  lineNumber: i + 1,
                });
              }
            }
          }
        }
    
        return {
          content: [
            {
              type: "text",
              text:
                brokenLinks.length > 0
                  ? `Found ${brokenLinks.length} broken links in ${files.length} files`
                  : `No broken links found in ${files.length} files`,
            },
          ],
          metadata: {
            brokenLinks,
            filesChecked: files.length,
            basePath: path.relative(this.docsDir, validBasePath),
          },
        };
      } catch (error) {
        const errorMessage =
          error instanceof Error ? error.message : String(error);
        return {
          content: [
            { type: "text", text: `Error validating links: ${errorMessage}` },
          ],
          isError: true,
        };
      }
    }
  • Zod schema defining the input parameters for the 'validate_documentation_links' tool: optional basePath and recursive flag.
    export const ValidateLinksSchema = ToolInputSchema.extend({
      basePath: z.string().optional().default(""),
      recursive: z.boolean().default(true),
    });
  • src/index.ts:284-289 (registration)
    Tool registration in the ListTools response, defining name, description, and input schema for 'validate_documentation_links'.
    {
      name: "validate_documentation_links",
      description:
        "Check for broken internal links in documentation files.",
      inputSchema: zodToJsonSchema(ValidateLinksSchema) as any,
    },
  • src/index.ts:470-481 (registration)
    Dispatch/registration in the CallToolRequest handler switch statement, parsing input with ValidateLinksSchema and calling documentHandler.validateLinks.
    case "validate_documentation_links": {
      const parsed = ValidateLinksSchema.safeParse(args);
      if (!parsed.success) {
        throw new Error(
          `Invalid arguments for validate_links: ${parsed.error}`
        );
      }
      return await documentHandler.validateLinks(
        parsed.data.basePath,
        parsed.data.recursive
      );
    }
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 states the tool checks for broken links but doesn't describe what 'check' entails—e.g., whether it's a read-only operation, if it modifies files, what happens on errors, or the output format. This leaves significant gaps for a tool with 3 parameters and no output schema.

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 with zero waste. It's front-loaded with the core purpose and avoids unnecessary elaboration, making it easy to parse quickly.

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 tool's complexity (3 parameters, no annotations, no output schema), the description is insufficient. It doesn't cover parameter meanings, behavioral traits, or output expectations, leaving the agent with inadequate information to use the tool effectively beyond a basic understanding of its purpose.

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

Parameters2/5

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

The schema description coverage is 0%, so the description must compensate for undocumented parameters. It mentions 'documentation files' but doesn't explain the 3 parameters (path, basePath, recursive) or their roles. This fails to add meaningful context beyond the bare schema, leaving parameters semantically unclear.

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 with a specific verb ('Check') and resource ('broken internal links in documentation files'), making it immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'validate_documentation_metadata' or 'check_documentation_health', which might have overlapping functionality.

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 like 'validate_documentation_metadata' or 'check_documentation_health'. It mentions what the tool does but offers no context about prerequisites, exclusions, or specific scenarios where it's most appropriate.

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/alekspetrov/mcp-docs-service'

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