sitemaps_delete
Remove a sitemap from Google Search Console by specifying the site URL and sitemap URL. Use this to clean up outdated or incorrect sitemaps.
Instructions
Delete a sitemap from Google Search Console.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| siteUrl | Yes | The site URL | |
| feedpath | Yes | The URL of the sitemap to delete |
Implementation Reference
- src/index.ts:329-358 (handler)The main handler for the 'sitemaps_delete' tool. It registers a server tool that accepts siteUrl and feedpath, calls the Google Webmasters API DELETE endpoint, and returns a success or error response.
// ── sitemaps_delete ── server.tool( "sitemaps_delete", "Delete a sitemap from Google Search Console.", { siteUrl: z.string().describe("The site URL"), feedpath: z.string().describe("The URL of the sitemap to delete"), }, async ({ siteUrl, feedpath }) => { try { const result = await apiCall( `${WEBMASTERS_BASE}/sites/${encodeSiteUrl(siteUrl)}/sitemaps/${encodeURIComponent(feedpath)}`, { method: "DELETE" }, ); return { content: [ { type: "text" as const, text: result.ok ? `Sitemap "${feedpath}" deleted successfully.` : result.body, }, ], isError: !result.ok, }; } catch (e) { return errorResult(e); } }, ); - src/index.ts:333-336 (schema)Input schema for sitemaps_delete: siteUrl (string) and feedpath (string), both required.
{ siteUrl: z.string().describe("The site URL"), feedpath: z.string().describe("The URL of the sitemap to delete"), }, - src/index.ts:329-358 (registration)Tool registration via server.tool() with name 'sitemaps_delete' and description 'Delete a sitemap from Google Search Console.'
// ── sitemaps_delete ── server.tool( "sitemaps_delete", "Delete a sitemap from Google Search Console.", { siteUrl: z.string().describe("The site URL"), feedpath: z.string().describe("The URL of the sitemap to delete"), }, async ({ siteUrl, feedpath }) => { try { const result = await apiCall( `${WEBMASTERS_BASE}/sites/${encodeSiteUrl(siteUrl)}/sitemaps/${encodeURIComponent(feedpath)}`, { method: "DELETE" }, ); return { content: [ { type: "text" as const, text: result.ok ? `Sitemap "${feedpath}" deleted successfully.` : result.body, }, ], isError: !result.ok, }; } catch (e) { return errorResult(e); } }, ); - src/index.ts:90-92 (helper)encodeSiteUrl helper function used to encode the site URL in the API request path.
function encodeSiteUrl(siteUrl: string): string { return encodeURIComponent(siteUrl); } - src/index.ts:94-107 (helper)apiCall helper function that performs the HTTP fetch with OAuth bearer token, used to call the Google API.
async function apiCall( url: string, options: RequestInit = {}, ): Promise<{ ok: boolean; status: number; body: string }> { const token = await getAccessToken(); const headers: Record<string, string> = { Authorization: `Bearer ${token}`, ...((options.headers as Record<string, string>) || {}), }; const res = await fetch(url, { ...options, headers }); const body = await res.text(); return { ok: res.ok, status: res.status, body }; }