report-referrer-spam
Identify and report spam referrer domains to clean up traffic analytics and enhance website security on WordPress sites. Submit domain details securely via REST API.
Instructions
Report a referrer as spam
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| domain | Yes | Domain to report as spam | |
| password | Yes | WordPress application password | |
| siteId | Yes | WordPress site ID | |
| siteUrl | Yes | WordPress site URL | |
| username | Yes | WordPress username |
Implementation Reference
- src/index.ts:1517-1557 (registration)Registration of the 'report-referrer-spam' MCP tool, including description, input schema using Zod, and inline handler function.server.tool( "report-referrer-spam", "Report a referrer as spam", { siteUrl: z.string().url().describe("WordPress site URL"), username: z.string().describe("WordPress username"), password: z.string().describe("WordPress application password"), siteId: z.number().describe("WordPress site ID"), domain: z.string().describe("Domain to report as spam"), }, async ({ siteUrl, username, password, siteId, domain }) => { try { const response = await makeWPRequest<any>({ siteUrl, endpoint: `sites/${siteId}/stats/referrers/spam/new`, method: "POST", auth: { username, password }, data: { domain } }); return { content: [ { type: "text", text: `Successfully reported domain "${domain}" as spam.`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error reporting referrer as spam: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } );
- src/index.ts:1527-1555 (handler)The handler function executes a POST request to the WordPress stats API endpoint `/sites/{siteId}/stats/referrers/spam/new` with the domain, using the shared makeWPRequest helper, and returns success or error message.async ({ siteUrl, username, password, siteId, domain }) => { try { const response = await makeWPRequest<any>({ siteUrl, endpoint: `sites/${siteId}/stats/referrers/spam/new`, method: "POST", auth: { username, password }, data: { domain } }); return { content: [ { type: "text", text: `Successfully reported domain "${domain}" as spam.`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error reporting referrer as spam: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } }
- src/index.ts:1520-1526 (schema)Zod schema for input parameters required by the tool.{ siteUrl: z.string().url().describe("WordPress site URL"), username: z.string().describe("WordPress username"), password: z.string().describe("WordPress application password"), siteId: z.number().describe("WordPress site ID"), domain: z.string().describe("Domain to report as spam"), },
- src/index.ts:158-194 (helper)Shared helper function used by the tool (and all others) to make authenticated requests to WordPress REST API.async function makeWPRequest<T>({ siteUrl, endpoint, method = 'GET', auth, data = null, params = null }: { siteUrl: string; endpoint: string; method?: 'GET' | 'POST' | 'PUT' | 'DELETE'; auth: { username: string; password: string }; data?: any; params?: any; }): Promise<T> { const authString = Buffer.from(`${auth.username}:${auth.password}`).toString('base64'); try { const response = await axios({ method, url: `${siteUrl}/wp-json/wp/v2/${endpoint}`, headers: { 'Authorization': `Basic ${authString}`, 'Content-Type': 'application/json', }, data: data, params: params }); return response.data as T; } catch (error) { if (axios.isAxiosError(error) && error.response) { throw new Error(`WordPress API error: ${error.response.data?.message || error.message}`); } throw error; } }