Skip to main content
Glama

update_navigation_order

Modify document navigation order by updating frontmatter to organize content structure in documentation systems.

Instructions

Update the navigation order of a document by modifying its frontmatter.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
orderYes

Implementation Reference

  • The DocumentHandler method that implements the tool logic: validates path, reads document, parses and updates frontmatter 'order' field, reconstructs and writes the file, returns success/error response.
    async updateNavigationOrder(
      docPath: string,
      order: number
    ): Promise<ToolResponse> {
      try {
        const validPath = await this.validatePath(docPath);
    
        // Check if file exists
        try {
          await fs.access(validPath);
        } catch {
          throw new Error(`File does not exist: ${docPath}`);
        }
    
        // Read the file
        const content = await fs.readFile(validPath, "utf-8");
    
        // Parse frontmatter
        const { frontmatter, content: docContent } = parseFrontmatter(content);
    
        // Update order in frontmatter
        frontmatter.order = order;
    
        // Reconstruct content with updated frontmatter
        let frontmatterStr = "---\n";
        for (const [key, value] of Object.entries(frontmatter)) {
          if (Array.isArray(value)) {
            frontmatterStr += `${key}:\n`;
            for (const item of value) {
              frontmatterStr += `  - ${item}\n`;
            }
          } else {
            frontmatterStr += `${key}: ${value}\n`;
          }
        }
        frontmatterStr += "---\n\n";
    
        const updatedContent = frontmatterStr + docContent;
    
        // Write updated content
        await fs.writeFile(validPath, updatedContent, "utf-8");
    
        return {
          content: [
            {
              type: "text",
              text: `Successfully updated navigation order for ${docPath} to ${order}`,
            },
          ],
          metadata: {
            path: docPath,
            order,
          },
        };
      } catch (error) {
        const errorMessage =
          error instanceof Error ? error.message : String(error);
        return {
          content: [
            {
              type: "text",
              text: `Error updating navigation order: ${errorMessage}`,
            },
          ],
          isError: true,
        };
      }
  • Zod schema for tool input validation: requires 'path' (string) and 'order' (number).
    export const UpdateNavigationOrderSchema = ToolInputSchema.extend({
      path: z.string(),
      order: z.number(),
    });
  • src/index.ts:273-277 (registration)
    Tool metadata registration in the MCP listTools response, defining name, description, and input schema.
      name: "update_documentation_navigation_order",
      description:
        "Update the navigation order of a document by modifying its frontmatter.",
      inputSchema: zodToJsonSchema(UpdateNavigationOrderSchema) as any,
    },
  • src/index.ts:442-453 (registration)
    Dispatch registration in the MCP callTool handler: parses arguments using schema and calls the documentHandler method.
    case "update_documentation_navigation_order": {
      const parsed = UpdateNavigationOrderSchema.safeParse(args);
      if (!parsed.success) {
        throw new Error(
          `Invalid arguments for update_navigation_order: ${parsed.error}`
        );
      }
      return await documentHandler.updateNavigationOrder(
        parsed.data.path,
        parsed.data.order
      );
    }

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