Skip to main content
Glama

manage_sitemap

Generate, validate, and manage sitemap.xml files for documentation sites to improve SEO, enable search engine submission, and track deployment changes.

Instructions

Generate, validate, and manage sitemap.xml as the source of truth for documentation links. Sitemap.xml is used for SEO, search engine submission, and deployment tracking.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesAction to perform: generate (create new), validate (check structure), update (sync with docs), list (show all URLs)
docsPathYesPath to documentation root directory
baseUrlNoBase URL for the site (e.g., https://user.github.io/repo). Required for generate/update actions.
includePatternsNoFile patterns to include (default: **/*.md, **/*.html, **/*.mdx)
excludePatternsNoFile patterns to exclude (default: node_modules, .git, dist, build, .documcp)
updateFrequencyNoDefault change frequency for pages
useGitHistoryNoUse git history for last modified dates (default: true)
sitemapPathNoCustom path for sitemap.xml (default: docsPath/sitemap.xml)

Implementation Reference

  • The main handler function for the 'manage_sitemap' tool. It parses input, validates directories, and dispatches to action-specific handlers (generate, validate, update, list) based on the 'action' parameter.
    export async function manageSitemap(
      input: ManageSitemapInput,
    ): Promise<{ content: any[] }> {
      const { action, docsPath, sitemapPath } = input;
    
      // Resolve sitemap path
      const resolvedSitemapPath = sitemapPath || path.join(docsPath, "sitemap.xml");
    
      try {
        // Verify docs directory exists
        try {
          await fs.access(docsPath);
        } catch {
          return formatMCPResponse({
            success: false,
            error: {
              code: "DOCS_DIR_NOT_FOUND",
              message: `Documentation directory not found: ${docsPath}`,
            },
            metadata: {
              toolVersion: "1.0.0",
              executionTime: Date.now(),
              timestamp: new Date().toISOString(),
            },
          });
        }
    
        switch (action) {
          case "generate":
            return await generateSitemapAction(input, resolvedSitemapPath);
    
          case "validate":
            return await validateSitemapAction(resolvedSitemapPath);
    
          case "update":
            return await updateSitemapAction(input, resolvedSitemapPath);
    
          case "list":
            return await listSitemapAction(resolvedSitemapPath);
    
          default:
            return formatMCPResponse({
              success: false,
              error: {
                code: "UNKNOWN_ACTION",
                message: `Unknown action: ${action}`,
              },
              metadata: {
                toolVersion: "1.0.0",
                executionTime: Date.now(),
                timestamp: new Date().toISOString(),
              },
            });
        }
      } catch (error) {
        return formatMCPResponse({
          success: false,
          error: {
            code: "SITEMAP_ERROR",
            message: `Error managing sitemap: ${
              error instanceof Error ? error.message : String(error)
            }`,
          },
          metadata: {
            toolVersion: "1.0.0",
            executionTime: Date.now(),
            timestamp: new Date().toISOString(),
          },
        });
      }
    }
  • Zod schema defining the input parameters for the manage_sitemap tool, including action types and optional configurations.
    export const ManageSitemapInputSchema = z.object({
      action: z
        .enum(["generate", "validate", "update", "list"])
        .describe(
          "Action to perform: generate (create new), validate (check structure), update (sync with docs), list (show all URLs)",
        ),
      docsPath: z.string().describe("Path to documentation root directory"),
      baseUrl: z
        .string()
        .optional()
        .describe(
          "Base URL for the site (e.g., https://user.github.io/repo). Required for generate/update actions.",
        ),
      includePatterns: z
        .array(z.string())
        .optional()
        .describe(
          "File patterns to include (default: **/*.md, **/*.html, **/*.mdx)",
        ),
      excludePatterns: z
        .array(z.string())
        .optional()
        .describe(
          "File patterns to exclude (default: node_modules, .git, dist, build, .documcp)",
        ),
      updateFrequency: z
        .enum(["always", "hourly", "daily", "weekly", "monthly", "yearly", "never"])
        .optional()
        .describe("Default change frequency for pages"),
      useGitHistory: z
        .boolean()
        .optional()
        .default(true)
        .describe("Use git history for last modified dates (default: true)"),
      sitemapPath: z
        .string()
        .optional()
        .describe("Custom path for sitemap.xml (default: docsPath/sitemap.xml)"),
    });
  • Helper function that handles the 'generate' action: validates baseUrl, generates sitemap XML using generateSitemap utility, writes to file, and formats output.
    async function generateSitemapAction(
      input: ManageSitemapInput,
      sitemapPath: string,
    ): Promise<{ content: any[] }> {
      const {
        docsPath,
        baseUrl,
        includePatterns,
        excludePatterns,
        updateFrequency,
      } = input;
    
      if (!baseUrl) {
        return formatMCPResponse({
          success: false,
          error: {
            code: "BASE_URL_REQUIRED",
            message: "baseUrl is required for generate action",
          },
          metadata: {
            toolVersion: "1.0.0",
            executionTime: 0,
            timestamp: new Date().toISOString(),
          },
        });
      }
    
      // Generate sitemap
      const { xml, urls, stats } = await generateSitemap({
        baseUrl,
        docsPath,
        includePatterns,
        excludePatterns,
        useGitHistory: input.useGitHistory,
        defaultChangeFreq: updateFrequency || "monthly",
      });
    
      // Write sitemap.xml
      await fs.writeFile(sitemapPath, xml, "utf-8");
    
      // Format output
      const output = formatGenerateOutput(sitemapPath, urls, stats);
    
      return formatMCPResponse({
        success: true,
        data: {
          action: "generate",
          sitemapPath,
          totalUrls: stats.totalUrls,
          categories: stats.byCategory,
          output,
        },
        metadata: {
          toolVersion: "1.0.0",
          executionTime: Date.now(),
          timestamp: new Date().toISOString(),
        },
      });
    }
  • Entry point handler dispatching to action-specific helpers.
    /**
     * Manage sitemap.xml for documentation
     */
    export async function manageSitemap(
      input: ManageSitemapInput,
    ): Promise<{ content: any[] }> {
      const { action, docsPath, sitemapPath } = input;
    
      // Resolve sitemap path
      const resolvedSitemapPath = sitemapPath || path.join(docsPath, "sitemap.xml");
    
      try {
        // Verify docs directory exists
        try {
          await fs.access(docsPath);
        } catch {
          return formatMCPResponse({
            success: false,
            error: {
              code: "DOCS_DIR_NOT_FOUND",
              message: `Documentation directory not found: ${docsPath}`,
            },
            metadata: {
              toolVersion: "1.0.0",
              executionTime: Date.now(),
              timestamp: new Date().toISOString(),
            },
          });
        }
    
        switch (action) {
          case "generate":
            return await generateSitemapAction(input, resolvedSitemapPath);
    
          case "validate":
            return await validateSitemapAction(resolvedSitemapPath);
    
          case "update":
            return await updateSitemapAction(input, resolvedSitemapPath);
    
          case "list":
            return await listSitemapAction(resolvedSitemapPath);
    
          default:
            return formatMCPResponse({
              success: false,
              error: {
                code: "UNKNOWN_ACTION",
                message: `Unknown action: ${action}`,
              },
              metadata: {
                toolVersion: "1.0.0",
                executionTime: Date.now(),
                timestamp: new Date().toISOString(),
              },
            });
        }
      } catch (error) {
        return formatMCPResponse({
          success: false,
          error: {
            code: "SITEMAP_ERROR",
            message: `Error managing sitemap: ${
              error instanceof Error ? error.message : String(error)
            }`,
          },
          metadata: {
            toolVersion: "1.0.0",
            executionTime: Date.now(),
            timestamp: new Date().toISOString(),
          },
        });
      }
    }
  • Helper for 'validate' action: checks sitemap existence, validates using validateSitemap utility, formats output.
    async function validateSitemapAction(
      sitemapPath: string,
    ): Promise<{ content: any[] }> {
      // Check if sitemap exists
      try {
        await fs.access(sitemapPath);
      } catch {
        return formatMCPResponse({
          success: false,
          error: {
            code: "SITEMAP_NOT_FOUND",
            message: `Sitemap not found: ${sitemapPath}. Use action: "generate" to create a new sitemap.`,
          },
          metadata: {
            toolVersion: "1.0.0",
            executionTime: 0,
            timestamp: new Date().toISOString(),
          },
        });
      }
    
      // Validate sitemap
      const validation = await validateSitemap(sitemapPath);
    
      // Format output
      const output = formatValidationOutput(sitemapPath, validation);
    
      return formatMCPResponse({
        success: validation.valid,
        data: {
          action: "validate",
          valid: validation.valid,
          errorCount: validation.errors.length,
          warningCount: validation.warnings.length,
          urlCount: validation.urlCount,
          output,
        },
        error: validation.valid
          ? undefined
          : {
              code: "VALIDATION_FAILED",
              message: `Sitemap validation failed with ${validation.errors.length} error(s)`,
            },
        metadata: {
          toolVersion: "1.0.0",
          executionTime: Date.now(),
          timestamp: new Date().toISOString(),
        },
      });
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While it mentions the tool's purpose and high-level use cases, it doesn't describe what 'manage' entails operationally, whether actions like 'generate' or 'update' modify files, what permissions are needed, error handling, or output format. For a tool with 8 parameters and multiple actions, this leaves significant behavioral gaps.

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 efficiently structured in two sentences: the first states the core functionality, the second explains the purpose. There's no wasted verbiage, though it could be slightly more front-loaded by integrating the use cases into the first sentence.

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?

For a tool with 8 parameters, multiple actions, and no output schema or annotations, the description is insufficient. It doesn't explain what happens after actions (e.g., what 'list' returns, what validation checks occur), doesn't mention file system impacts, and provides no guidance on parameter interactions. The complexity demands more comprehensive description given the lack of structured metadata.

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

Parameters3/5

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

Schema description coverage is 100%, providing detailed documentation for all 8 parameters. The description adds no parameter-specific information beyond what's already in the schema. According to scoring rules, when schema coverage is high (>80%), the baseline is 3 even with no param info in the description.

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

Purpose5/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 specific verbs ('generate, validate, and manage') and resource ('sitemap.xml'), plus its role as 'source of truth for documentation links'. It distinguishes from sibling tools like 'check_documentation_links' or 'validate_content' by focusing on sitemap-specific operations rather than general link checking or content validation.

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 mentions SEO, search engine submission, and deployment tracking as use cases, but provides no explicit guidance on when to use this tool versus alternatives like 'sync_code_to_docs' or 'track_documentation_freshness'. There's no mention of prerequisites, dependencies, or scenarios where other tools might be more 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/tosin2013/documcp'

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