update_navigation_order
Modify the navigation order of a document by updating its frontmatter with a specified path and order value. Enhances document organization within the MCP Documentation Service.
Instructions
Update the navigation order of a document by modifying its frontmatter.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| order | Yes | ||
| path | Yes |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"order": {
"type": "number"
},
"path": {
"type": "string"
}
},
"required": [
"path",
"order"
],
"type": "object"
}
Implementation Reference
- src/handlers/documents.ts:611-677 (handler)The DocumentHandler.updateNavigationOrder method implements the core logic: validates path, reads file, parses frontmatter, updates 'order' field, reconstructs and writes back the file with 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, }; }
- src/schemas/tools.ts:81-84 (schema)Zod schema defining input parameters: path (string) and order (number). Extends base ToolInputSchema.export const UpdateNavigationOrderSchema = ToolInputSchema.extend({ path: z.string(), order: z.number(), });
- src/index.ts:272-277 (registration)Tool registration in the listTools handler: defines name, description, and converts schema to JSON schema for MCP.{ 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)Switch case in callToolRequest handler: validates args with schema, calls documentHandler.updateNavigationOrder if valid.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 ); }