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;
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. 'View' suggests a read-only operation, but it doesn't specify whether this requires authentication (implied by parameters but not stated), rate limits, pagination behavior, or what format the referrer data returns. For an analytics tool with 6 parameters and no annotation coverage, 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.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that gets straight to the point with zero wasted words. It's appropriately sized for a tool with clear parameters in the schema, though the brevity contributes to gaps in other dimensions.

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 6-parameter analytics tool with no annotations and no output schema, the description is insufficient. It doesn't explain what referrers are in this context, what data format to expect, authentication requirements (though parameters imply them), or how this differs from other stats tools. The combination of rich parameters and lack of structured metadata demands more descriptive context.

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%, so the schema already documents all 6 parameters thoroughly. The description adds no additional parameter context beyond implying the tool operates on a 'site' (matching siteId and siteUrl parameters). No syntax hints, format details, or relationship explanations are provided beyond what's in the schema.

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

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'View a site's referrers' clearly states the action (view) and resource (referrers), making the purpose immediately understandable. It distinguishes this tool from siblings like get-clicks or get-country-views by focusing on referrers specifically. However, it doesn't explicitly mention that this is for WordPress site analytics, which could help differentiate it further from other analytics tools.

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 provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like get-stats-summary or get-site-stats that might provide overlapping or complementary functionality. There's no indication of prerequisites (e.g., authentication requirements) or typical use cases for referrer data versus other analytics.

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

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

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