Skip to main content
Glama

get-site-stats

Retrieve detailed WordPress site statistics, including traffic and performance metrics, by providing site URL, username, password, and site ID. Essential for monitoring and analyzing site activity over specific time periods.

Instructions

Get comprehensive stats for a WordPress site

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
passwordYesWordPress application password
periodNoTime period for stats
siteIdYesWordPress site ID
siteUrlYesWordPress site URL
usernameYesWordPress username

Implementation Reference

  • The handler function for the 'get-site-stats' tool. It fetches comprehensive site statistics from the WordPress site's Jetpack Stats API endpoint `/sites/${siteId}/stats`, processes the response to extract key metrics like visits, views, top posts, and top referrers, formats them into a readable text summary, and returns it as MCP content. Uses the shared makeWPRequest helper for the API call.
    async ({ siteUrl, username, password, siteId, period = "week" }) => {
      try {
        const stats = await makeWPRequest<any>({
          siteUrl,
          endpoint: `sites/${siteId}/stats`,
          auth: { username, password },
          params: { period }
        });
        
        // Format general site stats - fields will depend on API response
        let statsText = `Site #${siteId} Stats (${period}):\n\n`;
        
        if (stats) {
          // Add visitors and views if available
          if (stats.visits) {
            statsText += `Visitors: ${stats.visits || 0}\n`;
          }
          if (stats.views) {
            statsText += `Views: ${stats.views || 0}\n`;
          }
          
          // Add top posts if available
          if (stats.top_posts && Array.isArray(stats.top_posts)) {
            statsText += `\nTop Posts:\n`;
            statsText += stats.top_posts.slice(0, 5).map((post: any, index: number) => 
              `${index + 1}. "${post.title || "Untitled"}" - ${post.views || 0} views`
            ).join('\n');
          }
          
          // Add top referrers if available
          if (stats.referrers && Array.isArray(stats.referrers)) {
            statsText += `\n\nTop Referrers:\n`;
            statsText += stats.referrers.slice(0, 5).map((ref: any) => 
              `${ref.name || "Unknown"}: ${ref.views || 0} views`
            ).join('\n');
          }
          
          // Add more sections based on what's available in the API response
        } else {
          statsText += "No stats data found.";
        }
        
        return {
          content: [
            {
              type: "text",
              text: statsText,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error retrieving site stats: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
        };
      }
    }
  • src/index.ts:1444-1514 (registration)
    The registration of the 'get-site-stats' tool on the MCP server, specifying the tool name, description, Zod input schema for parameters (siteUrl, username, password, siteId, optional period), and linking to the handler function.
      "get-site-stats",
      "Get comprehensive stats for a WordPress site",
      {
        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"),
      },
      async ({ siteUrl, username, password, siteId, period = "week" }) => {
        try {
          const stats = await makeWPRequest<any>({
            siteUrl,
            endpoint: `sites/${siteId}/stats`,
            auth: { username, password },
            params: { period }
          });
          
          // Format general site stats - fields will depend on API response
          let statsText = `Site #${siteId} Stats (${period}):\n\n`;
          
          if (stats) {
            // Add visitors and views if available
            if (stats.visits) {
              statsText += `Visitors: ${stats.visits || 0}\n`;
            }
            if (stats.views) {
              statsText += `Views: ${stats.views || 0}\n`;
            }
            
            // Add top posts if available
            if (stats.top_posts && Array.isArray(stats.top_posts)) {
              statsText += `\nTop Posts:\n`;
              statsText += stats.top_posts.slice(0, 5).map((post: any, index: number) => 
                `${index + 1}. "${post.title || "Untitled"}" - ${post.views || 0} views`
              ).join('\n');
            }
            
            // Add top referrers if available
            if (stats.referrers && Array.isArray(stats.referrers)) {
              statsText += `\n\nTop Referrers:\n`;
              statsText += stats.referrers.slice(0, 5).map((ref: any) => 
                `${ref.name || "Unknown"}: ${ref.views || 0} views`
              ).join('\n');
            }
            
            // Add more sections based on what's available in the API response
          } else {
            statsText += "No stats data found.";
          }
          
          return {
            content: [
              {
                type: "text",
                text: statsText,
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error retrieving site stats: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
          };
        }
      }
    );
  • The Zod schema defining the input parameters for the 'get-site-stats' tool: required site URL, credentials, site ID, and optional time period (day/week/month/year).
    {
      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"),
    },
  • The makeWPRequest helper function used by the get-site-stats handler (and other tools) to perform authenticated HTTP requests to WordPress REST API endpoints using axios and Basic Auth.
    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. It states this is a 'get' operation (implying read-only), but doesn't mention authentication requirements, rate limits, error conditions, or what 'comprehensive stats' actually includes. For a tool with authentication parameters, this is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/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. There's no wasted verbiage or unnecessary elaboration, though it could be slightly more specific about what 'comprehensive stats' entails.

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 tool with 5 parameters (including authentication), no annotations, and no output schema, the description is insufficient. It doesn't explain what 'comprehensive stats' returns, how authentication works, or how this differs from similar statistical tools. The agent lacks crucial context for proper tool invocation.

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?

The schema description coverage is 100%, so all parameters are documented in the schema. The description adds no additional parameter information beyond what's already in the schema, which is acceptable given the complete schema coverage. The baseline of 3 is appropriate when the schema does the heavy lifting.

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 clearly states the action ('Get') and resource ('comprehensive stats for a WordPress site'), making the purpose understandable. However, it doesn't differentiate from sibling tools like 'get-stats-summary' or 'get-stats-highlights', which appear to offer similar statistical functionality.

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 like 'get-stats-summary' or 'get-stats-highlights'. There's no mention of prerequisites, use cases, or exclusions, leaving the agent without context for tool selection.

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