Skip to main content
Glama

generate_documentation_navigation

Creates navigation menus from markdown documentation by analyzing document structure and generating JSON for easy implementation.

Instructions

Generate a navigation structure from the markdown documents in the docs directory. Returns a JSON structure that can be used for navigation menus.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathNo
basePathNo
recursiveNo

Implementation Reference

  • The generateNavigation method in the NavigationHandler class executes the core logic of the 'generate_documentation_navigation' tool. It glob-searches for .md files, parses frontmatter for titles and orders, constructs a hierarchical navigation structure with directories, sorts by order, and returns JSON.
    async generateNavigation(basePath = ""): Promise<ToolResponse> {
      try {
        const baseDir = path.join(this.docsDir, basePath);
        const pattern = path.join(baseDir, "**/*.md");
    
        const files = await glob(pattern);
    
        // Sort files to ensure consistent order and process index.md files first
        files.sort((a, b) => {
          const aIsIndex = path.basename(a) === "index.md";
          const bIsIndex = path.basename(b) === "index.md";
    
          if (aIsIndex && !bIsIndex) return -1;
          if (!aIsIndex && bIsIndex) return 1;
    
          return a.localeCompare(b);
        });
    
        const navigation: any[] = [];
        const directoryMap: Record<string, any> = {};
    
        for (const file of files) {
          const relativePath = path.relative(this.docsDir, file);
          const content = await fs.readFile(file, "utf-8");
          const { frontmatter } = parseFrontmatter(content);
    
          const title = frontmatter.title || path.basename(file, ".md");
          const order =
            frontmatter.order !== undefined ? Number(frontmatter.order) : 999;
    
          const item = {
            title,
            path: relativePath,
            order,
            children: [],
          };
    
          const dirPath = path.dirname(relativePath);
    
          if (dirPath === "." || dirPath === basePath) {
            navigation.push(item);
          } else {
            // Create parent directories if they don't exist in the navigation
            const pathParts = dirPath.split(path.sep);
            let currentPath = "";
            let currentNavigation = navigation;
    
            for (const part of pathParts) {
              currentPath = currentPath ? path.join(currentPath, part) : part;
    
              if (!directoryMap[currentPath]) {
                const dirItem = {
                  title: part,
                  path: currentPath,
                  order: 0,
                  children: [],
                };
    
                directoryMap[currentPath] = dirItem;
                currentNavigation.push(dirItem);
              }
    
              currentNavigation = directoryMap[currentPath].children;
            }
    
            currentNavigation.push(item);
          }
        }
    
        // Sort navigation items by order
        function sortNavigation(items: any[]) {
          items.sort((a, b) => a.order - b.order);
    
          for (const item of items) {
            if (item.children && item.children.length > 0) {
              sortNavigation(item.children);
            }
          }
        }
    
        sortNavigation(navigation);
    
        return {
          content: [{ type: "text", text: JSON.stringify(navigation, null, 2) }],
        };
      } catch (error) {
        const errorMessage =
          error instanceof Error ? error.message : String(error);
        return {
          content: [
            {
              type: "text",
              text: `Error generating navigation: ${errorMessage}`,
            },
          ],
          isError: true,
        };
      }
    }
  • src/index.ts:236-241 (registration)
    Registration of the tool in the ListToolsRequestHandler, specifying name, description, and input schema (ListDocumentsSchema).
      name: "generate_documentation_navigation",
      description:
        "Generate a navigation structure from the markdown documents in the docs directory. " +
        "Returns a JSON structure that can be used for navigation menus.",
      inputSchema: zodToJsonSchema(ListDocumentsSchema) as any,
    },
  • Zod schema defining the input parameters for the tool: optional basePath (string) and recursive (boolean, default false). Extends ToolInputSchema.
    export const ListDocumentsSchema = ToolInputSchema.extend({
      basePath: z.string().optional(),
      recursive: z.boolean().default(false),
    });
  • src/index.ts:375-385 (registration)
    Dispatch handler in CallToolRequestHandler that validates input with ListDocumentsSchema and delegates to navigationHandler.generateNavigation(basePath).
    case "generate_documentation_navigation": {
      const parsed = ListDocumentsSchema.safeParse(args);
      if (!parsed.success) {
        throw new Error(
          `Invalid arguments for generate_navigation: ${parsed.error}`
        );
      }
      return await navigationHandler.generateNavigation(
        parsed.data.basePath
      );
    }
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. It mentions the output format ('JSON structure that can be used for navigation menus'), which adds some context, but fails to cover critical aspects like whether this is a read-only operation, if it modifies files, error handling, or performance considerations. For a tool with 3 parameters and no annotations, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and front-loaded, consisting of two clear sentences that directly state the tool's function and output. There's no wasted text, making it easy to parse. However, it could be slightly more structured by explicitly separating purpose from output details.

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, no annotations, no output schema), the description is incomplete. It explains the output format but misses critical details like parameter meanings, behavioral traits (e.g., read-only vs. write operations), and usage context. For a tool that generates navigation from documents, this leaves significant gaps in understanding how to invoke it correctly.

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?

With 0% schema description coverage, the description must compensate for the lack of parameter documentation. It doesn't explain any of the 3 parameters ('path', 'basePath', 'recursive'), such as what 'path' refers to, how 'basePath' affects the output, or when to use 'recursive'. This leaves the agent guessing about input semantics, failing to add meaningful value beyond the bare schema.

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: 'Generate a navigation structure from the markdown documents in the docs directory.' It specifies the verb ('generate'), resource ('navigation structure'), and source ('markdown documents in the docs directory'). However, it doesn't explicitly differentiate from sibling tools like 'update_navigation_order' or 'list_documents', which keeps it from a perfect score.

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, such as when to use 'list_documents' for a simple list or 'update_navigation_order' for modifying existing navigation. This lack of comparative guidance limits its utility for an AI agent.

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