A Model Context Protocol (MCP) server that provides access to the Plausible Analytics API for querying website statistics and analytics data.
- Full Plausible API Support: Query historical and real-time stats with filtering and dimensions
- Multiple Query Tools:
plausible_query
: Full-featured querying with filters and dimensionsplausible_aggregate
: Simple aggregate statsplausible_breakdown
: Stats broken down by dimensionsplausible_timeseries
: Time-based data for charts
- Robust Error Handling: Automatic retries, timeout support, and detailed error messages
- Connection Testing: Built-in health check on startup
- Comprehensive Logging: Debug, info, and error logging through MCP
- Node.js 16 or higher
- A Plausible Analytics account with API access
- Plausible API key (get from https://plausible.io/settings/api-keys)
# Clone the repository
git clone https://github.com/yourusername/plausible-mcp.git
cd plausible-mcp
# Install dependencies
npm install
# Build the TypeScript code
npm run build
npm install -g @your-org/mcp-plausible
Create a .env
file in the project root (see examples/.env.example
):
# Required
PLAUSIBLE_API_KEY=your-api-key-here
# Optional
PLAUSIBLE_API_URL=https://plausible.io # For self-hosted instances
PLAUSIBLE_TIMEOUT=30000 # Request timeout in ms
For VS Code extensions that support MCP (like Cline), add to your settings:
{
"cline.mcpServers": {
"plausible": {
"command": "node",
"args": ["/absolute/path/to/plausible-mcp/build/index.js"],
"env": {
"PLAUSIBLE_API_KEY": "${env:PLAUSIBLE_API_KEY}"
}
}
}
}
See examples/vscode-settings.json
for more configuration examples.
Add to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Linux: ~/.config/claude/claude_desktop_config.json
{
"mcpServers": {
"plausible": {
"command": "node",
"args": ["/absolute/path/to/plausible-mcp/build/index.js"],
"env": {
"PLAUSIBLE_API_KEY": "your-api-key-here"
}
}
}
}
Once configured, the MCP server provides four main tools:
This MCP server lets you query Plausible Analytics for any site you own, directly from VS Code, Claude Desktop, or any MCP-compatible client. You can:
- Get traffic, engagement, and conversion stats for your site
- Break down analytics by page, device, country, source, and more
- Run advanced filters and time-based queries
- Automate reporting and SEO analysis
- Get your Plausible API key from https://plausible.io/settings/api-keys
- Set up your
.env
file or VS Code/Claude config (see below) - Start the MCP server:
node build/index.js
- Connect with your MCP client and start querying!
{
"site_id": "alexop.dev",
"metrics": ["visitors", "pageviews", "bounce_rate"],
"date_range": "30d"
}
{
"site_id": "alexop.dev",
"metrics": ["visitors"],
"date_range": "30d",
"dimensions": ["visit:country_name", "visit:device"]
}
{
"site_id": "alexop.dev",
"metrics": ["visitors"],
"date_range": "30d",
"dimensions": ["visit:source", "visit:utm_campaign"]
}
{
"site_id": "alexop.dev",
"metrics": ["pageviews"],
"date_range": "7d",
"dimensions": ["time:hour"]
}
{
"site_id": "alexop.dev",
"metrics": ["conversion_rate"],
"date_range": "30d",
"dimensions": ["visit:source"]
}
{
"site_id": "alexop.dev",
"metrics": ["scroll_depth"],
"date_range": "30d",
"dimensions": ["event:page"]
}
- Top pages, landing and exit pages
- Device, browser, and OS breakdowns
- Geographic breakdowns (country, region, city)
- Traffic sources and UTM campaign performance
- Conversion rates and custom event tracking
- Scroll depth and time on page
- Hourly/daily/weekly/monthly traffic trends
- Advanced filters and segments
Full-featured querying with all Plausible API capabilities:
{
"site_id": "example.com",
"metrics": ["visitors", "pageviews", "bounce_rate"],
"date_range": "7d",
"filters": [
["is", "visit:country_name", ["United States", "Canada"]]
],
"dimensions": ["visit:source"],
"order_by": [["visitors", "desc"]],
"pagination": { "limit": 10 }
}
Simple aggregate stats without dimensions:
{
"site_id": "example.com",
"metrics": ["visitors", "pageviews"],
"date_range": "month"
}
Stats broken down by dimensions:
{
"site_id": "example.com",
"metrics": ["visitors"],
"date_range": "7d",
"dimensions": ["visit:country_name", "visit:device"],
"limit": 20
}
Time-based data for charts:
{
"site_id": "example.com",
"metrics": ["visitors", "pageviews"],
"date_range": "30d",
"interval": "time:day"
}
- Relative:
"day"
,"7d"
,"30d"
,"month"
,"6mo"
,"12mo"
,"year"
,"all"
- Custom:
["2024-01-01", "2024-01-31"]
(ISO 8601 format)
- Traffic:
visitors
,visits
,pageviews
,views_per_visit
- Engagement:
bounce_rate
,visit_duration
,scroll_depth
- Events:
events
,conversion_rate
,group_conversion_rate
- Revenue:
average_revenue
,total_revenue
- Other:
percentage
,time_on_page
visit:source
- Traffic sourcevisit:referrer
- Referrer URLvisit:utm_medium
- UTM mediumvisit:utm_source
- UTM sourcevisit:utm_campaign
- UTM campaignvisit:utm_content
- UTM contentvisit:utm_term
- UTM termvisit:device
- Device typevisit:browser
- Browser namevisit:browser_version
- Browser versionvisit:os
- Operating systemvisit:os_version
- OS versionvisit:country
- Country codevisit:country_name
- Country namevisit:region
- Region codevisit:region_name
- Region namevisit:city
- City codevisit:city_name
- City name
event:page
- Page pathevent:hostname
- Hostnameevent:goal
- Goal nameevent:props:*
- Custom properties
time
- Auto-detectedtime:hour
- Hourlytime:day
- Dailytime:week
- Weeklytime:month
- Monthly
["is", "visit:country", ["US", "CA"]]
["contains", "event:page", ["/blog/"]]
["matches", "visit:source", ["google.*"]]
["and", [
["is", "visit:device", ["Mobile"]],
["is", "visit:country", ["US"]]
]]
["or", [
["is", "visit:source", ["google"]],
["is", "visit:source", ["bing"]]
]]
["not", ["is", "visit:country", ["US"]]]
["has_done", ["is", "event:goal", ["Signup"]]]
["has_not_done", ["is", "event:goal", ["Purchase"]]]
- Automatic Retries: Failed requests are retried up to 3 times with exponential backoff
- Rate Limit Handling: Respects
Retry-After
headers from Plausible API - Timeout Support: Configurable request timeout (default 30s)
- Detailed Error Messages: Clear error messages with context
The server logs important events:
- Connection status on startup
- Tool invocations with parameters
- Success/failure of queries
- Detailed error information
To view logs:
- Claude Desktop:
tail -f ~/Library/Logs/Claude/mcp*.log
(macOS) - VS Code: Check extension output panel
# Install dependencies
npm install
# Run TypeScript compiler in watch mode
npm run build -- --watch
# Run linting
npm run lint
# Fix linting issues
npm run lint:fix
# Type checking
npm run typecheck
- Check if API key is set correctly
- Verify network connectivity
- For self-hosted instances, ensure
PLAUSIBLE_API_URL
is correct - Check logs for detailed error messages
- Default limit: 600 requests/hour
- Server automatically retries with backoff
- Check
Retry-After
header in logs
- "Authentication failed": Invalid API key
- "Not found": Site doesn't exist or you don't have access
- "Bad request": Check query parameters format
- Never commit API keys to version control
- Use environment variables for sensitive data
- Consider using secret management tools for production
- All inputs are validated before sending to API
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
MIT - See LICENSE file for details
- Plausible API Docs: https://plausible.io/docs/stats-api
- MCP Documentation: https://modelcontextprotocol.io
- Issues: https://github.com/yourusername/plausible-mcp/issues
- Initial release with full Plausible Stats API support
- Four specialized tools for different query types
- Robust error handling and retry logic
- Comprehensive logging through MCP
- Connection health check on startup