Skip to main content
Glama

get-top-posts

Retrieve a WordPress site's most viewed posts and pages within a specified time period using authenticated API access. Ideal for analyzing site traffic and content performance.

Instructions

View a site's top posts and pages by views

Input Schema

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

Implementation Reference

  • Full handler implementation for the 'get-top-posts' MCP tool. Registers the tool, defines input schema with Zod, and implements the logic to fetch top posts/pages by views from WordPress Jetpack stats API endpoint `sites/{siteId}/stats/top-posts`, formats the results, and returns them as text content.
    server.tool(
      "get-top-posts",
      "View a site's top posts and pages by views",
      {
        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 posts to return"),
      },
      async ({ siteUrl, username, password, siteId, period = "week", limit = 10 }) => {
        try {
          const topPosts = await makeWPRequest<{posts: WPTopPost[]}>({
            siteUrl,
            endpoint: `sites/${siteId}/stats/top-posts`,
            auth: { username, password },
            params: { period, limit }
          });
          
          const postsText = Array.isArray(topPosts.posts) && topPosts.posts.length > 0
            ? topPosts.posts.map((post, index) => 
                `${index + 1}. "${post.title}" (ID: ${post.id})
    Views: ${post.views || 0}
    Comments: ${post.comment_count || 0}
    Likes: ${post.likes || 0}
    URL: ${post.url || "No URL"}
    ---`
              ).join("\n")
            : "No top posts found";
          
          return {
            content: [
              {
                type: "text",
                text: `Top Posts for site #${siteId} (${period}):\n\n${postsText}`,
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error retrieving top posts: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
          };
        }
      }
    );
  • TypeScript interface defining the expected structure of individual top post data used in the get-top-posts tool response parsing.
    interface WPTopPost {
      id: number;
      title: string;
      url: string;
      views: number;
      comment_count: number;
      likes: number;
    }
  • Generic helper function makeWPRequest used by get-top-posts (and other tools) to make authenticated HTTP requests to WordPress REST API endpoints.
    // Helper function for making WordPress API requests
    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?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool is for viewing, implying a read-only operation, but doesn't mention authentication requirements, rate limits, or what the output looks like (e.g., format, pagination). For a tool with 6 parameters including credentials, this leaves significant gaps in understanding its behavior.

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 front-loads the core purpose without any wasted words. It's appropriately sized for the tool's complexity and gets straight to the point.

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?

Given the tool has 6 parameters (including authentication), no annotations, and no output schema, the description is incomplete. It doesn't address authentication needs, output format, or how it relates to sibling tools, leaving the agent with insufficient context for effective use.

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 fully documents all parameters. The description adds no additional meaning beyond implying the tool involves 'views' and 'top posts/pages,' which is already suggested by the tool name. This meets the baseline for high schema coverage without extra value.

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 verb ('View') and resource ('a site's top posts and pages by views'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'get-post-stats' or 'get-site-stats' that might provide related statistics, which prevents a perfect score.

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. With sibling tools like 'get-post-stats' and 'get-site-stats' available, there's no indication of how this tool differs in context or when it's the appropriate choice, leaving the agent without usage direction.

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