Skip to main content
Glama

get-country-views

Analyze a WordPress site's traffic by country to gain geographic insights. Specify the site URL, credentials, and time period to retrieve detailed view statistics.

Instructions

View a site's views by country

Input Schema

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

Implementation Reference

  • The handler function that executes the 'get-country-views' tool. It makes an authenticated API request to the WordPress Jetpack Stats endpoint `/sites/{siteId}/stats/country-views`, processes the response data typed as WPCountryView[], formats it into a readable text summary, and returns it in the MCP content format. Handles errors gracefully.
    async ({ siteUrl, username, password, siteId, period = "week", limit = 10 }) => { try { const countryData = await makeWPRequest<{country_views: WPCountryView[]}>({ siteUrl, endpoint: `sites/${siteId}/stats/country-views`, auth: { username, password }, params: { period, limit } }); const countriesText = Array.isArray(countryData.country_views) && countryData.country_views.length > 0 ? countryData.country_views.map((country) => `${country.country_name || "Unknown"} (${country.country_code || "??"}) Views: ${country.views || 0} Percentage: ${country.views_percent ? Math.round(country.views_percent * 100) / 100 + '%' : "0%"} ---` ).join("\n") : "No country data found"; return { content: [ { type: "text", text: `Views by Country for site #${siteId} (${period}):\n\n${countriesText}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error retrieving country views: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } }
  • Zod input schema defining parameters for the 'get-country-views' tool: siteUrl (required URL), username and password (auth), siteId (required number), optional period (enum: day/week/month/year), and limit (1-100).
    { 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 countries to return"), },
  • src/index.ts:1332-1334 (registration)
    Registration of the 'get-country-views' tool using McpServer.tool() method, specifying the tool name, description, input schema, and handler function.
    server.tool( "get-country-views", "View a site's views by country",
  • TypeScript interface WPCountryView used to type the country views data returned from the API in the handler.
    interface WPCountryView { country_code: string; country_name: string; views: number; views_percent: number; }

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