Skip to main content
Glama

get-stats-highlights

Retrieve key performance metrics for a WordPress site from the past seven days using site URL, username, password, and site ID for analysis and insights.

Instructions

Get highlight metrics for a WordPress site from the last seven days

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
passwordYesWordPress application password
siteIdYesWordPress site ID
siteUrlYesWordPress site URL
usernameYesWordPress username

Implementation Reference

  • src/index.ts:1118-1165 (registration)
    Registration of the 'get-stats-highlights' tool using server.tool, including description, input schema, and handler function.
    server.tool(
      "get-stats-highlights",
      "Get highlight metrics for a WordPress site from the last seven days",
      {
        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"),
      },
      async ({ siteUrl, username, password, siteId }) => {
        try {
          const highlights = await makeWPRequest<WPStatsHighlights>({
            siteUrl,
            endpoint: `sites/${siteId}/stats/highlights`,
            auth: { username, password }
          });
          
          const highlightsText = `
    Stats Highlights for site #${siteId}:
    Period: ${highlights.period || "Last 7 days"}
    Views: ${highlights.views || 0}
    Visitors: ${highlights.visitors || 0}
    Likes: ${highlights.likes || 0}
    Comments: ${highlights.comments || 0}
    Followers: ${highlights.followers || 0}
    Posts: ${highlights.posts || 0}
          `.trim();
          
          return {
            content: [
              {
                type: "text",
                text: highlightsText,
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error retrieving stats highlights: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
          };
        }
      }
    );
  • Handler function that makes API request to Jetpack stats endpoint `/sites/{siteId}/stats/highlights`, formats the WPStatsHighlights data, and returns formatted text response.
      async ({ siteUrl, username, password, siteId }) => {
        try {
          const highlights = await makeWPRequest<WPStatsHighlights>({
            siteUrl,
            endpoint: `sites/${siteId}/stats/highlights`,
            auth: { username, password }
          });
          
          const highlightsText = `
    Stats Highlights for site #${siteId}:
    Period: ${highlights.period || "Last 7 days"}
    Views: ${highlights.views || 0}
    Visitors: ${highlights.visitors || 0}
    Likes: ${highlights.likes || 0}
    Comments: ${highlights.comments || 0}
    Followers: ${highlights.followers || 0}
    Posts: ${highlights.posts || 0}
          `.trim();
          
          return {
            content: [
              {
                type: "text",
                text: highlightsText,
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error retrieving stats highlights: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
          };
        }
      }
  • Zod input schema defining parameters for 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"),
    },
  • TypeScript interface defining the structure of stats highlights response data.
    interface WPStatsHighlights {
      views: number;
      visitors: number;
      likes: number;
      comments: number;
      followers: number;
      posts: number;
      period: string;
    }
  • Helper function used by the tool to make authenticated requests to WordPress REST API endpoints.
    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