Skip to main content
Glama

get-referrers

Track and analyze incoming traffic sources for a WordPress site by retrieving detailed referrer data. Specify time period and limit results for precise insights into user origins.

Instructions

View a site's referrers

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of referrers to return
passwordYesWordPress application password
periodNoTime period for stats
siteIdYesWordPress site ID
siteUrlYesWordPress site URL
usernameYesWordPress username

Implementation Reference

  • src/index.ts:1280-1329 (registration)
    Registration of the 'get-referrers' tool using server.tool(), including schema and handler.
    server.tool( "get-referrers", "View a site's referrers", { 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"), period: z.enum(["day", "week", "month", "year"]).optional().describe("Time period for stats"), limit: z.number().min(1).max(100).optional().describe("Maximum number of referrers to return"), }, async ({ siteUrl, username, password, siteId, period = "week", limit = 10 }) => { try { const referrersData = await makeWPRequest<{referrers: WPReferrer[]}>({ siteUrl, endpoint: `sites/${siteId}/stats/referrers`, auth: { username, password }, params: { period, limit } }); const referrersText = Array.isArray(referrersData.referrers) && referrersData.referrers.length > 0 ? referrersData.referrers.map((ref) => `${ref.name || "Unknown"} (${ref.group || "Unknown Group"}) URL: ${ref.url || "No URL"} Views: ${ref.views || 0} ${ref.is_spam ? "⚠️ Marked as spam" : ""} ---` ).join("\n") : "No referrers found"; return { content: [ { type: "text", text: `Referrers for site #${siteId} (${period}):\n\n${referrersText}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error retrieving referrers: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } );
  • Handler function that fetches referrer stats from WordPress Jetpack API endpoint `/sites/{siteId}/stats/referrers` and formats the response as text.
    async ({ siteUrl, username, password, siteId, period = "week", limit = 10 }) => { try { const referrersData = await makeWPRequest<{referrers: WPReferrer[]}>({ siteUrl, endpoint: `sites/${siteId}/stats/referrers`, auth: { username, password }, params: { period, limit } }); const referrersText = Array.isArray(referrersData.referrers) && referrersData.referrers.length > 0 ? referrersData.referrers.map((ref) => `${ref.name || "Unknown"} (${ref.group || "Unknown Group"}) URL: ${ref.url || "No URL"} Views: ${ref.views || 0} ${ref.is_spam ? "⚠️ Marked as spam" : ""} ---` ).join("\n") : "No referrers found"; return { content: [ { type: "text", text: `Referrers for site #${siteId} (${period}):\n\n${referrersText}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error retrieving referrers: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } }
  • Zod schema defining input parameters for the get-referrers 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"), period: z.enum(["day", "week", "month", "year"]).optional().describe("Time period for stats"), limit: z.number().min(1).max(100).optional().describe("Maximum number of referrers to return"), },
  • TypeScript interface defining the structure of a WPReferrer object used in the tool's response parsing.
    interface WPReferrer { group: string; name: string; url: string; views: number; is_spam?: boolean; }
  • Shared helper function used by the tool 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; } }

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/prathammanocha/wordpress-mcp-server'

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