Skip to main content
Glama

validate_documentation_metadata

Validate that documentation files contain required metadata fields to ensure completeness and consistency across documents.

Instructions

Ensure all documents have required metadata fields.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathNo
basePathNo
requiredFieldsNo

Implementation Reference

  • The core handler function that implements the tool logic: scans all .md files in the basePath (default docs dir), parses frontmatter using parseFrontmatter helper, checks for required metadata fields (default: title, description, status), collects missing ones, computes completeness percentage, and returns a ToolResponse with results.
    /**
     * Validate metadata in documentation
     */
    async validateMetadata(
      basePath = "",
      requiredFields?: string[]
    ): Promise<ToolResponse> {
      try {
        const validBasePath = await this.validatePath(basePath || this.docsDir);
    
        // Default required fields if not specified
        const fields = requiredFields || ["title", "description", "status"];
    
        // Find all markdown files
        const files = await glob("**/*.md", { cwd: validBasePath });
    
        const missingMetadata: Array<{
          file: string;
          missingFields: string[];
        }> = [];
    
        // Check each file for metadata
        for (const file of files) {
          const filePath = path.join(validBasePath, file);
          const content = await fs.readFile(filePath, "utf-8");
    
          // Parse frontmatter
          const { frontmatter } = parseFrontmatter(content);
    
          // Check for required fields
          const missing = fields.filter((field) => !frontmatter[field]);
    
          if (missing.length > 0) {
            missingMetadata.push({
              file: path.relative(this.docsDir, filePath),
              missingFields: missing,
            });
          }
        }
    
        // Calculate completeness percentage
        const totalFields = files.length * fields.length;
        const missingFields = missingMetadata.reduce(
          (sum, item) => sum + item.missingFields.length,
          0
        );
        const completenessPercentage =
          totalFields > 0
            ? Math.round(((totalFields - missingFields) / totalFields) * 100)
            : 100;
    
        return {
          content: [
            {
              type: "text",
              text:
                missingMetadata.length > 0
                  ? `Found ${missingMetadata.length} files with missing metadata. Completeness: ${completenessPercentage}%`
                  : `All ${files.length} files have complete metadata. Completeness: 100%`,
            },
          ],
          metadata: {
            missingMetadata,
            filesChecked: files.length,
            requiredFields: fields,
            completenessPercentage,
            basePath: path.relative(this.docsDir, validBasePath),
          },
        };
      } catch (error) {
        const errorMessage =
          error instanceof Error ? error.message : String(error);
        return {
          content: [
            { type: "text", text: `Error validating metadata: ${errorMessage}` },
          ],
          isError: true,
        };
      }
    }
  • Zod schema defining the input parameters for the tool: optional basePath (defaults to root) and optional array of requiredFields.
    export const ValidateMetadataSchema = ToolInputSchema.extend({
      basePath: z.string().optional().default(""),
      requiredFields: z.array(z.string()).optional(),
    });
  • src/index.ts:290-294 (registration)
    Tool registration in the MCP server's listTools handler, specifying name, description, and input schema.
    {
      name: "validate_documentation_metadata",
      description: "Ensure all documents have required metadata fields.",
      inputSchema: zodToJsonSchema(ValidateMetadataSchema) as any,
    },
  • Dispatch handler in the main CallToolRequestSchema switch statement that validates input and calls the DocumentHandler's validateMetadata method.
    case "validate_documentation_metadata": {
      const parsed = ValidateMetadataSchema.safeParse(args);
      if (!parsed.success) {
        throw new Error(
          `Invalid arguments for validate_metadata: ${parsed.error}`
        );
      }
      return await documentHandler.validateMetadata(
        parsed.data.basePath,
        parsed.data.requiredFields
      );
    }
  • Helper function used by validateMetadata to parse YAML frontmatter from markdown files and extract metadata fields.
    export function parseFrontmatter(content: string): {
      frontmatter: Record<string, any>;
      content: string;
    } {
      const frontmatterRegex = /^---\s*\n([\s\S]*?)\n---\s*\n/;
      const match = content.match(frontmatterRegex);
    
      if (!match) {
        return { frontmatter: {}, content };
      }
    
      const frontmatterStr = match[1];
      const contentWithoutFrontmatter = content.slice(match[0].length);
    
      // Parse frontmatter as key-value pairs
      const frontmatter: Record<string, any> = {};
      const lines = frontmatterStr.split("\n");
    
      for (const line of lines) {
        const colonIndex = line.indexOf(":");
        if (colonIndex !== -1) {
          const key = line.slice(0, colonIndex).trim();
          let value = line.slice(colonIndex + 1).trim();
    
          // Handle quoted values
          if (value.startsWith('"') && value.endsWith('"')) {
            value = value.slice(1, -1);
          }
    
          // Handle arrays
          if (value.startsWith("[") && value.endsWith("]")) {
            try {
              value = JSON.parse(value);
            } catch {
              // Keep as string if parsing fails
            }
          }
    
          frontmatter[key] = value;
        }
      }
    
      return { frontmatter, content: contentWithoutFrontmatter };
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It implies a read-only validation operation ('ensure'), but doesn't disclose behavioral traits such as whether it modifies documents, requires specific permissions, handles errors, or returns detailed reports. For a tool with 3 parameters and no annotations, this is a significant gap in transparency.

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 no wasted words. It's front-loaded with the core action ('ensure'), making it easy to parse quickly. Every word contributes to the basic intent without redundancy or fluff, achieving optimal conciseness.

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 (3 parameters, 0% schema coverage, no annotations, no output schema), the description is incomplete. It doesn't explain what happens during validation, what output to expect, or how errors are handled. For a tool that likely returns validation results, the lack of behavioral and output context leaves significant gaps for an AI agent.

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?

Schema description coverage is 0%, so the description must compensate. It mentions 'required metadata fields', which loosely relates to the 'requiredFields' parameter, but doesn't explain 'path' or 'basePath' or how they interact. With 3 undocumented parameters, the description adds minimal value beyond hinting at one parameter's purpose, failing to adequately clarify semantics.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Ensure all documents have required metadata fields' states a clear verb ('ensure') and target ('documents'), but it's vague about scope and mechanism. It doesn't specify whether this validates a single document, a folder, or the entire documentation set, nor how it differs from sibling tools like 'validate_documentation_links' or 'check_documentation_health'. The purpose is understandable but lacks specificity for differentiation.

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. With siblings like 'check_documentation_health' and 'validate_documentation_links', the description doesn't indicate whether this is for pre-upload validation, batch checks, or specific contexts. There's no mention of prerequisites, exclusions, or recommended workflows, leaving usage ambiguous.

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