sitemap
Extract all related links from a URL to uncover its structure and find interconnected pages.
Instructions
Get all related links from a URL
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | URL to get sitemap |
Implementation Reference
- src/tools/sitemap.ts:10-42 (handler)The main handler function for the sitemap tool. Validates arguments via isValidSitemapArgs, makes an API request to the SITEMAP endpoint, and returns the links as JSON. On error, returns an error message.
export async function handleSitemap(args: unknown, apiKey?: string) { if (!isValidSitemapArgs(args)) { throw new McpError( ErrorCode.InvalidParams, "Invalid sitemap arguments" ); } try { const response = await makeRequest<SitemapResponse>( API_CONFIG.ENDPOINTS.SITEMAP, args, apiKey ); return { content: [{ type: "text", mimeType: "application/json", text: JSON.stringify(response.links, null, 2) }] }; } catch (error) { return { content: [{ type: "text", mimeType: "text/plain", text: `Sitemap API error: ${formatError(error)}` }], isError: true }; } } - src/types.ts:141-143 (schema)SitemapResponse interface defining the API response shape (links: string[]).
export interface SitemapResponse { links: string[]; } - src/types.ts:145-147 (schema)SitemapArgs interface defining input arguments (url: string).
export interface SitemapArgs { url: string; } - src/types.ts:149-160 (schema)Type guard function isValidSitemapArgs that validates the url argument is a non-empty string.
export function isValidSitemapArgs(args: unknown): args is SitemapArgs { if (typeof args !== 'object' || args === null) { return false; } const { url } = args as SitemapArgs; if (typeof url !== 'string' || url.trim().length === 0) { return false; } return true; - src/tools/index.ts:126-139 (registration)Tool definition registration: SITEMAP_TOOL with name 'sitemap', description, and inputSchema requiring a 'url' string. Exported in ALL_TOOLS array at line 185.
export const SITEMAP_TOOL: Tool = { name: "sitemap", description: "Get all related links from a URL", inputSchema: { type: "object", properties: { url: { type: "string", description: "URL to get sitemap" } }, required: ["url"] } };