get-streak-stats
Analyze WordPress site publishing activity by generating Calendar Heatmap stats using a secure API. Ideal for tracking and visualizing content productivity via site URL, username, password, and site ID.
Instructions
Get stats for Calendar Heatmap showing publishing activity
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"siteUrl": "<siteUrl>",
"username": "<username>",
"password": "<password>",
"siteId": "<siteId>"
},
"name": "get-streak-stats"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| password | Yes | WordPress application password | |
| siteId | Yes | WordPress site ID | |
| siteUrl | Yes | WordPress site URL | |
| username | Yes | WordPress username |
Implementation Reference
- src/index.ts:1712-1779 (handler)The handler function for the 'get-streak-stats' tool. It makes an API request to the WordPress Jetpack Stats endpoint `/sites/${siteId}/stats/streak`, processes the streak data by grouping publishing activity by month/year, formats it into a readable text summary, and returns it as a text content block. Handles errors gracefully.
async ({ siteUrl, username, password, siteId }) => { try { const streakData = await makeWPRequest<any>({ siteUrl, endpoint: `sites/${siteId}/stats/streak`, auth: { username, password } }); let streakText = `Publishing Activity for site #${siteId}:\n\n`; if (streakData && Array.isArray(streakData.data)) { // Group by month/year for better readability const groupedByMonth: Record<string, any[]> = {}; streakData.data.forEach((day: any) => { if (!day.date) return; const date = new Date(day.date); const monthYear = `${date.toLocaleString('default', { month: 'long' })} ${date.getFullYear()}`; if (!groupedByMonth[monthYear]) { groupedByMonth[monthYear] = []; } groupedByMonth[monthYear].push({ date: date.toLocaleDateString(), count: day.count || 0 }); }); // Format the output Object.keys(groupedByMonth).forEach(monthYear => { streakText += `${monthYear}:\n`; const days = groupedByMonth[monthYear]; const activeDays = days.filter(day => day.count > 0); if (activeDays.length > 0) { streakText += activeDays.map(day => `${day.date}: ${day.count} post(s)`).join('\n'); } else { streakText += "No publishing activity this month"; } streakText += "\n\n"; }); } else { streakText += "No publishing activity data found."; } return { content: [ { type: "text", text: streakText, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error retrieving streak stats: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } - src/index.ts:1706-1711 (schema)Input schema for the 'get-streak-stats' tool using Zod validation. Requires WordPress site URL, credentials, and site ID.
{ 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"), }, - src/index.ts:1703-1780 (registration)Registration of the 'get-streak-stats' tool on the MCP server using server.tool(), including name, description, input schema, and handler function.
server.tool( "get-streak-stats", "Get stats for Calendar Heatmap showing publishing activity", { 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 streakData = await makeWPRequest<any>({ siteUrl, endpoint: `sites/${siteId}/stats/streak`, auth: { username, password } }); let streakText = `Publishing Activity for site #${siteId}:\n\n`; if (streakData && Array.isArray(streakData.data)) { // Group by month/year for better readability const groupedByMonth: Record<string, any[]> = {}; streakData.data.forEach((day: any) => { if (!day.date) return; const date = new Date(day.date); const monthYear = `${date.toLocaleString('default', { month: 'long' })} ${date.getFullYear()}`; if (!groupedByMonth[monthYear]) { groupedByMonth[monthYear] = []; } groupedByMonth[monthYear].push({ date: date.toLocaleDateString(), count: day.count || 0 }); }); // Format the output Object.keys(groupedByMonth).forEach(monthYear => { streakText += `${monthYear}:\n`; const days = groupedByMonth[monthYear]; const activeDays = days.filter(day => day.count > 0); if (activeDays.length > 0) { streakText += activeDays.map(day => `${day.date}: ${day.count} post(s)`).join('\n'); } else { streakText += "No publishing activity this month"; } streakText += "\n\n"; }); } else { streakText += "No publishing activity data found."; } return { content: [ { type: "text", text: streakText, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error retrieving streak stats: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } );